Skip to content

Commit

Permalink
优化异常处理和用户提示
Browse files Browse the repository at this point in the history
  • Loading branch information
lc6464 committed Dec 9, 2023
1 parent 10c8cd5 commit 172a552
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
// 新的解析方式:https://github.com/execute233/Base16384.Net
/*
错误代码:
1. 无法解析命令行参数
2. 无法读取文件(可能是文件不存在)
3. Standard IO Stream 开启失败
4. 编解码失败
*/

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 All @@ -12,11 +19,22 @@
using var stdin = Console.OpenStandardInput();
if (args.Length == 2 || args[2] == "-") {
// Write to stdout
using var stdout = Console.OpenStandardOutput();
Base16384.EncodeToStream(stdin, stdout);
try {
using var stdout = Console.OpenStandardOutput();
try {
Base16384.EncodeToStream(stdin, stdout);
} catch {
return 4;
}
} catch {
return 3;
}
} else {
// Write to file
Base16384.EncodeToNewFile(stdin, new(args[2]));
FileInfo info = new(args[2]);
Console.Write($"<stdin> -> {info.Name} ... ");
Base16384.EncodeToNewFile(stdin, info);
Console.WriteLine("Done.");
}
} else {
// Read from file
Expand Down

0 comments on commit 172a552

Please sign in to comment.