/[pcsx2_0.9.7]/branch/debug/0.X/0.9.X/0.9.7/ramdump-lateset/pcsx2/gui/MainMenuClicks.cpp
ViewVC logotype

Contents of /branch/debug/0.X/0.9.X/0.9.7/ramdump-lateset/pcsx2/gui/MainMenuClicks.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 330 - (show annotations) (download)
Tue Dec 28 04:24:23 2010 UTC (9 years, 9 months ago) by william
File size: 15709 byte(s)
merged upstream r4154-r4160
1 /* PCSX2 - PS2 Emulator for PCs
2 * Copyright (C) 2002-2010 PCSX2 Dev Team
3 *
4 * PCSX2 is free software: you can redistribute it and/or modify it under the terms
5 * of the GNU Lesser General Public License as published by the Free Software Found-
6 * ation, either version 3 of the License, or (at your option) any later version.
7 *
8 * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10 * PURPOSE. See the GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License along with PCSX2.
13 * If not, see <http://www.gnu.org/licenses/>.
14 */
15
16 #include "PrecompiledHeader.h"
17
18 #include "CDVD/CDVD.h"
19 #include "GS.h"
20
21 #include "MainFrame.h"
22 #include "IsoDropTarget.h"
23
24 #include "Dialogs/ModalPopups.h"
25 #include "Dialogs/ConfigurationDialog.h"
26 #include "Dialogs/LogOptionsDialog.h"
27 #include "Dialogs/wxRamViewDialog.h"
28
29 #include "Utilities/IniInterface.h"
30
31 using namespace Dialogs;
32
33 void MainEmuFrame::SaveEmuOptions()
34 {
35 if (wxConfigBase* conf = GetAppConfig())
36 {
37 IniSaver saver(*conf);
38 g_Conf->EmuOptions.LoadSave(saver);
39 }
40 }
41
42 void MainEmuFrame::Menu_SysSettings_Click(wxCommandEvent &event)
43 {
44 AppOpenDialog<SysConfigDialog>( this );
45 }
46
47 void MainEmuFrame::Menu_McdSettings_Click(wxCommandEvent &event)
48 {
49 AppOpenDialog<McdConfigDialog>( this );
50 }
51
52 void MainEmuFrame::Menu_GameDatabase_Click(wxCommandEvent &event)
53 {
54 AppOpenDialog<GameDatabaseDialog>( this );
55 }
56
57 void MainEmuFrame::Menu_WindowSettings_Click(wxCommandEvent &event)
58 {
59 wxCommandEvent evt( pxEvt_SetSettingsPage );
60 evt.SetString( L"GS Window" );
61 AppOpenDialog<SysConfigDialog>( this )->GetEventHandler()->ProcessEvent( evt );
62 }
63
64 void MainEmuFrame::Menu_GSSettings_Click(wxCommandEvent &event)
65 {
66 wxCommandEvent evt( pxEvt_SetSettingsPage );
67 evt.SetString( L"GS" );
68 AppOpenDialog<SysConfigDialog>( this )->GetEventHandler()->ProcessEvent( evt );
69 }
70
71 void MainEmuFrame::Menu_SelectPluginsBios_Click(wxCommandEvent &event)
72 {
73 AppOpenDialog<ComponentsConfigDialog>( this );
74 }
75
76 void MainEmuFrame::Menu_Language_Click(wxCommandEvent &event)
77 {
78 //AppOpenDialog<InterfaceConfigDialog>( this );
79 InterfaceConfigDialog(this).ShowModal();
80 }
81
82 static void WipeSettings()
83 {
84 wxGetApp().CleanupRestartable();
85 wxGetApp().CleanupResources();
86
87 wxRemoveFile( GetSettingsFilename() );
88
89 // FIXME: wxRmdir doesn't seem to work here for some reason (possible file sharing issue
90 // with a plugin that leaves a file handle dangling maybe?). But deleting the inis folder
91 // manually from explorer does work. Can't think of a good work-around at the moment. --air
92
93 //wxRmdir( GetSettingsFolder().ToString() );
94
95 wxGetApp().GetRecentIsoManager().Clear();
96 g_Conf = new AppConfig();
97 sMainFrame.RemoveCdvdMenu();
98 }
99
100 void MainEmuFrame::RemoveCdvdMenu()
101 {
102 if( wxMenuItem* item = m_menuCDVD.FindItem(MenuId_IsoSelector) )
103 m_menuCDVD.Remove( item );
104 }
105
106 void MainEmuFrame::Menu_ResetAllSettings_Click(wxCommandEvent &event)
107 {
108 if( IsBeingDeleted() || m_RestartEmuOnDelete ) return;
109
110 {
111 ScopedCoreThreadPopup suspender;
112 if( !Msgbox::OkCancel( pxsFmt(
113 pxE( "!Notice:DeleteSettings",
114 L"This command clears %s settings and allows you to re-run the First-Time Wizard. You will need to "
115 L"manually restart %s after this operation.\n\n"
116 L"WARNING!! Click OK to delete *ALL* settings for %s and force-close the app, losing any current emulation progress. Are you absolutely sure?"
117 L"\n\n(note: settings for plugins are unaffected)"
118 ), pxGetAppName().c_str(), pxGetAppName().c_str(), pxGetAppName().c_str() ),
119 _("Reset all settings?") ) )
120 {
121 suspender.AllowResume();
122 return;
123 }
124 }
125
126 WipeSettings();
127 wxGetApp().PostMenuAction( MenuId_Exit );
128 }
129
130 // Return values:
131 // wxID_CANCEL - User canceled the action outright.
132 // wxID_RESET - User wants to reset the emu in addition to swap discs
133 // (anything else) - Standard swap, no reset. (hotswap!)
134 wxWindowID SwapOrReset_Iso( wxWindow* owner, IScopedCoreThread& core_control, const wxString& isoFilename, const wxString& descpart1 )
135 {
136 wxWindowID result = wxID_CANCEL;
137
138 if( (g_Conf->CdvdSource == CDVDsrc_Iso) && (isoFilename == g_Conf->CurrentIso) )
139 {
140 core_control.AllowResume();
141 return result;
142 }
143
144 if( SysHasValidState() )
145 {
146 core_control.DisallowResume();
147 wxDialogWithHelpers dialog( owner, _("Confirm ISO image change") );
148
149 dialog += dialog.Heading(descpart1);
150 dialog += dialog.GetCharHeight();
151 dialog += dialog.Text(isoFilename);
152 dialog += dialog.GetCharHeight();
153 dialog += dialog.Heading(_("Do you want to swap discs or boot the new image (via system reset)?"));
154
155 result = pxIssueConfirmation( dialog, MsgButtons().Reset().Cancel().Custom(_("Swap Disc"), "swap"), L"DragDrop.BootSwapIso" );
156 if( result == wxID_CANCEL )
157 {
158 core_control.AllowResume();
159 return result;
160 }
161 }
162
163 SysUpdateIsoSrcFile( isoFilename );
164 if( result == wxID_RESET )
165 {
166 core_control.DisallowResume();
167 sApp.SysExecute( CDVDsrc_Iso );
168 }
169 else
170 {
171 Console.Indent().WriteLn( "HotSwapping to new ISO src image!" );
172 g_Conf->CdvdSource = CDVDsrc_Iso;
173 //CoreThread.ChangeCdvdSource();
174 core_control.AllowResume();
175 }
176
177 return result;
178 }
179
180 wxWindowID SwapOrReset_CdvdSrc( wxWindow* owner, CDVD_SourceType newsrc )
181 {
182 if(newsrc == g_Conf->CdvdSource) return wxID_CANCEL;
183 wxWindowID result = wxID_CANCEL;
184 ScopedCoreThreadPopup core;
185
186 if( SysHasValidState() )
187 {
188 wxDialogWithHelpers dialog( owner, _("Confirm CDVD source change") );
189
190 wxString changeMsg;
191 changeMsg.Printf(_("You've selected to switch the CDVD source from %s to %s."),
192 CDVD_SourceLabels[g_Conf->CdvdSource], CDVD_SourceLabels[newsrc] );
193
194 dialog += dialog.Heading(changeMsg + L"\n\n" +
195 _("Do you want to swap discs or boot the new image (system reset)?")
196 );
197
198 result = pxIssueConfirmation( dialog, MsgButtons().Reset().Cancel().Custom(_("Swap Disc"), "swap"), L"DragDrop.BootSwapIso" );
199
200 if( result == wxID_CANCEL )
201 {
202 core.AllowResume();
203 sMainFrame.UpdateIsoSrcSelection();
204 return result;
205 }
206 }
207
208 CDVD_SourceType oldsrc = g_Conf->CdvdSource;
209 g_Conf->CdvdSource = newsrc;
210
211 if( result != wxID_RESET )
212 {
213 Console.Indent().WriteLn( L"(CdvdSource) HotSwapping CDVD source types from %s to %s.", CDVD_SourceLabels[oldsrc], CDVD_SourceLabels[newsrc] );
214 //CoreThread.ChangeCdvdSource();
215 sMainFrame.UpdateIsoSrcSelection();
216 core.AllowResume();
217 }
218 else
219 {
220 core.DisallowResume();
221 sApp.SysExecute( g_Conf->CdvdSource );
222 }
223
224 return result;
225 }
226
227 static wxString JoinFiletypes( const wxChar** src )
228 {
229 wxString dest;
230 while( *src != NULL )
231 {
232 if( *src[0] == 0 ) continue;
233 if( !dest.IsEmpty() )
234 dest += L";";
235
236 dest += pxsFmt(L"*.%s", *src);
237
238 if (wxFileName::IsCaseSensitive())
239 {
240 // omgosh! the filesystem is CaSE SeNSiTiVE!!
241 dest += pxsFmt(L";*.%s", *src).ToUpper();
242 }
243
244 ++src;
245 }
246
247 return dest;
248 }
249
250 // Returns FALSE if the user canceled the action.
251 bool MainEmuFrame::_DoSelectIsoBrowser( wxString& result )
252 {
253 static const wxChar* isoSupportedTypes[] =
254 {
255 L"iso", L"mdf", L"nrg", L"bin", L"img", NULL
256 };
257
258 const wxString isoSupportedLabel( JoinString(isoSupportedTypes, L" ") );
259 const wxString isoSupportedList( JoinFiletypes(isoSupportedTypes) );
260
261 wxArrayString isoFilterTypes;
262
263 isoFilterTypes.Add(pxsFmt(_("All Supported (%s)"), (isoSupportedLabel + L" .dump").c_str()));
264 isoFilterTypes.Add(isoSupportedList + L";*.dump");
265
266 isoFilterTypes.Add(pxsFmt(_("Disc Images (%s)"), isoSupportedLabel.c_str() ));
267 isoFilterTypes.Add(isoSupportedList);
268
269 isoFilterTypes.Add(pxsFmt(_("Blockdumps (%s)"), L".dump" ));
270 isoFilterTypes.Add(L"*.dump");
271
272 isoFilterTypes.Add(_("All Files (*.*)"));
273 isoFilterTypes.Add(L"*.*");
274
275 wxFileDialog ctrl( this, _("Select CDVD source iso..."), g_Conf->Folders.RunIso.ToString(), wxEmptyString,
276 JoinString(isoFilterTypes, L"|"), wxFD_OPEN | wxFD_FILE_MUST_EXIST );
277
278 if( ctrl.ShowModal() != wxID_CANCEL )
279 {
280 result = ctrl.GetPath();
281 g_Conf->Folders.RunIso = wxFileName( result ).GetPath();
282 return true;
283 }
284
285 return false;
286 }
287
288 bool MainEmuFrame::_DoSelectELFBrowser()
289 {
290 static const wxChar* elfFilterType = L"ELF Files (.elf)|*.elf;*.ELF";
291
292 wxFileDialog ctrl( this, _("Select ELF file..."), g_Conf->Folders.RunELF.ToString(), wxEmptyString,
293 (wxString)elfFilterType + L"|" + _("All Files (*.*)") + L"|*.*", wxFD_OPEN | wxFD_FILE_MUST_EXIST );
294
295 if( ctrl.ShowModal() != wxID_CANCEL )
296 {
297 g_Conf->Folders.RunELF = wxFileName( ctrl.GetPath() ).GetPath();
298 g_Conf->CurrentELF = ctrl.GetPath();
299 return true;
300 }
301
302 return false;
303 }
304
305 void MainEmuFrame::_DoBootCdvd()
306 {
307 ScopedCoreThreadPause paused_core;
308
309 if( g_Conf->CdvdSource == CDVDsrc_Iso )
310 {
311 bool selector = g_Conf->CurrentIso.IsEmpty();
312
313 if( !selector && !wxFileExists(g_Conf->CurrentIso) )
314 {
315 // User has an iso selected from a previous run, but it doesn't exist anymore.
316 // Issue a courtesy popup and then an Iso Selector to choose a new one.
317
318 wxDialogWithHelpers dialog( this, _("ISO file not found!") );
319 dialog += dialog.Heading(
320 _("An error occurred while trying to open the file:") + wxString(L"\n\n") + g_Conf->CurrentIso + L"\n\n" +
321 _("Error: The configured ISO file does not exist. Click OK to select a new ISO source for CDVD.")
322 );
323
324 pxIssueConfirmation( dialog, MsgButtons().OK() );
325
326 selector = true;
327 }
328
329 if( selector )
330 {
331 wxString result;
332 if( !_DoSelectIsoBrowser( result ) )
333 {
334 paused_core.AllowResume();
335 return;
336 }
337
338 SysUpdateIsoSrcFile( result );
339 }
340 }
341
342 if( SysHasValidState() )
343 {
344 wxDialogWithHelpers dialog( this, _("Confirm PS2 Reset") );
345 dialog += dialog.Heading( GetMsg_ConfirmSysReset() );
346 bool confirmed = (pxIssueConfirmation( dialog, MsgButtons().Yes().Cancel(), L"BootCdvd.ConfirmReset" ) != wxID_CANCEL);
347
348 if( !confirmed )
349 {
350 paused_core.AllowResume();
351 return;
352 }
353 }
354
355 sApp.SysExecute( g_Conf->CdvdSource );
356 }
357
358 void MainEmuFrame::Menu_CdvdSource_Click( wxCommandEvent &event )
359 {
360 CDVD_SourceType newsrc = CDVDsrc_NoDisc;
361
362 switch( event.GetId() )
363 {
364 case MenuId_Src_Iso: newsrc = CDVDsrc_Iso; break;
365 case MenuId_Src_Plugin: newsrc = CDVDsrc_Plugin; break;
366 case MenuId_Src_NoDisc: newsrc = CDVDsrc_NoDisc; break;
367 jNO_DEFAULT
368 }
369
370 SwapOrReset_CdvdSrc(this, newsrc);
371 }
372
373 void MainEmuFrame::Menu_BootCdvd_Click( wxCommandEvent &event )
374 {
375 g_Conf->EmuOptions.UseBOOT2Injection = false;
376 _DoBootCdvd();
377 }
378
379 void MainEmuFrame::Menu_BootCdvd2_Click( wxCommandEvent &event )
380 {
381 g_Conf->EmuOptions.UseBOOT2Injection = true;
382 _DoBootCdvd();
383 }
384
385 wxString GetMsg_IsoImageChanged()
386 {
387 return _("You have selected the following ISO image into PCSX2:\n\n");
388 }
389
390 void MainEmuFrame::Menu_IsoBrowse_Click( wxCommandEvent &event )
391 {
392 ScopedCoreThreadPopup core;
393 wxString isofile;
394
395 if( !_DoSelectIsoBrowser(isofile) )
396 {
397 core.AllowResume();
398 return;
399 }
400
401 SwapOrReset_Iso(this, core, isofile, GetMsg_IsoImageChanged());
402 AppSaveSettings(); // save the new iso selection; update menus!
403 }
404
405 void MainEmuFrame::Menu_MultitapToggle_Click( wxCommandEvent& )
406 {
407 g_Conf->EmuOptions.MultitapPort0_Enabled = GetMenuBar()->IsChecked( MenuId_Config_Multitap0Toggle );
408 g_Conf->EmuOptions.MultitapPort1_Enabled = GetMenuBar()->IsChecked( MenuId_Config_Multitap1Toggle );
409 AppApplySettings();
410 SaveEmuOptions();
411
412 //evt.Skip();
413 }
414
415 void MainEmuFrame::Menu_EnablePatches_Click( wxCommandEvent& )
416 {
417 g_Conf->EmuOptions.EnablePatches = GetMenuBar()->IsChecked( MenuId_EnablePatches );
418 SaveEmuOptions();
419 }
420
421 void MainEmuFrame::Menu_EnableCheats_Click( wxCommandEvent& )
422 {
423 g_Conf->EmuOptions.EnableCheats = GetMenuBar()->IsChecked( MenuId_EnableCheats );
424 SaveEmuOptions();
425 }
426
427 void MainEmuFrame::Menu_EnableHostFs_Click( wxCommandEvent& )
428 {
429 g_Conf->EmuOptions.HostFs = GetMenuBar()->IsChecked( MenuId_EnableHostFs );
430 SaveEmuOptions();
431 }
432
433 void MainEmuFrame::Menu_OpenELF_Click(wxCommandEvent&)
434 {
435 ScopedCoreThreadClose stopped_core;
436 if( _DoSelectELFBrowser() )
437 {
438 g_Conf->EmuOptions.UseBOOT2Injection = true;
439 sApp.SysExecute( g_Conf->CdvdSource, g_Conf->CurrentELF );
440 }
441
442 stopped_core.AllowResume();
443 }
444
445 void MainEmuFrame::Menu_LoadStates_Click(wxCommandEvent &event)
446 {
447 States_SetCurrentSlot( event.GetId() - MenuId_State_Load01 - 1 );
448 States_DefrostCurrentSlot();
449 }
450
451 void MainEmuFrame::Menu_SaveStates_Click(wxCommandEvent &event)
452 {
453 States_SetCurrentSlot( event.GetId() - MenuId_State_Save01 - 1 );
454 States_FreezeCurrentSlot();
455 }
456
457 void MainEmuFrame::Menu_LoadStateOther_Click(wxCommandEvent &event)
458 {
459 Console.WriteLn("If this were hooked up, it would load a savestate file.");
460 }
461
462 void MainEmuFrame::Menu_SaveStateOther_Click(wxCommandEvent &event)
463 {
464 Console.WriteLn("If this were hooked up, it would save a savestate file.");
465 }
466
467 void MainEmuFrame::Menu_Exit_Click(wxCommandEvent &event)
468 {
469 Close();
470 }
471
472 class SysExecEvent_ToggleSuspend : public SysExecEvent
473 {
474 public:
475 virtual ~SysExecEvent_ToggleSuspend() throw() {}
476
477 wxString GetEventName() const { return L"ToggleSuspendResume"; }
478
479 protected:
480 void InvokeEvent()
481 {
482 if( CoreThread.IsOpen() )
483 CoreThread.Suspend();
484 else
485 CoreThread.Resume();
486 }
487 };
488
489 void MainEmuFrame::Menu_SuspendResume_Click(wxCommandEvent &event)
490 {
491 if( !SysHasValidState() ) return;
492
493 // Disable the menu item. The state of the menu is indeterminate until the core thread
494 // has responded (it updates status after the plugins are loaded and emulation has
495 // engaged successfully).
496
497 EnableMenuItem( MenuId_Sys_SuspendResume, false );
498 GetSysExecutorThread().PostEvent( new SysExecEvent_ToggleSuspend() );
499 }
500
501 void MainEmuFrame::Menu_SysReset_Click(wxCommandEvent &event)
502 {
503 UI_DisableSysReset();
504 sApp.SysExecute();
505 }
506
507 void MainEmuFrame::Menu_SysShutdown_Click(wxCommandEvent &event)
508 {
509 //if( !SysHasValidState() && !CorePlugins.AreAnyInitialized() ) return;
510
511 UI_DisableSysShutdown();
512 CoreThread.Reset();
513 }
514
515 void MainEmuFrame::Menu_ConfigPlugin_Click(wxCommandEvent &event)
516 {
517 const int eventId = event.GetId() - MenuId_PluginBase_Settings;
518
519 PluginsEnum_t pid = (PluginsEnum_t)(eventId / PluginMenuId_Interval);
520
521 // Don't try to call the Patches config dialog until we write one.
522 if (event.GetId() == MenuId_Config_Patches) return;
523
524 if( !pxAssertDev( (eventId >= 0) || (pid < PluginId_Count), "Invalid plugin identifier passed to ConfigPlugin event handler." ) ) return;
525
526 wxWindowDisabler disabler;
527 ScopedCoreThreadPause paused_core( new SysExecEvent_SaveSinglePlugin(pid) );
528 GetCorePlugins().Configure( pid );
529 }
530
531 void MainEmuFrame::Menu_Debug_Open_Click(wxCommandEvent &event)
532 {
533 }
534
535 void MainEmuFrame::Menu_Debug_MemoryDump_Click(wxCommandEvent &event)
536 {
537 AppOpenDialog<wxRamViewDialog>( this );
538 }
539
540 void MainEmuFrame::Menu_Debug_Logging_Click(wxCommandEvent &event)
541 {
542 AppOpenDialog<LogOptionsDialog>( this );
543 }
544
545 void MainEmuFrame::Menu_ShowConsole(wxCommandEvent &event)
546 {
547 // Use messages to relay open/close commands (thread-safe)
548
549 g_Conf->ProgLogBox.Visible = event.IsChecked();
550 wxCommandEvent evt( wxEVT_COMMAND_MENU_SELECTED, g_Conf->ProgLogBox.Visible ? wxID_OPEN : wxID_CLOSE );
551 wxGetApp().ProgramLog_PostEvent( evt );
552 }
553
554 void MainEmuFrame::Menu_ShowConsole_Stdio(wxCommandEvent &event)
555 {
556 g_Conf->EmuOptions.ConsoleToStdio = GetMenuBar()->IsChecked( MenuId_Console_Stdio );
557 SaveEmuOptions();
558 }
559
560 void MainEmuFrame::Menu_PrintCDVD_Info(wxCommandEvent &event)
561 {
562 g_Conf->EmuOptions.CdvdVerboseReads = GetMenuBar()->IsChecked( MenuId_CDVD_Info );
563 const_cast<Pcsx2Config&>(EmuConfig).CdvdVerboseReads = g_Conf->EmuOptions.CdvdVerboseReads; // read-only in core thread, so it's safe to modify.
564 SaveEmuOptions();
565 }
566
567 void MainEmuFrame::Menu_ShowAboutBox(wxCommandEvent &event)
568 {
569 AppOpenDialog<AboutBoxDialog>( this );
570 }

  ViewVC Help
Powered by ViewVC 1.1.22