summaryrefslogtreecommitdiff
path: root/src/os
diff options
context:
space:
mode:
authorMichael Lutz <michi@icosahedron.de>2020-12-06 21:11:44 +0100
committerMichael Lutz <michi@icosahedron.de>2020-12-27 13:19:25 +0100
commitf3326d34e78bd28fba6d8cfd3bc455a506b429fe (patch)
tree307a0608a7fb1c211fd72a8b8326cfe9bb1d37a2 /src/os
parent0c6e8a8123c9f74db757272f73adcbd8621e012d (diff)
downloadopenttd-f3326d34e78bd28fba6d8cfd3bc455a506b429fe.tar.xz
Codechange: Use std::string in FIO search path handling.
Diffstat (limited to 'src/os')
-rw-r--r--src/os/windows/win32.cpp40
1 files changed, 21 insertions, 19 deletions
diff --git a/src/os/windows/win32.cpp b/src/os/windows/win32.cpp
index 7553740e7..bbb7e359a 100644
--- a/src/os/windows/win32.cpp
+++ b/src/os/windows/win32.cpp
@@ -458,24 +458,23 @@ void DetermineBasePaths(const char *exe)
{
extern std::array<std::string, NUM_SEARCHPATHS> _searchpaths;
- char tmp[MAX_PATH];
TCHAR path[MAX_PATH];
#ifdef WITH_PERSONAL_DIR
if (SUCCEEDED(OTTDSHGetFolderPath(nullptr, CSIDL_PERSONAL, nullptr, SHGFP_TYPE_CURRENT, path))) {
- strecpy(tmp, FS2OTTD(path), lastof(tmp));
- AppendPathSeparator(tmp, lastof(tmp));
- strecat(tmp, PERSONAL_DIR, lastof(tmp));
- AppendPathSeparator(tmp, lastof(tmp));
+ std::string tmp(FS2OTTD(path));
+ AppendPathSeparator(tmp);
+ tmp += PERSONAL_DIR;
+ AppendPathSeparator(tmp);
_searchpaths[SP_PERSONAL_DIR] = tmp;
} else {
_searchpaths[SP_PERSONAL_DIR].clear();
}
if (SUCCEEDED(OTTDSHGetFolderPath(nullptr, CSIDL_COMMON_DOCUMENTS, nullptr, SHGFP_TYPE_CURRENT, path))) {
- strecpy(tmp, FS2OTTD(path), lastof(tmp));
- AppendPathSeparator(tmp, lastof(tmp));
- strecat(tmp, PERSONAL_DIR, lastof(tmp));
- AppendPathSeparator(tmp, lastof(tmp));
+ std::string tmp(FS2OTTD(path));
+ AppendPathSeparator(tmp);
+ tmp += PERSONAL_DIR;
+ AppendPathSeparator(tmp);
_searchpaths[SP_SHARED_DIR] = tmp;
} else {
_searchpaths[SP_SHARED_DIR].clear();
@@ -486,10 +485,11 @@ void DetermineBasePaths(const char *exe)
#endif
if (_config_file.empty()) {
- /* Get the path to working directory of OpenTTD. */
- getcwd(tmp, lengthof(tmp));
- AppendPathSeparator(tmp, lastof(tmp));
- _searchpaths[SP_WORKING_DIR] = tmp;
+ char cwd[MAX_PATH];
+ getcwd(cwd, lengthof(cwd));
+ std::string cwd_s(cwd);
+ AppendPathSeparator(cwd_s);
+ _searchpaths[SP_WORKING_DIR] = cwd_s;
} else {
/* Use the folder of the config file as working directory. */
TCHAR config_dir[MAX_PATH];
@@ -498,9 +498,10 @@ void DetermineBasePaths(const char *exe)
DEBUG(misc, 0, "GetFullPathName failed (%lu)\n", GetLastError());
_searchpaths[SP_WORKING_DIR].clear();
} else {
- strecpy(tmp, convert_from_fs(config_dir, tmp, lengthof(tmp)), lastof(tmp));
- char *s = strrchr(tmp, PATHSEPCHAR);
- *(s + 1) = '\0';
+ std::string tmp(FS2OTTD(config_dir));
+ auto pos = tmp.find_last_of(PATHSEPCHAR);
+ if (pos != std::string::npos) tmp.erase(pos + 1);
+
_searchpaths[SP_WORKING_DIR] = tmp;
}
}
@@ -515,9 +516,10 @@ void DetermineBasePaths(const char *exe)
DEBUG(misc, 0, "GetFullPathName failed (%lu)\n", GetLastError());
_searchpaths[SP_BINARY_DIR].clear();
} else {
- strecpy(tmp, convert_from_fs(exec_dir, tmp, lengthof(tmp)), lastof(tmp));
- char *s = strrchr(tmp, PATHSEPCHAR);
- *(s + 1) = '\0';
+ std::string tmp(FS2OTTD(exec_dir));
+ auto pos = tmp.find_last_of(PATHSEPCHAR);
+ if (pos != std::string::npos) tmp.erase(pos + 1);
+
_searchpaths[SP_BINARY_DIR] = tmp;
}
}