diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index c71834ef60..90dd2544ca 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -432,9 +432,7 @@ DEF_CONSOLE_CMD(ConLoad) if (item != nullptr) { if (GetAbstractFileType(item->type) == FT_SAVEGAME) { _switch_mode = SM_LOAD_GAME; - _file_to_saveload.SetMode(item->type); - _file_to_saveload.SetName(item->name); - _file_to_saveload.SetTitle(item->title); + _file_to_saveload.Set(*item); } else { IConsolePrint(CC_ERROR, "'{}' is not a savegame.", file); } diff --git a/src/fios_gui.cpp b/src/fios_gui.cpp index 1ad14397f5..7a1cf0a06c 100644 --- a/src/fios_gui.cpp +++ b/src/fios_gui.cpp @@ -634,9 +634,7 @@ public: case WID_SL_LOAD_BUTTON: { if (this->selected == nullptr || _load_check_data.HasErrors()) break; - _file_to_saveload.SetMode(this->selected->type); - _file_to_saveload.SetName(this->selected->name); - _file_to_saveload.SetTitle(this->selected->title); + _file_to_saveload.Set(*this->selected); if (this->abstract_filetype == FT_HEIGHTMAP) { this->Close(); @@ -688,7 +686,7 @@ public: if (GetDetailedFileType(file->type) == DFT_GAME_FILE) { /* Other detailed file types cannot be checked before. */ - SaveOrLoad(name, SLO_CHECK, DFT_GAME_FILE, NO_DIRECTORY, false); + SaveOrLoad(file->name, SLO_CHECK, DFT_GAME_FILE, NO_DIRECTORY, false); } this->InvalidateData(SLIWD_SELECTION_CHANGES); @@ -705,9 +703,7 @@ public: this->OnClick(pt, WID_SL_LOAD_BUTTON, 1); } else { assert(this->abstract_filetype == FT_HEIGHTMAP); - _file_to_saveload.SetMode(file->type); - _file_to_saveload.SetName(file->name); - _file_to_saveload.SetTitle(file->title); + _file_to_saveload.Set(*file); this->Close(); ShowHeightmapLoad(); diff --git a/src/genworld_gui.cpp b/src/genworld_gui.cpp index a9dbb63b4c..2374ef635b 100644 --- a/src/genworld_gui.cpp +++ b/src/genworld_gui.cpp @@ -406,7 +406,7 @@ struct GenerateLandscapeWindow : public Window { uint widget_id; uint x; uint y; - char name[64]; + std::string name; GenerateLandscapeWindowMode mode; GenerateLandscapeWindow(WindowDesc *desc, WindowNumber number = 0) : Window(desc) @@ -1057,7 +1057,7 @@ static void _ShowGenerateLandscape(GenerateLandscapeWindowMode mode) if (mode == GLWM_HEIGHTMAP) { w->x = x; w->y = y; - strecpy(w->name, _file_to_saveload.title, lastof(w->name)); + w->name = _file_to_saveload.title; } SetWindowDirty(WC_GENERATE_LANDSCAPE, mode); diff --git a/src/openttd.cpp b/src/openttd.cpp index bcb6855702..e919e80b66 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -584,7 +584,7 @@ int openttd_main(int argc, char *argv[]) case 'e': _switch_mode = (_switch_mode == SM_LOAD_GAME || _switch_mode == SM_LOAD_SCENARIO ? SM_LOAD_SCENARIO : SM_EDITOR); break; case 'g': if (mgo.opt != nullptr) { - _file_to_saveload.SetName(mgo.opt); + _file_to_saveload.name = mgo.opt; bool is_scenario = _switch_mode == SM_EDITOR || _switch_mode == SM_LOAD_SCENARIO; _switch_mode = is_scenario ? SM_LOAD_SCENARIO : SM_LOAD_GAME; _file_to_saveload.SetMode(SLO_LOAD, is_scenario ? FT_SCENARIO : FT_SAVEGAME, DFT_GAME_FILE); diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index b9945597c6..0632451a71 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -3395,22 +3395,15 @@ void FileToSaveLoad::SetMode(SaveLoadOperation fop, AbstractFileType aft, Detail this->abstract_ftype = aft; } -/** - * Set the name of the file. - * @param name Name of the file. - */ -void FileToSaveLoad::SetName(const char *name) -{ - this->name = name; -} - /** * Set the title of the file. * @param title Title of the file. */ -void FileToSaveLoad::SetTitle(const char *title) +void FileToSaveLoad::Set(const FiosItem &item) { - strecpy(this->title, title, lastof(this->title)); + this->SetMode(item.type); + this->name = item.name; + this->title = item.title; } SaveLoadTable SaveLoadHandler::GetLoadDescription() const diff --git a/src/saveload/saveload.h b/src/saveload/saveload.h index 3c406c767b..ba5d5480fe 100644 --- a/src/saveload/saveload.h +++ b/src/saveload/saveload.h @@ -365,16 +365,15 @@ enum SaveOrLoadResult { /** Deals with the type of the savegame, independent of extension */ struct FileToSaveLoad { - SaveLoadOperation file_op; ///< File operation to perform. + SaveLoadOperation file_op; ///< File operation to perform. DetailedFileType detail_ftype; ///< Concrete file type (PNG, BMP, old save, etc). AbstractFileType abstract_ftype; ///< Abstract type of file (scenario, heightmap, etc). std::string name; ///< Name of the file. - char title[255]; ///< Internal name of the game. + std::string title; ///< Internal name of the game. void SetMode(FiosType ft); void SetMode(SaveLoadOperation fop, AbstractFileType aft, DetailedFileType dft); - void SetName(const char *name); - void SetTitle(const char *title); + void Set(const FiosItem &item); }; /** Types of save games. */