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:
company-desktop-computer committed 2026-10-22 10:06:51 +08:00
1 parent 8caea9e6bd
commit 4e658a8ae9
7 files changed
+71 -30

No files matched your search

@@ -6189,3 +6189,45 @@ extern "C"
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;
}
+3 -3
View File
@@ -4,7 +4,7 @@
#include "JMSJDlg.h"
#include "GLTKDlg.h"
#include "KTSetting.h"
#include "PoolSectionTemp.h"
#include "CoreTools.h"
DLLIMPEXP CString IDCreate();
@@ -271,7 +271,7 @@ void CHZQTDlg::OnBnClickedCheck1()
CString sScr;
if (dlg.GetCrossSectionScr(sScr))
{
CString sFullPath = GetPoolSectionSatPath(FilePath::GetSysDir());
CString sFullPath = CoreTools::getTempFilePath(_T("JMSJ_"), _T(".sat"), FilePath::GetSysDir());
CStdioFile file;
if (file.Open(sFullPath,CFile::modeCreate |CFile::modeWrite ))
@@ -393,7 +393,7 @@ void CHZQTDlg::SetFromWall(AcDbObjectId& id)
m_bUserDefSec = TRUE;
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;
if (file.Open(sFullPath,CFile::modeCreate |CFile::modeWrite ))
+2 -3
View File
@@ -3,7 +3,6 @@
#include "JMDBDlg.h"
#include "GLTKDlg.h"
#include "CoreTools.h"
#include "PoolSectionTemp.h"
IMPLEMENT_DYNAMIC(CJMDBDlg, CDialog)
@@ -88,7 +87,7 @@ void CJMDBDlg::OnBnClickedButton1()
CString sScr;
if (dlg.GetCrossSectionScr(sScr))
{
CString sFullPath = GetPoolSectionSatPath(FilePath::GetSysDir());
CString sFullPath = CoreTools::getTempFilePath(_T("JMSJ_"), _T(".sat"), FilePath::GetSysDir());
CStdioFile file;
if (file.Open(sFullPath,CFile::modeCreate |CFile::modeWrite ))
@@ -172,7 +171,7 @@ void CJMDBDlg::OnBnClickedButton2()
if (m_pSectionReg != NULL && bSuccess)
{
CString sFullPath = GetPoolSectionSatPath(FilePath::getSystemTemporaryFolder());
CString sFullPath = CoreTools::getTempFilePath(_T("JMSJ_"), _T(".sat"), FilePath::getSystemTemporaryFolder());
CString sRegionScrp = _T("");
CString sLine;
+3 -4
View File
@@ -1,7 +1,6 @@
#include "stdafx.h"
#include "JMSJDlg.h"
#include "CoreTools.h"
#include "PoolSectionTemp.h"
#include "JUXCDlg.h"
#include "GLTKDlg.h"
#include "BYCDlg.h"
@@ -79,7 +78,7 @@ BOOL CJMSJDlg::OnInitDialog()
void CJMSJDlg::ShowLastSection()
{
//1.截面
CString sFullPath = GetPoolSectionSatPath(FilePath::getSystemTemporaryFolder());
CString sFullPath = CoreTools::getTempFilePath(_T("JMSJ_"), _T(".sat"), FilePath::getSystemTemporaryFolder());
AcDbVoidPtrArray arBodyPtrs;
if ( Acad::eOk == AcDbBody::acisIn(sFullPath,arBodyPtrs) )
@@ -138,7 +137,7 @@ void CJMSJDlg::OnBnClickedBtaddtodb()
UpdateData(TRUE);
if (!m_curSection.pReg) return;
CString sFullPath = GetPoolSectionSatPath(FilePath::getSystemTemporaryFolder());
CString sFullPath = CoreTools::getTempFilePath(_T("JMSJ_"), _T(".sat"), FilePath::getSystemTemporaryFolder());
CString sRegionScrp = _T("");
CString sLine;
@@ -424,7 +423,7 @@ void CJMSJDlg::OnBnClickedBtselfromdb()
CString sScr,sScrT;
if (dlg.GetCrossSectionScr(sScr))
{
CString sFullPath = GetPoolSectionSatPath(FilePath::getSystemTemporaryFolder());
CString sFullPath = CoreTools::getTempFilePath(_T("JMSJ_"), _T(".sat"), FilePath::getSystemTemporaryFolder());
CStdioFile file;
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;
}
+13
View File
@@ -485,5 +485,18 @@ public:
// 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
);
};