From 3a6e2d69d4e649d03ba8ffa6d0884d590251af76 Mon Sep 17 00:00:00 2001 From: luoliangyi <87842688@qq.com> Date: Tue, 22 Aug 2023 09:36:59 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=8F=92=E5=85=A5=E6=89=AB?= =?UTF-8?q?=E6=8F=8F=E6=97=B6=E4=B8=8D=E5=90=8C=E6=A0=BC=E5=BC=8F=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=90=8D=E9=87=8D=E5=91=BD=E5=90=8D=E6=97=B6=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E7=9A=84=E6=B7=B7=E4=B9=B1=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/scanner2/mainwindow.cpp | 75 ++++++++++++++++++++++++------------- 1 file changed, 48 insertions(+), 27 deletions(-) diff --git a/app/scanner2/mainwindow.cpp b/app/scanner2/mainwindow.cpp index a32ff13c..57883e61 100644 --- a/app/scanner2/mainwindow.cpp +++ b/app/scanner2/mainwindow.cpp @@ -1347,7 +1347,7 @@ void MainWindow::on_scanFinishEvent() assert(ScanType_InsertScanInto == m_scanType); assert(-1 != m_scanInsertPos); - std::list backupFileNames; + std::list backupNames; int count = 0; m_thumb->getItemCount(&count); @@ -1363,8 +1363,12 @@ void MainWindow::on_scanFinishEvent() { HGChar filePath[256]; HGBase_GetFilePath(fileName.toLocal8Bit().toStdString().c_str(), filePath, 256); + HGChar name[256]; + HGBase_GetFileName(fileName.toLocal8Bit().toStdString().c_str(), name, 256); + HGChar filePrefix[256]; + HGBase_GetFilePrefix(name, filePrefix, 256); HGChar fileSuffix[256]; - HGBase_GetFileSuffix(fileName.toLocal8Bit().toStdString().c_str(), fileSuffix, 256); + HGBase_GetFileSuffix(name, fileSuffix, 256); HGChar uuid[256]; HGBase_GetUuid(uuid, 256); @@ -1378,7 +1382,7 @@ void MainWindow::on_scanFinishEvent() m_thumb->updateItem(fileName, newFileName, false); m_curBatchFileList.erase(iter); - backupFileNames.push_back(fileName); + backupNames.push_back(filePrefix); m_curBatchTmpFileList.push_back(newFileName); break; } @@ -1388,19 +1392,6 @@ void MainWindow::on_scanFinishEvent() std::list::iterator iter; for (iter = m_curBatchTmpFileList.begin(); iter != m_curBatchTmpFileList.end(); ++iter) { - if (!backupFileNames.empty()) - { - QString &newFileName = backupFileNames.front(); - - QFile file(*iter); - file.rename(newFileName); - m_thumb->updateItem(*iter, newFileName, false); - m_curBatchFileList.push_back(newFileName); - - backupFileNames.erase(backupFileNames.begin()); - continue; - } - HGChar filePath[256]; HGBase_GetFilePath((*iter).toLocal8Bit().toStdString().c_str(), filePath, 256); HGChar fileSuffix[256]; @@ -1410,27 +1401,57 @@ void MainWindow::on_scanFinishEvent() QString strFileSuffix = QString::fromLocal8Bit(fileSuffix); QString newFileName; - while (1) + while (!backupNames.empty()) { - newFileName = strFilePath + m_aquireIntoSaveParam.m_fileNamePrefix + QString("%1.%2") - .arg(m_aquireIntoSaveParam.m_fileNameStartIndex, m_aquireIntoSaveParam.m_fileNameDigits, 10, QLatin1Char('0')) - .arg(strFileSuffix); - QFileInfo fileInfo(newFileName); + QString fileName = strFilePath + backupNames.front() + "." + strFileSuffix; + QFileInfo fileInfo(fileName); if (fileInfo.isFile()) { - ++m_aquireIntoSaveParam.m_fileNameStartIndex; + backupNames.erase(backupNames.begin()); } else { + newFileName = fileName; break; } } - QFile file(*iter); - file.rename(newFileName); - m_thumb->updateItem(*iter, newFileName, false); - m_curBatchFileList.push_back(newFileName); - ++m_aquireIntoSaveParam.m_fileNameStartIndex; + if (!newFileName.isEmpty()) + { + QFile file(*iter); + file.rename(newFileName); + m_thumb->updateItem(*iter, newFileName, false); + m_curBatchFileList.push_back(newFileName); + backupNames.erase(backupNames.begin()); + } + else + { + while (1) + { + QString fileName = strFilePath + m_aquireIntoSaveParam.m_fileNamePrefix + QString("%1.%2") + .arg(m_aquireIntoSaveParam.m_fileNameStartIndex, m_aquireIntoSaveParam.m_fileNameDigits, 10, QLatin1Char('0')) + .arg(strFileSuffix); + QFileInfo fileInfo(fileName); + if (fileInfo.isFile()) + { + ++m_aquireIntoSaveParam.m_fileNameStartIndex; + } + else + { + newFileName = fileName; + break; + } + } + + if (!newFileName.isEmpty()) + { + QFile file(*iter); + file.rename(newFileName); + m_thumb->updateItem(*iter, newFileName, false); + m_curBatchFileList.push_back(newFileName); + ++m_aquireIntoSaveParam.m_fileNameStartIndex; + } + } } m_curBatchTmpFileList.clear();