From 563884105fbdce9cf5b3837be277e695e5ac0ab4 Mon Sep 17 00:00:00 2001 From: Patric Stout Date: Thu, 27 May 2021 17:56:39 +0100 Subject: [PATCH] Change: by default, make "unload all" leave stations empty (#9301) (cherry picked from commit 76484833643c1aff90d41eb01de70f7e8ba0ceb9) --- src/fileio.cpp | 29 +++++++++++++++++++++++++---- src/fileio_func.h | 2 +- src/openttd.cpp | 10 +++++++--- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/fileio.cpp b/src/fileio.cpp index 72f1809244..d5b1af809c 100644 --- a/src/fileio.cpp +++ b/src/fileio.cpp @@ -79,10 +79,22 @@ static bool IsValidSearchPath(Searchpath sp) return sp < _searchpaths.size() && !_searchpaths[sp].empty(); } -static void FillValidSearchPaths() +static void FillValidSearchPaths(bool only_local_path) { _valid_searchpaths.clear(); for (Searchpath sp = SP_FIRST_DIR; sp < NUM_SEARCHPATHS; sp++) { + if (only_local_path) { + switch (sp) { + case SP_WORKING_DIR: // Can be influence by "-c" option. + case SP_BINARY_DIR: // Most likely contains all the language files. + case SP_AUTODOWNLOAD_DIR: // Otherwise we cannot download in-game content. + break; + + default: + continue; + } + } + if (IsValidSearchPath(sp)) _valid_searchpaths.emplace_back(sp); } } @@ -958,11 +970,12 @@ std::string _personal_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. */ -void DeterminePaths(const char *exe) +void DeterminePaths(const char *exe, bool only_local_path) { DetermineBasePaths(exe); - FillValidSearchPaths(); + FillValidSearchPaths(only_local_path); #ifdef USE_XDG std::string config_home; @@ -1029,6 +1042,13 @@ void DeterminePaths(const char *exe) /* We are using the XDG configuration home for the config file, * then store the rest in the XDG data home folder. */ _personal_dir = _searchpaths[SP_PERSONAL_DIR_XDG]; + if (only_local_path) { + /* In case of XDG and we only want local paths and we detected that + * the user either manually indicated the XDG path or didn't use + * "-c" option, we change the working-dir to the XDG personal-dir, + * as this is most likely what the user is expecting. */ + _searchpaths[SP_WORKING_DIR] = _searchpaths[SP_PERSONAL_DIR_XDG]; + } } else #endif { @@ -1053,8 +1073,9 @@ void DeterminePaths(const char *exe) /* If we have network we make a directory for the autodownloading of content */ _searchpaths[SP_AUTODOWNLOAD_DIR] = _personal_dir + "content_download" PATHSEP; + DEBUG(misc, 4, "%s added as search path", _searchpaths[SP_AUTODOWNLOAD_DIR].c_str()); FioCreateDirectory(_searchpaths[SP_AUTODOWNLOAD_DIR]); - FillValidSearchPaths(); + FillValidSearchPaths(only_local_path); /* Create the directory for each of the types of content */ const Subdirectory dirs[] = { SCENARIO_DIR, HEIGHTMAP_DIR, BASESET_DIR, NEWGRF_DIR, AI_DIR, AI_LIBRARY_DIR, GAME_DIR, GAME_LIBRARY_DIR }; diff --git a/src/fileio_func.h b/src/fileio_func.h index f84acd3a46..5c02b2aaf5 100644 --- a/src/fileio_func.h +++ b/src/fileio_func.h @@ -27,7 +27,7 @@ const char *FiosGetScreenshotDir(); void SanitizeFilename(char *filename); void AppendPathSeparator(std::string &buf); -void DeterminePaths(const char *exe); +void DeterminePaths(const char *exe, bool only_local_path); std::unique_ptr ReadFileToMem(const std::string &filename, size_t &lenp, size_t maxsize); bool FileExists(const std::string &filename); bool ExtractTar(const std::string &tar_filename, Subdirectory subdir); diff --git a/src/openttd.cpp b/src/openttd.cpp index a094d5b6d7..4317694d96 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -249,6 +249,7 @@ static void ShowHelp() " -M music_set = Force the music set (see below)\n" " -c config_file = Use 'config_file' instead of 'openttd.cfg'\n" " -x = Never save configuration changes to disk\n" + " -X = Don't use global folders to search for files\n" " -q savegame = Write some information about the savegame and exit\n" " -Z = Write detailed version information and exit\n" "\n", @@ -681,6 +682,7 @@ static const OptionData _options[] = { GETOPT_SHORT_VALUE('G'), GETOPT_SHORT_VALUE('c'), GETOPT_SHORT_NOVAL('x'), + GETOPT_SHORT_NOVAL('X'), GETOPT_SHORT_VALUE('q'), GETOPT_SHORT_VALUE('K'), GETOPT_SHORT_NOVAL('h'), @@ -710,6 +712,7 @@ int openttd_main(int argc, char *argv[]) std::unique_ptr scanner(new AfterNewGRFScan()); bool dedicated = false; char *debuglog_conn = nullptr; + bool only_local_path = false; extern bool _dedicated_forks; _dedicated_forks = false; @@ -792,7 +795,7 @@ int openttd_main(int argc, char *argv[]) break; case 'q': case 'K': { - DeterminePaths(argv[0]); + DeterminePaths(argv[0], only_local_path); if (StrEmpty(mgo.opt)) { ret = 1; return ret; @@ -833,6 +836,7 @@ int openttd_main(int argc, char *argv[]) CrashLog::VersionInfoLog(); return ret; } + case 'X': only_local_path = true; break; case 'h': i = -2; // Force printing of help. break; @@ -846,7 +850,7 @@ int openttd_main(int argc, char *argv[]) * * The next two functions are needed to list the graphics sets. We can't do them earlier * because then we cannot show it on the debug console as that hasn't been configured yet. */ - DeterminePaths(argv[0]); + DeterminePaths(argv[0], only_local_path); TarScanner::DoScan(TarScanner::BASESET); BaseGraphics::FindSets(); BaseSounds::FindSets(); @@ -855,7 +859,7 @@ int openttd_main(int argc, char *argv[]) return ret; } - DeterminePaths(argv[0]); + DeterminePaths(argv[0], only_local_path); TarScanner::DoScan(TarScanner::BASESET); if (dedicated) DEBUG(net, 0, "Starting dedicated version %s", _openttd_revision);