FIOS fixes

pull/678/head
lucaFiorini 2 months ago
parent 26fff27e50
commit 4ee6381a1f

@ -43,6 +43,7 @@ static const char * const _subdirs[] = {
"save" PATHSEP "autosave" PATHSEP,
"scenario" PATHSEP,
"scenario" PATHSEP "heightmap" PATHSEP,
"orderlist" PATHSEP,
"gm" PATHSEP,
"data" PATHSEP,
"baseset" PATHSEP,
@ -1094,7 +1095,7 @@ void DeterminePaths(const char *exe, bool only_local_path)
DEBUG(misc, 1, "%s found as personal directory", _personal_dir.c_str());
static const Subdirectory default_subdirs[] = {
SAVE_DIR, AUTOSAVE_DIR, SCENARIO_DIR, HEIGHTMAP_DIR, BASESET_DIR, NEWGRF_DIR, AI_DIR, AI_LIBRARY_DIR, GAME_DIR, GAME_LIBRARY_DIR, SCREENSHOT_DIR, SOCIAL_INTEGRATION_DIR
SAVE_DIR, AUTOSAVE_DIR, SCENARIO_DIR, HEIGHTMAP_DIR, ORDERLIST_DIR, BASESET_DIR, NEWGRF_DIR, AI_DIR, AI_LIBRARY_DIR, GAME_DIR, GAME_LIBRARY_DIR, SCREENSHOT_DIR, SOCIAL_INTEGRATION_DIR
};
for (uint i = 0; i < lengthof(default_subdirs); i++) {

@ -36,7 +36,7 @@ enum DetailedFileType {
DFT_HEIGHTMAP_PNG, ///< PNG file.
/* Orderlist files */
DFT_ORDERLIST, ///< XML file.
DFT_ORDERLIST, ///< JSON file.
/* fios 'files' */
DFT_FIOS_DRIVE, ///< A drive (letter) entry.
@ -116,6 +116,7 @@ enum Subdirectory {
AUTOSAVE_DIR, ///< Subdirectory of save for autosaves
SCENARIO_DIR, ///< Base directory for all scenarios
HEIGHTMAP_DIR, ///< Subdirectory of scenario for heightmaps
ORDERLIST_DIR, ///< Subdirectort for all orderlists
OLD_GM_DIR, ///< Old subdirectory for the music
OLD_DATA_DIR, ///< Old subdirectory for the data.
BASESET_DIR, ///< Subdirectory for all base data (base sets, intro game)

@ -259,9 +259,23 @@ std::string FiosMakeHeightmapName(const char *name)
* @param name Filename to delete.
* @return Whether the file deletion was successful.
*/
bool FiosDelete(const char *name)
bool FiosDelete(const char *name,AbstractFileType ft)
{
std::string filename = FiosMakeSavegameName(name);
std::string filename;
switch (ft) {
case FT_SAVEGAME:
case FT_SCENARIO:
filename = FiosMakeSavegameName(name);
break;
case FT_ORDERLIST:
filename = FiosMakeOrderListName(name);
break;
default:
NOT_REACHED();
break;
}
return unlink(filename.c_str()) == 0;
}
@ -530,7 +544,7 @@ FiosType FiosGetOrderlistListCallback(SaveLoadOperation fop, const std::string &
if (ext == nullptr) ext = "";
if (StrEqualsIgnoreCase(ext, ".json")) {
GetFileTitle(file, title, last, SAVE_DIR);
GetFileTitle(file, title, last, ORDERLIST_DIR);
return FIOS_TYPE_ORDERLIST;
}
@ -548,7 +562,7 @@ void FiosGetOrderlistList(SaveLoadOperation fop, bool show_dirs, FileList &file_
{
static std::optional<std::string> fios_save_path;
if (!fios_save_path) fios_save_path = FioFindDirectory(SAVE_DIR);
if (!fios_save_path) fios_save_path = FioFindDirectory(ORDERLIST_DIR);
_fios_path = &(*fios_save_path);

@ -63,7 +63,7 @@ bool FiosBrowseTo(const FiosItem *item);
std::string FiosGetCurrentPath();
std::optional<uint64_t> FiosGetDiskFreeSpace(const std::string &path);
bool FiosDelete(const char *name);
bool FiosDelete(const char *name, AbstractFileType file_type);
std::string FiosMakeHeightmapName(const char *name);
std::string FiosMakeSavegameName(const char *name);
std::string FiosMakeOrderListName(const char *name);

@ -281,7 +281,10 @@ static constexpr NWidgetPart _nested_save_orderlist_dialog_widgets[] = {
EndContainer(),
/* Save button*/
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_SAVE_GAME), SetDataTip(STR_SAVELOAD_SAVE_BUTTON, STR_SAVELOAD_SAVE_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_DELETE_SELECTION), SetDataTip(STR_SAVELOAD_DELETE_BUTTON, STR_SAVELOAD_DELETE_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_SAVE_GAME), SetDataTip(STR_SAVELOAD_SAVE_BUTTON, STR_SAVELOAD_SAVE_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
EndContainer(),
EndContainer(),
EndContainer(),
@ -497,6 +500,10 @@ public:
o_dir.name = FioFindDirectory(HEIGHTMAP_DIR);
break;
case FT_ORDERLIST:
o_dir.name = FioFindDirectory(ORDERLIST_DIR);
break;
default:
o_dir.name = _personal_dir;
}
@ -909,7 +916,7 @@ public:
if (this->fop != SLO_SAVE) return;
if (this->IsWidgetLowered(WID_SL_DELETE_SELECTION)) { // Delete button clicked
if (!FiosDelete(this->filename_editbox.text.buf)) {
if (!FiosDelete(this->filename_editbox.text.buf, this->abstract_filetype)) {
ShowErrorMessage(STR_ERROR_UNABLE_TO_DELETE_FILE, INVALID_STRING_ID, WL_ERROR);
} else {
this->InvalidateData(SLIWD_RESCAN_FILES);

Loading…
Cancel
Save