OSDN Git Service

[Feature] --debug-consoleコマンドラインオプション追加(デバッグ用コンソール表示)
authorshimitei <shimitei@gmail.com>
Sat, 1 May 2021 07:55:58 +0000 (16:55 +0900)
committershimitei <shimitei@gmail.com>
Sat, 1 May 2021 07:55:58 +0000 (16:55 +0900)
デバッグ用コンソール表示のコマンドラインオプション(--debug-console)を追加する。
また、ハイフン('-')で始まらないオプションをセーブファイルパスとして扱うように変更する。

src/main-win.cpp
src/main-win/commandline-win.cpp
src/main-win/commandline-win.h

index 87432da..554801c 100644 (file)
 
 #include <cstdlib>
 #include <locale>
+#include <string>
 
 #include <commdlg.h>
 #include <direct.h>
@@ -1498,20 +1499,20 @@ static void setup_menus(void)
 }
 
 /*
- * Check for double clicked (or dragged) savefile
- *
+ * @brief Check for double clicked (or dragged) savefile
+ * @details
  * Apparently, Windows copies the entire filename into the first
  * piece of the "command line string".  Perhaps we should extract
  * the "basename" of that filename and append it to the "save" dir.
+ * @param player_ptr pointer of player_type
+ * @param savefile_option savefile path
  */
-static void check_for_save_file(player_type *player_ptr, LPSTR cmd_line)
+static void check_for_save_file(player_type *player_ptr, const std::string &savefile_option)
 {
-    char *s;
-    s = cmd_line;
-    if (!*s)
+    if (savefile_option.empty())
         return;
 
-    strcpy(savefile, s);
+    strcpy(savefile, savefile_option.c_str());
     validate_file(savefile);
     game_in_progress = TRUE;
     play_game(player_ptr, FALSE, FALSE);
@@ -2665,7 +2666,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInst, [[maybe_unused]] _In_opt_ HINSTANCE hPr
     term_activate(term_screen);
     init_angband(p_ptr, FALSE);
     initialized = TRUE;
-    check_for_save_file(p_ptr, lpCmdLine);
+    check_for_save_file(p_ptr, command_line.get_savefile_option());
     prt(_("[ファイル] メニューの [新規] または [開く] を選択してください。", "[Choose 'New' or 'Open' from the 'File' menu]"), 23, _(8, 17));
     term_fresh();
 
index e56cb41..e41f11c 100644 (file)
@@ -4,22 +4,53 @@
  */
 
 #include "main-win/commandline-win.h"
+#include "main-win/main-win-utils.h"
 #include "term/z-util.h"
 
+#include <iostream>
 #include <windows.h>
 
 // interface object
 CommandLine command_line{};
 
+namespace {
+// セーブファイル名
+std::string savefile_option;
+}
+
+/*!
+ * @brief コンソールを作成する
+ * @details
+ * 標準出力のみ対応。
+ */
+static void create_console(void)
+{
+    ::AllocConsole();
+    FILE *stream = NULL;
+    freopen_s(&stream, "CONOUT$", "w+", stdout);
+    std::cout << "Hengband debug console" << std::endl;
+}
+
 void CommandLine::handle(void)
 {
     int argc;
     LPWSTR *argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc);
     if (argv) {
         for (int i = 1; i < argc; i++) {
-            if (wcscmp(argv[i], L"--output-spoilers") == 0) {
+            fwprintf(stdout, L"argv[%d] : %s\n", i, argv[i]);
+            if (wcscmp(argv[i], L"--debug-console") == 0) {
+                create_console();
+                continue;
+            } else if (wcscmp(argv[i], L"--output-spoilers") == 0) {
                 create_debug_spoiler();
                 continue;
+            } else {
+                if (argv[i][0] != L'-') {
+                    // "-"で始まらない最初のオプションをセーブファイル名とみなす
+                    if (savefile_option.empty()) {
+                        savefile_option = to_multibyte(argv[i]).c_str();
+                    }
+                }
             }
         }
 
@@ -29,3 +60,8 @@ void CommandLine::handle(void)
         quit(NULL);
     }
 }
+
+const std::string &CommandLine::get_savefile_option(void)
+{
+    return savefile_option;
+}
index d15e659..e81d555 100644 (file)
@@ -4,6 +4,8 @@
  * @brief Windows版固有実装(コマンドライン)ヘッダ
  */
 
+#include <string>
+
 /*!
  * @brief コマンドライン情報管理
  */
@@ -19,9 +21,18 @@ public:
      * コマンドラインオプションは以下の通り。
      * オプション | 内容
      * ---------- | ----
+     * --debug-console | デバッグ用コンソール表示を行う
      * --output-spoilers | 全スポイラー出力を行う
+     * 「-」で始まらない最初のオプション | セーブファイルパス
      */
     void handle(void);
+
+    /*!
+     * @brief セーブファイル名取得
+     * @details 事前にhandle()を呼び出していること。
+     * @return コマンドラインで指定されているセーブファイル名。設定されていなければ空文字列を返す。
+     */
+    const std::string &get_savefile_option(void);
 };
 
 /*!