From e6323e6760245f3e8bdceefbeca19e320057ce22 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Thu, 28 Aug 2025 17:42:00 +0100 Subject: [PATCH] Fix: File/directory titles not updated if language is changed. (#14542) --- src/console_cmds.cpp | 6 +++--- src/fios.cpp | 18 +++++++++--------- src/fios.h | 2 +- src/fios_gui.cpp | 6 +++--- src/genworld_gui.cpp | 4 ++-- src/os/windows/win32.cpp | 5 ++++- src/saveload/saveload.h | 2 +- 7 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index 919f22684b..338c9a209a 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -569,7 +569,7 @@ static bool ConListFiles(std::span argv) _console_file_list_savegame.ValidateFileList(true); for (uint i = 0; i < _console_file_list_savegame.size(); i++) { - IConsolePrint(CC_DEFAULT, "{}) {}", i, _console_file_list_savegame[i].title); + IConsolePrint(CC_DEFAULT, "{}) {}", i, _console_file_list_savegame[i].title.GetDecodedString()); } return true; @@ -585,7 +585,7 @@ static bool ConListScenarios(std::span argv) _console_file_list_scenario.ValidateFileList(true); for (uint i = 0; i < _console_file_list_scenario.size(); i++) { - IConsolePrint(CC_DEFAULT, "{}) {}", i, _console_file_list_scenario[i].title); + IConsolePrint(CC_DEFAULT, "{}) {}", i, _console_file_list_scenario[i].title.GetDecodedString()); } return true; @@ -601,7 +601,7 @@ static bool ConListHeightmaps(std::span argv) _console_file_list_heightmap.ValidateFileList(true); for (uint i = 0; i < _console_file_list_heightmap.size(); i++) { - IConsolePrint(CC_DEFAULT, "{}) {}", i, _console_file_list_heightmap[i].title); + IConsolePrint(CC_DEFAULT, "{}) {}", i, _console_file_list_heightmap[i].title.GetDecodedString()); } return true; diff --git a/src/fios.cpp b/src/fios.cpp index 0a6beb038b..94a60a8a3f 100644 --- a/src/fios.cpp +++ b/src/fios.cpp @@ -52,7 +52,7 @@ bool FiosItem::operator< (const FiosItem &other) const if ((_savegame_sort_order & SORT_BY_NAME) == 0 && (*this).mtime != other.mtime) { r = ClampTo(this->mtime - other.mtime); } else { - r = StrNaturalCompare((*this).title, other.title); + r = StrNaturalCompare(this->title.GetDecodedString(), other.title.GetDecodedString()); } if (r == 0) return false; return (_savegame_sort_order & SORT_DESCENDING) ? r > 0 : r < 0; @@ -105,7 +105,7 @@ const FiosItem *FileList::FindItem(std::string_view file) for (const auto &it : *this) { const FiosItem *item = ⁢ if (file == item->name) return item; - if (file == item->title) return item; + if (file == item->title.GetDecodedString()) return item; } /* If no name matches, try to parse it as number */ @@ -120,7 +120,7 @@ const FiosItem *FileList::FindItem(std::string_view file) for (const auto &it : *this) { const FiosItem *item = ⁢ if (long_file == item->name) return item; - if (long_file == item->title) return item; + if (long_file == item->title.GetDecodedString()) return item; } return nullptr; @@ -145,7 +145,7 @@ bool FiosBrowseTo(const FiosItem *item) case DFT_FIOS_DRIVE: #if defined(_WIN32) assert(_fios_path != nullptr); - *_fios_path = std::string{ item->title, 0, 1 } + ":" PATHSEP; + *_fios_path = std::string{ item->name, 0, 1 } + ":" PATHSEP; #endif break; @@ -297,9 +297,9 @@ bool FiosFileScanner::AddFile(const std::string &filename, size_t, const std::st /* If the file doesn't have a title, use its filename */ if (title.empty()) { auto ps = filename.rfind(PATHSEPCHAR); - fios->title = StrMakeValid(filename.substr((ps == std::string::npos ? 0 : ps + 1))); + fios->title = GetEncodedString(STR_JUST_RAW_STRING, StrMakeValid(filename.substr((ps == std::string::npos ? 0 : ps + 1)))); } else { - fios->title = StrMakeValid(title); + fios->title = GetEncodedString(STR_JUST_RAW_STRING, StrMakeValid(title)); }; return true; @@ -329,7 +329,7 @@ static void FiosGetFileList(SaveLoadOperation fop, bool show_dirs, FiosGetTypeAn fios.type = FIOS_TYPE_PARENT; fios.mtime = 0; fios.name = ".."; - fios.title = GetString(STR_SAVELOAD_PARENT_DIRECTORY, ".."sv); + fios.title = GetEncodedString(STR_SAVELOAD_PARENT_DIRECTORY, ".."sv); sort_start = file_list.size(); } @@ -343,7 +343,7 @@ static void FiosGetFileList(SaveLoadOperation fop, bool show_dirs, FiosGetTypeAn fios.type = FIOS_TYPE_DIR; fios.mtime = 0; fios.name = FS2OTTD(dir_entry.path().filename().native()); - fios.title = GetString(STR_SAVELOAD_DIRECTORY, fios.name + PATHSEP); + fios.title = GetEncodedString(STR_SAVELOAD_DIRECTORY, fios.name + PATHSEP); } /* Sort the subdirs always by name, ascending, remember user-sorting order */ @@ -736,7 +736,7 @@ FiosNumberedSaveName::FiosNumberedSaveName(const std::string &prefix) : prefix(p std::sort(list.begin(), list.end()); _savegame_sort_order = order; - std::string_view name = list.begin()->title; + std::string name = list.begin()->title.GetDecodedString(); std::from_chars(name.data() + this->prefix.size(), name.data() + name.size(), this->number); } } diff --git a/src/fios.h b/src/fios.h index b2ef40183b..0436880f26 100644 --- a/src/fios.h +++ b/src/fios.h @@ -78,7 +78,7 @@ extern LoadCheckData _load_check_data; struct FiosItem { FiosType type; int64_t mtime; - std::string title; + EncodedString title; std::string name; bool operator< (const FiosItem &other) const; }; diff --git a/src/fios_gui.cpp b/src/fios_gui.cpp index 339837dd4b..dd4f92aa95 100644 --- a/src/fios_gui.cpp +++ b/src/fios_gui.cpp @@ -514,7 +514,7 @@ public: } else if (item == this->highlighted) { GfxFillRect(br.left, tr.top, br.right, tr.bottom, PC_VERY_DARK_BLUE); } - DrawString(tr, item->title, _fios_colours[item->type.detailed]); + DrawString(tr, item->title.GetDecodedString(), _fios_colours[item->type.detailed]); tr = tr.Translate(0, this->resize.step_height); } break; @@ -728,7 +728,7 @@ public: } if (this->fop == SLO_SAVE) { /* Copy clicked name to editbox */ - this->filename_editbox.text.Assign(file->title); + this->filename_editbox.text.Assign(file->title.GetDecodedString()); this->SetWidgetDirty(WID_SL_SAVE_OSK_TITLE); } } else if (!_load_check_data.HasErrors()) { @@ -860,7 +860,7 @@ public: } else { for (auto &it : this->fios_items) { this->string_filter.ResetState(); - this->string_filter.AddLine(it.title); + this->string_filter.AddLine(it.title.GetDecodedString()); /* We set the vector to show this fios element as filtered depending on the result of the filter */ if (this->string_filter.GetState()) { this->display_list.push_back(&it); diff --git a/src/genworld_gui.cpp b/src/genworld_gui.cpp index a85480e8eb..b91a51945e 100644 --- a/src/genworld_gui.cpp +++ b/src/genworld_gui.cpp @@ -391,7 +391,7 @@ struct GenerateLandscapeWindow : public Window { WidgetID widget_id{}; uint x = 0; uint y = 0; - std::string name{}; + EncodedString name{}; GenerateLandscapeWindowMode mode{}; GenerateLandscapeWindow(WindowDesc &desc, WindowNumber number = 0) : Window(desc) @@ -467,7 +467,7 @@ struct GenerateLandscapeWindow : public Window { } return GetString(_sea_lakes[_settings_newgame.difficulty.quantity_sea_lakes]); - case WID_GL_HEIGHTMAP_NAME_TEXT: return this->name; + case WID_GL_HEIGHTMAP_NAME_TEXT: return this->name.GetDecodedString(); case WID_GL_RIVER_PULLDOWN: return GetString(_rivers[_settings_newgame.game_creation.amount_of_rivers]); case WID_GL_SMOOTHNESS_PULLDOWN: return GetString(_smoothness[_settings_newgame.game_creation.tgen_smoothness]); case WID_GL_VARIETY_PULLDOWN: return GetString(_variety[_settings_newgame.game_creation.variety]); diff --git a/src/os/windows/win32.cpp b/src/os/windows/win32.cpp index 107436a1d8..ba4e2aa539 100644 --- a/src/os/windows/win32.cpp +++ b/src/os/windows/win32.cpp @@ -10,6 +10,7 @@ #include "../../stdafx.h" #include "../../debug.h" #include "../../gfx_func.h" +#include "../../strings_func.h" #include "../../textbuf_gui.h" #include "../../fileio_func.h" #include @@ -29,6 +30,8 @@ #include "../../thread.h" #include "../../library_loader.h" +#include "table/strings.h" + #include "../../safeguards.h" static bool _has_console; @@ -75,7 +78,7 @@ void FiosGetDrives(FileList &file_list) fios->mtime = 0; fios->name += (char)(s[0] & 0xFF); fios->name += ':'; - fios->title = fios->name; + fios->title = GetEncodedString(STR_JUST_RAW_STRING, fios->name); while (*s++ != '\0') { /* Nothing */ } } } diff --git a/src/saveload/saveload.h b/src/saveload/saveload.h index e5c2abc93f..ca2d16841f 100644 --- a/src/saveload/saveload.h +++ b/src/saveload/saveload.h @@ -424,7 +424,7 @@ struct FileToSaveLoad { SaveLoadOperation file_op; ///< File operation to perform. FiosType ftype; ///< File type. std::string name; ///< Name of the file. - std::string title; ///< Internal name of the game. + EncodedString title; ///< Internal name of the game. void SetMode(const FiosType &ft, SaveLoadOperation fop = SLO_LOAD); void Set(const FiosItem &item);