refactor: 水池截面中转文件改用 CoreTools::getTempFilePath
删除 Pool3dCmd/PoolSectionTemp.h,JMDBDlg、JMSJDlg、HZQTDlg 共 7 处
改为 CoreTools::getTempFilePath(_T("JMSJ_"), _T(".sat"), 目录)。
同时修 getTempFilePath 自身的问题:
- 传了有效父目录时 sParentPath 没有赋值,会拼出 "\JMSJ_xxx.sat"
- 父目录为空时仍对 pszParentPath 调 _taccess,参数可能是 NULL
- return sPath(); 语法错误
- objId 用 %lu 格式化 Adesk::ULongPtr,64 位下会截断,改 %I64u
temp-file-naming.md 同步改为介绍这个通用函数。
This commit is contained in:
1 parent
8caea9e6bd
commit
4e658a8ae9
7 files changed
+71
-30
No files matched your search
@@ -6189,3 +6189,45 @@ extern "C"
|
|||||||
return pRegAll;
|
return pRegAll;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CString CoreTools::getTempFilePath(LPCTSTR pszFileMainName
|
||||||
|
, LPCTSTR pszFileSuffix
|
||||||
|
, LPCTSTR pszParentPath
|
||||||
|
, const bool & bUsePID
|
||||||
|
, const AcDbObjectId & objId)
|
||||||
|
{
|
||||||
|
CString sPath(_T("")), sTemp;
|
||||||
|
|
||||||
|
if (!pszFileMainName || !pszFileSuffix)
|
||||||
|
return sPath;
|
||||||
|
|
||||||
|
CString sParentPath(_T(""));
|
||||||
|
if (pszParentPath == NULL || _taccess(pszParentPath, 0x00) != 0x00)
|
||||||
|
sParentPath = FilePath::getSystemTemporaryFolder();
|
||||||
|
else
|
||||||
|
sParentPath = pszParentPath;
|
||||||
|
|
||||||
|
if (_taccess(sParentPath, 0x00) != 0x0)
|
||||||
|
return sPath;
|
||||||
|
|
||||||
|
CString sFileName(pszFileMainName);
|
||||||
|
|
||||||
|
if (bUsePID)
|
||||||
|
{
|
||||||
|
unsigned long pid = (unsigned long)::GetCurrentProcessId();
|
||||||
|
sTemp.Format(_T("%lu"), pid);
|
||||||
|
sFileName += sTemp;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (objId.isValid())
|
||||||
|
{
|
||||||
|
sTemp.Format(_T("%I64u"), (unsigned __int64)objId.asOldId());
|
||||||
|
sFileName += sTemp;
|
||||||
|
}
|
||||||
|
|
||||||
|
sFileName += pszFileSuffix;
|
||||||
|
|
||||||
|
sPath = sParentPath + _T("\\") + sFileName;
|
||||||
|
|
||||||
|
return sPath;
|
||||||
|
}
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
#include "JMSJDlg.h"
|
#include "JMSJDlg.h"
|
||||||
#include "GLTKDlg.h"
|
#include "GLTKDlg.h"
|
||||||
#include "KTSetting.h"
|
#include "KTSetting.h"
|
||||||
#include "PoolSectionTemp.h"
|
#include "CoreTools.h"
|
||||||
|
|
||||||
DLLIMPEXP CString IDCreate();
|
DLLIMPEXP CString IDCreate();
|
||||||
|
|
||||||
@@ -271,7 +271,7 @@ void CHZQTDlg::OnBnClickedCheck1()
|
|||||||
CString sScr;
|
CString sScr;
|
||||||
if (dlg.GetCrossSectionScr(sScr))
|
if (dlg.GetCrossSectionScr(sScr))
|
||||||
{
|
{
|
||||||
CString sFullPath = GetPoolSectionSatPath(FilePath::GetSysDir());
|
CString sFullPath = CoreTools::getTempFilePath(_T("JMSJ_"), _T(".sat"), FilePath::GetSysDir());
|
||||||
|
|
||||||
CStdioFile file;
|
CStdioFile file;
|
||||||
if (file.Open(sFullPath,CFile::modeCreate |CFile::modeWrite ))
|
if (file.Open(sFullPath,CFile::modeCreate |CFile::modeWrite ))
|
||||||
@@ -393,7 +393,7 @@ void CHZQTDlg::SetFromWall(AcDbObjectId& id)
|
|||||||
m_bUserDefSec = TRUE;
|
m_bUserDefSec = TRUE;
|
||||||
pWall->GetSpecialtyData(AcDb::kForRead)->GetAt(KEY_SECTIONSCR,m_sRegScr);
|
pWall->GetSpecialtyData(AcDb::kForRead)->GetAt(KEY_SECTIONSCR,m_sRegScr);
|
||||||
|
|
||||||
CString sFullPath = GetPoolSectionSatPath(FilePath::GetSysDir());
|
CString sFullPath = CoreTools::getTempFilePath(_T("JMSJ_"), _T(".sat"), FilePath::GetSysDir());
|
||||||
|
|
||||||
CStdioFile file;
|
CStdioFile file;
|
||||||
if (file.Open(sFullPath,CFile::modeCreate |CFile::modeWrite ))
|
if (file.Open(sFullPath,CFile::modeCreate |CFile::modeWrite ))
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
#include "JMDBDlg.h"
|
#include "JMDBDlg.h"
|
||||||
#include "GLTKDlg.h"
|
#include "GLTKDlg.h"
|
||||||
#include "CoreTools.h"
|
#include "CoreTools.h"
|
||||||
#include "PoolSectionTemp.h"
|
|
||||||
|
|
||||||
IMPLEMENT_DYNAMIC(CJMDBDlg, CDialog)
|
IMPLEMENT_DYNAMIC(CJMDBDlg, CDialog)
|
||||||
|
|
||||||
@@ -88,7 +87,7 @@ void CJMDBDlg::OnBnClickedButton1()
|
|||||||
CString sScr;
|
CString sScr;
|
||||||
if (dlg.GetCrossSectionScr(sScr))
|
if (dlg.GetCrossSectionScr(sScr))
|
||||||
{
|
{
|
||||||
CString sFullPath = GetPoolSectionSatPath(FilePath::GetSysDir());
|
CString sFullPath = CoreTools::getTempFilePath(_T("JMSJ_"), _T(".sat"), FilePath::GetSysDir());
|
||||||
|
|
||||||
CStdioFile file;
|
CStdioFile file;
|
||||||
if (file.Open(sFullPath,CFile::modeCreate |CFile::modeWrite ))
|
if (file.Open(sFullPath,CFile::modeCreate |CFile::modeWrite ))
|
||||||
@@ -172,7 +171,7 @@ void CJMDBDlg::OnBnClickedButton2()
|
|||||||
|
|
||||||
if (m_pSectionReg != NULL && bSuccess)
|
if (m_pSectionReg != NULL && bSuccess)
|
||||||
{
|
{
|
||||||
CString sFullPath = GetPoolSectionSatPath(FilePath::getSystemTemporaryFolder());
|
CString sFullPath = CoreTools::getTempFilePath(_T("JMSJ_"), _T(".sat"), FilePath::getSystemTemporaryFolder());
|
||||||
|
|
||||||
CString sRegionScrp = _T("");
|
CString sRegionScrp = _T("");
|
||||||
CString sLine;
|
CString sLine;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "JMSJDlg.h"
|
#include "JMSJDlg.h"
|
||||||
#include "CoreTools.h"
|
#include "CoreTools.h"
|
||||||
#include "PoolSectionTemp.h"
|
|
||||||
#include "JUXCDlg.h"
|
#include "JUXCDlg.h"
|
||||||
#include "GLTKDlg.h"
|
#include "GLTKDlg.h"
|
||||||
#include "BYCDlg.h"
|
#include "BYCDlg.h"
|
||||||
@@ -79,7 +78,7 @@ BOOL CJMSJDlg::OnInitDialog()
|
|||||||
void CJMSJDlg::ShowLastSection()
|
void CJMSJDlg::ShowLastSection()
|
||||||
{
|
{
|
||||||
//1.截面
|
//1.截面
|
||||||
CString sFullPath = GetPoolSectionSatPath(FilePath::getSystemTemporaryFolder());
|
CString sFullPath = CoreTools::getTempFilePath(_T("JMSJ_"), _T(".sat"), FilePath::getSystemTemporaryFolder());
|
||||||
|
|
||||||
AcDbVoidPtrArray arBodyPtrs;
|
AcDbVoidPtrArray arBodyPtrs;
|
||||||
if ( Acad::eOk == AcDbBody::acisIn(sFullPath,arBodyPtrs) )
|
if ( Acad::eOk == AcDbBody::acisIn(sFullPath,arBodyPtrs) )
|
||||||
@@ -138,7 +137,7 @@ void CJMSJDlg::OnBnClickedBtaddtodb()
|
|||||||
UpdateData(TRUE);
|
UpdateData(TRUE);
|
||||||
|
|
||||||
if (!m_curSection.pReg) return;
|
if (!m_curSection.pReg) return;
|
||||||
CString sFullPath = GetPoolSectionSatPath(FilePath::getSystemTemporaryFolder());
|
CString sFullPath = CoreTools::getTempFilePath(_T("JMSJ_"), _T(".sat"), FilePath::getSystemTemporaryFolder());
|
||||||
|
|
||||||
CString sRegionScrp = _T("");
|
CString sRegionScrp = _T("");
|
||||||
CString sLine;
|
CString sLine;
|
||||||
@@ -424,7 +423,7 @@ void CJMSJDlg::OnBnClickedBtselfromdb()
|
|||||||
CString sScr,sScrT;
|
CString sScr,sScrT;
|
||||||
if (dlg.GetCrossSectionScr(sScr))
|
if (dlg.GetCrossSectionScr(sScr))
|
||||||
{
|
{
|
||||||
CString sFullPath = GetPoolSectionSatPath(FilePath::getSystemTemporaryFolder());
|
CString sFullPath = CoreTools::getTempFilePath(_T("JMSJ_"), _T(".sat"), FilePath::getSystemTemporaryFolder());
|
||||||
|
|
||||||
CStdioFile file;
|
CStdioFile file;
|
||||||
if (file.Open(sFullPath,CFile::modeCreate |CFile::modeWrite ))
|
if (file.Open(sFullPath,CFile::modeCreate |CFile::modeWrite ))
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
// 水池截面 SAT 中转文件路径。
|
|
||||||
// 同一个 CAD 进程内所有调用点返回同一路径;不同进程用 PID 区分,
|
|
||||||
// 避免两个实例同时写同一个 JMSJ.sat 互相覆盖。
|
|
||||||
inline CString GetPoolSectionSatPath(LPCTSTR lpszDir)
|
|
||||||
{
|
|
||||||
CString sPath;
|
|
||||||
sPath.Format(_T("%s\\JMSJ_%lu.sat"), lpszDir, (unsigned long)::GetCurrentProcessId());
|
|
||||||
return sPath;
|
|
||||||
}
|
|
||||||
@@ -485,5 +485,18 @@ public:
|
|||||||
// arInput 里面的曲线必须是同一平面内的,没有悬空边线
|
// arInput 里面的曲线必须是同一平面内的,没有悬空边线
|
||||||
// 并且确实组成了一个或者多个闭合的轮廓
|
// 并且确实组成了一个或者多个闭合的轮廓
|
||||||
static AcDbPolyline* getOuterContour(const AcDbVoidPtrArray &arInput);
|
static AcDbPolyline* getOuterContour(const AcDbVoidPtrArray &arInput);
|
||||||
|
|
||||||
|
// 获得一个临时文件路径
|
||||||
|
// pszFileMainName 是文件名称的主体部分,不包含后缀名, 在后面根据 bUsePID 决定是否加上进程号
|
||||||
|
// pszFileSuffix 是文件后缀名, 例如 ".txt" 或者 ".jpg"
|
||||||
|
// pszParentPath 是文件所在的父目录,如果为空,则使用系统临时目录
|
||||||
|
// bUsePID 是否在文件名中加入进程号,避免同名冲突
|
||||||
|
// objId 是实体id,如果不为空,则在文件名中加入实体id,避免同名冲突
|
||||||
|
static CString getTempFilePath(LPCTSTR pszFileMainName
|
||||||
|
, LPCTSTR pszFileSuffix
|
||||||
|
, LPCTSTR pszParentPath = NULL
|
||||||
|
, const bool &bUsePID = true
|
||||||
|
, const AcDbObjectId &objId = AcDbObjectId::kNull
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
+8
-9
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
## 规则
|
## 规则
|
||||||
|
|
||||||
1. 文件名必须带 `GetCurrentProcessId()`。同一进程内需要多次独立使用、彼此不能共享的,再加原子递增序号。
|
1. 文件名必须带 `GetCurrentProcessId()`,直接用 `CoreTools::getTempFilePath()` 生成。同一进程内需要多次独立使用、彼此不能共享的,再加原子递增序号。
|
||||||
2. 用完即删(`::DeleteFile`)。写读双方跨函数隐式传递的文件除外,见下文 `JMSJ.sat`。
|
2. 用完即删(`::DeleteFile`)。写读双方跨函数隐式传递的文件除外,见下文 `JMSJ.sat`。
|
||||||
3. 路径统一用 `FilePath::getSystemTemporaryFolder()`,不要落到安装目录。
|
3. 路径统一用 `FilePath::getSystemTemporaryFolder()`,不要落到安装目录。
|
||||||
4. 从 DWG 里读回来的文件名不可信,必须只取纯文件名,拒绝 `..\`、盘符等路径成分。
|
4. 从 DWG 里读回来的文件名不可信,必须只取纯文件名,拒绝 `..\`、盘符等路径成分。
|
||||||
@@ -45,20 +45,19 @@
|
|||||||
|
|
||||||
目录原本分两套:`JMDBDlg` / `JMSJDlg` 用 `FilePath::getSystemTemporaryFolder()`,`HZQTDlg` 用 `FilePath::GetSysDir()`(安装目录下的 `sys`)。两套互不相干,本次只加 PID 后缀,目录未动。
|
目录原本分两套:`JMDBDlg` / `JMSJDlg` 用 `FilePath::getSystemTemporaryFolder()`,`HZQTDlg` 用 `FilePath::GetSysDir()`(安装目录下的 `sys`)。两套互不相干,本次只加 PID 后缀,目录未动。
|
||||||
|
|
||||||
统一走 `Pool3dCmd/PoolSectionTemp.h`:
|
统一走 `CoreTools::getTempFilePath()`(`CoreCommand/CoreTools.cpp`):
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
inline CString GetPoolSectionSatPath(LPCTSTR lpszDir)
|
CString sFullPath = CoreTools::getTempFilePath(_T("JMSJ_"), _T(".sat")
|
||||||
{
|
, FilePath::getSystemTemporaryFolder());
|
||||||
CString sPath;
|
// -> <temp>\JMSJ_<pid>.sat
|
||||||
sPath.Format(_T("%s\\JMSJ_%lu.sat"), lpszDir, (unsigned long)::GetCurrentProcessId());
|
|
||||||
return sPath;
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
`getTempFilePath` 是通用工具:主名 + 可选进程号 + 可选实体 id + 后缀;父目录为空或不存在时落到系统临时目录。
|
||||||
|
|
||||||
同一进程内所有调用点返回同一路径,所以 `acisOut` 写完、`ShowLastSection` 再读这条隐式链路仍然成立;进程之间用 PID 隔离,两个 CAD 实例不会再互相覆盖。
|
同一进程内所有调用点返回同一路径,所以 `acisOut` 写完、`ShowLastSection` 再读这条隐式链路仍然成立;进程之间用 PID 隔离,两个 CAD 实例不会再互相覆盖。
|
||||||
|
|
||||||
**已知取舍**:`CJMSJDlg::ShowLastSection` 在 `OnInitDialog` 里读这个文件,本意是恢复上一次用的截面。加 PID 后只能读到本进程内上一次写的,跨进程/跨会话恢复失效。这个能力原本也不可靠——temp 目录会被清理,多实例还会互相覆盖。如果确实需要跨会话记忆,应改存注册表、ini 或文档数据库,而不是靠临时文件。
|
**已知取舍**:`CJMSJDlg::ShowLastSection` 在 `OnInitDialog` 里读这个文件,只用于对话框打开时显示上一个设计好的截面,不是功能数据。加 PID 后新进程读不到上个进程留下的截面,已确认可接受。
|
||||||
|
|
||||||
## 待处理
|
## 待处理
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user