From 8cf47f8221b74cc0f3ddcefdff467fd41feaeb4e Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Tue, 30 Mar 2021 18:28:36 -0700 Subject: [PATCH] Adds support for named rootfs configurations If the relative or absolute folder doesn't exist then FEX will search in the data folder for a rootFS named the same thing If the path exists then it is used. For example if my data folder contains `$HOME/.fex-emu/RootFS/Ubuntu_main/` and I set the RootFS option to `Ubuntu_main` Then this rootfs will be used. Allows you to easily select a rootfs in that folder without having the full file path. --- .../Source/Interface/Config/Config.cpp | 20 +++++++++++++++++-- .../Source/Interface/Config/Config.json | 9 ++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/External/FEXCore/Source/Interface/Config/Config.cpp b/External/FEXCore/Source/Interface/Config/Config.cpp index 083e441cb..99948f25b 100644 --- a/External/FEXCore/Source/Interface/Config/Config.cpp +++ b/External/FEXCore/Source/Interface/Config/Config.cpp @@ -237,7 +237,12 @@ namespace FEXCore::Config { } // Expand relative path to absolute - return std::filesystem::absolute(Path); + Path = std::filesystem::absolute(Path); + + // Only return if it exists + if (std::filesystem::exists(Path)) { + return Path; + } } return {}; } @@ -263,7 +268,18 @@ namespace FEXCore::Config { if (FEXCore::Config::Exists(FEXCore::Config::CONFIG_ROOTFS)) { FEX_CONFIG_OPT(PathName, ROOTFS); - ExpandPathIfExists(FEXCore::Config::CONFIG_ROOTFS, PathName()); + auto ExpandedString = ExpandPath(PathName()); + if (!ExpandedString.empty()) { + // Adjust the path if it ended up being relative + FEXCore::Config::EraseSet(FEXCore::Config::CONFIG_ROOTFS, ExpandedString); + } + else if (!PathName().empty()) { + // If the filesystem doesn't exist then let's see if it exists in the fex-emu folder + std::string NamedRootFS = GetDataDirectory() + "RootFS/" + PathName(); + if (std::filesystem::exists(NamedRootFS)) { + FEXCore::Config::EraseSet(FEXCore::Config::CONFIG_ROOTFS, NamedRootFS); + } + } } if (FEXCore::Config::Exists(FEXCore::Config::CONFIG_THUNKHOSTLIBS)) { FEX_CONFIG_OPT(PathName, THUNKHOSTLIBS); diff --git a/External/FEXCore/Source/Interface/Config/Config.json b/External/FEXCore/Source/Interface/Config/Config.json index 19c79f82f..7a6fa8f86 100644 --- a/External/FEXCore/Source/Interface/Config/Config.json +++ b/External/FEXCore/Source/Interface/Config/Config.json @@ -46,7 +46,14 @@ "Default": "", "ShortArg": "R", "Desc": [ - "Which Root filesystem prefix to use" + "Which Root filesystem prefix to use", + "This can be a filesystem path", + "\teg: ~/RootFS/Debian_x86_64", + "Or this can be a name of a rootfs", + "If the named rootfs exists in the FEX data folder then it will use that one", + "\teg: $HOME/.fex-emu/RootFS//", + "Or if you have XDG_DATA_HOME the config will search in that directory", + "\teg: $XDG_DATA_HOME/.fex-emu/RootFS//" ] }, "ThunkHostLibs": {