#include "config.h" #include #include 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("General", "isPS4Pro"); } void Config::Configuration::setNeoMode(bool enable) { setValue("General", "isPS4Pro", enable); } bool Config::Configuration::isFullscreenMode() { return getValue("General", "Fullscreen"); } void Config::Configuration::setFullscreenMode(bool enable) { setValue("General", "Fullscreen", enable); } std::string Config::Configuration::getLogFilter() { return getValue("General", "logFilter"); } void Config::Configuration::setLogFilter(const std::string& type) { setValue("General", "logFilter", type); } std::string Config::Configuration::getLogType() { return getValue("General", "logType"); } void Config::Configuration::setLogType(const std::string& type) { setValue("General", "logType", type); } std::string Config::Configuration::getUserName() { return getValue("General", "userName"); } void Config::Configuration::setUserName(const std::string& type) { setValue("General", "userName", type); } bool Config::Configuration::showSplash() { return getValue("General", "showSplash"); } void Config::Configuration::setShowSplash(bool enable) { return setValue("General", "showSplash", enable); } bool Config::Configuration::getUseSpecialPad() { return getValue("General", "useSpecialPad"); } void Config::Configuration::setUseSpecialPad(bool use) { setValue("General", "useSpecialPad", use); } int Config::Configuration::getSpecialPadClass() { return getValue("General", "specialPadClass"); } void Config::Configuration::setSpecialPadClass(int type) { setValue("General", "specialPadClass", type); } u32 Config::Configuration::getScreenWidth() { return getValue("General", "screenWidth"); } void Config::Configuration::setScreenWidth(u32 width) { setValue("General", "screenWidth", width); } u32 Config::Configuration::getScreenHeight() { return getValue("General", "screenHeight"); } void Config::Configuration::setScreenHeight(u32 height) { setValue("General", "screenHeight", height); } bool Config::Configuration::nullGpu() { return getValue("General", "nullGpu"); } void Config::Configuration::setNullGpu(bool enable) { setValue("General", "nullGpu", enable); } bool Config::Configuration::copyGPUCmdBuffers() { return getValue("General", "copyGPUBuffers"); } void Config::Configuration::setCopyGPUCmdBuffers(bool enable) { setValue("General", "copyGPUBuffers", enable); } bool Config::Configuration::dumpShaders() { return getValue("General", "dumpShaders"); } void Config::Configuration::setDumpShaders(bool enable) { setValue("General", "dumpShader", enable); } bool Config::Configuration::dumpPM4() { return getValue("General", "dumpPM4"); } void Config::Configuration::setDumpPM4(bool enable) { setValue("General", "dumpPM4", enable); } u32 Config::Configuration::vblankDiv() { return getValue("General", "vblankDivider"); } void Config::Configuration::setVblankDiv(u32 value) { setValue("General", "vblankDivider", value); } s32 Config::Configuration::getGpuId() { return getValue("Vulkan", "gpuId"); } void Config::Configuration::setGpuId(s32 selectedGpuId) { setValue("Vulkan", "gpuId", selectedGpuId); } bool Config::Configuration::vkValidationEnabled() { return getValue("Vulkan", "validation"); } void Config::Configuration::setVkValidation(bool enable) { setValue("Vulkan", "validation", enable); } bool Config::Configuration::vkValidationSyncEnabled() { return getValue("Vulkan", "validationSync"); } void Config::Configuration::setVkSyncValidation(bool enable) { setValue("Vulkan", "validationSync", enable); } bool Config::Configuration::vkValidationGpuEnabled() { return getValue("Vulkan", "validationGpu"); } void Config::Configuration::setVkValidationGpuEnabled(bool enable) { setValue("Vulkan", "validationGpu", enable); } bool Config::Configuration::isRdocEnabled() { return getValue("Vulkan", "rdocEnable"); } void Config::Configuration::setRdocEnabled(bool enable) { setValue("Vulkan", "rdocEnable", enable); } bool Config::Configuration::isMarkersEnabled() { return getValue("Vulkan", "rdocMarkersEnable"); } void Config::Configuration::setIsMarkersEnabled(bool enable) { setValue("Vulkan", "rdocMarkersEnable", enable); } bool Config::Configuration::debugDump() { return getValue("Vulkan", "debugDump"); } void Config::Configuration::setDebugDump(bool enable) { setValue("Vulkan", "debugDump", enable); } u32 Config::Configuration::getMainWindowTheme() { return getValue("GUI", "theme"); } void Config::Configuration::setMainWindowTheme(u32 theme) { setValue("GUI", "theme", theme); } u32 Config::Configuration::getIconSize() { return getValue("GUI", "iconSize"); } void Config::Configuration::setIconSize(u32 size) { setValue("GUI", "iconSize", size); } u32 Config::Configuration::getIconSizeGrid() { return getValue("GUI", "iconSizeGrid"); } void Config::Configuration::setIconSizeGrid(u32 size) { setValue("GUI", "iconSizeGrid", size); } u32 Config::Configuration::getSliderPosition() { return getValue("GUI", "sliderPos"); } void Config::Configuration::setSliderPosition(u32 pos) { setValue("GUI", "sliderPos", pos); } u32 Config::Configuration::getSliderPositionGrid() { return getValue("GUI", "sliderPosGrid"); } void Config::Configuration::setSliderPositionGrid(u32 pos) { setValue("GUI", "sliderPosGrid", pos); } u32 Config::Configuration::getTableMode() { return getValue("GUI", "gameTableMode"); } void Config::Configuration::setTableMode(u32 mode) { setValue("GUI", "gameTableMode", mode); } u32 Config::Configuration::getMainWindowWidth() { return getValue("GUI", "mwWidth"); } void Config::Configuration::setMainWindowWidth(u32 width) { setValue("GUI", "mwWidth", width); } u32 Config::Configuration::getMainWindowHeight() { return getValue("GUI", "mwHeight"); } void Config::Configuration::setMainWindowHeight(u32 height) { setValue("GUI", "mwHeight", height); } std::string Config::Configuration::getGameInstallDir() { return getValue("GUI", "installDir"); } void Config::Configuration::setGameInstallDir(const std::string& dir) { setValue("GUI", "installDir", dir); } u32 Config::Configuration::getMainWindowGeometryX() { return getValue("GUI", "geometryX"); } u32 Config::Configuration::getMainWindowGeometryY() { return getValue("GUI", "geometryY"); } u32 Config::Configuration::getMainWindowGeometryW() { return getValue("GUI", "geometryW"); } u32 Config::Configuration::getMainWindowGeometryH() { return getValue("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 Config::Configuration::getPkgViewer() { if (!data.contains("GUI")) return std::vector(); auto& gui = data["GUI"]; return toml::find_or>(gui, "pkgDirs", {}); } void Config::Configuration::setPkgViewer(const std::vector& pkgList) { data["GUI"]["pkgDirs"] = pkgList; } std::vector Config::Configuration::getElfViewer() { if (!data.contains("GUI")) return std::vector(); auto& gui = data["GUI"]; return toml::find_or>(gui, "elfDirs", {}); } void Config::Configuration::setElfViewer(const std::vector& elfList) { data["GUI"]["elfDirs"] = elfList; } std::vector Config::Configuration::getRecentFiles() { if (!data.contains("GUI")) return std::vector(); auto& gui = data["GUI"]; return toml::find_or>(gui, "recentFiles", {}); } void Config::Configuration::setRecentFiles(const std::vector& recentFiles) { data["GUI"]["recentFiles"] = recentFiles; } std::string Config::Configuration::getEmulatorLanguage() { return getValue("GUI", "emulatorLanguage"); } void Config::Configuration::setEmulatorLanguage(std::string language) { setValue("GUI", "emulatorLanguage", language); } u32 Config::Configuration::getConsoleLanguage() { return getValue("Settings", "consoleLanauge"); } void Config::Configuration::setLanguage(u32 language) { setValue("Settings", "consoleLanauge", language); } void Config::Configuration::setDefaultValues() { data = toml::table(c_defaultConfig); }