Skip to content

Commit

Permalink
修复批量编解码整个文件夹时不会自动创建子文件夹的问题;添加对 DEBUG 模式的快速操作功能
Browse files Browse the repository at this point in the history
  • Loading branch information
lc6464 committed Mar 4, 2024
1 parent 5f0a452 commit 20d5193
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
5 changes: 3 additions & 2 deletions Base16384.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
<PackageReference Include="LC6464.Base16384" Version="2.1.0" />
</ItemGroup>
<ItemGroup>
<Using Include="System.Runtime.InteropServices" />
<Using Include="LC6464.Base16384" />
<Using Include="ConsoleHelpers" />
<Using Include="LC6464.Base16384" />
<Using Include="System.Globalization" />
<Using Include="System.Runtime.InteropServices" />
</ItemGroup>
</Project>
1 change: 0 additions & 1 deletion Helpers.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using System.Globalization;

namespace ConsoleHelpers;

Expand Down
45 changes: 40 additions & 5 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@ 4. 编解码失败
5. 无法创建输出文件夹(可能是输出文件夹是一个已存在的文件)
*/

if (args is ["debug", string]) {
var lower = args[1].ToLower(new CultureInfo("en-US", false));
if (lower == "enable") {
Environment.SetEnvironmentVariable("Base16384_Net_Debug", "true");
Console.WriteLine("Debug mode is enabled.");
return 0;
}
if (lower == "disable") {
Environment.SetEnvironmentVariable("Base16384_Net_Debug", null);
Console.WriteLine("Debug mode is disabled.");
return 0;
}

Console.WriteLine("Usage: Base16384.Net.exe <\"e\" | \"d\"> <source | \"-\"> [out | \"-\"]");
return 1;
}


if (args.Length is not 2 and not 3 || args is not ["e", ..] and not ["d", ..]) {
Console.WriteLine("Usage: Base16384.Net.exe <\"e\" | \"d\"> <source | \"-\"> [out | \"-\"]");
Expand Down Expand Up @@ -93,12 +110,12 @@ 5. 无法创建输出文件夹(可能是输出文件夹是一个已存在的
output = new(Path.Combine(outputDirectoryInfo.FullName, input.Name));

if (output.Exists) {
Console.WriteLine($"{input.Name} -> {output.Name} ... The output file in the directory {outputDirectoryInfo.Name} already exists.");
Console.WriteLine($"{input.Name} -> {output.Name} ... The output file in the directory \"{outputDirectoryInfo.Name}\" already exists.");
continue;
}

if (!input.Exists) {
Console.WriteLine($"{input.Name} -> Source file not found.");
Console.WriteLine($"{input.Name} -> {output.Name} ... Source file not found.");
continue;
}

Expand Down Expand Up @@ -131,20 +148,38 @@ 5. 无法创建输出文件夹(可能是输出文件夹是一个已存在的
}

FileInfo output;
string relativePath;
DirectoryInfo outputParentDirectoryInfo;
string relativePath, relativeDirectory;

// foreach files in the list
foreach (var input in inputDirectoryInfo.EnumerateFiles("*", SearchOption.AllDirectories)) {
relativePath = Path.GetRelativePath(inputDirectoryInfo.FullName, input.FullName);
output = new(Path.Combine(outputDirectoryInfo.FullName, relativePath));
relativeDirectory = Path.GetDirectoryName(relativePath)!;
relativeDirectory = string.IsNullOrWhiteSpace(relativeDirectory) ? "." : relativeDirectory;

outputParentDirectoryInfo = output.Directory!;

if (!outputParentDirectoryInfo.Exists) {
if (File.Exists(outputParentDirectoryInfo.FullName)) {
Console.WriteLine($"{input.Name} -> {output.Name} ... The output directory \"{relativeDirectory}\" is an existing file.");
}

try {
outputParentDirectoryInfo.Create();
} catch (Exception e) {
Helpers.PrintException($"{input.Name} -> {output.Name} ... Failed to create output directory \"{outputParentDirectoryInfo.FullName}\".", e, 5);
continue;
}
}

if (output.Exists) {
Console.WriteLine($"{input.Name} -> {output.Name} ... The output file in the directory {Path.GetDirectoryName(relativePath)} already exists.");
Console.WriteLine($"{input.Name} -> {output.Name} ... The output file in the directory \"{relativeDirectory}\" already exists.");
continue;
}

if (!input.Exists) {
Console.WriteLine($"{input.Name} -> Source file not found.");
Console.WriteLine($"{input.Name} -> {output.Name} ... Source file not found.");
continue;
}

Expand Down

0 comments on commit 20d5193

Please sign in to comment.