Skip to content

Commit

Permalink
优化调试模式判定规则;移除无效的进程级别调试模式设置
Browse files Browse the repository at this point in the history
  • Loading branch information
lc6464 committed Mar 4, 2024
1 parent 20d5193 commit 7489568
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
3 changes: 2 additions & 1 deletion 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="ConsoleHelpers" />

<Using Include="LC6464.Base16384" />
<Using Include="ConsoleHelpers" />
<Using Include="System.Globalization" />
<Using Include="System.Runtime.InteropServices" />
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace ConsoleHelpers;

public static class Helpers {
public static readonly string? debugEnv = Environment.GetEnvironmentVariable("Base16384_Net_Debug");
public static readonly bool DEBUG = debugEnv is not null && debugEnv.ToLower(new CultureInfo("en-US", false)) is not "false" and not "0";
public static readonly bool DEBUG = !string.IsNullOrWhiteSpace(debugEnv) && debugEnv.ToLower(new CultureInfo("en-US", false)) is not "false" and not "0";


public static int PrintErrorMessage(string? message, string? debugMessage = null, int exitCode = 0) {
Expand All @@ -26,7 +26,7 @@ public static class Helpers {
Console.Write($"{inputName} -> {outputName} ... ");
}
try {
func(input, output);
_ = func(input, output);
} catch (Exception e) {
return PrintException(isStdOut ? null : "Failed.", e, 4);
}
Expand Down
12 changes: 7 additions & 5 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ 4. 编解码失败
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.");
Console.WriteLine("$env:Base16384_Net_Debug = 1");
Console.WriteLine("export Base16384_Net_Debug=1");
Console.WriteLine("set Base16384_Net_Debug=1");
return 0;
}
if (lower == "disable") {
Environment.SetEnvironmentVariable("Base16384_Net_Debug", null);
Console.WriteLine("Debug mode is disabled.");
Console.WriteLine("$env:Base16384_Net_Debug = $null");
Console.WriteLine("unset Base16384_Net_Debug");
Console.WriteLine("set Base16384_Net_Debug=");
return 0;
}

Expand Down Expand Up @@ -168,7 +170,7 @@ 4. 编解码失败
try {
outputParentDirectoryInfo.Create();
} catch (Exception e) {
Helpers.PrintException($"{input.Name} -> {output.Name} ... Failed to create output directory \"{outputParentDirectoryInfo.FullName}\".", e, 5);
_ = Helpers.PrintException($"{input.Name} -> {output.Name} ... Failed to create output directory \"{outputParentDirectoryInfo.FullName}\".", e, 5);
continue;
}
}
Expand Down

0 comments on commit 7489568

Please sign in to comment.