1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-02-02 09:04:29 +01:00

Fix #14620: Use full file path when deleting files. (#14623)

This commit is contained in:
Kuhnovic
2025-09-17 21:43:22 +02:00
committed by GitHub
parent 129825077b
commit 262c364a28
3 changed files with 13 additions and 15 deletions

View File

@@ -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<FiosType, std::string> FiosGetTypeAndNameProc(SaveLoadOperation fop, std::string_view filename, std::string_view ext);
/**

View File

@@ -112,7 +112,6 @@ bool FiosBrowseTo(const FiosItem *item);
std::string FiosGetCurrentPath();
std::optional<uint64_t> 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);

View File

@@ -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<FiosItem *> display_list{}; ///< Filtered display list
@@ -353,8 +353,10 @@ private:
{
auto *save_load_window = static_cast<SaveLoadWindow*>(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);
}
}
};