Add demo unit import.

This commit is contained in:
Guillaume Jacquemin 2020-07-22 08:55:12 +02:00
parent 6a30c7d037
commit 3f8af910e3
3 changed files with 46 additions and 2 deletions

View file

@ -54,14 +54,26 @@ EvtMainFrame::EvtMainFrame(wxWindow* parent): MainFrame(parent) {
_watcher.Connect(wxEVT_FSWATCHER, wxFileSystemWatcherEventHandler(EvtMainFrame::fileUpdateEvent), nullptr, this); _watcher.Connect(wxEVT_FSWATCHER, wxFileSystemWatcherEventHandler(EvtMainFrame::fileUpdateEvent), nullptr, this);
_watcher.AddTree(wxFileName(Utility::Directory::toNativeSeparators(_manager.saveDirectory()), wxPATH_WIN), _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())); 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<std::string> v = _manager.initialiseStagingArea(); std::vector<std::string> v = _manager.initialiseStagingArea();
for(const std::string& s : v) { for(const std::string& s : v) {
_stagingList->Append(s); _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); _gameCheckTimer.Start(3000);
if(!_manager.findScreenshotDirectory()) { if(!_manager.findScreenshotDirectory()) {

View file

@ -69,6 +69,35 @@ auto MassManager::lastError() -> std::string const& {
return _lastError; return _lastError;
} }
auto MassManager::hasDemoUnits() -> bool {
using Utility::Directory::Flag;
std::vector<std::string> 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<std::string> 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& { auto MassManager::saveDirectory() -> std::string const& {
return _saveDirectory; return _saveDirectory;
} }

View file

@ -58,6 +58,9 @@ class MassManager {
auto ready() -> bool; auto ready() -> bool;
auto lastError() -> std::string const&; auto lastError() -> std::string const&;
auto hasDemoUnits() -> bool;
void addDemoUnitsToStaging();
auto saveDirectory() -> std::string const&; auto saveDirectory() -> std::string const&;
auto stagingAreaDirectory() -> std::string const&; auto stagingAreaDirectory() -> std::string const&;
auto screenshotDirectory() -> std::string const&; auto screenshotDirectory() -> std::string const&;