Allowing Config class to resolve isFullscreen flag from CLI arguments

This commit is contained in:
Robyn Dressler 2024-10-08 20:07:03 -05:00
parent 2fd4861d3e
commit dbb08050d4
6 changed files with 38 additions and 19 deletions

View File

@ -41,6 +41,7 @@ static std::string logFilter;
static std::string logType = "async"; static std::string logType = "async";
static std::string userName = "shadPS4"; static std::string userName = "shadPS4";
static std::string updateChannel; static std::string updateChannel;
static std::string patchFile = "";
static bool useSpecialPad = false; static bool useSpecialPad = false;
static int specialPadClass = 1; static int specialPadClass = 1;
static bool isDebugDump = false; static bool isDebugDump = false;
@ -123,6 +124,10 @@ std::string getUpdateChannel() {
return updateChannel; return updateChannel;
} }
std::string getPatchFile() {
return patchFile;
}
bool getUseSpecialPad() { bool getUseSpecialPad() {
return useSpecialPad; return useSpecialPad;
} }
@ -275,6 +280,10 @@ void setUpdateChannel(const std::string& type) {
updateChannel = type; updateChannel = type;
} }
void setPatchFile(const std::string& fileName) {
patchFile = fileName;
}
void setUseSpecialPad(bool use) { void setUseSpecialPad(bool use) {
useSpecialPad = use; useSpecialPad = use;
} }
@ -435,6 +444,7 @@ void load(const std::filesystem::path& path) {
} }
isShowSplash = toml::find_or<bool>(general, "showSplash", true); isShowSplash = toml::find_or<bool>(general, "showSplash", true);
isAutoUpdate = toml::find_or<bool>(general, "autoUpdate", false); isAutoUpdate = toml::find_or<bool>(general, "autoUpdate", false);
patchFile = toml::find_or<std::string>(general, "patchFile", "");
} }
if (data.contains("Input")) { if (data.contains("Input")) {
@ -502,6 +512,18 @@ void load(const std::filesystem::path& path) {
m_language = toml::find_or<int>(settings, "consoleLanguage", 1); m_language = toml::find_or<int>(settings, "consoleLanguage", 1);
} }
} }
void loadArgs(int& argc, char* argv[]) {
for (int i = 0; i < argc; i++) {
const std::string arg = argv[i];
if (arg == "-p") {
patchFile = argv[i + 1];
} else if (arg == "-f") {
isFullscreen = true;
}
}
}
void save(const std::filesystem::path& path) { void save(const std::filesystem::path& path) {
toml::value data; toml::value data;
@ -533,6 +555,7 @@ void save(const std::filesystem::path& path) {
data["General"]["updateChannel"] = updateChannel; data["General"]["updateChannel"] = updateChannel;
data["General"]["showSplash"] = isShowSplash; data["General"]["showSplash"] = isShowSplash;
data["General"]["autoUpdate"] = isAutoUpdate; data["General"]["autoUpdate"] = isAutoUpdate;
data["General"]["patchFile"] = patchFile;
data["Input"]["useSpecialPad"] = useSpecialPad; data["Input"]["useSpecialPad"] = useSpecialPad;
data["Input"]["specialPadClass"] = specialPadClass; data["Input"]["specialPadClass"] = specialPadClass;
data["GPU"]["screenWidth"] = screenWidth; data["GPU"]["screenWidth"] = screenWidth;
@ -591,6 +614,7 @@ void setDefaultValues() {
} else { } else {
updateChannel = "Nightly"; updateChannel = "Nightly";
} }
patchFile = "";
useSpecialPad = false; useSpecialPad = false;
specialPadClass = 1; specialPadClass = 1;
isDebugDump = false; isDebugDump = false;

View File

@ -10,6 +10,7 @@
namespace Config { namespace Config {
void load(const std::filesystem::path& path); void load(const std::filesystem::path& path);
void save(const std::filesystem::path& path); void save(const std::filesystem::path& path);
void loadArgs(int& argc, char* argv[]);
bool isNeoMode(); bool isNeoMode();
bool isFullscreenMode(); bool isFullscreenMode();
@ -20,6 +21,7 @@ std::string getLogFilter();
std::string getLogType(); std::string getLogType();
std::string getUserName(); std::string getUserName();
std::string getUpdateChannel(); std::string getUpdateChannel();
std::string getPatchFile();
bool getUseSpecialPad(); bool getUseSpecialPad();
int getSpecialPadClass(); int getSpecialPadClass();
@ -54,6 +56,7 @@ void setLanguage(u32 language);
void setNeoMode(bool enable); void setNeoMode(bool enable);
void setUserName(const std::string& type); void setUserName(const std::string& type);
void setUpdateChannel(const std::string& type); void setUpdateChannel(const std::string& type);
void setPatchFile(const std::string& fileName);
void setUseSpecialPad(bool use); void setUseSpecialPad(bool use);
void setSpecialPadClass(int type); void setSpecialPadClass(int type);

View File

@ -220,6 +220,14 @@ void Emulator::Run(const std::filesystem::path& file) {
std::exit(0); std::exit(0);
} }
void Emulator::Run(int& argc, char* argv[]) {
//Load config options from arguments
Config::loadArgs(argc, argv);
MemoryPatcher::patchFile = Config::getPatchFile();
this->Run(argv[1]);
}
void Emulator::LoadSystemModules(const std::filesystem::path& file) { void Emulator::LoadSystemModules(const std::filesystem::path& file) {
constexpr std::array<SysModules, 13> ModulesToLoad{ constexpr std::array<SysModules, 13> ModulesToLoad{
{{"libSceNgs2.sprx", &Libraries::Ngs2::RegisterlibSceNgs2}, {{"libSceNgs2.sprx", &Libraries::Ngs2::RegisterlibSceNgs2},

View File

@ -26,6 +26,7 @@ public:
~Emulator(); ~Emulator();
void Run(const std::filesystem::path& file); void Run(const std::filesystem::path& file);
void Run(int& argc, char* argv[]);
private: private:
void LoadSystemModules(const std::filesystem::path& file); void LoadSystemModules(const std::filesystem::path& file);

View File

@ -2,7 +2,6 @@
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
#include <fmt/core.h> #include <fmt/core.h>
#include "common/memory_patcher.h"
#include "emulator.h" #include "emulator.h"
#ifdef _WIN32 #ifdef _WIN32
@ -24,16 +23,8 @@ int main(int argc, char* argv[]) {
return -1; return -1;
} }
for (int i = 0; i < argc; i++) {
std::string curArg = argv[i];
if (curArg == "-p") {
std::string patchFile = argv[i + 1];
MemoryPatcher::patchFile = patchFile;
}
}
Core::Emulator emulator; Core::Emulator emulator;
emulator.Run(argv[1]); emulator.Run(argc, argv);
return 0; return 0;
} }

View File

@ -2,7 +2,6 @@
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
#include "common/config.h" #include "common/config.h"
#include "common/memory_patcher.h"
#include "core/file_sys/fs.h" #include "core/file_sys/fs.h"
#include "emulator.h" #include "emulator.h"
#include "game_install_dialog.h" #include "game_install_dialog.h"
@ -45,14 +44,7 @@ int main(int argc, char* argv[]) {
// Check for command line arguments // Check for command line arguments
if (has_command_line_argument) { if (has_command_line_argument) {
Core::Emulator emulator; Core::Emulator emulator;
for (int i = 0; i < argc; i++) { emulator.Run(argc, argv);
std::string curArg = argv[i];
if (curArg == "-p") {
std::string patchFile = argv[i + 1];
MemoryPatcher::patchFile = patchFile;
}
}
emulator.Run(argv[1]);
} }
// Run the Qt application // Run the Qt application