From aafae49d2492db6753ad2da705cc21831e558669 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 27 Aug 2015 06:59:23 -0400 Subject: [PATCH 1/3] Main: Move commandline parsing handling to appropriate override functions --- Source/Core/DolphinWX/Main.cpp | 224 ++++++++++++++++----------------- Source/Core/DolphinWX/Main.h | 30 +++-- 2 files changed, 129 insertions(+), 125 deletions(-) diff --git a/Source/Core/DolphinWX/Main.cpp b/Source/Core/DolphinWX/Main.cpp index 150fef7f37..07bc456083 100644 --- a/Source/Core/DolphinWX/Main.cpp +++ b/Source/Core/DolphinWX/Main.cpp @@ -96,96 +96,12 @@ bool DolphinApp::Initialize(int& c, wxChar **v) bool DolphinApp::OnInit() { + if (!wxApp::OnInit()) + return false; + Bind(wxEVT_QUERY_END_SESSION, &DolphinApp::OnEndSession, this); Bind(wxEVT_END_SESSION, &DolphinApp::OnEndSession, this); - // Declarations and definitions - bool UseDebugger = false; - bool UseLogger = false; - bool selectVideoBackend = false; - bool selectAudioEmulation = false; - - wxString videoBackendName; - wxString audioEmulationName; - wxString userPath; - -#if wxUSE_CMDLINE_PARSER // Parse command lines - wxCmdLineEntryDesc cmdLineDesc[] = - { - { - wxCMD_LINE_SWITCH, "h", "help", - "Show this help message", - wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP - }, - { - wxCMD_LINE_SWITCH, "d", "debugger", - "Opens the debugger", - wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL - }, - { - wxCMD_LINE_SWITCH, "l", "logger", - "Opens the logger", - wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL - }, - { - wxCMD_LINE_OPTION, "e", "exec", - "Loads the specified file (ELF, DOL, GCM, ISO, WBFS, CISO, GCZ, WAD)", - wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL - }, - { - wxCMD_LINE_SWITCH, "b", "batch", - "Exit Dolphin with emulator", - wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL - }, - { - wxCMD_LINE_OPTION, "V", "video_backend", - "Specify a video backend", - wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL - }, - { - wxCMD_LINE_OPTION, "A", "audio_emulation", - "Low level (LLE) or high level (HLE) audio", - wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL - }, - { - wxCMD_LINE_OPTION, "m", "movie", - "Play a movie file", - wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL - }, - { - wxCMD_LINE_OPTION, "U", "user", - "User folder path", - wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL - }, - { - wxCMD_LINE_NONE, nullptr, nullptr, nullptr, wxCMD_LINE_VAL_NONE, 0 - } - }; - - // Gets the command line parameters - wxCmdLineParser parser(cmdLineDesc, argc, argv); - LoadFile = false; - if (argc == 2 && File::Exists(argv[1].ToUTF8().data())) - { - LoadFile = true; - FileToLoad = argv[1]; - } - else if (parser.Parse() != 0) - { - return false; - } - - UseDebugger = parser.Found("debugger"); - UseLogger = parser.Found("logger"); - if (!LoadFile) - LoadFile = parser.Found("exec", &FileToLoad); - BatchMode = parser.Found("batch"); - selectVideoBackend = parser.Found("video_backend", &videoBackendName); - selectAudioEmulation = parser.Found("audio_emulation", &audioEmulationName); - playMovie = parser.Found("movie", &movieFile); - parser.Found("user", &userPath); -#endif // wxUSE_CMDLINE_PARSER - // Register message box and translation handlers RegisterMsgAlertHandler(&wxMsgAlert); RegisterStringTranslator(&wxStringTranslator); @@ -194,22 +110,16 @@ bool DolphinApp::OnInit() wxHandleFatalExceptions(true); #endif - UICommon::SetUserDirectory(userPath.ToStdString()); + UICommon::SetUserDirectory(m_user_path.ToStdString()); UICommon::CreateDirectories(); - InitLanguageSupport(); // The language setting is loaded from the user directory + InitLanguageSupport(); // The language setting is loaded from the user directory UICommon::Init(); - if (selectVideoBackend && videoBackendName != wxEmptyString) - SConfig::GetInstance().m_strVideoBackend = - WxStrToStr(videoBackendName); + if (m_select_video_backend && !m_video_backend_name.empty()) + SConfig::GetInstance().m_strVideoBackend = WxStrToStr(m_video_backend_name); - if (selectAudioEmulation) - { - if (audioEmulationName == "HLE") - SConfig::GetInstance().bDSPHLE = true; - else if (audioEmulationName == "LLE") - SConfig::GetInstance().bDSPHLE = false; - } + if (m_select_audio_emulation) + SConfig::GetInstance().bDSPHLE = (m_audio_emulation_name.Upper() == "HLE"); VideoBackend::ActivateBackend(SConfig::GetInstance().m_strVideoBackend); @@ -251,9 +161,10 @@ bool DolphinApp::OnInit() #endif main_frame = new CFrame(nullptr, wxID_ANY, - StrToWxStr(scm_rev_str), - wxPoint(x, y), wxSize(w, h), - UseDebugger, BatchMode, UseLogger); + StrToWxStr(scm_rev_str), + wxPoint(x, y), wxSize(w, h), + m_use_debugger, m_batch_mode, m_use_logger); + SetTopWindow(main_frame); main_frame->SetMinSize(wxSize(400, 300)); @@ -262,27 +173,111 @@ bool DolphinApp::OnInit() return true; } -#ifdef __APPLE__ -void DolphinApp::MacOpenFile(const wxString &fileName) +void DolphinApp::OnInitCmdLine(wxCmdLineParser& parser) { - FileToLoad = fileName; - LoadFile = true; - main_frame->BootGame(WxStrToStr(FileToLoad)); + static const wxCmdLineEntryDesc desc[] = + { + { + wxCMD_LINE_SWITCH, "h", "help", + "Show this help message", + wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP + }, + { + wxCMD_LINE_SWITCH, "d", "debugger", + "Opens the debugger", + wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL + }, + { + wxCMD_LINE_SWITCH, "l", "logger", + "Opens the logger", + wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL + }, + { + wxCMD_LINE_OPTION, "e", "exec", + "Loads the specified file (ELF, DOL, GCM, ISO, WBFS, CISO, GCZ, WAD)", + wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL + }, + { + wxCMD_LINE_SWITCH, "b", "batch", + "Exit Dolphin with emulator", + wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL + }, + { + wxCMD_LINE_OPTION, "v", "video_backend", + "Specify a video backend", + wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL + }, + { + wxCMD_LINE_OPTION, "a", "audio_emulation", + "Low level (LLE) or high level (HLE) audio", + wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL + }, + { + wxCMD_LINE_OPTION, "m", "movie", + "Play a movie file", + wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL + }, + { + wxCMD_LINE_OPTION, "u", "user", + "User folder path", + wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL + }, + { + wxCMD_LINE_NONE, nullptr, nullptr, nullptr, wxCMD_LINE_VAL_NONE, 0 + } + }; + + parser.SetDesc(desc); +} + +bool DolphinApp::OnCmdLineParsed(wxCmdLineParser& parser) +{ + if (argc == 2 && File::Exists(argv[1].ToUTF8().data())) + { + m_load_file = true; + m_file_to_load = argv[1]; + } + else if (parser.Parse() != 0) + { + return false; + } + + if (!m_load_file) + m_load_file = parser.Found("exec", &m_file_to_load); + + m_use_debugger = parser.Found("debugger"); + m_use_logger = parser.Found("logger"); + m_batch_mode = parser.Found("batch"); + m_select_video_backend = parser.Found("video_backend", &m_video_backend_name); + m_select_audio_emulation = parser.Found("audio_emulation", &m_audio_emulation_name); + m_play_movie = parser.Found("movie", &m_movie_file); + parser.Found("user", &m_user_path); + + return true; +} + + +#ifdef __APPLE__ +void DolphinApp::MacOpenFile(const wxString& fileName) +{ + m_file_to_load = fileName; + m_load_file = true; + main_frame->BootGame(WxStrToStr(m_file_to_load)); } #endif void DolphinApp::AfterInit() { - if (!BatchMode) + if (!m_batch_mode) main_frame->UpdateGameList(); - if (playMovie && movieFile != wxEmptyString) + if (m_play_movie && !m_movie_file.empty()) { - if (Movie::PlayInput(WxStrToStr(movieFile))) + if (Movie::PlayInput(WxStrToStr(m_movie_file))) { - if (LoadFile && FileToLoad != wxEmptyString) + if (m_load_file && !m_file_to_load.empty()) { - main_frame->BootGame(WxStrToStr(FileToLoad)); + main_frame->BootGame(WxStrToStr(m_file_to_load)); } else { @@ -290,11 +285,10 @@ void DolphinApp::AfterInit() } } } - // First check if we have an exec command line. - else if (LoadFile && FileToLoad != wxEmptyString) + else if (m_load_file && !m_file_to_load.empty()) { - main_frame->BootGame(WxStrToStr(FileToLoad)); + main_frame->BootGame(WxStrToStr(m_file_to_load)); } // If we have selected Automatic Start, start the default ISO, // or if no default ISO exists, start the last loaded ISO diff --git a/Source/Core/DolphinWX/Main.h b/Source/Core/DolphinWX/Main.h index a28b3e94f9..c0415528ee 100644 --- a/Source/Core/DolphinWX/Main.h +++ b/Source/Core/DolphinWX/Main.h @@ -20,22 +20,32 @@ public: private: bool OnInit() override; int OnExit() override; + void OnInitCmdLine(wxCmdLineParser& parser) override; + bool OnCmdLineParsed(wxCmdLineParser& parser) override; void OnFatalException() override; - bool Initialize(int& c, wxChar **v) override; - void InitLanguageSupport(); + bool Initialize(int& c, wxChar** v) override; + #ifdef __APPLE__ void MacOpenFile(const wxString &fileName) override; #endif - bool BatchMode; - bool LoadFile; - bool playMovie; - wxString FileToLoad; - wxString movieFile; - wxLocale *m_locale; - - void AfterInit(); void OnEndSession(wxCloseEvent& event); + void InitLanguageSupport(); + void AfterInit(); + + bool m_batch_mode = false; + bool m_load_file = false; + bool m_play_movie = false; + bool m_use_debugger = false; + bool m_use_logger = false; + bool m_select_video_backend = false; + bool m_select_audio_emulation = false; + wxString m_video_backend_name; + wxString m_audio_emulation_name; + wxString m_user_path; + wxString m_file_to_load; + wxString m_movie_file; + wxLocale* m_locale; }; DECLARE_APP(DolphinApp); From 14ae1d23cf9cc67cf88074420b98ef6a0910b75f Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 27 Aug 2015 07:13:08 -0400 Subject: [PATCH 2/3] Main: Move unofficial build check to its own function Removes the need to explicitly call exit. --- Source/Core/DolphinWX/Main.cpp | 34 ++++++++++++++++++---------------- Source/Core/DolphinWX/Main.h | 1 + 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/Source/Core/DolphinWX/Main.cpp b/Source/Core/DolphinWX/Main.cpp index 07bc456083..a4d223ad95 100644 --- a/Source/Core/DolphinWX/Main.cpp +++ b/Source/Core/DolphinWX/Main.cpp @@ -96,7 +96,7 @@ bool DolphinApp::Initialize(int& c, wxChar **v) bool DolphinApp::OnInit() { - if (!wxApp::OnInit()) + if (!wxApp::OnInit() || DolphinEmulatorDotComTextFileExists()) return false; Bind(wxEVT_QUERY_END_SESSION, &DolphinApp::OnEndSession, this); @@ -131,20 +131,6 @@ bool DolphinApp::OnInit() int w = SConfig::GetInstance().iWidth; int h = SConfig::GetInstance().iHeight; - if (File::Exists("www.dolphin-emulator.com.txt")) - { - File::Delete("www.dolphin-emulator.com.txt"); - wxMessageDialog dlg(nullptr, _( - "This version of Dolphin was downloaded from a website stealing money from developers of the emulator. Please " - "download Dolphin from the official website instead: https://dolphin-emu.org/"), - _("Unofficial version detected"), wxOK | wxICON_WARNING); - dlg.ShowModal(); - - wxLaunchDefaultBrowser("https://dolphin-emu.org/?ref=badver"); - - exit(0); - } - // The following is not needed with X11, where window managers // do not allow windows to be created off the desktop. #ifdef _WIN32 @@ -256,7 +242,6 @@ bool DolphinApp::OnCmdLineParsed(wxCmdLineParser& parser) return true; } - #ifdef __APPLE__ void DolphinApp::MacOpenFile(const wxString& fileName) { @@ -266,6 +251,23 @@ void DolphinApp::MacOpenFile(const wxString& fileName) } #endif +bool DolphinApp::DolphinEmulatorDotComTextFileExists() +{ + if (!File::Exists("www.dolphin-emulator.com.txt")) + return false; + + File::Delete("www.dolphin-emulator.com.txt"); + wxMessageDialog dlg(nullptr, _( + "This version of Dolphin was downloaded from a website stealing money from developers of the emulator. Please " + "download Dolphin from the official website instead: https://dolphin-emu.org/"), + _("Unofficial version detected"), wxOK | wxICON_WARNING); + dlg.ShowModal(); + + wxLaunchDefaultBrowser("https://dolphin-emu.org/?ref=badver"); + + return true; +} + void DolphinApp::AfterInit() { if (!m_batch_mode) diff --git a/Source/Core/DolphinWX/Main.h b/Source/Core/DolphinWX/Main.h index c0415528ee..005e8c6fc4 100644 --- a/Source/Core/DolphinWX/Main.h +++ b/Source/Core/DolphinWX/Main.h @@ -32,6 +32,7 @@ private: void OnEndSession(wxCloseEvent& event); void InitLanguageSupport(); void AfterInit(); + static bool DolphinEmulatorDotComTextFileExists(); bool m_batch_mode = false; bool m_load_file = false; From 7fa0ecd046d2c9d6b63d958ea97bd33ccb776ea9 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 27 Aug 2015 08:12:34 -0400 Subject: [PATCH 3/3] Main: Make the wxLocale class member a unique_ptr --- Source/Core/DolphinWX/Main.cpp | 9 +++------ Source/Core/DolphinWX/Main.h | 3 ++- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Source/Core/DolphinWX/Main.cpp b/Source/Core/DolphinWX/Main.cpp index a4d223ad95..c75e53b976 100644 --- a/Source/Core/DolphinWX/Main.cpp +++ b/Source/Core/DolphinWX/Main.cpp @@ -314,7 +314,7 @@ void DolphinApp::InitLanguageSupport() // Load language if possible, fall back to system default otherwise if (wxLocale::IsAvailable(language)) { - m_locale = new wxLocale(language); + m_locale.reset(new wxLocale(language)); // Specify where dolphins *.gmo files are located on each operating system #ifdef _WIN32 @@ -330,14 +330,13 @@ void DolphinApp::InitLanguageSupport() if (!m_locale->IsOk()) { wxMessageBox(_("Error loading selected language. Falling back to system default."), _("Error")); - delete m_locale; - m_locale = new wxLocale(wxLANGUAGE_DEFAULT); + m_locale.reset(new wxLocale(wxLANGUAGE_DEFAULT)); } } else { wxMessageBox(_("The selected language is not supported by your system. Falling back to system default."), _("Error")); - m_locale = new wxLocale(wxLANGUAGE_DEFAULT); + m_locale.reset(new wxLocale(wxLANGUAGE_DEFAULT)); } } @@ -355,8 +354,6 @@ int DolphinApp::OnExit() Core::Shutdown(); UICommon::Shutdown(); - delete m_locale; - return wxApp::OnExit(); } diff --git a/Source/Core/DolphinWX/Main.h b/Source/Core/DolphinWX/Main.h index 005e8c6fc4..87dc6f4e4d 100644 --- a/Source/Core/DolphinWX/Main.h +++ b/Source/Core/DolphinWX/Main.h @@ -4,6 +4,7 @@ #pragma once +#include #include class CFrame; @@ -46,7 +47,7 @@ private: wxString m_user_path; wxString m_file_to_load; wxString m_movie_file; - wxLocale* m_locale; + std::unique_ptr m_locale; }; DECLARE_APP(DolphinApp);