From fec9e11e87a953f8268b4e1d0b02807363a7c00a Mon Sep 17 00:00:00 2001 From: lc6464 <64722907+lc6464@users.noreply.github.com> Date: Tue, 12 Dec 2023 23:37:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=A7=A3=E7=A0=81=E8=87=B3?= =?UTF-8?q?=20stdout=20=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Program.cs | 57 ++++++++++++++++++------------------------------------ 1 file changed, 19 insertions(+), 38 deletions(-) diff --git a/Program.cs b/Program.cs index 8a58eae..e3a8847 100644 --- a/Program.cs +++ b/Program.cs @@ -44,9 +44,9 @@ 4. 编解码失败 // Read from file if (args is [.., "-"]) { // Write to stdout - return !File.Exists(args[1]) - ? 2 - : Helpers.WriteToStdOut(Base16384.EncodeFromFileToStream, new FileInfo(args[1])); + return File.Exists(args[1]) + ? Helpers.WriteToStdOut(Base16384.EncodeFromFileToStream, new FileInfo(args[1])) + : 2; } else if (args.Length == 2) { // Write to .decoded file if (!File.Exists(args[1])) { @@ -96,28 +96,20 @@ 4. 编解码失败 using var stdin = Console.OpenStandardInput(); if (args.Length == 2 || args[2] == "-") { // Write to stdout - try { - using var stdout = Console.OpenStandardOutput(); - try { - Base16384.DecodeToStream(stdin, stdout); - } catch { - return 4; - } - } catch { - return 3; - } - } else { - // Write to file - FileInfo info = new(args[2]); - Console.Write($" -> {info.Name} ... "); - try { - Base16384.DecodeToNewFile(stdin, info); - } catch { - Console.WriteLine("Failed."); - return 4; - } - Console.WriteLine("Done."); + return Helpers.WriteToStdOut(Base16384.DecodeToStream, stdin); + } + + // Write to file + FileInfo info = new(args[2]); + Console.Write($" -> {info.Name} ... "); + try { + Base16384.DecodeToNewFile(stdin, info); + } catch { + Console.WriteLine("Failed."); + return 4; } + Console.WriteLine("Done."); + } catch { if (args.Length != 2 && args[2] != "-") { Console.WriteLine("Can not open stdin."); @@ -128,20 +120,9 @@ 4. 编解码失败 // Read from file if (args is [.., "-"]) { // Write to stdout - if (!File.Exists(args[1])) { - Console.WriteLine("Source file not found."); - return 2; - } - try { - using var stdout = Console.OpenStandardOutput(); - try { - Base16384.DecodeFromFileToStream(new(args[1]), stdout); - } catch { - return 4; - } - } catch { - return 3; - } + return File.Exists(args[1]) + ? Helpers.WriteToStdOut(Base16384.DecodeFromFileToStream, new FileInfo(args[1])) + : 2; } else if (args.Length == 2) { // Write to .decoded file if (!File.Exists(args[1])) {