From 0c0d82d311761d8bf8ccfa4eaba71d404d17a8b1 Mon Sep 17 00:00:00 2001 From: Chenx221 Date: Wed, 28 Aug 2024 19:11:23 +0800 Subject: [PATCH] up --- Comic_CBZ_Helper/Program.cs | 57 +++++++++++++------------------------ 1 file changed, 19 insertions(+), 38 deletions(-) diff --git a/Comic_CBZ_Helper/Program.cs b/Comic_CBZ_Helper/Program.cs index 330858e..e071b21 100644 --- a/Comic_CBZ_Helper/Program.cs +++ b/Comic_CBZ_Helper/Program.cs @@ -8,7 +8,6 @@ namespace Comic_CBZ_Helper { class Program { - private static readonly object lockObject = new(); static void Main() { // 设置控制台的输出编码为UTF-8 @@ -103,13 +102,17 @@ namespace Comic_CBZ_Helper // 检查漫画文件夹是否存在 if (!Directory.Exists(comicFolder)) { - lock (consoleLock) - { - Console.WriteLine($"漫画文件夹 {comicFolder} 不存在。"); - } throw new DirectoryNotFoundException($"漫画文件夹 {comicFolder} 不存在。"); } + // 临时存储重命名后的文件路径 + string tempFolder = Path.Combine(comicFolder, "temp"); + // 检查 temp 文件夹是否存在,如果存在,则删除 + if (Directory.Exists(tempFolder)) + { + Directory.Delete(tempFolder, true); // true 表示递归删除文件夹中的所有内容 + } + // 确保漫画文件夹中包含图像文件 string[] imageFiles = Directory.GetFiles(comicFolder, "*.*", SearchOption.AllDirectories) .Where(file => file.ToLower().EndsWith(".jpg") || file.ToLower().EndsWith(".png") || file.ToLower().EndsWith(".webp") || file.ToLower().EndsWith(".avif")) @@ -117,11 +120,8 @@ namespace Comic_CBZ_Helper if (imageFiles.Length == 0) { - lock (consoleLock) - { - Console.WriteLine($"在漫画文件夹 {comicFolder} 中未找到任何图像文件。"); - } - continue; // 继续处理下一个漫画文件夹 + Console.WriteLine($"在漫画文件夹 {comicFolder} 中未找到任何图像文件。"); + return;//stop } // Sort the imageFiles using the NaturalSortComparer @@ -133,21 +133,12 @@ namespace Comic_CBZ_Helper // 检查 CBZ 文件是否已经存在,若存在则跳过当前漫画文件夹的处理 if (File.Exists(cbzFileName)) { - lock (consoleLock) - { - Console.WriteLine($"CBZ 文件 {cbzFileName} 已存在,跳过。"); - } + Console.WriteLine($"CBZ 文件 {cbzFileName} 已存在,跳过。"); + count++; + processedFolders++; continue; } - // 临时存储重命名后的文件路径 - string tempFolder = Path.Combine(comicFolder, "temp"); - // 检查 temp 文件夹是否存在,如果存在,则删除 - if (Directory.Exists(tempFolder)) - { - Directory.Delete(tempFolder, true); // true 表示递归删除文件夹中的所有内容 - } - // 创建新的 temp 文件夹 Directory.CreateDirectory(tempFolder); @@ -182,29 +173,19 @@ namespace Comic_CBZ_Helper Directory.Delete(tempFolder, true); // 增加日期 - lock (lockObject) - { - currentDate = currentDate.AddHours(7); - count++; - } + currentDate = currentDate.AddHours(7); + count++; - lock (consoleLock) - { - Console.WriteLine($"漫画文件夹 {comicFolder} 转换完成。"); - } - - Interlocked.Increment(ref processedFolders); - lock (consoleLock) - { - ShowProgress(processedFolders, totalFolders); - } + Console.WriteLine($"漫画文件夹 {comicFolder} 转换完成。"); + processedFolders++; + ShowProgress(processedFolders, totalFolders); } } catch (DirectoryNotFoundException ex) { // 处理异常,例如输出错误信息并停止程序 Console.WriteLine(ex.Message); - PauseBeforeExit(0); // 停止程序,并等待用户按任意键退出 + PauseBeforeExit(count); // 停止程序,并等待用户按任意键退出 }