From 4277c028bc2a0f6561838a550ebf4f5c42a1cc25 Mon Sep 17 00:00:00 2001 From: shimitei Date: Sat, 1 May 2021 16:55:58 +0900 Subject: [PATCH] =?utf8?q?[Feature]=20--debug-console=E3=82=B3=E3=83=9E?= =?utf8?q?=E3=83=B3=E3=83=89=E3=83=A9=E3=82=A4=E3=83=B3=E3=82=AA=E3=83=97?= =?utf8?q?=E3=82=B7=E3=83=A7=E3=83=B3=E8=BF=BD=E5=8A=A0=EF=BC=88=E3=83=87?= =?utf8?q?=E3=83=90=E3=83=83=E3=82=B0=E7=94=A8=E3=82=B3=E3=83=B3=E3=82=BD?= =?utf8?q?=E3=83=BC=E3=83=AB=E8=A1=A8=E7=A4=BA=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit デバッグ用コンソール表示のコマンドラインオプション(--debug-console)を追加する。 また、ハイフン('-')で始まらないオプションをセーブファイルパスとして扱うように変更する。 --- src/main-win.cpp | 17 +++++++++-------- src/main-win/commandline-win.cpp | 38 +++++++++++++++++++++++++++++++++++++- src/main-win/commandline-win.h | 11 +++++++++++ 3 files changed, 57 insertions(+), 9 deletions(-) diff --git a/src/main-win.cpp b/src/main-win.cpp index 87432da28..554801c3a 100644 --- a/src/main-win.cpp +++ b/src/main-win.cpp @@ -126,6 +126,7 @@ #include #include +#include #include #include @@ -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(); diff --git a/src/main-win/commandline-win.cpp b/src/main-win/commandline-win.cpp index e56cb41ba..e41f11c4d 100644 --- a/src/main-win/commandline-win.cpp +++ b/src/main-win/commandline-win.cpp @@ -4,22 +4,53 @@ */ #include "main-win/commandline-win.h" +#include "main-win/main-win-utils.h" #include "term/z-util.h" +#include #include // 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; +} diff --git a/src/main-win/commandline-win.h b/src/main-win/commandline-win.h index d15e6591e..e81d55509 100644 --- a/src/main-win/commandline-win.h +++ b/src/main-win/commandline-win.h @@ -4,6 +4,8 @@ * @brief Windows版固有実装(コマンドライン)ヘッダ */ +#include + /*! * @brief コマンドライン情報管理 */ @@ -19,9 +21,18 @@ public: * コマンドラインオプションは以下の通り。 * オプション | 内容 * ---------- | ---- + * --debug-console | デバッグ用コンソール表示を行う * --output-spoilers | 全スポイラー出力を行う + * 「-」で始まらない最初のオプション | セーブファイルパス */ void handle(void); + + /*! + * @brief セーブファイル名取得 + * @details 事前にhandle()を呼び出していること。 + * @return コマンドラインで指定されているセーブファイル名。設定されていなければ空文字列を返す。 + */ + const std::string &get_savefile_option(void); }; /*! -- 2.11.0