Skip to content

Commit

Permalink
优化 encode-from-stdin 部分异常处理和用户提示
Browse files Browse the repository at this point in the history
  • Loading branch information
lc6464 committed Dec 9, 2023
1 parent 172a552 commit 0e67105
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,37 @@ 4. 编解码失败
// Encode mode
if (args[1] == "-") {
// Read from stdin
using var stdin = Console.OpenStandardInput();
if (args.Length == 2 || args[2] == "-") {
// Write to stdout
try {
using var stdout = Console.OpenStandardOutput();
try {
using var stdin = Console.OpenStandardInput();
if (args.Length == 2 || args[2] == "-") {
// Write to stdout
try {
using var stdout = Console.OpenStandardOutput();
try {
Base16384.EncodeToStream(stdin, stdout);
} catch {
return 4;
}
} catch {
return 3;
}
} else {
// Write to file
FileInfo info = new(args[2]);
Console.Write($"<stdin> -> {info.Name} ... ");
try {
Base16384.EncodeToStream(stdin, stdout);
Base16384.EncodeToNewFile(stdin, info);
} catch {
Console.WriteLine("Failed.");
return 4;
}
} catch {
return 3;
Console.WriteLine("Done.");
}
} else {
// Write to file
FileInfo info = new(args[2]);
Console.Write($"<stdin> -> {info.Name} ... ");
Base16384.EncodeToNewFile(stdin, info);
Console.WriteLine("Done.");
} catch {
if (args.Length != 2 && args[2] != "-") {
Console.WriteLine("Can not open stdin.");
}
return 3;
}
} else {
// Read from file
Expand Down

0 comments on commit 0e67105

Please sign in to comment.