diff --git a/CSRender/Program.cs b/CSRender/Program.cs index 642517bb80e4c34eddda762f8515424c81e68a9d..0fa041568f037336465e4182b13806df7e4988e7 100644 --- a/CSRender/Program.cs +++ b/CSRender/Program.cs @@ -34,7 +34,7 @@ namespace CSRenderMain { [DataMember] public string pdfPathRef = ""; //比較ファイル [DataMember] - public string outuptImageDir = ""; // /O + public string outputImageDir = ""; // /O [DataMember] public string dpi = "72.0"; // /D [DataMember] @@ -193,8 +193,16 @@ For more information,see /H /? or /? } //大文字小文字無視でオプションチェック var eIgnoreCase = StringComparer.OrdinalIgnoreCase; - // オプションチェックローカル関数 + // ローカル関数:オプションチェック bool isOpt(params string[] opts) => opts.Contains(wd, eIgnoreCase); + // ローカル関数:オプションの値を取得 + string getValue(string defaultValue = "" ) { + if ( qu.Count == 0 ) + return defaultValue; + if ( Regex.Match( qu.Peek(), $@"^[\/\-]" ).Success ) + return defaultValue; // 次のオプションキー -> 初期値を返す + return qu.Dequeue(); //値をキューから取り出す + } // ボックスオプション辞書 var BoxSelOptDic = new Dictionary(eIgnoreCase) { ["/BM"] = "Media", ["/BT"] = "Trim", ["/BB"] = "Bleed", ["/BC"] = "Crop", @@ -204,34 +212,34 @@ For more information,see /H /? or /? DispHelpDetail(); return -1; } else if (isOpt("/F","/Tgt","/Target")) { - pm.pdfPath = (qu.Count > 0) ? qu.Dequeue() : "";// next word. + pm.pdfPath = getValue(); // next value. } else if (isOpt("/Ref","/Reference")) { - pm.pdfPathRef = (qu.Count > 0) ? qu.Dequeue() : "";// next word. + pm.pdfPathRef = getValue(); // next value. } else if (isOpt("/O","/Output")) { - pm.outuptImageDir = (qu.Count > 0) ? qu.Dequeue() : "";// next word. + pm.outputImageDir = getValue(); // next value. } else if (isOpt("/D","/DPI")) { - pm.dpi = (qu.Count > 0) ? qu.Dequeue() : "";// next word. + pm.dpi = getValue(); // next value. if (!double.TryParse(pm.dpi, out double dmy)) { Console.WriteLine($"解像度が不正です:/D {pm.dpi}"); DispHelpNoArg(); return -1; } } else if (isOpt("/Para")) { - string paraNum = (qu.Count > 0) ? qu.Dequeue() : "";// next word. + string paraNum = getValue(); // next value. if (!int.TryParse(paraNum, out pm.para)) { Console.WriteLine($"並行数が不正です:/para {paraNum}"); DispHelpNoArg(); return -1; } } else if (isOpt("/ParaPage")) { - string paraNum = (qu.Count > 0) ? qu.Dequeue() : "";// next word. + string paraNum = getValue(); // next value. if (!int.TryParse(paraNum, out pm.paraPage)){ Console.WriteLine($"並行数(ページスレッド数が不正です:/ParaPage {paraNum}"); DispHelpNoArg(); return -1; } } else if (isOpt("/P","/Page")) { - pm.pageRange = (qu.Count > 0) ? qu.Dequeue() : "";// next word. + pm.pageRange = getValue(); // next value. } else if (isOpt("/JPG", "/JPEG")) { pm.imageType = "JPG"; } else if (isOpt("/PNG")) { @@ -243,7 +251,7 @@ For more information,see /H /? or /? } else if (isOpt("/BMP")) { pm.imageType = "BMP"; } else if (isOpt("/JPEGQ")) { - pm.jpegQ = (qu.Count > 0) ? qu.Dequeue() : "";// next word. + pm.jpegQ = getValue(); // next value. if (!int.TryParse(pm.jpegQ, out int dmy)) { Console.WriteLine($"JPEG Qualityが不正です:/JPEGQ {pm.jpegQ}"); DispHelpNoArg(); @@ -254,7 +262,7 @@ For more information,see /H /? or /? return -1; } } else if (isOpt("/M")) { - pm.mode = (qu.Count > 0) ? qu.Dequeue() : "";// next word. + pm.mode = getValue(); // next value. } else if (BoxSelOptDic.ContainsKey(wd)) { pm.boxSelect = BoxSelOptDic[wd];// "/BT" -> "Trim",... } else if (isOpt("/HASH")) { @@ -266,7 +274,7 @@ For more information,see /H /? or /? pm.bFC = true; } else if (isOpt("/PDFium")) { pm.bPDFium = true; - var flgStr = (qu.Count > 0) ? qu.Dequeue() : "";// next word. + var flgStr = getValue(); // next value. if (!int.TryParse(flgStr, out int dmy)) { Console.WriteLine($"PDFiumフラグが不正です:/PDFium {flgStr}"); return -1; @@ -280,11 +288,11 @@ For more information,see /H /? or /? return -1; } } else if (isOpt("/Verbose")) { - var arg = (qu.Count > 0) ? (!qu.Peek().StartsWith("/")? qu.Dequeue() : "True") : "True";// next word. + var arg = getValue("True"); // next value. string[] sel = {"True","1","ON"}; pm.bVerbose = sel.Contains(arg, eIgnoreCase); } else if (isOpt("/SubExe")) { - pm.subExe = (qu.Count > 0) ? qu.Dequeue() : null;// next word. + pm.subExe = getValue(null); // next value. var sp = pm.subExe.Split(':'); if (sp.Length < 2 ) { Console.WriteLine($"SubExe指定は\":\"区切りが必要: {pm.subExe}"); @@ -293,7 +301,7 @@ For more information,see /H /? or /? } else if (isOpt("/NoExeSepa")) { pm.bExeSepa = false; } else if (isOpt("/RESULT")) { - pm.resultPath = (qu.Count > 0) ? qu.Dequeue() : "";// next word. + pm.resultPath = getValue(""); // next value. } else if (wd.First() == '/') { // 処理の無いオプションを明示的に無視する Console.WriteLine($"Warning::Ignore opt:{wd}"); @@ -310,7 +318,6 @@ For more information,see /H /? or /? } } // ↑引数解析終わり - setEcho(pm.bVerbose); if (pm.bVerbose) echo("Varbose Mode!"); @@ -418,7 +425,7 @@ For more information,see /H /? or /? } } var watch = System.Diagnostics.Stopwatch.StartNew(); // 時間の生成と計測開始を同時に行う - var otDir = pm.outuptImageDir; + var otDir = pm.outputImageDir; if (otDir == "") { if ( bDir ) { var suffix = pm.bFC ? ".DiffImage": ".IMG"; @@ -431,7 +438,7 @@ For more information,see /H /? or /? // 出力ディレクトリの作成 // 元PDFの同一フォルダにIMGフォルダを作成する otDir = Path.Combine(Directory.GetParent(pm.pdfPath).FullName, "IMG"); } - pm.outuptImageDir = otDir;// pmに戻す + pm.outputImageDir = otDir;// pmに戻す } var otHashPath = ""; var otHashPath2 = "";