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 userName = "shadPS4";
static std::string updateChannel;
static std::string patchFile = "";
static bool useSpecialPad = false;
static int specialPadClass = 1;
static bool isDebugDump = false;
@ -123,6 +124,10 @@ std::string getUpdateChannel() {
return updateChannel;
}
std::string getPatchFile() {
return patchFile;
}
bool getUseSpecialPad() {
return useSpecialPad;
}
@ -275,6 +280,10 @@ void setUpdateChannel(const std::string& type) {
updateChannel = type;
}
void setPatchFile(const std::string& fileName) {
patchFile = fileName;
}
void setUseSpecialPad(bool use) {
useSpecialPad = use;
}
@ -435,6 +444,7 @@ void load(const std::filesystem::path& path) {
}
isShowSplash = toml::find_or<bool>(general, "showSplash", true);
isAutoUpdate = toml::find_or<bool>(general, "autoUpdate", false);
patchFile = toml::find_or<std::string>(general, "patchFile", "");
}
if (data.contains("Input")) {
@ -502,6 +512,18 @@ void load(const std::filesystem::path& path) {
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) {
toml::value data;
@ -533,6 +555,7 @@ void save(const std::filesystem::path& path) {
data["General"]["updateChannel"] = updateChannel;
data["General"]["showSplash"] = isShowSplash;
data["General"]["autoUpdate"] = isAutoUpdate;
data["General"]["patchFile"] = patchFile;
data["Input"]["useSpecialPad"] = useSpecialPad;
data["Input"]["specialPadClass"] = specialPadClass;
data["GPU"]["screenWidth"] = screenWidth;
@ -591,6 +614,7 @@ void setDefaultValues() {
} else {
updateChannel = "Nightly";
}
patchFile = "";
useSpecialPad = false;
specialPadClass = 1;
isDebugDump = false;

View File

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

View File

@ -220,6 +220,14 @@ void Emulator::Run(const std::filesystem::path& file) {
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) {
constexpr std::array<SysModules, 13> ModulesToLoad{
{{"libSceNgs2.sprx", &Libraries::Ngs2::RegisterlibSceNgs2},

View File

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

View File

@ -2,7 +2,6 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include <fmt/core.h>
#include "common/memory_patcher.h"
#include "emulator.h"
#ifdef _WIN32
@ -24,16 +23,8 @@ int main(int argc, char* argv[]) {
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;
emulator.Run(argv[1]);
emulator.Run(argc, argv);
return 0;
}

View File

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