update
This commit is contained in:
parent
a189e42524
commit
33372f6eaa
@ -8,6 +8,7 @@ namespace ConsoleApp1
|
|||||||
{
|
{
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
|
private static readonly object lockObject = new();
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
// 设置控制台的输出编码为UTF-8
|
// 设置控制台的输出编码为UTF-8
|
||||||
@ -77,15 +78,21 @@ namespace ConsoleApp1
|
|||||||
// 获取所有漫画文件夹
|
// 获取所有漫画文件夹
|
||||||
comicFolders = new List<string>(Directory.GetDirectories(parentFolder));
|
comicFolders = new List<string>(Directory.GetDirectories(parentFolder));
|
||||||
}
|
}
|
||||||
|
int totalFolders = comicFolders.Count;
|
||||||
|
int processedFolders = 0;
|
||||||
|
object consoleLock = new();
|
||||||
|
|
||||||
// 设置初始日期
|
// 设置初始日期
|
||||||
DateTime currentDate = new(2020, 1, 1, 0, 0, 0);
|
DateTime currentDate = new(2020, 1, 1, 0, 0, 0);
|
||||||
int count = 0;
|
int count = 0;
|
||||||
// 循环处理每个漫画文件夹
|
// 循环处理每个漫画文件夹
|
||||||
foreach (string comicFolder in comicFolders)
|
Parallel.ForEach(comicFolders, new ParallelOptions { MaxDegreeOfParallelism = 4 }, comicFolder =>
|
||||||
|
{
|
||||||
|
lock (consoleLock)
|
||||||
{
|
{
|
||||||
// 输出开始处理提示信息
|
// 输出开始处理提示信息
|
||||||
Console.WriteLine($"开始处理漫画文件夹 {comicFolder}...");
|
Console.WriteLine($"开始处理漫画文件夹 {comicFolder}...");
|
||||||
|
}
|
||||||
|
|
||||||
// 确保漫画文件夹中包含图像文件
|
// 确保漫画文件夹中包含图像文件
|
||||||
string[] imageFiles = Directory.GetFiles(comicFolder, "*.*", SearchOption.AllDirectories)
|
string[] imageFiles = Directory.GetFiles(comicFolder, "*.*", SearchOption.AllDirectories)
|
||||||
@ -93,9 +100,12 @@ namespace ConsoleApp1
|
|||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
if (imageFiles.Length == 0)
|
if (imageFiles.Length == 0)
|
||||||
|
{
|
||||||
|
lock (consoleLock)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"在漫画文件夹 {comicFolder} 中未找到任何图像文件 (.jpg or .png)。");
|
Console.WriteLine($"在漫画文件夹 {comicFolder} 中未找到任何图像文件 (.jpg or .png)。");
|
||||||
continue; // 继续处理下一个漫画文件夹
|
}
|
||||||
|
return; // 继续处理下一个漫画文件夹
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort the imageFiles using the NaturalSortComparer
|
// Sort the imageFiles using the NaturalSortComparer
|
||||||
@ -106,13 +116,23 @@ namespace ConsoleApp1
|
|||||||
|
|
||||||
// 检查 CBZ 文件是否已经存在,若存在则跳过当前漫画文件夹的处理
|
// 检查 CBZ 文件是否已经存在,若存在则跳过当前漫画文件夹的处理
|
||||||
if (File.Exists(cbzFileName))
|
if (File.Exists(cbzFileName))
|
||||||
|
{
|
||||||
|
lock (consoleLock)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"CBZ 文件 {cbzFileName} 已存在,跳过。");
|
Console.WriteLine($"CBZ 文件 {cbzFileName} 已存在,跳过。");
|
||||||
continue;
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 临时存储重命名后的文件路径
|
// 临时存储重命名后的文件路径
|
||||||
string tempFolder = Path.Combine(comicFolder, "temp");
|
string tempFolder = Path.Combine(comicFolder, "temp");
|
||||||
|
// 检查 temp 文件夹是否存在,如果存在,则删除
|
||||||
|
if (Directory.Exists(tempFolder))
|
||||||
|
{
|
||||||
|
Directory.Delete(tempFolder, true); // true 表示递归删除文件夹中的所有内容
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建新的 temp 文件夹
|
||||||
Directory.CreateDirectory(tempFolder);
|
Directory.CreateDirectory(tempFolder);
|
||||||
|
|
||||||
// 重新编号并复制图像文件到临时文件夹
|
// 重新编号并复制图像文件到临时文件夹
|
||||||
@ -146,15 +166,40 @@ namespace ConsoleApp1
|
|||||||
Directory.Delete(tempFolder, true);
|
Directory.Delete(tempFolder, true);
|
||||||
|
|
||||||
// 增加日期
|
// 增加日期
|
||||||
|
lock (lockObject)
|
||||||
|
{
|
||||||
currentDate = currentDate.AddHours(7);
|
currentDate = currentDate.AddHours(7);
|
||||||
|
|
||||||
Console.WriteLine($"漫画文件夹 {comicFolder} 转换完成。");
|
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
PauseBeforeExit(count);
|
lock (consoleLock)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"漫画文件夹 {comicFolder} 转换完成。");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Interlocked.Increment(ref processedFolders);
|
||||||
|
lock (consoleLock)
|
||||||
|
{
|
||||||
|
ShowProgress(processedFolders, totalFolders);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
PauseBeforeExit(count);
|
||||||
|
}
|
||||||
|
private static void ShowProgress(int current, int total)
|
||||||
|
{
|
||||||
|
Console.CursorLeft = 0;
|
||||||
|
int width = 50; // 进度条宽度
|
||||||
|
int progress = (int)((current / (double)total) * width);
|
||||||
|
Console.Write("[");
|
||||||
|
Console.Write(new string('=', progress));
|
||||||
|
Console.Write(new string(' ', width - progress));
|
||||||
|
Console.Write($"] {current}/{total} 完成");
|
||||||
|
if (current == total)
|
||||||
|
{
|
||||||
|
Console.WriteLine("\n处理完成!");
|
||||||
|
}
|
||||||
|
}
|
||||||
// 生成 ComicInfo.xml 内容
|
// 生成 ComicInfo.xml 内容
|
||||||
private static string GenerateComicInfoXml(string comicFolder)
|
private static string GenerateComicInfoXml(string comicFolder)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user