Compare commits

..

No commits in common. "master" and "1.0.2" have entirely different histories.

View File

@ -8,6 +8,7 @@ namespace Comic_CBZ_Helper
{
class Program
{
private static readonly object lockObject = new();
static void Main()
{
// 设置控制台的输出编码为UTF-8
@ -83,46 +84,59 @@ namespace Comic_CBZ_Helper
}
int totalFolders = comicFolders.Count;
int processedFolders = 0;
object consoleLock = new();
// 设置初始日期
DateTime currentDate = new(2020, 1, 1, 0, 0, 0);
int count = 0;
int timeInc = 7;
// 寻找合适的日期增加量
DateTime tempDate = currentDate;
while (tempDate.AddHours(comicFolders.Count * timeInc) >= DateTime.Now)
{
timeInc--;
if (timeInc == 0)
{
Console.WriteLine("日期增加量无效,请修改代码");
return;
}
tempDate = currentDate;
}
Console.WriteLine($"日期增加量为{timeInc}小时");
// 循环处理每个漫画文件夹
try
{
foreach (var comicFolder in comicFolders)
{
lock (consoleLock)
{
// 输出开始处理提示信息
Console.WriteLine($"开始处理漫画 {Path.GetFileName(comicFolder)}...");
}
// 检查漫画文件夹是否存在
if (!Directory.Exists(comicFolder))
{
lock (consoleLock)
{
Console.WriteLine($"漫画文件夹 {comicFolder} 不存在。");
return; //stop
}
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(".avif"))
.ToArray();
if (imageFiles.Length == 0)
{
lock (consoleLock)
{
Console.WriteLine($"在漫画文件夹 {comicFolder} 中未找到任何图像文件。");
}
continue; // 继续处理下一个漫画文件夹
}
// Sort the imageFiles using the NaturalSortComparer
Array.Sort(imageFiles, new NaturalSortComparer());
// 生成 CBZ 文件名为漫画文件夹的名称
string cbzFileName = Path.Combine(outputFolder, $"{Path.GetFileName(comicFolder)}.cbz");
// 检查 CBZ 文件是否已经存在,若存在则跳过当前漫画文件夹的处理
if (File.Exists(cbzFileName))
{
lock (consoleLock)
{
Console.WriteLine($"CBZ 文件 {cbzFileName} 已存在,跳过。");
count++;
processedFolders++;
currentDate = currentDate.AddHours(timeInc);
}
continue;
}
@ -134,21 +148,6 @@ namespace Comic_CBZ_Helper
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"))
.ToArray();
if (imageFiles.Length == 0)
{
Console.WriteLine($"在漫画文件夹 {comicFolder} 中未找到任何图像文件。");
return; //stop
}
// Sort the imageFiles using the NaturalSortComparer
Array.Sort(imageFiles, new NaturalSortComparer());
// 创建新的 temp 文件夹
Directory.CreateDirectory(tempFolder);
@ -183,13 +182,30 @@ namespace Comic_CBZ_Helper
Directory.Delete(tempFolder, true);
// 增加日期
currentDate = currentDate.AddHours(timeInc);
lock (lockObject)
{
currentDate = currentDate.AddHours(7);
count++;
processedFolders++;
}
lock (consoleLock)
{
Console.WriteLine($"漫画文件夹 {comicFolder} 转换完成。");
}
Interlocked.Increment(ref processedFolders);
lock (consoleLock)
{
ShowProgress(processedFolders, totalFolders);
}
}
}
catch (DirectoryNotFoundException ex)
{
// 处理异常,例如输出错误信息并停止程序
Console.WriteLine(ex.Message);
PauseBeforeExit(0); // 停止程序,并等待用户按任意键退出
}
PauseBeforeExit(count);