From afd0313802e72bc3db3fa132cc18fbe33a3bc9fc Mon Sep 17 00:00:00 2001 From: Kuhnovic <68320206+Kuhnovic@users.noreply.github.com> Date: Wed, 17 Sep 2025 21:43:22 +0200 Subject: [PATCH] Fix #14620: Use full file path when deleting files. (#14623) --- src/fios.cpp | 10 ---------- src/fios.h | 1 - src/fios_gui.cpp | 17 +++++++++++++---- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/fios.cpp b/src/fios.cpp index 94a60a8a3f..fc02d43da7 100644 --- a/src/fios.cpp +++ b/src/fios.cpp @@ -230,16 +230,6 @@ std::string FiosMakeHeightmapName(std::string_view name) return FiosMakeFilename(_fios_path, name, fmt::format(".{}", GetCurrentScreenshotExtension())); } -/** - * Delete a file. - * @param name Filename to delete. - * @return Whether the file deletion was successful. - */ -bool FiosDelete(std::string_view name) -{ - return FioRemove(FiosMakeSavegameName(name)); -} - typedef std::tuple FiosGetTypeAndNameProc(SaveLoadOperation fop, std::string_view filename, std::string_view ext); /** diff --git a/src/fios.h b/src/fios.h index 0436880f26..0da3311f7b 100644 --- a/src/fios.h +++ b/src/fios.h @@ -112,7 +112,6 @@ bool FiosBrowseTo(const FiosItem *item); std::string FiosGetCurrentPath(); std::optional FiosGetDiskFreeSpace(const std::string &path); -bool FiosDelete(std::string_view name); std::string FiosMakeHeightmapName(std::string_view name); std::string FiosMakeSavegameName(std::string_view name); diff --git a/src/fios_gui.cpp b/src/fios_gui.cpp index c9f48dd0d0..ef5c5961c4 100644 --- a/src/fios_gui.cpp +++ b/src/fios_gui.cpp @@ -327,13 +327,13 @@ private: QueryString filename_editbox; ///< Filename editbox. AbstractFileType abstract_filetype{}; /// Type of file to select. SaveLoadOperation fop{}; ///< File operation to perform. - FileList fios_items{}; ///< Save game list. + FileList fios_items{}; ///< Item list. FiosItem o_dir{}; ///< Original dir (home dir for this browser) - const FiosItem *selected = nullptr; ///< Selected game in #fios_items, or \c nullptr. + const FiosItem *selected = nullptr; ///< Selected item in #fios_items, or \c nullptr. const FiosItem *highlighted = nullptr; ///< Item in fios_items highlighted by mouse pointer, or \c nullptr. Scrollbar *vscroll = nullptr; - StringFilter string_filter{}; ///< Filter for available games. + StringFilter string_filter{}; ///< Filter for available items. QueryString filter_editbox; ///< Filter editbox; std::vector display_list{}; ///< Filtered display list @@ -353,8 +353,10 @@ private: { auto *save_load_window = static_cast(window); + assert(save_load_window->selected != nullptr); + if (confirmed) { - if (!FiosDelete(save_load_window->filename_editbox.text.GetText())) { + if (!FioRemove(save_load_window->selected->name)) { ShowErrorMessage(GetEncodedString(STR_ERROR_UNABLE_TO_DELETE_FILE), {}, WL_ERROR); } else { save_load_window->InvalidateData(SLIWD_RESCAN_FILES); @@ -909,6 +911,8 @@ public: /* Selection changes */ if (!gui_scope) break; + if (this->fop == SLO_SAVE) this->SetWidgetDisabledState(WID_SL_DELETE_SELECTION, this->selected == nullptr); + if (this->fop != SLO_LOAD) break; switch (this->abstract_filetype) { @@ -947,6 +951,11 @@ public: this->string_filter.SetFilterTerm(this->filter_editbox.text.GetText()); this->InvalidateData(SLIWD_FILTER_CHANGES); } + + if (wid == WID_SL_SAVE_OSK_TITLE) { + this->selected = nullptr; + this->InvalidateData(SLIWD_SELECTION_CHANGES); + } } };