1
0
Fork 0

Codechange: let FiosBrowseTo return a bool

pull/10740/head
Rubidium 2023-04-16 21:27:01 +02:00 committed by rubidium42
parent c829930440
commit f0a1ddd81c
4 changed files with 9 additions and 11 deletions

View File

@ -433,7 +433,7 @@ DEF_CONSOLE_CMD(ConLoad)
if (GetAbstractFileType(item->type) == FT_SAVEGAME) { if (GetAbstractFileType(item->type) == FT_SAVEGAME) {
_switch_mode = SM_LOAD_GAME; _switch_mode = SM_LOAD_GAME;
_file_to_saveload.SetMode(item->type); _file_to_saveload.SetMode(item->type);
_file_to_saveload.SetName(FiosBrowseTo(item)); _file_to_saveload.SetName(item->name);
_file_to_saveload.SetTitle(item->title); _file_to_saveload.SetTitle(item->title);
} else { } else {
IConsolePrint(CC_ERROR, "'{}' is not a savegame.", file); IConsolePrint(CC_ERROR, "'{}' is not a savegame.", file);

View File

@ -145,9 +145,9 @@ StringID FiosGetDescText(const char **path, uint64 *total_free)
/** /**
* Browse to a new path based on the passed \a item, starting at #_fios_path. * Browse to a new path based on the passed \a item, starting at #_fios_path.
* @param *item Item telling us what to do. * @param *item Item telling us what to do.
* @return A filename w/path if we reached a file, otherwise \c nullptr. * @return \c true when the path got changed.
*/ */
const char *FiosBrowseTo(const FiosItem *item) bool FiosBrowseTo(const FiosItem *item)
{ {
switch (item->type) { switch (item->type) {
case FIOS_TYPE_DRIVE: case FIOS_TYPE_DRIVE:
@ -191,10 +191,10 @@ const char *FiosBrowseTo(const FiosItem *item)
case FIOS_TYPE_OLD_SCENARIO: case FIOS_TYPE_OLD_SCENARIO:
case FIOS_TYPE_PNG: case FIOS_TYPE_PNG:
case FIOS_TYPE_BMP: case FIOS_TYPE_BMP:
return item->name; return false;
} }
return nullptr; return true;
} }
/** /**

View File

@ -117,7 +117,7 @@ void FiosGetSavegameList(SaveLoadOperation fop, FileList &file_list);
void FiosGetScenarioList(SaveLoadOperation fop, FileList &file_list); void FiosGetScenarioList(SaveLoadOperation fop, FileList &file_list);
void FiosGetHeightmapList(SaveLoadOperation fop, FileList &file_list); void FiosGetHeightmapList(SaveLoadOperation fop, FileList &file_list);
const char *FiosBrowseTo(const FiosItem *item); bool FiosBrowseTo(const FiosItem *item);
StringID FiosGetDescText(const char **path, uint64 *total_free); StringID FiosGetDescText(const char **path, uint64 *total_free);
bool FiosDelete(const char *name); bool FiosDelete(const char *name);

View File

@ -634,9 +634,8 @@ public:
case WID_SL_LOAD_BUTTON: { case WID_SL_LOAD_BUTTON: {
if (this->selected == nullptr || _load_check_data.HasErrors()) break; if (this->selected == nullptr || _load_check_data.HasErrors()) break;
const char *name = FiosBrowseTo(this->selected);
_file_to_saveload.SetMode(this->selected->type); _file_to_saveload.SetMode(this->selected->type);
_file_to_saveload.SetName(name); _file_to_saveload.SetName(this->selected->name);
_file_to_saveload.SetTitle(this->selected->title); _file_to_saveload.SetTitle(this->selected->title);
if (this->abstract_filetype == FT_HEIGHTMAP) { if (this->abstract_filetype == FT_HEIGHTMAP) {
@ -676,8 +675,7 @@ public:
} }
const FiosItem *file = &this->fios_items[y]; const FiosItem *file = &this->fios_items[y];
const char *name = FiosBrowseTo(file); if (FiosBrowseTo(file)) {
if (name == nullptr) {
/* Changed directory, need refresh. */ /* Changed directory, need refresh. */
this->InvalidateData(SLIWD_RESCAN_FILES); this->InvalidateData(SLIWD_RESCAN_FILES);
break; break;
@ -708,7 +706,7 @@ public:
} else { } else {
assert(this->abstract_filetype == FT_HEIGHTMAP); assert(this->abstract_filetype == FT_HEIGHTMAP);
_file_to_saveload.SetMode(file->type); _file_to_saveload.SetMode(file->type);
_file_to_saveload.SetName(name); _file_to_saveload.SetName(file->name);
_file_to_saveload.SetTitle(file->title); _file_to_saveload.SetTitle(file->title);
this->Close(); this->Close();