MCPcopy Create free account
hub / github.com/FEX-Emu/FEX / GetConfigDirectory

Function GetConfigDirectory

Source/Common/Config.cpp:572–607  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

570}
571
572fextl::string GetConfigDirectory(bool Global, const PortableInformation& PortableInfo) {
573 const char* ConfigOverride = getenv("FEX_APP_CONFIG_LOCATION");
574 if (PortableInfo.IsPortable && (Global || !ConfigOverride)) {
575 return fextl::fmt::format("{}/fex-emu/", PortableInfo.InterpreterPath);
576 } else if (PortableInfo.IsPortable && ConfigOverride && !Global) {
577 fextl::string AppConfigStr = ConfigOverride;
578 if (PortableInfo.IsPortable && FHU::Filesystem::IsRelative(AppConfigStr)) {
579 AppConfigStr = PortableInfo.InterpreterPath + AppConfigStr;
580 }
581
582 return AppConfigStr;
583 }
584
585 fextl::string ConfigDir;
586 if (Global) {
587 ConfigDir = GLOBAL_DATA_DIRECTORY;
588 } else {
589 const char* HomeDir = GetHomeDirectory();
590 const char* ConfigXDG = getenv("XDG_CONFIG_HOME");
591 if (ConfigOverride) {
592 // Config override completely overrides the config directory
593 ConfigDir = ConfigOverride;
594 } else {
595 ConfigDir = ConfigXDG ? ConfigXDG : HomeDir;
596 ConfigDir += "/.fex-emu/";
597 }
598
599 // Ensure the folder structure is created for our configuration
600 if (!FHU::Filesystem::Exists(ConfigDir) && !FHU::Filesystem::CreateDirectories(ConfigDir)) {
601 // Let's go local in this case
602 return "./";
603 }
604 }
605
606 return ConfigDir;
607}
608
609fextl::string GetConfigFileLocation(bool Global, const PortableInformation& PortableInfo) {
610 return GetConfigDirectory(Global, PortableInfo) + "Config.json";

Callers 5

GetApplicationConfigFunction · 0.85
GetConfigFileLocationFunction · 0.85
InitializeConfigsFunction · 0.85
LoadThunkDatabaseMethod · 0.85
LoadThunkDatabaseFunction · 0.85

Calls 6

getenvFunction · 0.85
formatFunction · 0.85
IsRelativeFunction · 0.85
GetHomeDirectoryFunction · 0.85
CreateDirectoriesFunction · 0.85
ExistsFunction · 0.50

Tested by

no test coverage detected