MainFrame: add logic to unsafe mode checkbox.

This commit is contained in:
Guillaume Jacquemin 2021-03-05 14:56:28 +01:00
parent 0b1ecc52f5
commit 5b23303a48
2 changed files with 133 additions and 70 deletions

View file

@ -192,6 +192,7 @@ void EvtMainFrame::companyRenameEvent(wxMouseEvent&) {
int result = dialog.ShowModal(); int result = dialog.ShowModal();
if(result == wxID_OK) { if(result == wxID_OK) {
if(_unsafeMode == false) {
switch(_mbManager.gameState()) { switch(_mbManager.gameState()) {
case GameState::Unknown: case GameState::Unknown:
errorMessage(error_prefix + "For security reasons, renaming the company is disabled if the game's status is unknown."); errorMessage(error_prefix + "For security reasons, renaming the company is disabled if the game's status is unknown.");
@ -212,6 +213,18 @@ void EvtMainFrame::companyRenameEvent(wxMouseEvent&) {
break; break;
} }
} }
else {
if(!_profileManager.currentProfile()->renameCompany(dialog.getName())) {
errorMessage(error_prefix + _profileManager.currentProfile()->lastError());
}
else {
_profileChoice->SetString(_profileChoice->GetCurrentSelection(),
wxString::Format("%s%s",
_profileManager.currentProfile()->companyName(),
_profileManager.currentProfile()->type() == ProfileType::Demo ? " (Demo)" : ""));
}
}
}
} }
void EvtMainFrame::importMassEvent(wxCommandEvent&) { void EvtMainFrame::importMassEvent(wxCommandEvent&) {
@ -238,6 +251,7 @@ void EvtMainFrame::importMassEvent(wxCommandEvent&) {
return; return;
} }
if(_unsafeMode == false) {
switch(_mbManager.gameState()) { switch(_mbManager.gameState()) {
case GameState::Unknown: case GameState::Unknown:
errorMessage(error_prefix + "For security reasons, importing is disabled if the game's status is unknown."); errorMessage(error_prefix + "For security reasons, importing is disabled if the game's status is unknown.");
@ -252,6 +266,12 @@ void EvtMainFrame::importMassEvent(wxCommandEvent&) {
break; break;
} }
} }
else {
if(!_massManager->importMass(staged_selection, selected_hangar)) {
errorMessage(error_prefix + _massManager->lastError());
}
}
}
void EvtMainFrame::exportMassEvent(wxCommandEvent&) { void EvtMainFrame::exportMassEvent(wxCommandEvent&) {
const static std::string error_prefix = "Export failed:\n\n"; const static std::string error_prefix = "Export failed:\n\n";
@ -279,6 +299,7 @@ void EvtMainFrame::moveMassEvent(wxCommandEvent&) {
return; return;
} }
if(_unsafeMode == false) {
switch(_mbManager.gameState()) { switch(_mbManager.gameState()) {
case GameState::Unknown: case GameState::Unknown:
errorMessage(error_prefix + "For security reasons, moving a M.A.S.S. is disabled if the game's status is unknown."); errorMessage(error_prefix + "For security reasons, moving a M.A.S.S. is disabled if the game's status is unknown.");
@ -293,6 +314,12 @@ void EvtMainFrame::moveMassEvent(wxCommandEvent&) {
break; break;
} }
} }
else {
if(!_massManager->moveMass(source_slot, choice - 1)) {
errorMessage(error_prefix + _massManager->lastError());
}
}
}
void EvtMainFrame::deleteMassEvent(wxCommandEvent&) { void EvtMainFrame::deleteMassEvent(wxCommandEvent&) {
const static std::string error_prefix = "Deletion failed:\n\n"; const static std::string error_prefix = "Deletion failed:\n\n";
@ -302,6 +329,7 @@ void EvtMainFrame::deleteMassEvent(wxCommandEvent&) {
return; return;
} }
if(_unsafeMode == false) {
switch(_mbManager.gameState()) { switch(_mbManager.gameState()) {
case GameState::Unknown: case GameState::Unknown:
errorMessage(error_prefix + "For security reasons, deleting a M.A.S.S. is disabled if the game's status is unknown."); errorMessage(error_prefix + "For security reasons, deleting a M.A.S.S. is disabled if the game's status is unknown.");
@ -316,6 +344,12 @@ void EvtMainFrame::deleteMassEvent(wxCommandEvent&) {
break; break;
} }
} }
else {
if(!_massManager->deleteMass(_installedListView->GetFirstSelected())) {
errorMessage(error_prefix + _massManager->lastError());
}
}
}
void EvtMainFrame::renameMassEvent(wxCommandEvent&) { void EvtMainFrame::renameMassEvent(wxCommandEvent&) {
const static std::string error_prefix = "Rename failed:\n\n"; const static std::string error_prefix = "Rename failed:\n\n";
@ -325,6 +359,7 @@ void EvtMainFrame::renameMassEvent(wxCommandEvent&) {
int result = dialog.ShowModal(); int result = dialog.ShowModal();
if(result == wxID_OK) { if(result == wxID_OK) {
if(_unsafeMode == false) {
switch(_mbManager.gameState()) { switch(_mbManager.gameState()) {
case GameState::Unknown: case GameState::Unknown:
errorMessage(error_prefix + "For security reasons, renaming a M.A.S.S. is disabled if the game's status is unknown."); errorMessage(error_prefix + "For security reasons, renaming a M.A.S.S. is disabled if the game's status is unknown.");
@ -339,6 +374,12 @@ void EvtMainFrame::renameMassEvent(wxCommandEvent&) {
break; break;
} }
} }
else {
if(!_massManager->renameMass(_installedListView->GetFirstSelected(), dialog.getName())) {
errorMessage(error_prefix + _massManager->lastError());
}
}
}
} }
void EvtMainFrame::openSaveDirEvent(wxCommandEvent&) { void EvtMainFrame::openSaveDirEvent(wxCommandEvent&) {
@ -465,6 +506,25 @@ void EvtMainFrame::gameCheckTimerEvent(wxTimerEvent&) {
isGameRunning(); isGameRunning();
} }
void EvtMainFrame::unsafeCheckboxEvent(wxCommandEvent& event) {
if(event.IsChecked() == true) {
int confirmation = wxMessageBox("Are you sure you want to enable unsafe mode ?\n\n"
"Unsafe mode will allow you to perform changes even while the game is running, which can result in weird behaviour or even data corruption.",
"Question", wxYES_NO|wxCENTRE|wxICON_WARNING, this);
if(confirmation == wxYES) {
_unsafeMode = true;
}
else {
_unsafeCheckbox->SetValue(false);
}
}
else {
_unsafeMode = false;
}
updateCommandsState();
}
void EvtMainFrame::saveFileEventHandler(int event_type, const wxString& event_file, const wxFileSystemWatcherEvent& event) { void EvtMainFrame::saveFileEventHandler(int event_type, const wxString& event_file, const wxFileSystemWatcherEvent& event) {
wxRegEx regex; wxRegEx regex;
@ -649,11 +709,11 @@ void EvtMainFrame::updateCommandsState() {
GameState game_state = _mbManager.gameState(); GameState game_state = _mbManager.gameState();
MassState mass_state = _massManager->massState(selection); MassState mass_state = _massManager->massState(selection);
_importButton->Enable(selection != -1 && staged_selection != -1 && game_state == GameState::NotRunning); _importButton->Enable(selection != -1 && staged_selection != -1 && (_unsafeMode == true || game_state == GameState::NotRunning));
_exportButton->Enable(selection != -1); _exportButton->Enable(selection != -1);
_moveButton->Enable(selection != -1 && game_state == GameState::NotRunning && mass_state == MassState::Valid); _moveButton->Enable(selection != -1 && (_unsafeMode == true || game_state == GameState::NotRunning) && mass_state == MassState::Valid);
_deleteButton->Enable(selection != -1 && game_state == GameState::NotRunning && mass_state != MassState::Empty); _deleteButton->Enable(selection != -1 && (_unsafeMode == true || game_state == GameState::NotRunning) && mass_state != MassState::Empty);
_renameButton->Enable(selection != -1 && game_state == GameState::NotRunning && mass_state == MassState::Valid); _renameButton->Enable(selection != -1 && (_unsafeMode == true || game_state == GameState::NotRunning) && mass_state == MassState::Valid);
_deleteStagedButton->Enable(staged_selection != -1); _deleteStagedButton->Enable(staged_selection != -1);
long screenshot_selection = _screenshotsList->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); long screenshot_selection = _screenshotsList->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);

View file

@ -75,6 +75,7 @@ class EvtMainFrame: public MainFrame {
void tabChangeEvent(wxNotebookEvent& event); void tabChangeEvent(wxNotebookEvent& event);
void fileUpdateEvent(wxFileSystemWatcherEvent& event); void fileUpdateEvent(wxFileSystemWatcherEvent& event);
void gameCheckTimerEvent(wxTimerEvent&); void gameCheckTimerEvent(wxTimerEvent&);
void unsafeCheckboxEvent(wxCommandEvent& event);
private: private:
void saveFileEventHandler(int event_type, const wxString& event_file, const wxFileSystemWatcherEvent& event); void saveFileEventHandler(int event_type, const wxString& event_file, const wxFileSystemWatcherEvent& event);
@ -97,6 +98,8 @@ class EvtMainFrame: public MainFrame {
void warningMessage(const wxString& message); void warningMessage(const wxString& message);
void errorMessage(const wxString& message); void errorMessage(const wxString& message);
bool _unsafeMode = false;
MassBuilderManager _mbManager; MassBuilderManager _mbManager;
ProfileManager _profileManager; ProfileManager _profileManager;
Containers::Pointer<MassManager> _massManager; Containers::Pointer<MassManager> _massManager;