Merge pull request #876 from Sonicadvance1/QOL_config

Implements a couple quality of life configuration option handling
This commit is contained in:
Stefanos Kornilios Mitsis Poiitidis 2021-03-22 18:23:52 +02:00 committed by GitHub
commit fbc49c1648
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 61 additions and 1 deletions

View File

@ -4,7 +4,9 @@
#include "Interface/Context/Context.h"
#include <FEXCore/Config/Config.h>
#include <filesystem>
#include <map>
#include <sys/sysinfo.h>
namespace FEXCore::Config {
void SetConfig(FEXCore::Context::Context *CTX, ConfigOption Option, uint64_t Config) {
@ -87,8 +89,66 @@ namespace FEXCore::Config {
}
}
std::string ExpandPath(std::string PathName) {
std::filesystem::path Path{PathName};
// Expand home if it exists
if (Path.is_relative()) {
std::string Home = getenv("HOME") ?: "";
// Home expansion only works if it is the first character
// This matches bash behaviour
if (PathName.at(0) == '~') {
PathName.replace(0, 1, Home);
return PathName;
}
// Expand relative path to absolute
return std::filesystem::absolute(Path);
}
return {};
}
void ReloadMetaLayer() {
Meta->Load();
// Do configuration option fix ups after everything is reloaded
if (FEXCore::Config::Exists(FEXCore::Config::CONFIG_EMULATED_CPU_CORES)) {
FEX_CONFIG_OPT(Cores, EMULATED_CPU_CORES);
if (Cores == 0) {
// When the number of emulated CPU cores is zero then auto detect
FEXCore::Config::EraseSet(FEXCore::Config::CONFIG_EMULATED_CPU_CORES, std::to_string(get_nprocs_conf()));
}
}
auto ExpandPathIfExists = [](FEXCore::Config::ConfigOption Config, std::string PathName) {
auto NewPath = ExpandPath(PathName);
if (!NewPath.empty()) {
FEXCore::Config::EraseSet(Config, NewPath);
}
};
if (FEXCore::Config::Exists(FEXCore::Config::CONFIG_ROOTFSPATH)) {
FEX_CONFIG_OPT(PathName, ROOTFSPATH);
ExpandPathIfExists(FEXCore::Config::CONFIG_ROOTFSPATH, PathName());
}
if (FEXCore::Config::Exists(FEXCore::Config::CONFIG_THUNKHOSTLIBSPATH)) {
FEX_CONFIG_OPT(PathName, THUNKHOSTLIBSPATH);
ExpandPathIfExists(FEXCore::Config::CONFIG_THUNKHOSTLIBSPATH, PathName());
}
if (FEXCore::Config::Exists(FEXCore::Config::CONFIG_THUNKGUESTLIBSPATH)) {
FEX_CONFIG_OPT(PathName, THUNKGUESTLIBSPATH);
ExpandPathIfExists(FEXCore::Config::CONFIG_THUNKGUESTLIBSPATH, PathName());
}
if (FEXCore::Config::Exists(FEXCore::Config::CONFIG_THUNKCONFIGPATH)) {
FEX_CONFIG_OPT(PathName, THUNKCONFIGPATH);
ExpandPathIfExists(FEXCore::Config::CONFIG_THUNKCONFIGPATH, PathName());
}
if (FEXCore::Config::Exists(FEXCore::Config::CONFIG_OUTPUTLOG)) {
FEX_CONFIG_OPT(PathName, OUTPUTLOG);
if (PathName() != "stdout" && PathName() != "stderr") {
ExpandPathIfExists(FEXCore::Config::CONFIG_OUTPUTLOG, PathName());
}
}
}
void AddLayer(std::unique_ptr<FEXCore::Config::Layer> _Layer) {

View File

@ -66,7 +66,7 @@ namespace FEX::ArgLoader {
CPUGroup.add_option("-T", "--Threads")
.dest("Threads")
.help("Number of physical hardware threads to tell the process we have")
.help("Number of physical hardware threads to tell the process we have. 0 will auto detect.")
.set_default(1);
CPUGroup.add_option("--smc-checks")