1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-25 22:42:04 +02:00

possibility to delete unsupported saves

This commit is contained in:
Laserlicht
2024-10-31 21:57:20 +01:00
parent e45be3c5e6
commit 1f0847660b
8 changed files with 78 additions and 2 deletions

View File

@@ -42,9 +42,11 @@
#include "../../lib/mapping/CMapInfo.h"
#include "../../lib/mapping/CMapHeader.h"
#include "../../lib/mapping/MapFormat.h"
#include "../../lib/networkPacks/PacksForLobby.h"
#include "../../lib/texts/CGeneralTextHandler.h"
#include "../../lib/texts/TextOperations.h"
#include "../../lib/TerrainHandler.h"
#include "../../lib/UnlockGuard.h"
bool mapSorter::operator()(const std::shared_ptr<ElementInfo> aaa, const std::shared_ptr<ElementInfo> bbb)
{
@@ -823,6 +825,15 @@ void SelectionTab::parseMaps(const std::unordered_set<ResourcePath> & files)
void SelectionTab::parseSaves(const std::unordered_set<ResourcePath> & files)
{
enum Choice { NONE, REMAIN, DELETE };
Choice deleteUnsupported = NONE;
auto doDeleteUnsupported = [](std::string file){
LobbyDelete ld;
ld.type = LobbyDelete::SAVEGAME;
ld.name = file;
CSH->sendLobbyPack(ld);
};
for(auto & file : files)
{
try
@@ -863,7 +874,28 @@ void SelectionTab::parseSaves(const std::unordered_set<ResourcePath> & files)
}
catch(const std::exception & e)
{
logGlobal->error("Error: Failed to process %s: %s", file.getName(), e.what());
// asking for deletion of unsupported saves
if(CSH->isHost())
{
if(deleteUnsupported == DELETE)
doDeleteUnsupported(file.getName());
else if(deleteUnsupported == NONE)
{
CInfoWindow::showYesNoDialog(CGI->generaltexth->translate("vcmi.lobby.deleteUnsupportedSave"), std::vector<std::shared_ptr<CComponent>>(), [&deleteUnsupported, doDeleteUnsupported, file](){
doDeleteUnsupported(file.getName());
deleteUnsupported = DELETE;
}, [&deleteUnsupported](){ deleteUnsupported = REMAIN; });
while(deleteUnsupported == NONE)
{
auto unlockInterface = vstd::makeUnlockGuard(GH.interfaceMutex);
boost::this_thread::sleep_for(boost::chrono::milliseconds(5));
}
}
}
if(deleteUnsupported != DELETE)
logGlobal->error("Error: Failed to process %s: %s", file.getName(), e.what());
}
}
}