mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-04-21 20:14:45 +00:00
Push updated config
Add ConfigsDir to PathType Add create_path call for the new Configs directory
This commit is contained in:
parent
411449cd51
commit
a89f87409f
6 changed files with 1298 additions and 489 deletions
File diff suppressed because it is too large
Load diff
|
@ -2,12 +2,334 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "types.h"
|
||||
|
||||
#include <fmt/core.h>
|
||||
#include <toml.hpp>
|
||||
|
||||
#include "common/path_util.h"
|
||||
|
||||
#define u32 uint32_t
|
||||
#define s32 int32_t
|
||||
|
||||
namespace Config {
|
||||
// Name of the global configuration
|
||||
static std::string c_globalTitleId = "config";
|
||||
static std::string c_configExtension = ".toml";
|
||||
|
||||
class Configuration;
|
||||
|
||||
class ConfigManager {
|
||||
private:
|
||||
// This is the map of title id <-> configuraation
|
||||
std::map<std::string, std::shared_ptr<Config::Configuration>> configurations;
|
||||
std::string currentTitleId = c_globalTitleId;
|
||||
|
||||
// ConfigManager() = default;
|
||||
// virtual ~ConfigManager() = default;
|
||||
|
||||
public:
|
||||
void loadConfigurations();
|
||||
|
||||
void setCurrentConfigId(std::string titleId);
|
||||
|
||||
void setDefaultConfigId();
|
||||
|
||||
const std::string getCurrentConfigId();
|
||||
|
||||
std::shared_ptr<Config::Configuration> getCurrentConfig();
|
||||
};
|
||||
|
||||
class Configuration {
|
||||
private:
|
||||
const toml::table c_defaultConfig = {
|
||||
{"titleId", c_globalTitleId},
|
||||
{"General",
|
||||
toml::table{
|
||||
{"isPS4Pro", false},
|
||||
{"Fullscreen", false},
|
||||
{"logFilter", ""},
|
||||
{"logType", "async"},
|
||||
{"userName", "shadPS4"},
|
||||
{"showSplash", false},
|
||||
{"useSpecialPad", false},
|
||||
{"specialPadClass", 1},
|
||||
{"screenWidth", 1280},
|
||||
{"screenHeight", 720},
|
||||
{"nullGpu", false},
|
||||
{"copyGPUBuffers", false},
|
||||
{"dumpShaders", false},
|
||||
{"dumpPM4", false},
|
||||
{"vblankDivider", 1},
|
||||
}},
|
||||
{
|
||||
"Vulkan",
|
||||
toml::table{
|
||||
{"gpuId", (-1)},
|
||||
{"validation", false},
|
||||
{"validationSync", false}, // Breaking change
|
||||
{"validationGpu", false}, // Breaking change
|
||||
{"rdocEnable", false},
|
||||
{"rdocMarkersEnable", false},
|
||||
{"debugDump", false}, // Breaking change
|
||||
{"crashDiagnostic", false},
|
||||
},
|
||||
},
|
||||
{
|
||||
"GUI",
|
||||
toml::table{{"theme", 0},
|
||||
{"iconSize", 36},
|
||||
{"iconSizeGrid", 69},
|
||||
{"sliderPos", 0},
|
||||
{"sliderPosGrid", 0},
|
||||
{"gameTableMode", 0},
|
||||
{"mwWidth", 1280}, // Breaking change
|
||||
{"mwHeight", 720}, // Breaking change
|
||||
{"installDir", ""},
|
||||
{"geometryX", 400}, // Breaking change
|
||||
{"geometryY", 400}, // Breaking change
|
||||
{"geometryW", 1280}, // Breaking change
|
||||
{"geometryH", 720}, // Breaking change
|
||||
{"pkgDirs", toml::array{}},
|
||||
{"elfDirs", toml::array{}},
|
||||
{"recentFiles", toml::array{}},
|
||||
{"emulatorLanguage", "en"}},
|
||||
},
|
||||
{
|
||||
"Settings",
|
||||
toml::table{{"consoleLanguage", 1}},
|
||||
},
|
||||
};
|
||||
|
||||
protected:
|
||||
// Title id of the game, or "global" for global settings
|
||||
std::string titleId;
|
||||
|
||||
// Toml data, do not modify this directly
|
||||
toml::value data;
|
||||
|
||||
public:
|
||||
/// <summary>
|
||||
/// Create a new configuration with defaults
|
||||
/// </summary>
|
||||
Configuration();
|
||||
|
||||
/// <summary>
|
||||
/// Load configuration from file path
|
||||
/// </summary>
|
||||
/// <param name="path">Path of configuration file</param>
|
||||
Configuration(const std::filesystem::path& path);
|
||||
|
||||
/// <summary>
|
||||
/// Loads a configuration from file path
|
||||
/// </summary>
|
||||
/// <param name="path">Path of configuration file</param>
|
||||
void load(const std::filesystem::path& path);
|
||||
|
||||
/// <summary>
|
||||
/// Saves a configuration to file path
|
||||
/// </summary>
|
||||
/// <param name="path">Path of configuration file</param>
|
||||
void save(const std::filesystem::path& path);
|
||||
|
||||
/// <summary>
|
||||
/// This function will iterate through all of the section and entries in the default
|
||||
/// configuration
|
||||
///
|
||||
/// It will check to make sure that all of the categories, and keys match in both name and type
|
||||
/// </summary>
|
||||
/// <param name="path">Path of configuration file to check</param>
|
||||
/// <returns>True if there is a structural difference in config files, false if no
|
||||
/// difference</returns>
|
||||
bool configVersionDifference(const std::filesystem::path& path);
|
||||
|
||||
template <typename T>
|
||||
T getValue(const char* category, const char* key) {
|
||||
// Debug logging for profiling
|
||||
fmt::print("DBG: getValue ({}) ({})\n", category, key);
|
||||
|
||||
if (!c_defaultConfig.contains(category))
|
||||
return T();
|
||||
|
||||
const toml::value& defaultGeneral = c_defaultConfig.at(category);
|
||||
|
||||
auto defaultValue = toml::find_or<T>(defaultGeneral, key, T());
|
||||
|
||||
if (data.contains(category)) {
|
||||
const toml::value& general = data.at(category);
|
||||
|
||||
return toml::find_or<T>(general, key, defaultValue);
|
||||
}
|
||||
|
||||
return T();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void setValue(const char* category, const char* key, T value) {
|
||||
if (!data.contains(category))
|
||||
return;
|
||||
|
||||
auto& dataCategory = data[category];
|
||||
|
||||
if (!dataCategory.contains(key))
|
||||
return;
|
||||
|
||||
data[category][key] = value;
|
||||
}
|
||||
|
||||
/*
|
||||
* Alright, making some changes here, first is keeping the
|
||||
* default config and the C++ functions in the same order
|
||||
*/
|
||||
|
||||
const std::string& getTitleId() const;
|
||||
|
||||
#pragma region General settings
|
||||
bool isNeoMode();
|
||||
void setNeoMode(bool enable);
|
||||
|
||||
bool isFullscreenMode();
|
||||
void setFullscreenMode(bool enable);
|
||||
|
||||
std::string getLogFilter();
|
||||
void setLogFilter(const std::string& type);
|
||||
|
||||
std::string getLogType();
|
||||
void setLogType(const std::string& type);
|
||||
|
||||
std::string getUserName();
|
||||
void setUserName(const std::string& type);
|
||||
|
||||
bool showSplash();
|
||||
void setShowSplash(bool enable);
|
||||
|
||||
bool getUseSpecialPad();
|
||||
void setUseSpecialPad(bool use);
|
||||
|
||||
int getSpecialPadClass();
|
||||
void setSpecialPadClass(int type);
|
||||
|
||||
u32 getScreenWidth();
|
||||
void setScreenWidth(u32 width);
|
||||
|
||||
u32 getScreenHeight();
|
||||
void setScreenHeight(u32 height);
|
||||
|
||||
bool nullGpu();
|
||||
void setNullGpu(bool enable);
|
||||
|
||||
bool copyGPUCmdBuffers();
|
||||
void setCopyGPUCmdBuffers(bool enable);
|
||||
|
||||
bool dumpShaders();
|
||||
void setDumpShaders(bool enable);
|
||||
|
||||
bool dumpPM4();
|
||||
void setDumpPM4(bool enable);
|
||||
|
||||
u32 vblankDiv();
|
||||
void setVblankDiv(u32 value);
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Vulkan settings
|
||||
s32 getGpuId();
|
||||
void setGpuId(s32 selectedGpuId);
|
||||
|
||||
bool vkValidationEnabled();
|
||||
void setVkValidation(bool enable);
|
||||
|
||||
bool vkValidationSyncEnabled();
|
||||
void setVkSyncValidation(bool enable);
|
||||
|
||||
bool vkValidationGpuEnabled();
|
||||
void setVkValidationGpuEnabled(bool enable);
|
||||
|
||||
bool isRdocEnabled();
|
||||
void setRdocEnabled(bool enable);
|
||||
|
||||
bool vkMarkersEnabled();
|
||||
void setVkMarkersEnabled(bool enable);
|
||||
|
||||
bool debugDump();
|
||||
void setDebugDump(bool enable);
|
||||
|
||||
bool vkCrashDiagnostic();
|
||||
void setVkCrashDiagnostic(bool enable);
|
||||
#pragma endregion
|
||||
|
||||
#pragma region GUI settings
|
||||
u32 getMainWindowTheme();
|
||||
void setMainWindowTheme(u32 theme);
|
||||
|
||||
u32 getIconSize();
|
||||
void setIconSize(u32 size);
|
||||
|
||||
u32 getIconSizeGrid();
|
||||
void setIconSizeGrid(u32 size);
|
||||
|
||||
u32 getSliderPosition();
|
||||
void setSliderPosition(u32 pos);
|
||||
|
||||
u32 getSliderPositionGrid();
|
||||
void setSliderPositionGrid(u32 pos);
|
||||
|
||||
u32 getTableMode();
|
||||
void setTableMode(u32 mode);
|
||||
|
||||
u32 getMainWindowWidth();
|
||||
void setMainWindowWidth(u32 width);
|
||||
|
||||
u32 getMainWindowHeight();
|
||||
void setMainWindowHeight(u32 height);
|
||||
|
||||
std::string getGameInstallDir();
|
||||
void setGameInstallDir(const std::string& dir);
|
||||
|
||||
u32 getMainWindowGeometryX();
|
||||
u32 getMainWindowGeometryY();
|
||||
u32 getMainWindowGeometryW();
|
||||
u32 getMainWindowGeometryH();
|
||||
void setMainWindowGeometry(u32 x, u32 y, u32 w, u32 h);
|
||||
|
||||
std::vector<std::string> getPkgViewer();
|
||||
void setPkgViewer(const std::vector<std::string>& pkgList);
|
||||
|
||||
std::vector<std::string> getElfViewer();
|
||||
void setElfViewer(const std::vector<std::string>& elfList);
|
||||
|
||||
std::vector<std::string> getRecentFiles();
|
||||
void setRecentFiles(const std::vector<std::string>& recentFiles);
|
||||
|
||||
std::string getEmulatorLanguage();
|
||||
void setEmulatorLanguage(std::string language);
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Console settings
|
||||
u32 getConsoleLanguage();
|
||||
void setLanguage(u32 language);
|
||||
#pragma endregion
|
||||
|
||||
/// <summary>
|
||||
/// Sets the data to the default values
|
||||
/// </summary>
|
||||
void setDefaultValues();
|
||||
};
|
||||
|
||||
/*
|
||||
* ============================================================
|
||||
* THIS IS TO TEST FUNCTIONALITY, EVENTUALLY NUKE BELOW
|
||||
*
|
||||
* NOTE: For all of these should fall back on defaults in event config
|
||||
* manager is busted for whatever reason (which should not happen)
|
||||
* ============================================================
|
||||
*/
|
||||
void load(const std::filesystem::path& path);
|
||||
void save(const std::filesystem::path& path);
|
||||
|
||||
|
@ -31,6 +353,8 @@ bool copyGPUCmdBuffers();
|
|||
bool dumpShaders();
|
||||
bool dumpPM4();
|
||||
bool isRdocEnabled();
|
||||
bool vkMarkersEnabled();
|
||||
bool vkCrashDiagnosticEnabled();
|
||||
u32 vblankDiv();
|
||||
|
||||
void setDebugDump(bool enable);
|
||||
|
@ -61,8 +385,6 @@ void setRdocEnabled(bool enable);
|
|||
bool vkValidationEnabled();
|
||||
bool vkValidationSyncEnabled();
|
||||
bool vkValidationGpuEnabled();
|
||||
bool vkMarkersEnabled();
|
||||
bool vkCrashDiagnosticEnabled();
|
||||
|
||||
// Gui
|
||||
void setMainWindowGeometry(u32 x, u32 y, u32 w, u32 h);
|
||||
|
@ -102,4 +424,4 @@ void setDefaultValues();
|
|||
|
||||
// settings
|
||||
u32 GetLanguage();
|
||||
}; // namespace Config
|
||||
} // namespace Config
|
|
@ -117,6 +117,7 @@ static auto UserPaths = [] {
|
|||
create_path(PathType::PatchesDir, user_dir / PATCHES_DIR);
|
||||
create_path(PathType::AddonsDir, user_dir / ADDONS_DIR);
|
||||
create_path(PathType::MetaDataDir, user_dir / METADATA_DIR);
|
||||
create_path(PathType::ConfigsDir, user_dir / CONFIGS_DIR);
|
||||
|
||||
return paths;
|
||||
}();
|
||||
|
|
|
@ -24,6 +24,7 @@ enum class PathType {
|
|||
PatchesDir, // Where patches are stored.
|
||||
AddonsDir, // Where additional content is stored.
|
||||
MetaDataDir, // Where game metadata (e.g. trophies and menu backgrounds) is stored.
|
||||
ConfigsDir, // Where configuration files are stored.
|
||||
};
|
||||
|
||||
constexpr auto PORTABLE_DIR = "user";
|
||||
|
@ -42,7 +43,6 @@ constexpr auto CAPTURES_DIR = "captures";
|
|||
constexpr auto CHEATS_DIR = "cheats";
|
||||
constexpr auto PATCHES_DIR = "patches";
|
||||
constexpr auto ADDONS_DIR = "addcont";
|
||||
constexpr auto METADATA_DIR = "game_data";
|
||||
|
||||
// Filenames
|
||||
constexpr auto LOG_FILE = "shad_log.txt";
|
||||
|
|
|
@ -38,8 +38,8 @@ namespace Core {
|
|||
|
||||
Emulator::Emulator() {
|
||||
// Read configuration file.
|
||||
const auto config_dir = Common::FS::GetUserPath(Common::FS::PathType::UserDir);
|
||||
Config::load(config_dir / "config.toml");
|
||||
const auto configs_dir = Common::FS::GetUserPath(Common::FS::PathType::ConfigsDir);
|
||||
Config::load(configs_dir / "config.toml");
|
||||
|
||||
// Initialize NT API functions
|
||||
#ifdef _WIN32
|
||||
|
@ -77,8 +77,8 @@ Emulator::Emulator() {
|
|||
}
|
||||
|
||||
Emulator::~Emulator() {
|
||||
const auto config_dir = Common::FS::GetUserPath(Common::FS::PathType::UserDir);
|
||||
Config::save(config_dir / "config.toml");
|
||||
const auto configs_dir = Common::FS::GetUserPath(Common::FS::PathType::ConfigsDir);
|
||||
Config::save(configs_dir / "config.toml");
|
||||
}
|
||||
|
||||
void Emulator::Run(const std::filesystem::path& file) {
|
||||
|
|
|
@ -15,7 +15,9 @@ int main(int argc, char* argv[]) {
|
|||
|
||||
// Load configurations and initialize Qt application
|
||||
const auto user_dir = Common::FS::GetUserPath(Common::FS::PathType::UserDir);
|
||||
Config::load(user_dir / "config.toml");
|
||||
const auto configs_dir = Common::FS::GetUserPath(Common::FS::PathType::ConfigsDir);
|
||||
Config::load(configs_dir / "config.toml");
|
||||
std::filesystem::create_directory(user_dir / "game_data");
|
||||
|
||||
// Check if elf or eboot.bin path was passed as a command line argument
|
||||
bool has_command_line_argument = argc > 1;
|
||||
|
|
Loading…
Add table
Reference in a new issue