Skip to content

Commit

Permalink
Fix OpenRCT2#18199: Dots in the game save's name get truncated
Browse files Browse the repository at this point in the history
  • Loading branch information
CookiePLMonster committed Aug 6, 2023
1 parent 2615fb7 commit b98bc62
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
21 changes: 3 additions & 18 deletions src/openrct2-ui/windows/LoadSave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ static void Select(const char* path)
{
SetAndSaveConfigPath(gConfigGeneral.LastSaveTrackDirectory, pathBuffer);

const auto withExtension = Path::WithExtension(pathBuffer, "td6");
const auto withExtension = Path::WithExtension(pathBuffer, ".td6");
String::Set(pathBuffer, sizeof(pathBuffer), withExtension.c_str());

RCT2::T6Exporter t6Export{ _trackDesign };
Expand Down Expand Up @@ -408,35 +408,30 @@ static void Select(const char* path)
static u8string OpenSystemFileBrowser(bool isSave)
{
OpenRCT2::Ui::FileDialogDesc desc = {};
u8string extension{};
auto fileType = FileExtension::Unknown;
u8string extension;
StringId title = STR_NONE;
switch (_type & 0x0E)
{
case LOADSAVETYPE_GAME:
extension = u8".park";
fileType = FileExtension::PARK;
title = isSave ? STR_FILE_DIALOG_TITLE_SAVE_GAME : STR_FILE_DIALOG_TITLE_LOAD_GAME;
desc.Filters.emplace_back(LanguageGetString(STR_OPENRCT2_SAVED_GAME), GetFilterPatternByType(_type, isSave));
break;

case LOADSAVETYPE_LANDSCAPE:
extension = u8".park";
fileType = FileExtension::PARK;
title = isSave ? STR_FILE_DIALOG_TITLE_SAVE_LANDSCAPE : STR_FILE_DIALOG_TITLE_LOAD_LANDSCAPE;
desc.Filters.emplace_back(LanguageGetString(STR_OPENRCT2_LANDSCAPE_FILE), GetFilterPatternByType(_type, isSave));
break;

case LOADSAVETYPE_SCENARIO:
extension = u8".park";
fileType = FileExtension::PARK;
title = STR_FILE_DIALOG_TITLE_SAVE_SCENARIO;
desc.Filters.emplace_back(LanguageGetString(STR_OPENRCT2_SCENARIO_FILE), GetFilterPatternByType(_type, isSave));
break;

case LOADSAVETYPE_TRACK:
extension = u8".td6";
fileType = FileExtension::TD6;
title = isSave ? STR_FILE_DIALOG_TITLE_SAVE_TRACK : STR_FILE_DIALOG_TITLE_INSTALL_NEW_TRACK_DESIGN;
desc.Filters.emplace_back(LanguageGetString(STR_OPENRCT2_TRACK_DESIGN_FILE), GetFilterPatternByType(_type, isSave));
break;
Expand Down Expand Up @@ -476,17 +471,7 @@ static u8string OpenSystemFileBrowser(bool isSave)
desc.Filters.emplace_back(LanguageGetString(STR_ALL_FILES), "*");

desc.Title = LanguageGetString(title);

u8string outPath = ContextOpenCommonFileDialog(desc);
if (!outPath.empty())
{
// When the given save type was given, Windows still interprets a filename with a dot in its name as a custom
// extension, meaning files like "My Coaster v1.2" will not get the .td6 extension by default.
if (isSave && GetFileExtensionType(outPath) != fileType)
outPath = Path::WithExtension(outPath, extension);
}

return outPath;
return ContextOpenCommonFileDialog(desc);
}

class LoadSaveWindow final : public Window
Expand Down
16 changes: 15 additions & 1 deletion src/openrct2/core/Path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,21 @@ namespace Path

u8string WithExtension(u8string_view path, u8string_view newExtension)
{
return fs::u8path(path).replace_extension(fs::u8path(newExtension)).u8string();
auto p = fs::u8path(path);

fs::path extensionWithDot;
if (!newExtension.empty() && newExtension.front() != '.')
{
extensionWithDot += ".";
}
extensionWithDot += fs::u8path(newExtension);

if (p.extension() != extensionWithDot)
{
p += extensionWithDot;
}

return p.u8string();
}

bool IsAbsolute(u8string_view path)
Expand Down

0 comments on commit b98bc62

Please sign in to comment.