shadPS4/src/common/config.cpp

458 lines
13 KiB
C++

#include "config.h"
#include <filesystem>
#include <iostream>
using namespace Config;
Config::Configuration::Configuration() {
setDefaultValues();
}
Config::Configuration::Configuration(const std::filesystem::path& path) : Config::Configuration() {
load(path);
}
void Config::Configuration::load(const std::filesystem::path& path) {
// Validate that the incoming configuration file exists
std::error_code error;
if (!std::filesystem::exists(path, error)) {
save(path);
std::cerr << "file path (" << path << ") does not exist." << std::endl;
return;
}
// Attempt to parse the configuration data
try {
data = toml::parse(path);
} catch (std::exception& ex) {
std::cerr << "got exception: " << ex.what() << std::endl;
return;
}
}
void Config::Configuration::save(const std::filesystem::path& path) {
std::error_code error;
if (std::filesystem::exists(path, error)) {
try {
data = toml::parse(path);
} catch (const std::exception& ex) {
return;
}
} else {
if (error) {
}
std::cout << "saving new configuration file (" << path << ")." << std::endl;
}
std::ofstream saveFile(path, std::ios::out);
saveFile << data;
saveFile.close();
}
bool Configuration::configVersionDifference(const std::filesystem::path& path) {
// Validate that the incoming configuration file exists
std::error_code error;
if (!std::filesystem::exists(path, error)) {
std::cerr << "file path (" << path << ") does not exist." << std::endl;
return true;
}
// Attempt to parse the configuration data
toml::value oldConfigData;
try {
oldConfigData = toml::parse(path);
} catch (std::exception& ex) {
std::cerr << "got exception: " << ex.what() << std::endl;
return true;
}
// Iterate checking for new entries that do not exist in the provided config
for (auto& item : c_defaultConfig) {
// Get the key name
auto& defaultFirst = item.first;
auto& defaultSecond = item.second;
std::cout << "checking for key (" << defaultFirst << ") in old config." << std::endl;
// Check to see if the old configuration contains the key provided
if (oldConfigData.contains(defaultFirst)) {
std::cout << "checking (" << defaultFirst.c_str() << ") type (" << defaultSecond.type()
<< " = " << oldConfigData[defaultFirst].type() << ")" << std::endl;
// Check to see that the types match for the second
if (oldConfigData[defaultFirst].type() != defaultSecond.type()) {
std::cout << "mismatch type found!" << std::endl;
return true;
}
} else // If the key does not exist in the old config but exists in the new, mark difference
{
std::cout << "key (" << defaultFirst << ") is not found in old config." << std::endl;
return true;
}
auto& oldConfigSecond = oldConfigData[defaultFirst];
// If there is a nested table, check the sub-entries
if (defaultSecond.is_table()) {
toml::table secondTable = defaultSecond.as_table();
for (auto& tableItemPair : secondTable) {
auto& secondItemFirst = tableItemPair.first;
auto& secondItemSecond = tableItemPair.second;
std::cout << "checking for key (" << secondItemFirst << ") in old config."
<< std::endl;
if (oldConfigSecond.contains(secondItemFirst)) {
std::cout << "checking (" << secondItemFirst.c_str() << ") type ("
<< secondItemSecond.type() << " = "
<< oldConfigSecond[secondItemFirst].type() << ")" << std::endl;
// Check for type match
if (oldConfigSecond[secondItemFirst].type() != secondItemSecond.type()) {
std::cout << "mismatch type found!" << std::endl;
return true;
}
} else {
std::cout << "key (" << secondItemFirst << ") is not found in old config."
<< std::endl;
return true;
}
}
}
}
return false;
}
bool Config::Configuration::isNeoMode() {
return getValue<bool>("General", "isPS4Pro");
}
void Config::Configuration::setNeoMode(bool enable) {
setValue("General", "isPS4Pro", enable);
}
bool Config::Configuration::isFullscreenMode() {
return getValue<bool>("General", "Fullscreen");
}
void Config::Configuration::setFullscreenMode(bool enable) {
setValue("General", "Fullscreen", enable);
}
std::string Config::Configuration::getLogFilter() {
return getValue<std::string>("General", "logFilter");
}
void Config::Configuration::setLogFilter(const std::string& type) {
setValue("General", "logFilter", type);
}
std::string Config::Configuration::getLogType() {
return getValue<std::string>("General", "logType");
}
void Config::Configuration::setLogType(const std::string& type) {
setValue("General", "logType", type);
}
std::string Config::Configuration::getUserName() {
return getValue<std::string>("General", "userName");
}
void Config::Configuration::setUserName(const std::string& type) {
setValue("General", "userName", type);
}
bool Config::Configuration::showSplash() {
return getValue<bool>("General", "showSplash");
}
void Config::Configuration::setShowSplash(bool enable) {
return setValue("General", "showSplash", enable);
}
bool Config::Configuration::getUseSpecialPad() {
return getValue<bool>("General", "useSpecialPad");
}
void Config::Configuration::setUseSpecialPad(bool use) {
setValue("General", "useSpecialPad", use);
}
int Config::Configuration::getSpecialPadClass() {
return getValue<int>("General", "specialPadClass");
}
void Config::Configuration::setSpecialPadClass(int type) {
setValue("General", "specialPadClass", type);
}
u32 Config::Configuration::getScreenWidth() {
return getValue<uint32_t>("General", "screenWidth");
}
void Config::Configuration::setScreenWidth(u32 width) {
setValue("General", "screenWidth", width);
}
u32 Config::Configuration::getScreenHeight() {
return getValue<uint32_t>("General", "screenHeight");
}
void Config::Configuration::setScreenHeight(u32 height) {
setValue("General", "screenHeight", height);
}
bool Config::Configuration::nullGpu() {
return getValue<bool>("General", "nullGpu");
}
void Config::Configuration::setNullGpu(bool enable) {
setValue("General", "nullGpu", enable);
}
bool Config::Configuration::copyGPUCmdBuffers() {
return getValue<bool>("General", "copyGPUBuffers");
}
void Config::Configuration::setCopyGPUCmdBuffers(bool enable) {
setValue("General", "copyGPUBuffers", enable);
}
bool Config::Configuration::dumpShaders() {
return getValue<bool>("General", "dumpShaders");
}
void Config::Configuration::setDumpShaders(bool enable) {
setValue("General", "dumpShader", enable);
}
bool Config::Configuration::dumpPM4() {
return getValue<bool>("General", "dumpPM4");
}
void Config::Configuration::setDumpPM4(bool enable) {
setValue("General", "dumpPM4", enable);
}
u32 Config::Configuration::vblankDiv() {
return getValue<u32>("General", "vblankDivider");
}
void Config::Configuration::setVblankDiv(u32 value) {
setValue("General", "vblankDivider", value);
}
s32 Config::Configuration::getGpuId() {
return getValue<s32>("Vulkan", "gpuId");
}
void Config::Configuration::setGpuId(s32 selectedGpuId) {
setValue("Vulkan", "gpuId", selectedGpuId);
}
bool Config::Configuration::vkValidationEnabled() {
return getValue<bool>("Vulkan", "validation");
}
void Config::Configuration::setVkValidation(bool enable) {
setValue("Vulkan", "validation", enable);
}
bool Config::Configuration::vkValidationSyncEnabled() {
return getValue<bool>("Vulkan", "validationSync");
}
void Config::Configuration::setVkSyncValidation(bool enable) {
setValue("Vulkan", "validationSync", enable);
}
bool Config::Configuration::vkValidationGpuEnabled() {
return getValue<bool>("Vulkan", "validationGpu");
}
void Config::Configuration::setVkValidationGpuEnabled(bool enable) {
setValue("Vulkan", "validationGpu", enable);
}
bool Config::Configuration::isRdocEnabled() {
return getValue<bool>("Vulkan", "rdocEnable");
}
void Config::Configuration::setRdocEnabled(bool enable) {
setValue("Vulkan", "rdocEnable", enable);
}
bool Config::Configuration::isMarkersEnabled() {
return getValue<bool>("Vulkan", "rdocMarkersEnable");
}
void Config::Configuration::setIsMarkersEnabled(bool enable) {
setValue("Vulkan", "rdocMarkersEnable", enable);
}
bool Config::Configuration::debugDump() {
return getValue<bool>("Vulkan", "debugDump");
}
void Config::Configuration::setDebugDump(bool enable) {
setValue("Vulkan", "debugDump", enable);
}
u32 Config::Configuration::getMainWindowTheme() {
return getValue<u32>("GUI", "theme");
}
void Config::Configuration::setMainWindowTheme(u32 theme) {
setValue("GUI", "theme", theme);
}
u32 Config::Configuration::getIconSize() {
return getValue<u32>("GUI", "iconSize");
}
void Config::Configuration::setIconSize(u32 size) {
setValue("GUI", "iconSize", size);
}
u32 Config::Configuration::getIconSizeGrid() {
return getValue<u32>("GUI", "iconSizeGrid");
}
void Config::Configuration::setIconSizeGrid(u32 size) {
setValue("GUI", "iconSizeGrid", size);
}
u32 Config::Configuration::getSliderPosition() {
return getValue<u32>("GUI", "sliderPos");
}
void Config::Configuration::setSliderPosition(u32 pos) {
setValue("GUI", "sliderPos", pos);
}
u32 Config::Configuration::getSliderPositionGrid() {
return getValue<u32>("GUI", "sliderPosGrid");
}
void Config::Configuration::setSliderPositionGrid(u32 pos) {
setValue("GUI", "sliderPosGrid", pos);
}
u32 Config::Configuration::getTableMode() {
return getValue<u32>("GUI", "gameTableMode");
}
void Config::Configuration::setTableMode(u32 mode) {
setValue("GUI", "gameTableMode", mode);
}
u32 Config::Configuration::getMainWindowWidth() {
return getValue<u32>("GUI", "mwWidth");
}
void Config::Configuration::setMainWindowWidth(u32 width) {
setValue("GUI", "mwWidth", width);
}
u32 Config::Configuration::getMainWindowHeight() {
return getValue<u32>("GUI", "mwHeight");
}
void Config::Configuration::setMainWindowHeight(u32 height) {
setValue("GUI", "mwHeight", height);
}
std::string Config::Configuration::getGameInstallDir() {
return getValue<std::string>("GUI", "installDir");
}
void Config::Configuration::setGameInstallDir(const std::string& dir) {
setValue("GUI", "installDir", dir);
}
u32 Config::Configuration::getMainWindowGeometryX() {
return getValue<u32>("GUI", "geometryX");
}
u32 Config::Configuration::getMainWindowGeometryY() {
return getValue<u32>("GUI", "geometryY");
}
u32 Config::Configuration::getMainWindowGeometryW() {
return getValue<u32>("GUI", "geometryW");
}
u32 Config::Configuration::getMainWindowGeometryH() {
return getValue<u32>("GUI", "geometryH");
}
void Config::Configuration::setMainWindowGeometry(u32 x, u32 y, u32 w, u32 h) {
setValue("GUI", "geometryX", x);
setValue("GUI", "geometryY", y);
setValue("GUI", "geometryW", w);
setValue("GUI", "geometryH", h);
}
std::vector<std::string> Config::Configuration::getPkgViewer() {
if (!data.contains("GUI"))
return std::vector<std::string>();
auto& gui = data["GUI"];
return toml::find_or<std::vector<std::string>>(gui, "pkgDirs", {});
}
void Config::Configuration::setPkgViewer(const std::vector<std::string>& pkgList) {
data["GUI"]["pkgDirs"] = pkgList;
}
std::vector<std::string> Config::Configuration::getElfViewer() {
if (!data.contains("GUI"))
return std::vector<std::string>();
auto& gui = data["GUI"];
return toml::find_or<std::vector<std::string>>(gui, "elfDirs", {});
}
void Config::Configuration::setElfViewer(const std::vector<std::string>& elfList) {
data["GUI"]["elfDirs"] = elfList;
}
std::vector<std::string> Config::Configuration::getRecentFiles() {
if (!data.contains("GUI"))
return std::vector<std::string>();
auto& gui = data["GUI"];
return toml::find_or<std::vector<std::string>>(gui, "recentFiles", {});
}
void Config::Configuration::setRecentFiles(const std::vector<std::string>& recentFiles) {
data["GUI"]["recentFiles"] = recentFiles;
}
std::string Config::Configuration::getEmulatorLanguage() {
return getValue<std::string>("GUI", "emulatorLanguage");
}
void Config::Configuration::setEmulatorLanguage(std::string language) {
setValue("GUI", "emulatorLanguage", language);
}
u32 Config::Configuration::getConsoleLanguage() {
return getValue<u32>("Settings", "consoleLanauge");
}
void Config::Configuration::setLanguage(u32 language) {
setValue("Settings", "consoleLanauge", language);
}
void Config::Configuration::setDefaultValues() {
data = toml::table(c_defaultConfig);
}