diff --git a/Program.cs b/Program.cs index 90a345f..d564e57 100644 --- a/Program.cs +++ b/Program.cs @@ -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($" -> {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($" -> {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