From b06efa2d13de311ddd70e3322913f57bdd9ed5c2 Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Fri, 1 Nov 2024 01:16:01 +0100 Subject: [PATCH] delete folder --- client/lobby/SelectionTab.cpp | 12 ++++++++---- server/NetPacksLobbyServer.cpp | 8 ++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/client/lobby/SelectionTab.cpp b/client/lobby/SelectionTab.cpp index a8e1a273d..b9a56242a 100644 --- a/client/lobby/SelectionTab.cpp +++ b/client/lobby/SelectionTab.cpp @@ -208,7 +208,6 @@ SelectionTab::SelectionTab(ESelectionScreen Type) case ESelectionScreen::saveGame: positionsToShow = 16; tabTitle = "{" + CGI->generaltexth->arraytxt[231] + "}"; - tabTitleDelete = "{red|" + CGI->generaltexth->translate("vcmi.lobby.deleteSaveGameTitle") + "}"; break; case ESelectionScreen::campaignList: tabTitle = "{" + CGI->generaltexth->allTexts[726] + "}"; @@ -232,7 +231,7 @@ SelectionTab::SelectionTab(ESelectionScreen Type) sortByDate->setOverlay(std::make_shared(ImagePath::builtin("lobby/selectionTabSortDate"))); buttonsSortBy.push_back(sortByDate); - if(tabType == ESelectionScreen::loadGame || tabType == ESelectionScreen::saveGame || tabType == ESelectionScreen::newGame) + if(tabType == ESelectionScreen::loadGame || tabType == ESelectionScreen::newGame) { buttonDeleteMode = std::make_shared(Point(367, 18), AnimationPath::builtin("lobby/deleteButton"), CButton::tooltip("", CGI->generaltexth->translate("vcmi.lobby.deleteMode")), [this, tabTitle, tabTitleDelete](){ deleteMode = !deleteMode; @@ -343,8 +342,6 @@ void SelectionTab::clickReleased(const Point & cursorPosition) return; } - std::cout << (curItems[py]->isFolder ? curItems[py]->folderName : curItems[py]->fullFileURI) << "\n"; - if(!curItems[py]->isFolder) CInfoWindow::showYesNoDialog(CGI->generaltexth->translate("vcmi.lobby.deleteFile") + "\n\n" + curItems[py]->fullFileURI, std::vector>(), [this, py](){ LobbyDelete ld; @@ -352,6 +349,13 @@ void SelectionTab::clickReleased(const Point & cursorPosition) ld.name = curItems[py]->fileURI; CSH->sendLobbyPack(ld); }, nullptr); + else + CInfoWindow::showYesNoDialog(CGI->generaltexth->translate("vcmi.lobby.deleteFolder") + "\n\n" + curFolder + curItems[py]->folderName, std::vector>(), [this, py](){ + LobbyDelete ld; + ld.type = LobbyDelete::SAVEGAME_FOLDER; + ld.name = curFolder + curItems[py]->folderName; + CSH->sendLobbyPack(ld); + }, nullptr); } } #ifdef VCMI_MOBILE diff --git a/server/NetPacksLobbyServer.cpp b/server/NetPacksLobbyServer.cpp index c9458e50e..2f645d9f7 100644 --- a/server/NetPacksLobbyServer.cpp +++ b/server/NetPacksLobbyServer.cpp @@ -447,6 +447,14 @@ void ApplyOnServerNetPackVisitor::visitLobbyDelete(LobbyDelete & pack) auto res = ResourcePath(pack.name, pack.type == LobbyDelete::SAVEGAME ? EResType::SAVEGAME : EResType::MAP); auto file = boost::filesystem::canonical(*CResourceHandler::get()->getResourceName(res)); boost::filesystem::remove(file); + if(boost::filesystem::is_empty(file.parent_path())) + boost::filesystem::remove(file.parent_path()); + } + else if(pack.type == LobbyDelete::SAVEGAME_FOLDER) + { + auto res = ResourcePath("Saves/" + pack.name, EResType::DIRECTORY); + auto folder = boost::filesystem::canonical(*CResourceHandler::get()->getResourceName(res)); + boost::filesystem::remove_all(folder); } LobbyUpdateState lus;