diff --git a/GUI/EvtMainFrame.cpp b/GUI/EvtMainFrame.cpp index 48ca4c8..1bee70e 100644 --- a/GUI/EvtMainFrame.cpp +++ b/GUI/EvtMainFrame.cpp @@ -54,14 +54,26 @@ EvtMainFrame::EvtMainFrame(wxWindow* parent): MainFrame(parent) { _watcher.Connect(wxEVT_FSWATCHER, wxFileSystemWatcherEventHandler(EvtMainFrame::fileUpdateEvent), nullptr, this); _watcher.AddTree(wxFileName(Utility::Directory::toNativeSeparators(_manager.saveDirectory()), wxPATH_WIN), wxFSW_EVENT_CREATE|wxFSW_EVENT_DELETE|wxFSW_EVENT_MODIFY|wxFSW_EVENT_RENAME, wxString::Format("*%s.sav", _manager.steamId())); - _watcher.AddTree(wxFileName(Utility::Directory::toNativeSeparators(_manager.stagingAreaDirectory()), wxPATH_WIN), - wxFSW_EVENT_CREATE|wxFSW_EVENT_DELETE|wxFSW_EVENT_MODIFY|wxFSW_EVENT_RENAME, "*.sav"); + + if(_manager.hasDemoUnits()) { + int result = wxMessageBox("M.A.S.S.es from the demo version of the game were found.\n\n" + "Do you want to move them to the staging area ?\n" + "WARNING: M.A.S.S.es from the demo version will keep parts you haven't unlocked in the main game, so you might get an advantage if you haven't progressed to that point.", + "Question", wxCENTRE|wxYES_NO|wxICON_QUESTION, this); + + if(result == wxYES) { + _manager.addDemoUnitsToStaging(); + } + } std::vector v = _manager.initialiseStagingArea(); for(const std::string& s : v) { _stagingList->Append(s); } + _watcher.AddTree(wxFileName(Utility::Directory::toNativeSeparators(_manager.stagingAreaDirectory()), wxPATH_WIN), + wxFSW_EVENT_CREATE|wxFSW_EVENT_DELETE|wxFSW_EVENT_MODIFY|wxFSW_EVENT_RENAME, "*.sav"); + _gameCheckTimer.Start(3000); if(!_manager.findScreenshotDirectory()) { diff --git a/MassManager/MassManager.cpp b/MassManager/MassManager.cpp index dea0e4d..cc02ec4 100644 --- a/MassManager/MassManager.cpp +++ b/MassManager/MassManager.cpp @@ -69,6 +69,35 @@ auto MassManager::lastError() -> std::string const& { return _lastError; } +auto MassManager::hasDemoUnits() -> bool { + using Utility::Directory::Flag; + std::vector list = Utility::Directory::list(_saveDirectory, Flag::SkipSpecial|Flag::SkipDirectories|Flag::SkipDotAndDotDot); + + for(const std::string& file : list) { + if(Utility::String::beginsWith(file, "DemoUnit") && Utility::String::endsWith(file, ".sav")) { + return true; + } + } + + return false; +} + +void MassManager::addDemoUnitsToStaging() { + using Utility::Directory::Flag; + std::vector list = Utility::Directory::list(_saveDirectory, Flag::SkipSpecial|Flag::SkipDirectories|Flag::SkipDotAndDotDot); + + auto predicate = [](const std::string& name)->bool{ + return !(Utility::String::endsWith(name, ".sav") && Utility::String::beginsWith(name, "DemoUnit")); + }; + + list.erase(std::remove_if(list.begin(), list.end(), predicate), list.end()); + + for(const std::string& file : list) { + Utility::Directory::move(Utility::Directory::join(_saveDirectory, file), + Utility::Directory::join(_stagingAreaDirectory, file)); + } +} + auto MassManager::saveDirectory() -> std::string const& { return _saveDirectory; } diff --git a/MassManager/MassManager.h b/MassManager/MassManager.h index e1b3b34..1c610b4 100644 --- a/MassManager/MassManager.h +++ b/MassManager/MassManager.h @@ -58,6 +58,9 @@ class MassManager { auto ready() -> bool; auto lastError() -> std::string const&; + auto hasDemoUnits() -> bool; + void addDemoUnitsToStaging(); + auto saveDirectory() -> std::string const&; auto stagingAreaDirectory() -> std::string const&; auto screenshotDirectory() -> std::string const&;