From f8ad0695ff2431cb90640be52b523d6434bdbf83 Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期五, 22 八月 2025 15:48:03 +0800
Subject: [PATCH] Merge branch 'LWQ' into liuyang
---
Common_Class/AutoFileCleanupTool/AutoFileCleanupToolDlg.cpp | 92 +++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 86 insertions(+), 6 deletions(-)
diff --git a/Common_Class/AutoFileCleanupTool/AutoFileCleanupToolDlg.cpp b/Common_Class/AutoFileCleanupTool/AutoFileCleanupToolDlg.cpp
index b22c993..2657c2b 100644
--- a/Common_Class/AutoFileCleanupTool/AutoFileCleanupToolDlg.cpp
+++ b/Common_Class/AutoFileCleanupTool/AutoFileCleanupToolDlg.cpp
@@ -9,6 +9,9 @@
#include "afxdialogex.h"
#include "Config.h"
+#include <string>
+#include <functional>
+
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
@@ -82,6 +85,88 @@
, m_bDeleteEmptyFolders(FALSE) // 榛樿涓嶅垹闄ょ┖鏂囦欢澶�
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
+}
+
+void CAutoFileCleanupToolDlg::PerformCleanupTask()
+{
+ // 閬嶅巻婧愮洰褰�
+ CFileFind finder;
+ CString strSearchPath = m_strSourceFolder + _T("\\*.*");
+
+ if (!finder.FindFile(strSearchPath)) {
+ AppendLogLineRichStyled(_T("Source folder not found or empty."), LOG_COLOR_WARNING);
+ return;
+ }
+
+ std::function<void(const CString&)> ProcessFolder;
+ ProcessFolder = [&](const CString& strFolderPath) {
+ CFileFind subFinder;
+ BOOL bWorking = subFinder.FindFile(strFolderPath + _T("\\*.*"));
+ while (bWorking) {
+ bWorking = subFinder.FindNextFile();
+ if (subFinder.IsDots()) {
+ continue;
+ }
+
+ CString srcPath = subFinder.GetFilePath();
+ CString relPath = srcPath.Mid(m_strSourceFolder.GetLength() + 1);
+ CString dstPath = m_strTargetFolder + _T("\\") + relPath;
+
+ if (subFinder.IsDirectory()) {
+ ProcessFolder(srcPath); // 閫掑綊澶勭悊瀛愭枃浠跺す
+ continue;
+ }
+
+ // 姣旇緝鏂囦欢
+ CFileStatus srcStatus, dstStatus;
+ if (CFile::GetStatus(srcPath, srcStatus) && CFile::GetStatus(dstPath, dstStatus)) {
+ if (srcStatus.m_size == dstStatus.m_size) {
+ if (m_bSafeMode) {
+ AppendLogLineRichStyled(_T("Simulated delete: ") + srcPath, LOG_COLOR_WARNING);
+ }
+ else {
+ CFile::Remove(srcPath);
+ if (PathFileExists(srcPath)) {
+ AppendLogLineRichStyled(_T("Failed to delete: ") + srcPath, LOG_COLOR_ERROR);
+ }
+ else {
+ AppendLogLineRichStyled(_T("Deleted: ") + srcPath, LOG_COLOR_SUCCESS);
+ }
+ }
+ }
+ }
+ }
+ subFinder.Close();
+
+ // 鍒犻櫎绌烘枃浠跺す锛堝彲閫夛級
+ if (m_bDeleteEmptyFolders) {
+ BOOL bFound = finder.FindFile(strFolderPath + _T("\\*.*"));
+ BOOL bEmpty = TRUE;
+ while (bFound) {
+ bFound = finder.FindNextFile();
+
+ if (finder.IsDots()) {
+ continue;
+ }
+
+ // 鏈夋枃浠舵垨鏂囦欢澶癸紝涓嶆槸绌虹殑
+ bEmpty = FALSE;
+ break;
+ }
+ finder.Close();
+
+ if (bEmpty) {
+ if (RemoveDirectory(strFolderPath)) {
+ AppendLogLineRichStyled(_T("Deleted empty folder: ") + strFolderPath, LOG_COLOR_SUCCESS);
+ }
+ else {
+ AppendLogLineRichStyled(_T("Failed to delete empty folder: ") + strFolderPath, LOG_COLOR_ERROR);
+ }
+ }
+ }
+ };
+
+ ProcessFolder(m_strSourceFolder);
}
void CAutoFileCleanupToolDlg::SaveSettings()
@@ -458,12 +543,7 @@
// 娓呯悊閫昏緫鏀捐繖閲�
AppendLogLineRichStyled(_T("Performing auto cleanup..."), LOG_COLOR_NORMAL);
- if (m_bSafeMode) {
- AppendLogLineRichStyled(_T("Safe mode: No files will be deleted."), LOG_COLOR_NORMAL);
- }
- else {
- AppendLogLineRichStyled(_T("Scanning and cleaning files..."), LOG_COLOR_NORMAL);
- }
+ PerformCleanupTask();
AppendLogLineRichStyled(_T("Cleanup cycle completed."), LOG_COLOR_SUCCESS);
}
--
Gitblit v1.9.3