mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-28 01:04:50 +01:00
Merge pull request #7150 from Broxzier/absolute-path
Make custom paths absolute and show full path in load/save window
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
#include <algorithm>
|
||||
#include <ctime>
|
||||
#include <memory>
|
||||
#include <openrct2-ui/interface/Widget.h>
|
||||
#include <openrct2-ui/windows/Window.h>
|
||||
#include <openrct2/config/Config.h>
|
||||
#include <openrct2/Context.h>
|
||||
@@ -24,9 +25,9 @@
|
||||
#include <openrct2/core/Guard.hpp>
|
||||
#include <openrct2/core/Path.hpp>
|
||||
#include <openrct2/core/String.hpp>
|
||||
#include <openrct2/core/Util.hpp>
|
||||
#include <openrct2/Editor.h>
|
||||
#include <openrct2/Game.h>
|
||||
#include <openrct2-ui/interface/Widget.h>
|
||||
#include <openrct2/localisation/Localisation.h>
|
||||
#include <openrct2/platform/platform.h>
|
||||
#include <openrct2/platform/Platform2.h>
|
||||
@@ -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<IFileScanner>(Path::ScanDirectory(filter, false));
|
||||
while (scanner->Next())
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "../core/Memory.hpp"
|
||||
#include "../core/Path.hpp"
|
||||
#include "../core/String.hpp"
|
||||
#include "../core/Util.hpp"
|
||||
#include "../network/network.h"
|
||||
#include "../object/ObjectRepository.h"
|
||||
#include "../OpenRCT2.h"
|
||||
@@ -197,25 +198,29 @@ exitcode_t CommandLine::HandleCommandDefault()
|
||||
|
||||
if (_userDataPath != nullptr)
|
||||
{
|
||||
String::Set(gCustomUserDataPath, sizeof(gCustomUserDataPath), _userDataPath);
|
||||
utf8 absolutePath[MAX_PATH]{};
|
||||
Path::GetAbsolute(absolutePath, Util::CountOf(absolutePath), _userDataPath);
|
||||
String::Set(gCustomUserDataPath, Util::CountOf(gCustomUserDataPath), absolutePath);
|
||||
Memory::Free(_userDataPath);
|
||||
}
|
||||
|
||||
if (_openrctDataPath != nullptr)
|
||||
{
|
||||
String::Set(gCustomOpenrctDataPath, sizeof(gCustomOpenrctDataPath), _openrctDataPath);
|
||||
utf8 absolutePath[MAX_PATH]{};
|
||||
Path::GetAbsolute(absolutePath, Util::CountOf(absolutePath), _openrctDataPath);
|
||||
String::Set(gCustomOpenrctDataPath, Util::CountOf(gCustomOpenrctDataPath), absolutePath);
|
||||
Memory::Free(_openrctDataPath);
|
||||
}
|
||||
|
||||
if (_rct2DataPath != nullptr)
|
||||
{
|
||||
String::Set(gCustomRCT2DataPath, sizeof(gCustomRCT2DataPath), _rct2DataPath);
|
||||
String::Set(gCustomRCT2DataPath, Util::CountOf(gCustomRCT2DataPath), _rct2DataPath);
|
||||
Memory::Free(_rct2DataPath);
|
||||
}
|
||||
|
||||
if (_password != nullptr)
|
||||
{
|
||||
String::Set(gCustomPassword, sizeof(gCustomPassword), _password);
|
||||
String::Set(gCustomPassword, Util::CountOf(gCustomPassword), _password);
|
||||
Memory::Free(_password);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user