#include <cstdlib>
#include <locale>
+#include <string>
#include <commdlg.h>
#include <direct.h>
}
/*
- * 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);
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();
*/
#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();
+ }
+ }
}
}
quit(NULL);
}
}
+
+const std::string &CommandLine::get_savefile_option(void)
+{
+ return savefile_option;
+}
* @brief Windows版固有実装(コマンドライン)ヘッダ
*/
+#include <string>
+
/*!
* @brief コマンドライン情報管理
*/
* コマンドラインオプションは以下の通り。
* オプション | 内容
* ---------- | ----
+ * --debug-console | デバッグ用コンソール表示を行う
* --output-spoilers | 全スポイラー出力を行う
+ * 「-」で始まらない最初のオプション | セーブファイルパス
*/
void handle(void);
+
+ /*!
+ * @brief セーブファイル名取得
+ * @details 事前にhandle()を呼び出していること。
+ * @return コマンドラインで指定されているセーブファイル名。設定されていなければ空文字列を返す。
+ */
+ const std::string &get_savefile_option(void);
};
/*!