diff --git a/src/fileio.cpp b/src/fileio.cpp index d9396f8ef1..c4e98eacca 100644 --- a/src/fileio.cpp +++ b/src/fileio.cpp @@ -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++) { diff --git a/src/fileio_type.h b/src/fileio_type.h index 26b0ab2948..8c0a1ba475 100644 --- a/src/fileio_type.h +++ b/src/fileio_type.h @@ -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) diff --git a/src/fios.cpp b/src/fios.cpp index 2eb2d7244e..ec7c58b142 100644 --- a/src/fios.cpp +++ b/src/fios.cpp @@ -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 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); diff --git a/src/fios.h b/src/fios.h index 00e91225ec..6a092b7093 100644 --- a/src/fios.h +++ b/src/fios.h @@ -63,7 +63,7 @@ bool FiosBrowseTo(const FiosItem *item); std::string FiosGetCurrentPath(); std::optional 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); diff --git a/src/fios_gui.cpp b/src/fios_gui.cpp index f30f237746..08eeb49e9d 100644 --- a/src/fios_gui.cpp +++ b/src/fios_gui.cpp @@ -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);