diff --git a/GUI/EvtMainFrame.cpp b/GUI/EvtMainFrame.cpp index 0c734b0..58c96cc 100644 --- a/GUI/EvtMainFrame.cpp +++ b/GUI/EvtMainFrame.cpp @@ -23,6 +23,8 @@ #include #include #include +#include +#include #define WIN32_LEAN_AND_MEAN #include @@ -190,6 +192,36 @@ void EvtMainFrame::deleteEvent(wxCommandEvent&) { } } +void EvtMainFrame::backupEvent(wxCommandEvent&) { + wxString current_timestamp = wxDateTime::Now().Format("%Y-%m-%d_%H-%M-%S"); + + wxFileDialog save_dialog{this, "Choose output location", _saveDirectory, + wxString::Format("backup_%s_%s.zip", _localSteamId, current_timestamp), "Zip archive (*zip)|*zip", + wxFD_SAVE|wxFD_OVERWRITE_PROMPT}; + + if(save_dialog.ShowModal() == wxID_CANCEL) { + return; + } + + wxFFileOutputStream out{save_dialog.GetPath()}; + wxZipOutputStream zip{out}; + + { + zip.PutNextEntry(wxString::Format("Profile%s.sav", _localSteamId)); + wxFFileInputStream profile_stream{wxString::Format("%s\\Profile%s.sav", Utility::Directory::toNativeSeparators(_saveDirectory), _localSteamId), "rb"}; + zip.Write(profile_stream); + } + + for(int i = 0; i < 32; ++i) { + std::string unit_file = Utility::formatString("Unit{:.2d}{}.sav", i, _localSteamId); + if(Utility::Directory::exists(Utility::Directory::join(_saveDirectory, unit_file))) { + zip.PutNextEntry(unit_file); + wxFFileInputStream unit_stream{Utility::Directory::toNativeSeparators(Utility::Directory::join(_saveDirectory, unit_file))}; + zip.Write(unit_stream); + } + } +} + void EvtMainFrame::openSaveDirEvent(wxCommandEvent&) { wxExecute("explorer.exe " + Utility::Directory::toNativeSeparators(_saveDirectory)); } diff --git a/GUI/EvtMainFrame.h b/GUI/EvtMainFrame.h index 4fdb62e..d6d3c0a 100644 --- a/GUI/EvtMainFrame.h +++ b/GUI/EvtMainFrame.h @@ -32,6 +32,7 @@ class EvtMainFrame: public MainFrame { void importEvent(wxCommandEvent&); void moveEvent(wxCommandEvent&); void deleteEvent(wxCommandEvent&); + void backupEvent(wxCommandEvent&); void openSaveDirEvent(wxCommandEvent&); void installedSelectionEvent(wxListEvent&); void listColumnDragEvent(wxListEvent&); diff --git a/GUI/MainFrame.cpp b/GUI/MainFrame.cpp index 431da5d..b9fa595 100644 --- a/GUI/MainFrame.cpp +++ b/GUI/MainFrame.cpp @@ -49,8 +49,11 @@ MainFrame::MainFrame( wxWindow* parent, wxWindowID id, const wxString& title, co bSizerSecondRow->Add( 0, 0, 1, wxEXPAND, 5 ); + _zipButton = new wxButton( sbSizerInstalled->GetStaticBox(), wxID_ANY, wxT("Backup save files"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizerSecondRow->Add( _zipButton, 2, wxALL|wxEXPAND, 5 ); + _openSaveDirButton = new wxButton( sbSizerInstalled->GetStaticBox(), wxID_ANY, wxT("Open save directory"), wxDefaultPosition, wxDefaultSize, 0 ); - bSizerSecondRow->Add( _openSaveDirButton, 1, wxEXPAND|wxALL, 5 ); + bSizerSecondRow->Add( _openSaveDirButton, 2, wxEXPAND|wxALL, 5 ); bSizerSecondRow->Add( 0, 0, 1, wxEXPAND, 5 ); @@ -104,6 +107,7 @@ MainFrame::MainFrame( wxWindow* parent, wxWindowID id, const wxString& title, co _importButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::importEvent ), NULL, this ); _moveButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::moveEvent ), NULL, this ); _deleteButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::deleteEvent ), NULL, this ); + _zipButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::backupEvent ), NULL, this ); _openSaveDirButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::openSaveDirEvent ), NULL, this ); this->Connect( wxID_ANY, wxEVT_TIMER, wxTimerEventHandler( MainFrame::gameCheckTimerEvent ) ); } @@ -114,6 +118,7 @@ MainFrame::~MainFrame() _importButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::importEvent ), NULL, this ); _moveButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::moveEvent ), NULL, this ); _deleteButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::deleteEvent ), NULL, this ); + _zipButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::backupEvent ), NULL, this ); _openSaveDirButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::openSaveDirEvent ), NULL, this ); this->Disconnect( wxID_ANY, wxEVT_TIMER, wxTimerEventHandler( MainFrame::gameCheckTimerEvent ) ); diff --git a/GUI/MainFrame.fbp b/GUI/MainFrame.fbp index a63cab5..123c85c 100644 --- a/GUI/MainFrame.fbp +++ b/GUI/MainFrame.fbp @@ -394,10 +394,83 @@ 0 + + 5 + wxALL|wxEXPAND + 2 + + 1 + 1 + 1 + 1 + + + + + + + + + 1 + 0 + 1 + + 1 + + 0 + 0 + + Dock + 0 + Left + 1 + + 1 + + + 0 + 0 + wxID_ANY + Backup save files + + 0 + + 0 + + + 0 + + 1 + _zipButton + 1 + + + protected + 1 + + + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + backupEvent + + 5 wxEXPAND|wxALL - 1 + 2 1 1 diff --git a/GUI/MainFrame.h b/GUI/MainFrame.h index 3e0a8e3..984f759 100644 --- a/GUI/MainFrame.h +++ b/GUI/MainFrame.h @@ -40,6 +40,7 @@ class MainFrame : public wxFrame wxButton* _importButton; wxButton* _moveButton; wxButton* _deleteButton; + wxButton* _zipButton; wxButton* _openSaveDirButton; wxStaticText* _riskLabel; wxStaticText* _gameStatusLabel; @@ -51,6 +52,7 @@ class MainFrame : public wxFrame virtual void importEvent( wxCommandEvent& event ) { event.Skip(); } virtual void moveEvent( wxCommandEvent& event ) { event.Skip(); } virtual void deleteEvent( wxCommandEvent& event ) { event.Skip(); } + virtual void backupEvent( wxCommandEvent& event ) { event.Skip(); } virtual void openSaveDirEvent( wxCommandEvent& event ) { event.Skip(); } virtual void gameCheckTimerEvent( wxTimerEvent& event ) { event.Skip(); }