Merge branch 'master' into jgrpp
# Conflicts: # .github/workflows/ci-build.yml # .github/workflows/commit-checker.yml # src/openttd.cpp
This commit is contained in:
@@ -1122,11 +1122,32 @@ void DetermineBasePaths(const char *exe)
|
||||
_searchpaths[SP_SHARED_DIR] = nullptr;
|
||||
#endif
|
||||
|
||||
if (getcwd(tmp, MAX_PATH) == nullptr) *tmp = '\0';
|
||||
AppendPathSeparator(tmp, lastof(tmp));
|
||||
_searchpaths[SP_WORKING_DIR] = stredup(tmp);
|
||||
char cwd[MAX_PATH];
|
||||
if (getcwd(cwd, MAX_PATH) == nullptr) *cwd = '\0';
|
||||
|
||||
_do_scan_working_directory = DoScanWorkingDirectory();
|
||||
if (_config_file == nullptr) {
|
||||
/* Get the path to working directory of OpenTTD. */
|
||||
if (getcwd(tmp, MAX_PATH) == nullptr) *tmp = '\0';
|
||||
AppendPathSeparator(tmp, lastof(tmp));
|
||||
_searchpaths[SP_WORKING_DIR] = stredup(tmp);
|
||||
|
||||
_do_scan_working_directory = DoScanWorkingDirectory();
|
||||
} else {
|
||||
/* Use the folder of the config file as working directory. */
|
||||
char *config_dir = stredup(_config_file);
|
||||
char *end = strrchr(config_dir, PATHSEPCHAR);
|
||||
if (end == nullptr) {
|
||||
free(config_dir);
|
||||
|
||||
/* _config_file is not in a folder, so use current directory. */
|
||||
if (getcwd(tmp, MAX_PATH) == nullptr) *tmp = '\0';
|
||||
AppendPathSeparator(tmp, lastof(tmp));
|
||||
_searchpaths[SP_WORKING_DIR] = stredup(tmp);
|
||||
} else {
|
||||
end[1] = '\0';
|
||||
_searchpaths[SP_WORKING_DIR] = config_dir;
|
||||
}
|
||||
}
|
||||
|
||||
/* Change the working directory to that one of the executable */
|
||||
if (ChangeWorkingDirectoryToExecutable(exe)) {
|
||||
@@ -1137,9 +1158,9 @@ void DetermineBasePaths(const char *exe)
|
||||
_searchpaths[SP_BINARY_DIR] = nullptr;
|
||||
}
|
||||
|
||||
if (_searchpaths[SP_WORKING_DIR] != nullptr) {
|
||||
if (cwd[0] != '\0') {
|
||||
/* Go back to the current working directory. */
|
||||
if (chdir(_searchpaths[SP_WORKING_DIR]) != 0) {
|
||||
if (chdir(cwd) != 0) {
|
||||
DEBUG(misc, 0, "Failed to return to working directory!");
|
||||
}
|
||||
}
|
||||
@@ -1189,15 +1210,9 @@ void DeterminePaths(const char *exe)
|
||||
DEBUG(misc, 4, "%s added as search path", _searchpaths[sp]);
|
||||
}
|
||||
|
||||
char *config_dir;
|
||||
const char *config_dir;
|
||||
if (_config_file != nullptr) {
|
||||
config_dir = stredup(_config_file);
|
||||
char *end = strrchr(config_dir, PATHSEPCHAR);
|
||||
if (end == nullptr) {
|
||||
config_dir[0] = '\0';
|
||||
} else {
|
||||
end[1] = '\0';
|
||||
}
|
||||
config_dir = _searchpaths[SP_WORKING_DIR];
|
||||
} else {
|
||||
char personal_dir[MAX_PATH];
|
||||
if (FioFindFullPath(personal_dir, lastof(personal_dir), BASE_DIR, "openttd.cfg") != nullptr) {
|
||||
@@ -1240,7 +1255,6 @@ 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];
|
||||
FioCreateDirectory(_personal_dir);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
@@ -1248,9 +1262,9 @@ void DeterminePaths(const char *exe)
|
||||
}
|
||||
|
||||
/* Make the necessary folders */
|
||||
#if defined(WITH_PERSONAL_DIR)
|
||||
FioCreateDirectory(config_dir);
|
||||
if (config_dir != _personal_dir) FioCreateDirectory(_personal_dir);
|
||||
#if defined(WITH_PERSONAL_DIR)
|
||||
FioCreateDirectory(_personal_dir);
|
||||
#endif
|
||||
|
||||
DEBUG(misc, 3, "%s found as personal directory", _personal_dir);
|
||||
|
Reference in New Issue
Block a user