| 570 | } |
| 571 | |
| 572 | fextl::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 | |
| 609 | fextl::string GetConfigFileLocation(bool Global, const PortableInformation& PortableInfo) { |
| 610 | return GetConfigDirectory(Global, PortableInfo) + "Config.json"; |
no test coverage detected