diff --git a/src/MassManager/MassManager.cpp b/src/MassManager/MassManager.cpp index e9069d9..767c4dd 100644 --- a/src/MassManager/MassManager.cpp +++ b/src/MassManager/MassManager.cpp @@ -105,8 +105,8 @@ auto MassManager::exportMass(Int hangar) -> bool { } Containers::String source = Utility::Path::join(_saveDirectory, _hangars[hangar].filename()); - Containers::String dest = Utility::Path::join(_stagingAreaDirectory, - Utility::format("{}_{}.sav", _hangars[hangar].name(), _account)); + Containers::String dest = Utility::Path::join(_stagingAreaDirectory, + Utility::format("{}_{}.sav", _hangars[hangar].name(), _account)); if(!Utility::Path::copy(source, dest)) { _lastError = Utility::format("Couldn't export data from hangar {:.2d} to {}", hangar, dest); @@ -200,6 +200,26 @@ void MassManager::refreshStagedMasses() { } } +void MassManager::refreshStagedMass(Containers::StringView filename) { + Utility::Debug{} << "Refreshing staged unit with filename" << filename; + + bool file_exists = Utility::Path::exists(Utility::Path::join(_stagingAreaDirectory, filename)); + auto it = _stagedMasses.find(filename); + + if(file_exists) { + auto name = Mass::getNameFromFile(Utility::Path::join(_stagingAreaDirectory, filename)); + if(name) { + _stagedMasses[filename] = *name; + } + else if(it != _stagedMasses.cend()) { + _stagedMasses.erase(it); + } + } + else if(it != _stagedMasses.cend()) { + _stagedMasses.erase(it); + } +} + auto MassManager::deleteStagedMass(Containers::StringView filename) -> bool { if(_stagedMasses.find(filename) == _stagedMasses.cend()) { _lastError = "The file "_s + filename + " couldn't be found in the list of staged M.A.S.S.es."_s; diff --git a/src/MassManager/MassManager.h b/src/MassManager/MassManager.h index caa9c39..330d98d 100644 --- a/src/MassManager/MassManager.h +++ b/src/MassManager/MassManager.h @@ -44,6 +44,7 @@ class MassManager { auto stagedMasses() -> std::map const&; void refreshStagedMasses(); + void refreshStagedMass(Containers::StringView filename); auto deleteStagedMass(Containers::StringView filename) -> bool; private: diff --git a/src/SaveTool/SaveTool.h b/src/SaveTool/SaveTool.h index d281234..91ec2f5 100644 --- a/src/SaveTool/SaveTool.h +++ b/src/SaveTool/SaveTool.h @@ -94,7 +94,7 @@ class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener FileDeleted = efsw::Action::Delete, FileModified = efsw::Action::Modified, FileMoved = efsw::Action::Moved, - StagedUpdate + StagedUpdate = 1 << 3 }; void fileUpdateEvent(SDL_Event& event); diff --git a/src/SaveTool/SaveTool_FileWatcher.cpp b/src/SaveTool/SaveTool_FileWatcher.cpp index 41a8586..bd5b25f 100644 --- a/src/SaveTool/SaveTool_FileWatcher.cpp +++ b/src/SaveTool/SaveTool_FileWatcher.cpp @@ -32,8 +32,10 @@ void SaveTool::handleFileAction(efsw::WatchID watch_id, SDL_zero(event); event.type = _fileEventId; + event.user.data1 = Containers::String{Containers::AllocatedInit, filename.c_str()}.release(); + if(watch_id == _watchIDs[StagingDir] && Utility::String::endsWith(filename, ".sav")) { - event.user.code = StagedUpdate; + event.user.code = StagedUpdate | action; SDL_PushEvent(&event); return; } @@ -47,7 +49,6 @@ void SaveTool::handleFileAction(efsw::WatchID watch_id, } event.user.code = action; - event.user.data1 = Containers::String{Containers::AllocatedInit, filename.c_str()}.release(); if(action == efsw::Actions::Moved) { event.user.data2 = Containers::String{Containers::AllocatedInit, old_filename.c_str()}.release(); } @@ -56,12 +57,13 @@ void SaveTool::handleFileAction(efsw::WatchID watch_id, } void SaveTool::fileUpdateEvent(SDL_Event& event) { - if(event.user.code == StagedUpdate) { - _massManager->refreshStagedMasses(); + Containers::String filename{static_cast(event.user.data1), std::strlen(static_cast(event.user.data1)), nullptr}; + + if((event.user.code & StagedUpdate) == StagedUpdate) { + _massManager->refreshStagedMass(filename); return; } - Containers::String filename{static_cast(event.user.data1), std::strlen(static_cast(event.user.data1)), nullptr}; Containers::String old_filename; Int index = 0;