From 172a552349dc8203969bdaf7c85cf34cb17190f1 Mon Sep 17 00:00:00 2001 From: lc6464 <64722907+lc6464@users.noreply.github.com> Date: Sat, 9 Dec 2023 16:28:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=BC=82=E5=B8=B8=E5=A4=84?= =?UTF-8?q?=E7=90=86=E5=92=8C=E7=94=A8=E6=88=B7=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Program.cs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/Program.cs b/Program.cs index adf7304..90a345f 100644 --- a/Program.cs +++ b/Program.cs @@ -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\"> [out | \"-\"]"); @@ -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($" -> {info.Name} ... "); + Base16384.EncodeToNewFile(stdin, info); + Console.WriteLine("Done."); } } else { // Read from file