diff options
Diffstat (limited to 'src/yuzu_cmd')
| -rw-r--r-- | src/yuzu_cmd/config.cpp | 10 | ||||
| -rw-r--r-- | src/yuzu_cmd/config.h | 5 | ||||
| -rw-r--r-- | src/yuzu_cmd/yuzu.cpp | 22 |
3 files changed, 27 insertions, 10 deletions
diff --git a/src/yuzu_cmd/config.cpp b/src/yuzu_cmd/config.cpp index f93b76a4f..fc16f0f0c 100644 --- a/src/yuzu_cmd/config.cpp +++ b/src/yuzu_cmd/config.cpp | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <memory> | 5 | #include <memory> |
| 6 | #include <optional> | ||
| 6 | #include <sstream> | 7 | #include <sstream> |
| 7 | 8 | ||
| 8 | // Ignore -Wimplicit-fallthrough due to https://github.com/libsdl-org/SDL/issues/4307 | 9 | // Ignore -Wimplicit-fallthrough due to https://github.com/libsdl-org/SDL/issues/4307 |
| @@ -28,11 +29,12 @@ | |||
| 28 | 29 | ||
| 29 | namespace FS = Common::FS; | 30 | namespace FS = Common::FS; |
| 30 | 31 | ||
| 31 | Config::Config() { | 32 | const std::filesystem::path default_config_path = |
| 32 | // TODO: Don't hardcode the path; let the frontend decide where to put the config files. | 33 | FS::GetYuzuPath(FS::YuzuPath::ConfigDir) / "sdl2-config.ini"; |
| 33 | sdl2_config_loc = FS::GetYuzuPath(FS::YuzuPath::ConfigDir) / "sdl2-config.ini"; | ||
| 34 | sdl2_config = std::make_unique<INIReader>(FS::PathToUTF8String(sdl2_config_loc)); | ||
| 35 | 34 | ||
| 35 | Config::Config(std::optional<std::filesystem::path> config_path) | ||
| 36 | : sdl2_config_loc{config_path.value_or(default_config_path)}, | ||
| 37 | sdl2_config{std::make_unique<INIReader>(FS::PathToUTF8String(sdl2_config_loc))} { | ||
| 36 | Reload(); | 38 | Reload(); |
| 37 | } | 39 | } |
| 38 | 40 | ||
diff --git a/src/yuzu_cmd/config.h b/src/yuzu_cmd/config.h index 1ee932be2..f61ba23ec 100644 --- a/src/yuzu_cmd/config.h +++ b/src/yuzu_cmd/config.h | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | 6 | ||
| 7 | #include <filesystem> | 7 | #include <filesystem> |
| 8 | #include <memory> | 8 | #include <memory> |
| 9 | #include <optional> | ||
| 9 | #include <string> | 10 | #include <string> |
| 10 | 11 | ||
| 11 | #include "common/settings.h" | 12 | #include "common/settings.h" |
| @@ -13,14 +14,14 @@ | |||
| 13 | class INIReader; | 14 | class INIReader; |
| 14 | 15 | ||
| 15 | class Config { | 16 | class Config { |
| 16 | std::unique_ptr<INIReader> sdl2_config; | ||
| 17 | std::filesystem::path sdl2_config_loc; | 17 | std::filesystem::path sdl2_config_loc; |
| 18 | std::unique_ptr<INIReader> sdl2_config; | ||
| 18 | 19 | ||
| 19 | bool LoadINI(const std::string& default_contents = "", bool retry = true); | 20 | bool LoadINI(const std::string& default_contents = "", bool retry = true); |
| 20 | void ReadValues(); | 21 | void ReadValues(); |
| 21 | 22 | ||
| 22 | public: | 23 | public: |
| 23 | Config(); | 24 | explicit Config(std::optional<std::filesystem::path> config_path); |
| 24 | ~Config(); | 25 | ~Config(); |
| 25 | 26 | ||
| 26 | void Reload(); | 27 | void Reload(); |
diff --git a/src/yuzu_cmd/yuzu.cpp b/src/yuzu_cmd/yuzu.cpp index 8198cde16..14bf82f39 100644 --- a/src/yuzu_cmd/yuzu.cpp +++ b/src/yuzu_cmd/yuzu.cpp | |||
| @@ -62,7 +62,8 @@ static void PrintHelp(const char* argv0) { | |||
| 62 | "-f, --fullscreen Start in fullscreen mode\n" | 62 | "-f, --fullscreen Start in fullscreen mode\n" |
| 63 | "-h, --help Display this help and exit\n" | 63 | "-h, --help Display this help and exit\n" |
| 64 | "-v, --version Output version information and exit\n" | 64 | "-v, --version Output version information and exit\n" |
| 65 | "-p, --program Pass following string as arguments to executable\n"; | 65 | "-p, --program Pass following string as arguments to executable\n" |
| 66 | "-c, --config Load the specified configuration file\n"; | ||
| 66 | } | 67 | } |
| 67 | 68 | ||
| 68 | static void PrintVersion() { | 69 | static void PrintVersion() { |
| @@ -74,7 +75,6 @@ int main(int argc, char** argv) { | |||
| 74 | Common::Log::Initialize(); | 75 | Common::Log::Initialize(); |
| 75 | Common::Log::SetColorConsoleBackendEnabled(true); | 76 | Common::Log::SetColorConsoleBackendEnabled(true); |
| 76 | Common::DetachedTasks detached_tasks; | 77 | Common::DetachedTasks detached_tasks; |
| 77 | Config config; | ||
| 78 | 78 | ||
| 79 | int option_index = 0; | 79 | int option_index = 0; |
| 80 | #ifdef _WIN32 | 80 | #ifdef _WIN32 |
| @@ -87,19 +87,24 @@ int main(int argc, char** argv) { | |||
| 87 | } | 87 | } |
| 88 | #endif | 88 | #endif |
| 89 | std::string filepath; | 89 | std::string filepath; |
| 90 | std::optional<std::string> config_path; | ||
| 91 | std::string program_args; | ||
| 90 | 92 | ||
| 91 | bool fullscreen = false; | 93 | bool fullscreen = false; |
| 92 | 94 | ||
| 93 | static struct option long_options[] = { | 95 | static struct option long_options[] = { |
| 96 | // clang-format off | ||
| 94 | {"fullscreen", no_argument, 0, 'f'}, | 97 | {"fullscreen", no_argument, 0, 'f'}, |
| 95 | {"help", no_argument, 0, 'h'}, | 98 | {"help", no_argument, 0, 'h'}, |
| 96 | {"version", no_argument, 0, 'v'}, | 99 | {"version", no_argument, 0, 'v'}, |
| 97 | {"program", optional_argument, 0, 'p'}, | 100 | {"program", optional_argument, 0, 'p'}, |
| 101 | {"config", required_argument, 0, 'c'}, | ||
| 98 | {0, 0, 0, 0}, | 102 | {0, 0, 0, 0}, |
| 103 | // clang-format on | ||
| 99 | }; | 104 | }; |
| 100 | 105 | ||
| 101 | while (optind < argc) { | 106 | while (optind < argc) { |
| 102 | int arg = getopt_long(argc, argv, "g:fhvp::", long_options, &option_index); | 107 | int arg = getopt_long(argc, argv, "g:fhvp::c:", long_options, &option_index); |
| 103 | if (arg != -1) { | 108 | if (arg != -1) { |
| 104 | switch (static_cast<char>(arg)) { | 109 | switch (static_cast<char>(arg)) { |
| 105 | case 'f': | 110 | case 'f': |
| @@ -113,9 +118,12 @@ int main(int argc, char** argv) { | |||
| 113 | PrintVersion(); | 118 | PrintVersion(); |
| 114 | return 0; | 119 | return 0; |
| 115 | case 'p': | 120 | case 'p': |
| 116 | Settings::values.program_args = argv[optind]; | 121 | program_args = argv[optind]; |
| 117 | ++optind; | 122 | ++optind; |
| 118 | break; | 123 | break; |
| 124 | case 'c': | ||
| 125 | config_path = optarg; | ||
| 126 | break; | ||
| 119 | } | 127 | } |
| 120 | } else { | 128 | } else { |
| 121 | #ifdef _WIN32 | 129 | #ifdef _WIN32 |
| @@ -127,6 +135,12 @@ int main(int argc, char** argv) { | |||
| 127 | } | 135 | } |
| 128 | } | 136 | } |
| 129 | 137 | ||
| 138 | Config config{config_path}; | ||
| 139 | |||
| 140 | if (!program_args.empty()) { | ||
| 141 | Settings::values.program_args = program_args; | ||
| 142 | } | ||
| 143 | |||
| 130 | #ifdef _WIN32 | 144 | #ifdef _WIN32 |
| 131 | LocalFree(argv_w); | 145 | LocalFree(argv_w); |
| 132 | #endif | 146 | #endif |