From ced75956d145672f92e9315fb6199d75eba2ade7 Mon Sep 17 00:00:00 2001 From: Hielke Morsink Date: Thu, 8 Feb 2018 00:10:55 +0100 Subject: [PATCH] Populate loadsave window with absolute path When pressing "up", the code would look for the parent in the given path, which doesn't work well with relative paths. This commit fixes this behaviour. --- src/openrct2-ui/windows/LoadSave.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/openrct2-ui/windows/LoadSave.cpp b/src/openrct2-ui/windows/LoadSave.cpp index cb89a9f3ef..e12fa159fd 100644 --- a/src/openrct2-ui/windows/LoadSave.cpp +++ b/src/openrct2-ui/windows/LoadSave.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -24,9 +25,9 @@ #include #include #include +#include #include #include -#include #include #include #include @@ -746,10 +747,12 @@ static void window_loadsave_sort_list() static void window_loadsave_populate_list(rct_window *w, sint32 includeNewItem, const char *directory, const char *extension) { - safe_strcpy(_directory, directory, sizeof(_directory)); + utf8 absoluteDirectory[MAX_PATH]; + Path::GetAbsolute(absoluteDirectory, Util::CountOf(absoluteDirectory), directory); + safe_strcpy(_directory, absoluteDirectory, Util::CountOf(_directory)); if (_extension != extension) { - safe_strcpy(_extension, extension, sizeof(_extension)); + safe_strcpy(_extension, extension, Util::CountOf(_extension)); } _shortenedDirectory[0] = '\0'; @@ -781,7 +784,7 @@ static void window_loadsave_populate_list(rct_window *w, sint32 includeNewItem, else { // Remove the separator at the end of the path, if present - safe_strcpy(_parentDirectory, directory, sizeof(_parentDirectory)); + safe_strcpy(_parentDirectory, absoluteDirectory, Util::CountOf(_parentDirectory)); if (_parentDirectory[strlen(_parentDirectory) - 1] == *PATH_SEPARATOR || _parentDirectory[strlen(_parentDirectory) - 1] == '/') _parentDirectory[strlen(_parentDirectory) - 1] = '\0'; @@ -816,13 +819,13 @@ static void window_loadsave_populate_list(rct_window *w, sint32 includeNewItem, w->disabled_widgets &= ~(1 << WIDX_NEW_FOLDER); // List all directories - auto subDirectories = Path::GetDirectories(directory); + auto subDirectories = Path::GetDirectories(absoluteDirectory); for (const auto &sdName : subDirectories) { auto subDir = sdName + PATH_SEPARATOR; LoadSaveListItem newListItem; - newListItem.path = Path::Combine(directory, subDir); + newListItem.path = Path::Combine(absoluteDirectory, subDir); newListItem.name = subDir; newListItem.type = TYPE_DIRECTORY; newListItem.loaded = false; @@ -833,15 +836,15 @@ static void window_loadsave_populate_list(rct_window *w, sint32 includeNewItem, // List all files with the wanted extensions char filter[MAX_PATH]; char extCopy[64]; - safe_strcpy(extCopy, extension, sizeof(extCopy)); + safe_strcpy(extCopy, extension, Util::CountOf(extCopy)); char * extToken; bool showExtension = false; extToken = strtok(extCopy, ";"); while (extToken != nullptr) { - safe_strcpy(filter, directory, sizeof(filter)); - safe_strcat_path(filter, "*", sizeof(filter)); - path_append_extension(filter, extToken, sizeof(filter)); + safe_strcpy(filter, directory, Util::CountOf(filter)); + safe_strcat_path(filter, "*", Util::CountOf(filter)); + path_append_extension(filter, extToken, Util::CountOf(filter)); auto scanner = std::unique_ptr(Path::ScanDirectory(filter, false)); while (scanner->Next())