OSDN Git Service

[Feature] --debug-consoleコマンドラインオプション追加(デバッグ用コンソール表示)
[hengbandforosx/hengbandosx.git] / src / main-win / commandline-win.cpp
1 /*!
2  * @file commandline-win.cpp
3  * @brief Windows版固有実装(コマンドライン)
4  */
5
6 #include "main-win/commandline-win.h"
7 #include "main-win/main-win-utils.h"
8 #include "term/z-util.h"
9
10 #include <iostream>
11 #include <windows.h>
12
13 // interface object
14 CommandLine command_line{};
15
16 namespace {
17 // セーブファイル名
18 std::string savefile_option;
19 }
20
21 /*!
22  * @brief コンソールを作成する
23  * @details
24  * 標準出力のみ対応。
25  */
26 static void create_console(void)
27 {
28     ::AllocConsole();
29     FILE *stream = NULL;
30     freopen_s(&stream, "CONOUT$", "w+", stdout);
31     std::cout << "Hengband debug console" << std::endl;
32 }
33
34 void CommandLine::handle(void)
35 {
36     int argc;
37     LPWSTR *argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc);
38     if (argv) {
39         for (int i = 1; i < argc; i++) {
40             fwprintf(stdout, L"argv[%d] : %s\n", i, argv[i]);
41             if (wcscmp(argv[i], L"--debug-console") == 0) {
42                 create_console();
43                 continue;
44             } else if (wcscmp(argv[i], L"--output-spoilers") == 0) {
45                 create_debug_spoiler();
46                 continue;
47             } else {
48                 if (argv[i][0] != L'-') {
49                     // "-"で始まらない最初のオプションをセーブファイル名とみなす
50                     if (savefile_option.empty()) {
51                         savefile_option = to_multibyte(argv[i]).c_str();
52                     }
53                 }
54             }
55         }
56
57         ::LocalFree(argv);
58     } else {
59         fprintf(stdout, "CommandLineToArgvW failed.");
60         quit(NULL);
61     }
62 }
63
64 const std::string &CommandLine::get_savefile_option(void)
65 {
66     return savefile_option;
67 }