Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions FEXCore/Scripts/config_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def print_man_environment_tail():
"APP_CONFIG_LOCATION",
[
"Allows the user to override where FEX looks for configuration files",
"By default FEX will look in {$HOME, $XDG_CONFIG_HOME}/.fex-emu/",
"By default FEX will look in ${XDG_CONFIG_HOME, $HOME/.config}/fex-emu/",
"This will override the full path",
"If FEX_PORTABLE is declared then relative paths are also supported",
"For FEX: Relative to the FEX binary",
Expand All @@ -168,7 +168,7 @@ def print_man_environment_tail():
"APP_CONFIG",
[
"Allows the user to override where FEX looks for only the application config file",
"By default FEX will look in {$HOME, $XDG_CONFIG_HOME}/.fex-emu/Config.json",
"By default FEX will look in ${XDG_CONFIG_HOME, $HOME/.config}/fex-emu/Config.json",
"This will override this file location",
"One must be careful with this option as it will override any applications that load with execve as well"
"If you need to support applications that execve then use FEX_APP_CONFIG_LOCATION instead"
Expand All @@ -182,7 +182,7 @@ def print_man_environment_tail():
"APP_DATA_LOCATION",
[
"Allows the user to override where FEX looks for data files",
"By default FEX will look in {$HOME, $XDG_DATA_HOME}/.fex-emu/",
"By default FEX will look in {$XDG_DATA_HOME, $HOME/.local/share}/fex-emu/",
"This will override the full path",
"This is the folder where FEX stores generated files like IR cache"
],
Expand All @@ -204,7 +204,7 @@ def print_man_environment_tail():
"APP_CACHE_LOCATION",
[
"Allows the user to override where FEX stores and loads cache files",
"By default FEX will look in $XDG_CACHE_HOME/fex-emu/ or $HOME/.cache/fex-emu/",
"By default FEX will look in ${XDG_CACHE_HOME, $HOME/.cache}/fex-emu/",
"This will override the full path, trailing forward-slash is expected to exist",
],
"''", True)
Expand Down Expand Up @@ -234,7 +234,7 @@ def print_man_header():
def print_man_tail():
tail ='''.Sh FILES
.Bl -tag -width "$prefix/share/fex-emu/GuestThunks" -compact
.It Pa $XDG_HOME_DIR/.fex-emu
.It Pa $XDG_CONFIG_DIR/fex-emu
Default FEX user configuration directory
.It Pa $prefix/share/fex-emu/AppConfig
System level application configuration files
Expand Down
14 changes: 7 additions & 7 deletions FEXCore/Source/Interface/Config/Config.json.in
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@
"\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/<RootFS name>/",
"Or if you have XDG_DATA_HOME the config will search in that directory",
"\teg: $XDG_DATA_HOME/.fex-emu/RootFS/<RootFS name>/"
"\teg: $XDG_DATA_HOME/fex-emu/RootFS/<RootFS name>/",
"Or if XDG_DATA_HOME is unset the config will use a fallback",
"\teg: $HOME/.local/share/fex-emu/RootFS/<RootFS name>/"
]
},
"ThunkHostLibs": {
Expand All @@ -155,9 +155,9 @@
"\teg: ~/MyThunkConfig.json",
"Or this can be a named of a Thunk config file",
"If the named config file exists in the FEX data folder folder the it will use that one",
"\teg: $HOME/.fex-emu/ThunkConfigs/<ThunkConfig name>",
"Or if you have XDG_DATA_HOME the config will search in that directory",
"\teg: $XDG_DATA_HOME/.fex-emu/ThunkConfigs/<ThunkConfig name>"
"\teg: $XDG_DATA_HOME/fex-emu/ThunkConfigs/<ThunkConfig name>",
"Or if XDG_DATA_HOME is unset the config will search in a fallback path",
"\teg: $HOME/.local/share/fex-emu/ThunkConfigs/<ThunkConfig name>"
]
},
"Env": {
Expand Down Expand Up @@ -387,7 +387,7 @@
"Default": "",
"Desc": [
"Redirects the telemetry folder that FEX usually writes to.",
"By default telemetry data is stored in {$FEX_APP_DATA_LOCATION,{$XDG_DATA_HOME,$HOME}/.fex-emu/Telemetry/}"
"By default telemetry data is stored in {$FEX_APP_DATA_LOCATION,{$XDG_DATA_HOME,$HOME}/fex-emu/Telemetry/}"
]
},
"ProfileStats": {
Expand Down
10 changes: 7 additions & 3 deletions Scripts/InstallFEX.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,18 +293,22 @@ def GetRootFSPath():
if HomeDir == None:
HomeDir = "."

Path = HomeDir
Path = HomeDir + "/.local/share"
DataXDG = os.getenv("XDG_DATA_HOME")
if DataXDG != None:
Path = DataXDG

Path = Path + "/.fex-emu"
Path = Path + "/fex-emu"

DataOverride = os.getenv("FEX_APP_DATA_LOCATION")

if DataOverride != None:
Path = DataOverride

LegacyDir = HomeDir + "/.fex-emu"
if os.path.isdir(LegacyDir):
Path = LegacyDir

_RootFSPath = Path + "/RootFS/"

return _RootFSPath
Expand Down Expand Up @@ -420,4 +424,4 @@ def main():
ExitWithStatus(0)

if __name__ == "__main__":
sys.exit(main())
sys.exit(main())
90 changes: 62 additions & 28 deletions Source/Common/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <FEXHeaderUtils/SymlinkChecks.h>

#include <cstring>
#include <fmt/format.h>
#include <functional>
#ifndef _WIN32
#include <linux/limits.h>
Expand Down Expand Up @@ -555,20 +556,31 @@ fextl::string GetDataDirectory(bool Global, const PortableInformation& PortableI
return fextl::fmt::format("{}/fex-emu/", PortableInfo.InterpreterPath);
}

fextl::string DataDir {};
if (Global) {
DataDir = GLOBAL_DATA_DIRECTORY;
return GLOBAL_DATA_DIRECTORY;
}

const char* HomeDir = GetHomeDirectory();
const char* DataXDG = getenv("XDG_DATA_HOME");
const fextl::string LegacyDir = fextl::string {HomeDir} + "/.fex-emu";

// If $HOME/.fex-emu exists, use that
if (FHU::Filesystem::Exists(LegacyDir)) {
return LegacyDir;
}

// use ~/.local/share if XDG_DATA_HOME is unset
const std::string fallback = fmt::format("{}/.local/share", HomeDir);

fextl::string DataDir {};
if (DataOverride) {
// Data override will override the complete directory
DataDir = DataOverride;
} else {
const char* HomeDir = GetHomeDirectory();
const char* DataXDG = getenv("XDG_DATA_HOME");
if (DataOverride) {
// Data override will override the complete directory
DataDir = DataOverride;
} else {
DataDir = DataXDG ?: HomeDir;
DataDir += "/.fex-emu/";
}
DataDir = DataXDG ? DataXDG : fallback;
DataDir += "/fex-emu/";
}

return DataDir;
}

Expand All @@ -594,25 +606,31 @@ fextl::string GetConfigDirectory(bool Global, const PortableInformation& Portabl

fextl::string ConfigDir;
if (Global) {
ConfigDir = GLOBAL_DATA_DIRECTORY;
} else {
const char* HomeDir = GetHomeDirectory();
const char* ConfigXDG = getenv("XDG_CONFIG_HOME");
if (ConfigOverride) {
// Config override completely overrides the config directory
ConfigDir = ConfigOverride;
} else {
ConfigDir = ConfigXDG ? ConfigXDG : HomeDir;
ConfigDir += "/.fex-emu/";
}
return GLOBAL_DATA_DIRECTORY;
}

// Ensure the folder structure is created for our configuration
if (!FHU::Filesystem::Exists(ConfigDir) && !FHU::Filesystem::CreateDirectories(ConfigDir)) {
// Let's go local in this case
return "./";
}
const char* HomeDir = GetHomeDirectory();
const char* ConfigXDG = getenv("XDG_CONFIG_HOME");

const fextl::string LegacyDir = fextl::string {HomeDir} + "/.fex-emu";

// If $HOME/.fex-emu exists, use that
if (FHU::Filesystem::Exists(LegacyDir)) {
return LegacyDir;
}

// use ~/.config if XDG_CONFIG_HOME is unset
const std::string fallback = fmt::format("{}/.config", HomeDir);

if (ConfigOverride) {
// Config override will override the complete directory
ConfigDir = ConfigOverride;
} else {
ConfigDir = ConfigXDG ? ConfigXDG : fallback;
ConfigDir += "/fex-emu/";
}


return ConfigDir;
}

Expand All @@ -630,9 +648,25 @@ fextl::string GetCacheDirectory() {
}
#endif

fextl::string CacheDir;
const char* HomeDir = GetHomeDirectory();
const char* CacheXDG = getenv("XDG_CACHE_HOME");
return (CacheXDG ? fextl::string {CacheXDG} : (fextl::string {HomeDir} + "/.cache")) + "/fex-emu/";

const fextl::string LegacyDir = fextl::string {HomeDir} + "/.fex-emu";

// If $HOME/.fex-emu exists, use that
if (FHU::Filesystem::Exists(LegacyDir)) {
return LegacyDir;
}

// use ~/.cache if XDG_CACHE_HOME is unset
const std::string fallback = fmt::format("{}/.cache", HomeDir);

CacheDir = CacheXDG ? CacheXDG : fallback;
CacheDir += "/fex-emu/";

return CacheDir;

#else
const char* PrefixAppData = getenv("LOCALAPPDATA");
return PrefixAppData ? (fextl::string {PrefixAppData} + "\\fex-emu\\") : fextl::string {".\\"};
Expand Down