移除多线程支持
This commit is contained in:
parent
e403e27d22
commit
642e0a2864
@ -70,8 +70,12 @@ namespace Comic_CBZ_Helper
|
||||
List<string> comicFolders;
|
||||
if (runMode == "1") // init模式
|
||||
{
|
||||
List<string> folderOrder = new(File.ReadAllLines(listFilePath));
|
||||
comicFolders = [.. Directory.GetDirectories(parentFolder).OrderBy(folder => folderOrder.IndexOf(Path.GetFileName(folder)))];
|
||||
comicFolders = new(File.ReadAllLines(listFilePath));
|
||||
for (int i = 0; i < comicFolders.Count; i++)
|
||||
{
|
||||
comicFolders[i] = Path.Combine(parentFolder, comicFolders[i]);
|
||||
}
|
||||
//comicFolders = [.. Directory.GetDirectories(parentFolder).OrderBy(folder => folderOrder.IndexOf(Path.GetFileName(folder)))];
|
||||
}
|
||||
else // append模式或其他
|
||||
{
|
||||
@ -86,17 +90,29 @@ namespace Comic_CBZ_Helper
|
||||
DateTime currentDate = new(2020, 1, 1, 0, 0, 0);
|
||||
int count = 0;
|
||||
// 循环处理每个漫画文件夹
|
||||
Parallel.ForEach(comicFolders, new ParallelOptions { MaxDegreeOfParallelism = 4 }, comicFolder =>
|
||||
try
|
||||
{
|
||||
foreach (var comicFolder in comicFolders)
|
||||
{
|
||||
lock (consoleLock)
|
||||
{
|
||||
// 输出开始处理提示信息
|
||||
Console.WriteLine($"开始处理漫画文件夹 {comicFolder}...");
|
||||
Console.WriteLine($"开始处理漫画 {Path.GetFileName(comicFolder)}...");
|
||||
}
|
||||
|
||||
// 检查漫画文件夹是否存在
|
||||
if (!Directory.Exists(comicFolder))
|
||||
{
|
||||
lock (consoleLock)
|
||||
{
|
||||
Console.WriteLine($"漫画文件夹 {comicFolder} 不存在。");
|
||||
}
|
||||
throw new DirectoryNotFoundException($"漫画文件夹 {comicFolder} 不存在。");
|
||||
}
|
||||
|
||||
// 确保漫画文件夹中包含图像文件
|
||||
string[] imageFiles = Directory.GetFiles(comicFolder, "*.*", SearchOption.AllDirectories)
|
||||
.Where(file => file.ToLower().EndsWith(".jpg") || file.ToLower().EndsWith(".png") || file.ToLower().EndsWith(".webp") || file.ToLower().EndsWith(".webp") || file.ToLower().EndsWith(".avif"))
|
||||
.Where(file => file.ToLower().EndsWith(".jpg") || file.ToLower().EndsWith(".png") || file.ToLower().EndsWith(".webp") || file.ToLower().EndsWith(".avif"))
|
||||
.ToArray();
|
||||
|
||||
if (imageFiles.Length == 0)
|
||||
@ -105,7 +121,7 @@ namespace Comic_CBZ_Helper
|
||||
{
|
||||
Console.WriteLine($"在漫画文件夹 {comicFolder} 中未找到任何图像文件。");
|
||||
}
|
||||
return; // 继续处理下一个漫画文件夹
|
||||
continue; // 继续处理下一个漫画文件夹
|
||||
}
|
||||
|
||||
// Sort the imageFiles using the NaturalSortComparer
|
||||
@ -121,7 +137,7 @@ namespace Comic_CBZ_Helper
|
||||
{
|
||||
Console.WriteLine($"CBZ 文件 {cbzFileName} 已存在,跳过。");
|
||||
}
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
|
||||
// 临时存储重命名后的文件路径
|
||||
@ -182,7 +198,15 @@ namespace Comic_CBZ_Helper
|
||||
{
|
||||
ShowProgress(processedFolders, totalFolders);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (DirectoryNotFoundException ex)
|
||||
{
|
||||
// 处理异常,例如输出错误信息并停止程序
|
||||
Console.WriteLine(ex.Message);
|
||||
PauseBeforeExit(0); // 停止程序,并等待用户按任意键退出
|
||||
}
|
||||
|
||||
|
||||
PauseBeforeExit(count);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user