* Acquire the base paths (personal dir and game data dir), * fill all other paths (save dir, autosave dir etc) and * make the save and scenario directories. * @param exe the path from the current path to the executable * @param only_local_path Whether we shouldn't fill searchpaths with global folders. */
| 878 | * @param only_local_path Whether we shouldn't fill searchpaths with global folders. |
| 879 | */ |
| 880 | void DeterminePaths(std::string_view exe, bool only_local_path) |
| 881 | { |
| 882 | DetermineBasePaths(exe); |
| 883 | FillValidSearchPaths(only_local_path); |
| 884 | |
| 885 | #ifdef USE_XDG |
| 886 | std::string config_home; |
| 887 | std::string homedir = GetHomeDir(); |
| 888 | if (auto xdg_config_home = GetEnv("XDG_CONFIG_HOME"); xdg_config_home.has_value()) { |
| 889 | config_home = *xdg_config_home; |
| 890 | config_home += PATHSEP; |
| 891 | config_home += PERSONAL_DIR[0] == '.' ? &PERSONAL_DIR[1] : PERSONAL_DIR; |
| 892 | } else if (!homedir.empty()) { |
| 893 | /* Defaults to ~/.config */ |
| 894 | config_home = std::move(homedir); |
| 895 | config_home += PATHSEP ".config" PATHSEP; |
| 896 | config_home += PERSONAL_DIR[0] == '.' ? &PERSONAL_DIR[1] : PERSONAL_DIR; |
| 897 | } |
| 898 | AppendPathSeparator(config_home); |
| 899 | #endif |
| 900 | |
| 901 | for (Searchpath sp : _valid_searchpaths) { |
| 902 | if (sp == SP_WORKING_DIR && !_do_scan_working_directory) continue; |
| 903 | Debug(misc, 3, "{} added as search path", _searchpaths[sp]); |
| 904 | } |
| 905 | |
| 906 | std::string config_dir; |
| 907 | if (!_config_file.empty()) { |
| 908 | config_dir = _searchpaths[SP_WORKING_DIR]; |
| 909 | } else { |
| 910 | std::string personal_dir = FioFindFullPath(BASE_DIR, "openttd.cfg"); |
| 911 | if (!personal_dir.empty()) { |
| 912 | auto end = personal_dir.find_last_of(PATHSEPCHAR); |
| 913 | if (end != std::string::npos) personal_dir.erase(end + 1); |
| 914 | config_dir = std::move(personal_dir); |
| 915 | } else { |
| 916 | #ifdef USE_XDG |
| 917 | /* No previous configuration file found. Use the configuration folder from XDG. */ |
| 918 | config_dir = config_home; |
| 919 | #else |
| 920 | static const Searchpath new_openttd_cfg_order[] = { |
| 921 | SP_PERSONAL_DIR, SP_BINARY_DIR, SP_WORKING_DIR, SP_SHARED_DIR, SP_INSTALLATION_DIR |
| 922 | }; |
| 923 | |
| 924 | config_dir.clear(); |
| 925 | for (const auto &searchpath : new_openttd_cfg_order) { |
| 926 | if (IsValidSearchPath(searchpath)) { |
| 927 | config_dir = _searchpaths[searchpath]; |
| 928 | break; |
| 929 | } |
| 930 | } |
| 931 | #endif |
| 932 | } |
| 933 | _config_file = config_dir + "openttd.cfg"; |
| 934 | } |
| 935 | |
| 936 | Debug(misc, 1, "{} found as config directory", config_dir); |
| 937 |
no test coverage detected