diff options
author | Patric Stout <truebrain@openttd.org> | 2020-12-13 20:54:20 +0100 |
---|---|---|
committer | Michael Lutz <michi@icosahedron.de> | 2020-12-13 22:45:50 +0100 |
commit | b7851e51adf0fb0d39ed34a579cf6fe68d8949be (patch) | |
tree | 95d13a70f46a9a8f4502c3955e9d98355c6b3a66 /src/os | |
parent | a660dce295d448ce6ef9911ee1cbd6e63af6618b (diff) | |
download | openttd-b7851e51adf0fb0d39ed34a579cf6fe68d8949be.tar.xz |
Fix: set SP_WORKING_DIR earlier with '-c'
On Windows, relative folders don't work so well. So we need to
lookup the full path. This is best done in DetermineBasePaths()
and as a bonus that only sets SP_WORKING_DIR once.
Diffstat (limited to 'src/os')
-rw-r--r-- | src/os/windows/win32.cpp | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/src/os/windows/win32.cpp b/src/os/windows/win32.cpp index 1bdbc3c2a..468234391 100644 --- a/src/os/windows/win32.cpp +++ b/src/os/windows/win32.cpp @@ -451,6 +451,7 @@ char *getcwd(char *buf, size_t size) return buf; } +extern char *_config_file; void DetermineBasePaths(const char *exe) { @@ -481,10 +482,25 @@ void DetermineBasePaths(const char *exe) _searchpaths[SP_SHARED_DIR] = nullptr; #endif - /* Get the path to working directory of OpenTTD */ - getcwd(tmp, lengthof(tmp)); - AppendPathSeparator(tmp, lastof(tmp)); - _searchpaths[SP_WORKING_DIR] = stredup(tmp); + if (_config_file == nullptr) { + /* Get the path to working directory of OpenTTD. */ + getcwd(tmp, lengthof(tmp)); + AppendPathSeparator(tmp, lastof(tmp)); + _searchpaths[SP_WORKING_DIR] = stredup(tmp); + } else { + /* Use the folder of the config file as working directory. */ + TCHAR config_dir[MAX_PATH]; + _tcsncpy(path, convert_to_fs(_config_file, path, lengthof(path)), lengthof(path)); + if (!GetFullPathName(path, lengthof(config_dir), config_dir, nullptr)) { + DEBUG(misc, 0, "GetFullPathName failed (%lu)\n", GetLastError()); + _searchpaths[SP_WORKING_DIR] = nullptr; + } else { + strecpy(tmp, convert_from_fs(config_dir, tmp, lengthof(tmp)), lastof(tmp)); + char *s = strrchr(tmp, PATHSEPCHAR); + *(s + 1) = '\0'; + _searchpaths[SP_WORKING_DIR] = stredup(tmp); + } + } if (!GetModuleFileName(nullptr, path, lengthof(path))) { DEBUG(misc, 0, "GetModuleFileName failed (%lu)\n", GetLastError()); |