From 1cbae66bb33237c07c7731a3983b75d24480a221 Mon Sep 17 00:00:00 2001 From: Jonathan Li Date: Sun, 4 Oct 2015 20:49:53 +0100 Subject: [PATCH] pcsx2: Make memory card dialog modal There were bugs in the UI handling that allowed you to resume emulation when the memory card dialog was opened, which could potentially cause data loss/corruption. Make the memory card dialog modal to prevent this. Although it's possible to do with a modeless dialog, the solution will be much more complicated and less future proof. This also fixes the emulation resume bug after closing the memory card dialog. --- pcsx2/gui/Dialogs/ConfigurationDialog.h | 4 ---- pcsx2/gui/Dialogs/McdConfigDialog.cpp | 28 ------------------------ pcsx2/gui/MainMenuClicks.cpp | 5 ++++- pcsx2/gui/Panels/MemoryCardListPanel.cpp | 23 ++----------------- 4 files changed, 6 insertions(+), 54 deletions(-) diff --git a/pcsx2/gui/Dialogs/ConfigurationDialog.h b/pcsx2/gui/Dialogs/ConfigurationDialog.h index 4db685607a..44c094a58b 100644 --- a/pcsx2/gui/Dialogs/ConfigurationDialog.h +++ b/pcsx2/gui/Dialogs/ConfigurationDialog.h @@ -155,7 +155,6 @@ namespace Dialogs protected: Panels::BaseMcdListPanel* m_panel_mcdlist; - bool m_needs_suspending; public: virtual ~McdConfigDialog() throw() {} @@ -163,9 +162,6 @@ namespace Dialogs static wxString GetNameStatic() { return L"McdConfig"; } wxString GetDialogName() const { return GetNameStatic(); } - virtual bool Show( bool show=true ); - virtual int ShowModal(); - protected: virtual wxString& GetConfSettingsTabName() const { return g_Conf->McdSettingsTabName; } //void OnMultitapClicked( wxCommandEvent& evt ); diff --git a/pcsx2/gui/Dialogs/McdConfigDialog.cpp b/pcsx2/gui/Dialogs/McdConfigDialog.cpp index cbe6a440fe..33ea27fe17 100644 --- a/pcsx2/gui/Dialogs/McdConfigDialog.cpp +++ b/pcsx2/gui/Dialogs/McdConfigDialog.cpp @@ -101,7 +101,6 @@ Dialogs::McdConfigDialog::McdConfigDialog( wxWindow* parent ) : BaseConfigurationDialog( parent, _("MemoryCard Manager"), 600 ) { m_panel_mcdlist = new MemoryCardListPanel_Simple( this ); - m_needs_suspending = false; wxFlexGridSizer* s_flex=new wxFlexGridSizer(3,1, 0, 0); s_flex->AddGrowableCol(0); @@ -152,30 +151,3 @@ void Dialogs::McdConfigDialog::OnMultitapClicked( wxCommandEvent& evt ) m_panel_mcdlist->SetMultitapEnabled( (int)box->GetClientData(), box->IsChecked() ); } */ -bool Dialogs::McdConfigDialog::Show( bool show ) -{ - // Suspend the emulation before any file operations on the memory cards can be done. - if( show && CoreThread.IsRunning() ) - { - m_needs_suspending = true; - CoreThread.Suspend(); - } - else if( !show && m_needs_suspending == true ) - { - m_needs_suspending = false; - CoreThread.Resume(); - } - - if( show && m_panel_mcdlist ) - m_panel_mcdlist->OnShown(); - - return _parent::Show( show ); -} - -int Dialogs::McdConfigDialog::ShowModal() -{ - if( m_panel_mcdlist ) - m_panel_mcdlist->OnShown(); - - return _parent::ShowModal(); -} diff --git a/pcsx2/gui/MainMenuClicks.cpp b/pcsx2/gui/MainMenuClicks.cpp index b8f7474ebc..937c5b7f67 100644 --- a/pcsx2/gui/MainMenuClicks.cpp +++ b/pcsx2/gui/MainMenuClicks.cpp @@ -15,6 +15,7 @@ #include "PrecompiledHeader.h" +#include "App.h" #include "CDVD/CDVD.h" #include "GS.h" @@ -37,7 +38,9 @@ void MainEmuFrame::Menu_SysSettings_Click(wxCommandEvent &event) void MainEmuFrame::Menu_McdSettings_Click(wxCommandEvent &event) { - AppOpenDialog( this ); + ScopedCoreThreadClose closed_core; + closed_core.AllowResume(); + AppOpenModalDialog(wxEmptyString, this); } void MainEmuFrame::Menu_GameDatabase_Click(wxCommandEvent &event) diff --git a/pcsx2/gui/Panels/MemoryCardListPanel.cpp b/pcsx2/gui/Panels/MemoryCardListPanel.cpp index 75bd3f5aef..40638ee8b2 100644 --- a/pcsx2/gui/Panels/MemoryCardListPanel.cpp +++ b/pcsx2/gui/Panels/MemoryCardListPanel.cpp @@ -618,9 +618,6 @@ void Panels::MemoryCardListPanel_Simple::Apply() { _parent::Apply(); - ScopedCoreThreadClose closed_core; - closed_core.AllowResume(); - int used=0; Console.WriteLn( L"Apply Memory cards:" ); for( uint slot=0; slot<8; ++slot ) @@ -736,8 +733,6 @@ void Panels::MemoryCardListPanel_Simple::UiCreateNewCard( McdSlotItem& card ) return; } - ScopedCoreThreadClose closed_core; - Dialogs::CreateMemoryCardDialog dialog( this, m_FolderPicker->GetPath(), L"my memory card" ); wxWindowID result = dialog.ShowModal(); @@ -756,7 +751,6 @@ void Panels::MemoryCardListPanel_Simple::UiCreateNewCard( McdSlotItem& card ) Apply(); RefreshSelections(); - closed_core.AllowResume(); } void Panels::MemoryCardListPanel_Simple::UiConvertCard( McdSlotItem& card ) { @@ -765,8 +759,6 @@ void Panels::MemoryCardListPanel_Simple::UiConvertCard( McdSlotItem& card ) { return; } - ScopedCoreThreadClose closed_core; - AppConfig::McdOptions config; config.Filename = card.Filename.GetFullName(); config.Enabled = card.IsEnabled; @@ -778,8 +770,6 @@ void Panels::MemoryCardListPanel_Simple::UiConvertCard( McdSlotItem& card ) { Apply(); RefreshSelections(); } - - closed_core.AllowResume(); } void Panels::MemoryCardListPanel_Simple::UiDeleteCard( McdSlotItem& card ) @@ -804,7 +794,6 @@ void Panels::MemoryCardListPanel_Simple::UiDeleteCard( McdSlotItem& card ) if( result ) { - ScopedCoreThreadClose closed_core; wxFileName fullpath( m_FolderPicker->GetPath() + card.Filename.GetFullName()); @@ -818,7 +807,6 @@ void Panels::MemoryCardListPanel_Simple::UiDeleteCard( McdSlotItem& card ) } RefreshSelections(); - closed_core.AllowResume(); } } @@ -873,7 +861,6 @@ bool Panels::MemoryCardListPanel_Simple::UiDuplicateCard(McdSlotItem& src, McdSl wxFileName destfile( basepath + dest.Filename); ScopedBusyCursor doh( Cursor_ReallyBusy ); - ScopedCoreThreadClose closed_core; if( !( ( srcfile.FileExists() && wxCopyFile( srcfile.GetFullPath(), destfile.GetFullPath(), true ) ) || ( !srcfile.FileExists() && CopyDirectory( srcfile.GetFullPath(), destfile.GetFullPath() ) ) ) ) @@ -886,8 +873,7 @@ bool Panels::MemoryCardListPanel_Simple::UiDuplicateCard(McdSlotItem& src, McdSl wxString content; Msgbox::Alert( heading + L"\n\n" + content, _("Copy failed!") ); - - closed_core.AllowResume(); + return false; } @@ -903,7 +889,6 @@ bool Panels::MemoryCardListPanel_Simple::UiDuplicateCard(McdSlotItem& src, McdSl Apply(); DoRefresh(); - closed_core.AllowResume(); return true; } @@ -940,8 +925,6 @@ void Panels::MemoryCardListPanel_Simple::UiRenameCard( McdSlotItem& card ) break; } - ScopedCoreThreadClose closed_core; - bool origEnabled=card.IsEnabled; card.IsEnabled=false; Apply(); @@ -950,8 +933,7 @@ void Panels::MemoryCardListPanel_Simple::UiRenameCard( McdSlotItem& card ) card.IsEnabled=origEnabled; Apply(); Msgbox::Alert( _("Error: Rename could not be completed.\n"), _("Rename memory card") ); - - closed_core.AllowResume(); + return; } @@ -960,7 +942,6 @@ void Panels::MemoryCardListPanel_Simple::UiRenameCard( McdSlotItem& card ) Apply(); RefreshSelections(); - closed_core.AllowResume(); } void Panels::MemoryCardListPanel_Simple::OnCreateOrDeleteCard(wxCommandEvent& evt)