mirror of
https://github.com/starr-dusT/yuzu-mainline
synced 2024-03-05 21:12:25 -08:00
Merge pull request #8025 from lat9nq/cmd-specify-config
yuzu_cmd: Allow user to specify config file location
This commit is contained in:
commit
17ebe211ec
@ -3,6 +3,7 @@
|
|||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <optional>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
// Ignore -Wimplicit-fallthrough due to https://github.com/libsdl-org/SDL/issues/4307
|
// Ignore -Wimplicit-fallthrough due to https://github.com/libsdl-org/SDL/issues/4307
|
||||||
@ -29,11 +30,12 @@
|
|||||||
|
|
||||||
namespace FS = Common::FS;
|
namespace FS = Common::FS;
|
||||||
|
|
||||||
Config::Config() {
|
const std::filesystem::path default_config_path =
|
||||||
// TODO: Don't hardcode the path; let the frontend decide where to put the config files.
|
FS::GetYuzuPath(FS::YuzuPath::ConfigDir) / "sdl2-config.ini";
|
||||||
sdl2_config_loc = FS::GetYuzuPath(FS::YuzuPath::ConfigDir) / "sdl2-config.ini";
|
|
||||||
sdl2_config = std::make_unique<INIReader>(FS::PathToUTF8String(sdl2_config_loc));
|
|
||||||
|
|
||||||
|
Config::Config(std::optional<std::filesystem::path> config_path)
|
||||||
|
: sdl2_config_loc{config_path.value_or(default_config_path)},
|
||||||
|
sdl2_config{std::make_unique<INIReader>(FS::PathToUTF8String(sdl2_config_loc))} {
|
||||||
Reload();
|
Reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "common/settings.h"
|
#include "common/settings.h"
|
||||||
@ -13,14 +14,14 @@
|
|||||||
class INIReader;
|
class INIReader;
|
||||||
|
|
||||||
class Config {
|
class Config {
|
||||||
std::unique_ptr<INIReader> sdl2_config;
|
|
||||||
std::filesystem::path sdl2_config_loc;
|
std::filesystem::path sdl2_config_loc;
|
||||||
|
std::unique_ptr<INIReader> sdl2_config;
|
||||||
|
|
||||||
bool LoadINI(const std::string& default_contents = "", bool retry = true);
|
bool LoadINI(const std::string& default_contents = "", bool retry = true);
|
||||||
void ReadValues();
|
void ReadValues();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Config();
|
explicit Config(std::optional<std::filesystem::path> config_path);
|
||||||
~Config();
|
~Config();
|
||||||
|
|
||||||
void Reload();
|
void Reload();
|
||||||
|
@ -66,7 +66,8 @@ static void PrintHelp(const char* argv0) {
|
|||||||
"-f, --fullscreen Start in fullscreen mode\n"
|
"-f, --fullscreen Start in fullscreen mode\n"
|
||||||
"-h, --help Display this help and exit\n"
|
"-h, --help Display this help and exit\n"
|
||||||
"-v, --version Output version information and exit\n"
|
"-v, --version Output version information and exit\n"
|
||||||
"-p, --program Pass following string as arguments to executable\n";
|
"-p, --program Pass following string as arguments to executable\n"
|
||||||
|
"-c, --config Load the specified configuration file\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
static void PrintVersion() {
|
static void PrintVersion() {
|
||||||
@ -78,7 +79,6 @@ int main(int argc, char** argv) {
|
|||||||
Common::Log::Initialize();
|
Common::Log::Initialize();
|
||||||
Common::Log::SetColorConsoleBackendEnabled(true);
|
Common::Log::SetColorConsoleBackendEnabled(true);
|
||||||
Common::DetachedTasks detached_tasks;
|
Common::DetachedTasks detached_tasks;
|
||||||
Config config;
|
|
||||||
|
|
||||||
int option_index = 0;
|
int option_index = 0;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@ -91,19 +91,24 @@ int main(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
std::string filepath;
|
std::string filepath;
|
||||||
|
std::optional<std::string> config_path;
|
||||||
|
std::string program_args;
|
||||||
|
|
||||||
bool fullscreen = false;
|
bool fullscreen = false;
|
||||||
|
|
||||||
static struct option long_options[] = {
|
static struct option long_options[] = {
|
||||||
|
// clang-format off
|
||||||
{"fullscreen", no_argument, 0, 'f'},
|
{"fullscreen", no_argument, 0, 'f'},
|
||||||
{"help", no_argument, 0, 'h'},
|
{"help", no_argument, 0, 'h'},
|
||||||
{"version", no_argument, 0, 'v'},
|
{"version", no_argument, 0, 'v'},
|
||||||
{"program", optional_argument, 0, 'p'},
|
{"program", optional_argument, 0, 'p'},
|
||||||
|
{"config", required_argument, 0, 'c'},
|
||||||
{0, 0, 0, 0},
|
{0, 0, 0, 0},
|
||||||
|
// clang-format on
|
||||||
};
|
};
|
||||||
|
|
||||||
while (optind < argc) {
|
while (optind < argc) {
|
||||||
int arg = getopt_long(argc, argv, "g:fhvp::", long_options, &option_index);
|
int arg = getopt_long(argc, argv, "g:fhvp::c:", long_options, &option_index);
|
||||||
if (arg != -1) {
|
if (arg != -1) {
|
||||||
switch (static_cast<char>(arg)) {
|
switch (static_cast<char>(arg)) {
|
||||||
case 'f':
|
case 'f':
|
||||||
@ -117,9 +122,12 @@ int main(int argc, char** argv) {
|
|||||||
PrintVersion();
|
PrintVersion();
|
||||||
return 0;
|
return 0;
|
||||||
case 'p':
|
case 'p':
|
||||||
Settings::values.program_args = argv[optind];
|
program_args = argv[optind];
|
||||||
++optind;
|
++optind;
|
||||||
break;
|
break;
|
||||||
|
case 'c':
|
||||||
|
config_path = optarg;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@ -131,6 +139,12 @@ int main(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Config config{config_path};
|
||||||
|
|
||||||
|
if (!program_args.empty()) {
|
||||||
|
Settings::values.program_args = program_args;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
LocalFree(argv_w);
|
LocalFree(argv_w);
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user