Changeset - r27194:98f2b221171c
[Not reviewed]
master
0 4 0
Rubidium - 17 months ago 2023-04-16 19:27:01
rubidium@openttd.org
Codechange: let FiosBrowseTo return a bool
4 files changed with 9 insertions and 11 deletions:
0 comments (0 inline, 0 general)
src/console_cmds.cpp
Show inline comments
 
@@ -430,13 +430,13 @@ DEF_CONSOLE_CMD(ConLoad)
 
	_console_file_list.ValidateFileList();
 
	const FiosItem *item = _console_file_list.FindItem(file);
 
	if (item != nullptr) {
 
		if (GetAbstractFileType(item->type) == FT_SAVEGAME) {
 
			_switch_mode = SM_LOAD_GAME;
 
			_file_to_saveload.SetMode(item->type);
 
			_file_to_saveload.SetName(FiosBrowseTo(item));
 
			_file_to_saveload.SetName(item->name);
 
			_file_to_saveload.SetTitle(item->title);
 
		} else {
 
			IConsolePrint(CC_ERROR, "'{}' is not a savegame.", file);
 
		}
 
	} else {
 
		IConsolePrint(CC_ERROR, "'{}' cannot be found.", file);
src/fios.cpp
Show inline comments
 
@@ -142,15 +142,15 @@ StringID FiosGetDescText(const char **pa
 
	return FiosGetDiskFreeSpace(*path, total_free) ? STR_SAVELOAD_BYTES_FREE : STR_ERROR_UNABLE_TO_READ_DRIVE;
 
}
 

	
 
/**
 
 * Browse to a new path based on the passed \a item, starting at #_fios_path.
 
 * @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) {
 
		case FIOS_TYPE_DRIVE:
 
#if defined(_WIN32) || defined(__OS2__)
 
			assert(_fios_path != nullptr);
 
			*_fios_path = std::string{ item->title[0] } + ":" PATHSEP;
 
@@ -188,16 +188,16 @@ const char *FiosBrowseTo(const FiosItem 
 
		case FIOS_TYPE_FILE:
 
		case FIOS_TYPE_OLDFILE:
 
		case FIOS_TYPE_SCENARIO:
 
		case FIOS_TYPE_OLD_SCENARIO:
 
		case FIOS_TYPE_PNG:
 
		case FIOS_TYPE_BMP:
 
			return item->name;
 
			return false;
 
	}
 

	
 
	return nullptr;
 
	return true;
 
}
 

	
 
/**
 
 * Construct a filename from its components in destination buffer \a buf.
 
 * @param path Directory path, may be \c nullptr.
 
 * @param name Filename.
src/fios.h
Show inline comments
 
@@ -114,13 +114,13 @@ extern SortingBits _savegame_sort_order;
 
void ShowSaveLoadDialog(AbstractFileType abstract_filetype, SaveLoadOperation fop);
 

	
 
void FiosGetSavegameList(SaveLoadOperation fop, FileList &file_list);
 
void FiosGetScenarioList(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);
 
bool FiosDelete(const char *name);
 
std::string FiosMakeHeightmapName(const char *name);
 
std::string FiosMakeSavegameName(const char *name);
 

	
src/fios_gui.cpp
Show inline comments
 
@@ -631,15 +631,14 @@ public:
 
				this->InvalidateData(SLIWD_RESCAN_FILES);
 
				break;
 

	
 
			case WID_SL_LOAD_BUTTON: {
 
				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.SetName(name);
 
				_file_to_saveload.SetName(this->selected->name);
 
				_file_to_saveload.SetTitle(this->selected->title);
 

	
 
				if (this->abstract_filetype == FT_HEIGHTMAP) {
 
					this->Close();
 
					ShowHeightmapLoad();
 
				} else if (!_load_check_data.HasNewGrfs() || _load_check_data.grf_compatibility != GLC_NOT_FOUND || _settings_client.gui.UserIsAllowedToChangeNewGRFs()) {
 
@@ -673,14 +672,13 @@ public:
 
				while (i <= y) {
 
					if (!this->fios_items_shown[i]) y++;
 
					i++;
 
				}
 
				const FiosItem *file = &this->fios_items[y];
 

	
 
				const char *name = FiosBrowseTo(file);
 
				if (name == nullptr) {
 
				if (FiosBrowseTo(file)) {
 
					/* Changed directory, need refresh. */
 
					this->InvalidateData(SLIWD_RESCAN_FILES);
 
					break;
 
				}
 

	
 
				if (click_count == 1) {
 
@@ -705,13 +703,13 @@ public:
 
					if (this->fop == SLO_LOAD) {
 
						if (this->abstract_filetype == FT_SAVEGAME || this->abstract_filetype == FT_SCENARIO) {
 
							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(name);
 
							_file_to_saveload.SetName(file->name);
 
							_file_to_saveload.SetTitle(file->title);
 

	
 
							this->Close();
 
							ShowHeightmapLoad();
 
						}
 
					}
0 comments (0 inline, 0 general)