diff options
Diffstat (limited to '')
| -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 b74411c84..131bc2201 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 |
| @@ -29,11 +30,12 @@ | |||
| 29 | 30 | ||
| 30 | namespace FS = Common::FS; | 31 | namespace FS = Common::FS; |
| 31 | 32 | ||
| 32 | Config::Config() { | 33 | const std::filesystem::path default_config_path = |
| 33 | // TODO: Don't hardcode the path; let the frontend decide where to put the config files. | 34 | FS::GetYuzuPath(FS::YuzuPath::ConfigDir) / "sdl2-config.ini"; |
| 34 | sdl2_config_loc = FS::GetYuzuPath(FS::YuzuPath::ConfigDir) / "sdl2-config.ini"; | ||
| 35 | sdl2_config = std::make_unique<INIReader>(FS::PathToUTF8String(sdl2_config_loc)); | ||
| 36 | 35 | ||
| 36 | Config::Config(std::optional<std::filesystem::path> config_path) | ||
| 37 | : sdl2_config_loc{config_path.value_or(default_config_path)}, | ||
| 38 | sdl2_config{std::make_unique<INIReader>(FS::PathToUTF8String(sdl2_config_loc))} { | ||
| 37 | Reload(); | 39 | Reload(); |
| 38 | } | 40 | } |
| 39 | 41 | ||
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 b44ea0cc4..f6d563017 100644 --- a/src/yuzu_cmd/yuzu.cpp +++ b/src/yuzu_cmd/yuzu.cpp | |||
| @@ -66,7 +66,8 @@ static void PrintHelp(const char* argv0) { | |||
| 66 | "-f, --fullscreen Start in fullscreen mode\n" | 66 | "-f, --fullscreen Start in fullscreen mode\n" |
| 67 | "-h, --help Display this help and exit\n" | 67 | "-h, --help Display this help and exit\n" |
| 68 | "-v, --version Output version information and exit\n" | 68 | "-v, --version Output version information and exit\n" |
| 69 | "-p, --program Pass following string as arguments to executable\n"; | 69 | "-p, --program Pass following string as arguments to executable\n" |
| 70 | "-c, --config Load the specified configuration file\n"; | ||
| 70 | } | 71 | } |
| 71 | 72 | ||
| 72 | static void PrintVersion() { | 73 | static void PrintVersion() { |
| @@ -78,7 +79,6 @@ int main(int argc, char** argv) { | |||
| 78 | Common::Log::Initialize(); | 79 | Common::Log::Initialize(); |
| 79 | Common::Log::SetColorConsoleBackendEnabled(true); | 80 | Common::Log::SetColorConsoleBackendEnabled(true); |
| 80 | Common::DetachedTasks detached_tasks; | 81 | Common::DetachedTasks detached_tasks; |
| 81 | Config config; | ||
| 82 | 82 | ||
| 83 | int option_index = 0; | 83 | int option_index = 0; |
| 84 | #ifdef _WIN32 | 84 | #ifdef _WIN32 |
| @@ -91,19 +91,24 @@ int main(int argc, char** argv) { | |||
| 91 | } | 91 | } |
| 92 | #endif | 92 | #endif |
| 93 | std::string filepath; | 93 | std::string filepath; |
| 94 | std::optional<std::string> config_path; | ||
| 95 | std::string program_args; | ||
| 94 | 96 | ||
| 95 | bool fullscreen = false; | 97 | bool fullscreen = false; |
| 96 | 98 | ||
| 97 | static struct option long_options[] = { | 99 | static struct option long_options[] = { |
| 100 | // clang-format off | ||
| 98 | {"fullscreen", no_argument, 0, 'f'}, | 101 | {"fullscreen", no_argument, 0, 'f'}, |
| 99 | {"help", no_argument, 0, 'h'}, | 102 | {"help", no_argument, 0, 'h'}, |
| 100 | {"version", no_argument, 0, 'v'}, | 103 | {"version", no_argument, 0, 'v'}, |
| 101 | {"program", optional_argument, 0, 'p'}, | 104 | {"program", optional_argument, 0, 'p'}, |
| 105 | {"config", required_argument, 0, 'c'}, | ||
| 102 | {0, 0, 0, 0}, | 106 | {0, 0, 0, 0}, |
| 107 | // clang-format on | ||
| 103 | }; | 108 | }; |
| 104 | 109 | ||
| 105 | while (optind < argc) { | 110 | while (optind < argc) { |
| 106 | int arg = getopt_long(argc, argv, "g:fhvp::", long_options, &option_index); | 111 | int arg = getopt_long(argc, argv, "g:fhvp::c:", long_options, &option_index); |
| 107 | if (arg != -1) { | 112 | if (arg != -1) { |
| 108 | switch (static_cast<char>(arg)) { | 113 | switch (static_cast<char>(arg)) { |
| 109 | case 'f': | 114 | case 'f': |
| @@ -117,9 +122,12 @@ int main(int argc, char** argv) { | |||
| 117 | PrintVersion(); | 122 | PrintVersion(); |
| 118 | return 0; | 123 | return 0; |
| 119 | case 'p': | 124 | case 'p': |
| 120 | Settings::values.program_args = argv[optind]; | 125 | program_args = argv[optind]; |
| 121 | ++optind; | 126 | ++optind; |
| 122 | break; | 127 | break; |
| 128 | case 'c': | ||
| 129 | config_path = optarg; | ||
| 130 | break; | ||
| 123 | } | 131 | } |
| 124 | } else { | 132 | } else { |
| 125 | #ifdef _WIN32 | 133 | #ifdef _WIN32 |
| @@ -131,6 +139,12 @@ int main(int argc, char** argv) { | |||
| 131 | } | 139 | } |
| 132 | } | 140 | } |
| 133 | 141 | ||
| 142 | Config config{config_path}; | ||
| 143 | |||
| 144 | if (!program_args.empty()) { | ||
| 145 | Settings::values.program_args = program_args; | ||
| 146 | } | ||
| 147 | |||
| 134 | #ifdef _WIN32 | 148 | #ifdef _WIN32 |
| 135 | LocalFree(argv_w); | 149 | LocalFree(argv_w); |
| 136 | #endif | 150 | #endif |