EvtMainFrame: add staging area stuff.

This commit is contained in:
Guillaume Jacquemin 2020-01-16 00:35:43 +01:00 committed by Guillaume Jacquemin
parent 5878bf4856
commit 99ee8e75a3
2 changed files with 104 additions and 59 deletions

View file

@ -51,6 +51,13 @@ 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, wxString::Format("*.sav"));
std::vector<std::string> v = _manager.initialiseStagingArea();
for(const std::string& s : v) {
_stagingList->Append(s);
}
_gameCheckTimer.Start(3000);
}
@ -73,30 +80,21 @@ void EvtMainFrame::importEvent(wxCommandEvent&) {
long selected_hangar = _installedListView->GetFirstSelected();
HangarState hangar_state = _manager.hangarState(selected_hangar);
if(hangar_state == HangarState::Filled &&
wxMessageBox(wxString::Format("Hangar %.2d is already occupied by the M.A.S.S. named \"%s\". Are you sure you want to import a M.A.S.S. to this hangar ?",
selected_hangar + 1, *(_manager.massName(selected_hangar))),
"Question", wxYES_NO|wxCENTRE|wxICON_QUESTION, this) == wxNO) {
return;
int staged_selection = _stagingList->GetSelection();
int confirmation;
if(hangar_state == HangarState::Filled) {
confirmation = wxMessageBox(wxString::Format("Hangar %.2d is already occupied by the M.A.S.S. named \"%s\". Are you sure you want to import the M.A.S.S. named \"%s\" to this hangar ?",
selected_hangar + 1, *(_manager.massName(selected_hangar)), _manager.stagedMassName(staged_selection)),
"Question", wxYES_NO|wxCENTRE|wxICON_QUESTION, this);
}
else {
confirmation = wxMessageBox(wxString::Format("Are you sure you want to import the M.A.S.S. named \"%s\" to hangar %.2d ?", _manager.stagedMassName(staged_selection), selected_hangar + 1),
"Question", wxYES_NO|wxCENTRE|wxICON_QUESTION, this);
}
wxFileDialog dialog(this, "Select a unit file", wxEmptyString, wxEmptyString, "M.A.S.S. Builder unit files (*.sav)|*.sav", wxFD_OPEN|wxFD_FILE_MUST_EXIST);
if(dialog.ShowModal() == wxID_CANCEL) {
return;
}
const std::string source_file = dialog.GetPath().ToUTF8().data();
Containers::Optional<std::string> mass_name = _manager.getMassName(source_file);
if(!mass_name) {
errorMessage(error_prefix + _manager.lastError());
return;
}
if(wxMessageBox(wxString::Format("Are you sure you want to import the M.A.S.S. named \"%s\" to hangar %.2d ?", *mass_name, selected_hangar + 1),
"Question", wxYES_NO|wxCENTRE|wxICON_QUESTION, this) == wxNO) {
if(confirmation == wxNO) {
return;
}
@ -105,7 +103,7 @@ void EvtMainFrame::importEvent(wxCommandEvent&) {
errorMessage(error_prefix + "For security reasons, importing is disabled if the game's status is unknown.");
break;
case GameState::NotRunning:
if(!_manager.importMass(source_file, selected_hangar)) {
if(!_manager.importMass(staged_selection, selected_hangar)) {
errorMessage(error_prefix + _manager.lastError());
}
break;
@ -115,6 +113,16 @@ void EvtMainFrame::importEvent(wxCommandEvent&) {
}
}
void EvtMainFrame::exportEvent(wxCommandEvent&) {
const static std::string error_prefix = "Export failed:\n\n";
long slot = _installedListView->GetFirstSelected();
if(!_manager.exportMass(slot)) {
errorMessage(error_prefix + _manager.lastError());
}
}
void EvtMainFrame::moveEvent(wxCommandEvent&) {
const static std::string error_prefix = "Move failed:\n\n";
@ -214,6 +222,7 @@ void EvtMainFrame::fileUpdateEvent(wxFileSystemWatcherEvent& event) {
wxMilliSleep(50);
if(event.GetPath().GetPath(wxPATH_GET_VOLUME, wxPATH_WIN) == Utility::Directory::toNativeSeparators(_manager.saveDirectory())) {
wxRegEx regex;
switch (event_type) {
@ -267,6 +276,41 @@ void EvtMainFrame::fileUpdateEvent(wxFileSystemWatcherEvent& event) {
}
break;
}
}
else if(event.GetPath().GetPath(wxPATH_GET_VOLUME, wxPATH_WIN) == Utility::Directory::toNativeSeparators(_manager.stagingAreaDirectory())) {
int index;
switch(event_type) {
case wxFSW_EVENT_CREATE:
index = _manager.updateStagedMass(event_file.ToUTF8().data());
if(index != -1) {
_stagingList->Insert(wxString::Format("%s (%s)", _manager.stagedMassName(index), event_file), index);
}
break;
case wxFSW_EVENT_DELETE:
index = _manager.removeStagedMass(event_file.ToUTF8().data());
if(index != -1) {
_stagingList->Delete(index);
}
break;
case wxFSW_EVENT_MODIFY:
index = _manager.updateStagedMass(event_file.ToUTF8().data());
if(index != -1) {
_stagingList->SetString(index, wxString::Format("%s (%s)", _manager.stagedMassName(index), event_file));
}
break;
case wxFSW_EVENT_RENAME:
index = _manager.removeStagedMass(event_file.ToUTF8().data());
if(index != -1) {
_stagingList->Delete(index);
}
index = _manager.updateStagedMass(event.GetNewPath().GetFullName().ToUTF8().data());
if(index != -1) {
_stagingList->Insert(wxString::Format("%s (%s)", _manager.stagedMassName(index), event.GetNewPath().GetFullName()), index);
}
break;
}
}
_lastWatcherEventType = event_type;

View file

@ -34,6 +34,7 @@ class EvtMainFrame: public MainFrame {
protected:
void importEvent(wxCommandEvent&);
void exportEvent(wxCommandEvent&);
void moveEvent(wxCommandEvent&);
void deleteEvent(wxCommandEvent&);
void backupEvent(wxCommandEvent&);