2024-02-23 22:32:32 +01:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2023-08-14 19:17:01 +02:00
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
#include <string>
|
2023-10-26 22:29:05 +02:00
|
|
|
#include <fmt/core.h>
|
2023-11-05 12:22:18 +01:00
|
|
|
#include <toml.hpp>
|
2024-02-23 22:32:32 +01:00
|
|
|
#include "config.h"
|
2023-08-14 19:17:01 +02:00
|
|
|
|
|
|
|
namespace Config {
|
|
|
|
|
2024-05-27 00:07:46 +02:00
|
|
|
static bool isNeo = false;
|
|
|
|
static u32 screenWidth = 1280;
|
|
|
|
static u32 screenHeight = 720;
|
|
|
|
static s32 gpuId = -1; // Vulkan physical device index. Set to negative for auto select
|
|
|
|
static std::string logFilter;
|
|
|
|
static std::string logType = "sync";
|
|
|
|
static bool isDebugDump = false;
|
|
|
|
static bool isLibc = true;
|
|
|
|
static bool isShowSplash = false;
|
|
|
|
static bool isNullGpu = false;
|
|
|
|
static bool shouldDumpShaders = false;
|
2024-06-01 22:50:03 +02:00
|
|
|
static bool shouldDumpPM4 = false;
|
2024-06-07 09:12:43 +02:00
|
|
|
static bool vkValidation = false;
|
|
|
|
static bool vkValidationSync = false;
|
2023-08-14 19:17:01 +02:00
|
|
|
|
2024-03-25 08:26:59 +01:00
|
|
|
bool isLleLibc() {
|
|
|
|
return isLibc;
|
|
|
|
}
|
2024-02-23 21:57:57 +01:00
|
|
|
bool isNeoMode() {
|
|
|
|
return isNeo;
|
|
|
|
}
|
2024-02-27 23:10:34 +01:00
|
|
|
|
2024-02-23 21:57:57 +01:00
|
|
|
u32 getScreenWidth() {
|
|
|
|
return screenWidth;
|
|
|
|
}
|
2024-02-27 23:10:34 +01:00
|
|
|
|
2024-02-23 21:57:57 +01:00
|
|
|
u32 getScreenHeight() {
|
|
|
|
return screenHeight;
|
|
|
|
}
|
2024-02-27 23:10:34 +01:00
|
|
|
|
2024-04-29 23:19:12 +02:00
|
|
|
s32 getGpuId() {
|
2024-04-28 01:19:04 +02:00
|
|
|
return gpuId;
|
|
|
|
}
|
|
|
|
|
2024-02-27 23:10:34 +01:00
|
|
|
std::string getLogFilter() {
|
|
|
|
return logFilter;
|
2024-02-23 21:57:57 +01:00
|
|
|
}
|
2023-08-16 09:34:04 +02:00
|
|
|
|
2024-03-11 13:06:39 +01:00
|
|
|
std::string getLogType() {
|
|
|
|
return logType;
|
|
|
|
}
|
|
|
|
|
2024-03-11 12:26:33 +01:00
|
|
|
bool debugDump() {
|
|
|
|
return isDebugDump;
|
|
|
|
}
|
|
|
|
|
2024-05-16 15:58:14 +02:00
|
|
|
bool showSplash() {
|
|
|
|
return isShowSplash;
|
|
|
|
}
|
|
|
|
|
2024-05-22 20:19:42 +02:00
|
|
|
bool nullGpu() {
|
|
|
|
return isNullGpu;
|
|
|
|
}
|
|
|
|
|
2024-05-27 00:07:46 +02:00
|
|
|
bool dumpShaders() {
|
|
|
|
return shouldDumpShaders;
|
|
|
|
}
|
|
|
|
|
2024-06-01 22:50:03 +02:00
|
|
|
bool dumpPM4() {
|
|
|
|
return shouldDumpPM4;
|
|
|
|
}
|
|
|
|
|
2024-06-07 09:12:43 +02:00
|
|
|
bool vkValidationEnabled() {
|
|
|
|
return vkValidation;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool vkValidationSyncEnabled() {
|
|
|
|
return vkValidationSync;
|
|
|
|
}
|
|
|
|
|
2023-08-14 19:17:01 +02:00
|
|
|
void load(const std::filesystem::path& path) {
|
|
|
|
// If the configuration file does not exist, create it and return
|
|
|
|
std::error_code error;
|
|
|
|
if (!std::filesystem::exists(path, error)) {
|
|
|
|
save(path);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
toml::value data;
|
|
|
|
|
|
|
|
try {
|
|
|
|
data = toml::parse(path);
|
|
|
|
} catch (std::exception& ex) {
|
2023-10-26 22:29:05 +02:00
|
|
|
fmt::print("Got exception trying to load config file. Exception: {}\n", ex.what());
|
2023-08-14 19:17:01 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data.contains("General")) {
|
|
|
|
auto generalResult = toml::expect<toml::value>(data.at("General"));
|
|
|
|
if (generalResult.is_ok()) {
|
|
|
|
auto general = generalResult.unwrap();
|
|
|
|
|
|
|
|
isNeo = toml::find_or<toml::boolean>(general, "isPS4Pro", false);
|
2024-02-27 23:10:34 +01:00
|
|
|
logFilter = toml::find_or<toml::string>(general, "logFilter", "");
|
2024-03-11 13:06:39 +01:00
|
|
|
logType = toml::find_or<toml::string>(general, "logType", "sync");
|
2024-05-16 15:58:14 +02:00
|
|
|
isShowSplash = toml::find_or<toml::boolean>(general, "showSplash", true);
|
2023-08-16 09:34:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (data.contains("GPU")) {
|
2024-04-28 18:14:56 +02:00
|
|
|
auto gpuResult = toml::expect<toml::value>(data.at("GPU"));
|
|
|
|
if (gpuResult.is_ok()) {
|
|
|
|
auto gpu = gpuResult.unwrap();
|
2023-08-16 09:34:04 +02:00
|
|
|
|
2024-04-28 18:14:56 +02:00
|
|
|
screenWidth = toml::find_or<toml::integer>(gpu, "screenWidth", screenWidth);
|
|
|
|
screenHeight = toml::find_or<toml::integer>(gpu, "screenHeight", screenHeight);
|
|
|
|
gpuId = toml::find_or<toml::integer>(gpu, "gpuId", 0);
|
2024-05-22 20:19:42 +02:00
|
|
|
isNullGpu = toml::find_or<toml::boolean>(gpu, "nullGpu", false);
|
2024-05-27 00:07:46 +02:00
|
|
|
shouldDumpShaders = toml::find_or<toml::boolean>(gpu, "dumpShaders", false);
|
2024-06-01 22:50:03 +02:00
|
|
|
shouldDumpPM4 = toml::find_or<toml::boolean>(gpu, "dumpPM4", false);
|
2023-08-14 19:17:01 +02:00
|
|
|
}
|
|
|
|
}
|
2024-06-07 09:12:43 +02:00
|
|
|
if (data.contains("Vulkan")) {
|
|
|
|
const auto vkResult = toml::expect<toml::value>(data.at("Vulkan"));
|
|
|
|
if (vkResult.is_ok()) {
|
|
|
|
auto vk = vkResult.unwrap();
|
|
|
|
|
|
|
|
vkValidation = toml::find_or<toml::boolean>(vk, "validation", true);
|
|
|
|
vkValidationSync = toml::find_or<toml::boolean>(vk, "validation_sync", true);
|
|
|
|
}
|
|
|
|
}
|
2024-03-11 12:26:33 +01:00
|
|
|
if (data.contains("Debug")) {
|
|
|
|
auto debugResult = toml::expect<toml::value>(data.at("Debug"));
|
|
|
|
if (debugResult.is_ok()) {
|
|
|
|
auto debug = debugResult.unwrap();
|
|
|
|
|
|
|
|
isDebugDump = toml::find_or<toml::boolean>(debug, "DebugDump", false);
|
|
|
|
}
|
|
|
|
}
|
2024-03-25 08:26:59 +01:00
|
|
|
if (data.contains("LLE")) {
|
2024-03-27 07:41:14 +01:00
|
|
|
auto lleResult = toml::expect<toml::value>(data.at("LLE"));
|
|
|
|
if (lleResult.is_ok()) {
|
|
|
|
auto lle = lleResult.unwrap();
|
2024-03-25 08:26:59 +01:00
|
|
|
|
2024-03-27 07:41:14 +01:00
|
|
|
isLibc = toml::find_or<toml::boolean>(lle, "libc", true);
|
2024-03-25 08:26:59 +01:00
|
|
|
}
|
|
|
|
}
|
2023-08-14 19:17:01 +02:00
|
|
|
}
|
|
|
|
void save(const std::filesystem::path& path) {
|
|
|
|
toml::basic_value<toml::preserve_comments> data;
|
|
|
|
|
|
|
|
std::error_code error;
|
|
|
|
if (std::filesystem::exists(path, error)) {
|
|
|
|
try {
|
|
|
|
data = toml::parse<toml::preserve_comments>(path);
|
|
|
|
} catch (const std::exception& ex) {
|
2023-10-26 22:29:05 +02:00
|
|
|
fmt::print("Exception trying to parse config file. Exception: {}\n", ex.what());
|
2023-08-14 19:17:01 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (error) {
|
2024-02-23 21:57:57 +01:00
|
|
|
fmt::print("Filesystem error accessing {} (error: {})\n", path.string(),
|
|
|
|
error.message().c_str());
|
2023-08-14 19:17:01 +02:00
|
|
|
}
|
2023-10-26 22:29:05 +02:00
|
|
|
fmt::print("Saving new configuration file {}\n", path.string());
|
2023-08-14 19:17:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
data["General"]["isPS4Pro"] = isNeo;
|
2024-02-27 23:10:34 +01:00
|
|
|
data["General"]["logFilter"] = logFilter;
|
2024-03-11 13:06:39 +01:00
|
|
|
data["General"]["logType"] = logType;
|
2024-05-16 15:58:14 +02:00
|
|
|
data["General"]["showSplash"] = isShowSplash;
|
2024-04-28 01:19:04 +02:00
|
|
|
data["GPU"]["gpuId"] = gpuId;
|
2023-08-16 09:34:04 +02:00
|
|
|
data["GPU"]["screenWidth"] = screenWidth;
|
|
|
|
data["GPU"]["screenHeight"] = screenHeight;
|
2024-05-22 20:19:42 +02:00
|
|
|
data["GPU"]["nullGpu"] = isNullGpu;
|
2024-05-27 00:07:46 +02:00
|
|
|
data["GPU"]["dumpShaders"] = shouldDumpShaders;
|
2024-06-01 22:50:03 +02:00
|
|
|
data["GPU"]["dumpPM4"] = shouldDumpPM4;
|
2024-06-07 09:12:43 +02:00
|
|
|
data["Vulkan"]["validation"] = vkValidation;
|
|
|
|
data["Vulkan"]["validation_sync"] = vkValidationSync;
|
2024-03-11 12:26:33 +01:00
|
|
|
data["Debug"]["DebugDump"] = isDebugDump;
|
2024-03-25 08:26:59 +01:00
|
|
|
data["LLE"]["libc"] = isLibc;
|
2023-08-14 19:17:01 +02:00
|
|
|
|
|
|
|
std::ofstream file(path, std::ios::out);
|
|
|
|
file << data;
|
|
|
|
file.close();
|
|
|
|
}
|
2024-02-23 21:57:57 +01:00
|
|
|
} // namespace Config
|