From 2ed05a95bbe05d25936756e83be2312023adcfe7 Mon Sep 17 00:00:00 2001 From: lvjunjie Date: Thu, 28 May 2026 14:18:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=9D=E5=AD=98=E6=88=90=E6=9E=9C=E5=89=8D?= =?UTF-8?q?=E5=85=88=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=E5=A4=B9=E4=B8=AD?= =?UTF-8?q?=E6=97=A7=E6=96=87=E4=BB=B6=E5=86=8D=E4=BF=9D=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/nmNum/nmData/nmDataAnalyzeManager.cpp | 46 +++++++++++++++++++++++ Src/nmNum/nmSubWnd/nmSubWndUtils.cpp | 6 +-- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/Src/nmNum/nmData/nmDataAnalyzeManager.cpp b/Src/nmNum/nmData/nmDataAnalyzeManager.cpp index d2812ed..809e7dc 100644 --- a/Src/nmNum/nmData/nmDataAnalyzeManager.cpp +++ b/Src/nmNum/nmData/nmDataAnalyzeManager.cpp @@ -64,9 +64,47 @@ #include #include +#include #include +#include namespace { +// 清空指定目录下的所有旧文件和子目录,但保留目录本身 +bool clearDirectoryContents(const QString& dirPath) +{ + if(dirPath.trimmed().isEmpty()) { + return false; + } + + QDir dir(dirPath); + if(dir.isRoot()) { + qDebug() << QString("Refuse to clear root directory: %1").arg(dirPath); + return false; + } + + if(!dir.exists()) { + return true; + } + + QFileInfoList entries = dir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries | QDir::Hidden | QDir::System); + for(int i = 0; i < entries.size(); ++i) { + const QFileInfo& entry = entries.at(i); + bool bRemoved = false; + + if(entry.isDir() && !entry.isSymLink()) { + bRemoved = clearDirectoryContents(entry.absoluteFilePath()) && dir.rmdir(entry.fileName()); + } else { + bRemoved = QFile::remove(entry.absoluteFilePath()); + } + + if(!bRemoved) { + qDebug() << QString("Failed to remove old result item: %1").arg(entry.absoluteFilePath()); + return false; + } + } + + return true; +} // 多条PVT曲线都可能带压力横坐标,只保存第一次读到的有效横坐标 void setPebiPressureIfEmpty(nmDataPvtParaForPebi* pPvtPara, const QVector& vecX) @@ -3306,6 +3344,14 @@ bool nmDataAnalyzeManager::saveNmResult(QString sRstCode, iSubWndFitting* pSubWn if(pContextProvider == nullptr || !pContextProvider->getSaveResultDir(pSubWndF, sRstCode, sDir)) { return false; } + + // sDir为当前成果窗口目录 + // 保存前先清空成果ID目录下的旧内容,避免旧RstWnd目录或残留文件继续被加载 + QString sResultRootPath = QFileInfo(sDir).dir().absolutePath(); + if(!clearDirectoryContents(sResultRootPath)) { + return false; + } + QString sResultPath = sDir + "/Results"; this->ensureDirectoryExists(sResultPath); // 将数据写入Json文件 diff --git a/Src/nmNum/nmSubWnd/nmSubWndUtils.cpp b/Src/nmNum/nmSubWnd/nmSubWndUtils.cpp index 4a1b255..c012ce2 100644 --- a/Src/nmNum/nmSubWnd/nmSubWndUtils.cpp +++ b/Src/nmNum/nmSubWnd/nmSubWndUtils.cpp @@ -725,10 +725,8 @@ bool nmSubWndUtils::saveRsts(iSubWnd* pSubWnd, \ } // 如果存在,则对当前分析数据进行保存 - if(pDataManager->saveNmResult(sRstName, pSubWndF)) { - // 保存成功 - } else { - // 保存失败 + if(!pDataManager->saveNmResult(sRstName, pSubWndF)) { + return false; } } else if(pSubWnd->getWndID() == "5118") { return true;