Merge pull request #2916 from lioncash/wx
DolphinWX: Minor changes to Main
This commit is contained in:
commit
4218fb4eea
|
@ -96,21 +96,72 @@ bool DolphinApp::Initialize(int& c, wxChar **v)
|
||||||
|
|
||||||
bool DolphinApp::OnInit()
|
bool DolphinApp::OnInit()
|
||||||
{
|
{
|
||||||
|
if (!wxApp::OnInit() || DolphinEmulatorDotComTextFileExists())
|
||||||
|
return false;
|
||||||
|
|
||||||
Bind(wxEVT_QUERY_END_SESSION, &DolphinApp::OnEndSession, this);
|
Bind(wxEVT_QUERY_END_SESSION, &DolphinApp::OnEndSession, this);
|
||||||
Bind(wxEVT_END_SESSION, &DolphinApp::OnEndSession, this);
|
Bind(wxEVT_END_SESSION, &DolphinApp::OnEndSession, this);
|
||||||
|
|
||||||
// Declarations and definitions
|
// Register message box and translation handlers
|
||||||
bool UseDebugger = false;
|
RegisterMsgAlertHandler(&wxMsgAlert);
|
||||||
bool UseLogger = false;
|
RegisterStringTranslator(&wxStringTranslator);
|
||||||
bool selectVideoBackend = false;
|
|
||||||
bool selectAudioEmulation = false;
|
|
||||||
|
|
||||||
wxString videoBackendName;
|
#if wxUSE_ON_FATAL_EXCEPTION
|
||||||
wxString audioEmulationName;
|
wxHandleFatalExceptions(true);
|
||||||
wxString userPath;
|
#endif
|
||||||
|
|
||||||
#if wxUSE_CMDLINE_PARSER // Parse command lines
|
UICommon::SetUserDirectory(m_user_path.ToStdString());
|
||||||
wxCmdLineEntryDesc cmdLineDesc[] =
|
UICommon::CreateDirectories();
|
||||||
|
InitLanguageSupport(); // The language setting is loaded from the user directory
|
||||||
|
UICommon::Init();
|
||||||
|
|
||||||
|
if (m_select_video_backend && !m_video_backend_name.empty())
|
||||||
|
SConfig::GetInstance().m_strVideoBackend = WxStrToStr(m_video_backend_name);
|
||||||
|
|
||||||
|
if (m_select_audio_emulation)
|
||||||
|
SConfig::GetInstance().bDSPHLE = (m_audio_emulation_name.Upper() == "HLE");
|
||||||
|
|
||||||
|
VideoBackend::ActivateBackend(SConfig::GetInstance().m_strVideoBackend);
|
||||||
|
|
||||||
|
// Enable the PNG image handler for screenshots
|
||||||
|
wxImage::AddHandler(new wxPNGHandler);
|
||||||
|
|
||||||
|
int x = SConfig::GetInstance().iPosX;
|
||||||
|
int y = SConfig::GetInstance().iPosY;
|
||||||
|
int w = SConfig::GetInstance().iWidth;
|
||||||
|
int h = SConfig::GetInstance().iHeight;
|
||||||
|
|
||||||
|
// The following is not needed with X11, where window managers
|
||||||
|
// do not allow windows to be created off the desktop.
|
||||||
|
#ifdef _WIN32
|
||||||
|
// Out of desktop check
|
||||||
|
int leftPos = GetSystemMetrics(SM_XVIRTUALSCREEN);
|
||||||
|
int topPos = GetSystemMetrics(SM_YVIRTUALSCREEN);
|
||||||
|
int width = GetSystemMetrics(SM_CXVIRTUALSCREEN);
|
||||||
|
int height = GetSystemMetrics(SM_CYVIRTUALSCREEN);
|
||||||
|
if ((leftPos + width) < (x + w) || leftPos > x || (topPos + height) < (y + h) || topPos > y)
|
||||||
|
x = y = wxDefaultCoord;
|
||||||
|
#elif defined __APPLE__
|
||||||
|
if (y < 1)
|
||||||
|
y = wxDefaultCoord;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
main_frame = new CFrame(nullptr, wxID_ANY,
|
||||||
|
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));
|
||||||
|
|
||||||
|
AfterInit();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DolphinApp::OnInitCmdLine(wxCmdLineParser& parser)
|
||||||
|
{
|
||||||
|
static const wxCmdLineEntryDesc desc[] =
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
wxCMD_LINE_SWITCH, "h", "help",
|
wxCMD_LINE_SWITCH, "h", "help",
|
||||||
|
@ -138,12 +189,12 @@ bool DolphinApp::OnInit()
|
||||||
wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL
|
wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
wxCMD_LINE_OPTION, "V", "video_backend",
|
wxCMD_LINE_OPTION, "v", "video_backend",
|
||||||
"Specify a video backend",
|
"Specify a video backend",
|
||||||
wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL
|
wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
wxCMD_LINE_OPTION, "A", "audio_emulation",
|
wxCMD_LINE_OPTION, "a", "audio_emulation",
|
||||||
"Low level (LLE) or high level (HLE) audio",
|
"Low level (LLE) or high level (HLE) audio",
|
||||||
wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL
|
wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL
|
||||||
},
|
},
|
||||||
|
@ -153,7 +204,7 @@ bool DolphinApp::OnInit()
|
||||||
wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL
|
wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
wxCMD_LINE_OPTION, "U", "user",
|
wxCMD_LINE_OPTION, "u", "user",
|
||||||
"User folder path",
|
"User folder path",
|
||||||
wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL
|
wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL
|
||||||
},
|
},
|
||||||
|
@ -162,127 +213,73 @@ bool DolphinApp::OnInit()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Gets the command line parameters
|
parser.SetDesc(desc);
|
||||||
wxCmdLineParser parser(cmdLineDesc, argc, argv);
|
}
|
||||||
LoadFile = false;
|
|
||||||
|
bool DolphinApp::OnCmdLineParsed(wxCmdLineParser& parser)
|
||||||
|
{
|
||||||
if (argc == 2 && File::Exists(argv[1].ToUTF8().data()))
|
if (argc == 2 && File::Exists(argv[1].ToUTF8().data()))
|
||||||
{
|
{
|
||||||
LoadFile = true;
|
m_load_file = true;
|
||||||
FileToLoad = argv[1];
|
m_file_to_load = argv[1];
|
||||||
}
|
}
|
||||||
else if (parser.Parse() != 0)
|
else if (parser.Parse() != 0)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
UseDebugger = parser.Found("debugger");
|
if (!m_load_file)
|
||||||
UseLogger = parser.Found("logger");
|
m_load_file = parser.Found("exec", &m_file_to_load);
|
||||||
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
|
m_use_debugger = parser.Found("debugger");
|
||||||
RegisterMsgAlertHandler(&wxMsgAlert);
|
m_use_logger = parser.Found("logger");
|
||||||
RegisterStringTranslator(&wxStringTranslator);
|
m_batch_mode = parser.Found("batch");
|
||||||
|
m_select_video_backend = parser.Found("video_backend", &m_video_backend_name);
|
||||||
#if wxUSE_ON_FATAL_EXCEPTION
|
m_select_audio_emulation = parser.Found("audio_emulation", &m_audio_emulation_name);
|
||||||
wxHandleFatalExceptions(true);
|
m_play_movie = parser.Found("movie", &m_movie_file);
|
||||||
#endif
|
parser.Found("user", &m_user_path);
|
||||||
|
|
||||||
UICommon::SetUserDirectory(userPath.ToStdString());
|
|
||||||
UICommon::CreateDirectories();
|
|
||||||
InitLanguageSupport(); // The language setting is loaded from the user directory
|
|
||||||
UICommon::Init();
|
|
||||||
|
|
||||||
if (selectVideoBackend && videoBackendName != wxEmptyString)
|
|
||||||
SConfig::GetInstance().m_strVideoBackend =
|
|
||||||
WxStrToStr(videoBackendName);
|
|
||||||
|
|
||||||
if (selectAudioEmulation)
|
|
||||||
{
|
|
||||||
if (audioEmulationName == "HLE")
|
|
||||||
SConfig::GetInstance().bDSPHLE = true;
|
|
||||||
else if (audioEmulationName == "LLE")
|
|
||||||
SConfig::GetInstance().bDSPHLE = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
VideoBackend::ActivateBackend(SConfig::GetInstance().m_strVideoBackend);
|
|
||||||
|
|
||||||
// Enable the PNG image handler for screenshots
|
|
||||||
wxImage::AddHandler(new wxPNGHandler);
|
|
||||||
|
|
||||||
int x = SConfig::GetInstance().iPosX;
|
|
||||||
int y = SConfig::GetInstance().iPosY;
|
|
||||||
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
|
|
||||||
// Out of desktop check
|
|
||||||
int leftPos = GetSystemMetrics(SM_XVIRTUALSCREEN);
|
|
||||||
int topPos = GetSystemMetrics(SM_YVIRTUALSCREEN);
|
|
||||||
int width = GetSystemMetrics(SM_CXVIRTUALSCREEN);
|
|
||||||
int height = GetSystemMetrics(SM_CYVIRTUALSCREEN);
|
|
||||||
if ((leftPos + width) < (x + w) || leftPos > x || (topPos + height) < (y + h) || topPos > y)
|
|
||||||
x = y = wxDefaultCoord;
|
|
||||||
#elif defined __APPLE__
|
|
||||||
if (y < 1)
|
|
||||||
y = wxDefaultCoord;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
main_frame = new CFrame(nullptr, wxID_ANY,
|
|
||||||
StrToWxStr(scm_rev_str),
|
|
||||||
wxPoint(x, y), wxSize(w, h),
|
|
||||||
UseDebugger, BatchMode, UseLogger);
|
|
||||||
SetTopWindow(main_frame);
|
|
||||||
main_frame->SetMinSize(wxSize(400, 300));
|
|
||||||
|
|
||||||
AfterInit();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
void DolphinApp::MacOpenFile(const wxString &fileName)
|
void DolphinApp::MacOpenFile(const wxString& fileName)
|
||||||
{
|
{
|
||||||
FileToLoad = fileName;
|
m_file_to_load = fileName;
|
||||||
LoadFile = true;
|
m_load_file = true;
|
||||||
main_frame->BootGame(WxStrToStr(FileToLoad));
|
main_frame->BootGame(WxStrToStr(m_file_to_load));
|
||||||
}
|
}
|
||||||
#endif
|
#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()
|
void DolphinApp::AfterInit()
|
||||||
{
|
{
|
||||||
if (!BatchMode)
|
if (!m_batch_mode)
|
||||||
main_frame->UpdateGameList();
|
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
|
else
|
||||||
{
|
{
|
||||||
|
@ -290,11 +287,10 @@ void DolphinApp::AfterInit()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// First check if we have an exec command line.
|
// 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,
|
// If we have selected Automatic Start, start the default ISO,
|
||||||
// or if no default ISO exists, start the last loaded ISO
|
// or if no default ISO exists, start the last loaded ISO
|
||||||
|
@ -318,7 +314,7 @@ void DolphinApp::InitLanguageSupport()
|
||||||
// Load language if possible, fall back to system default otherwise
|
// Load language if possible, fall back to system default otherwise
|
||||||
if (wxLocale::IsAvailable(language))
|
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
|
// Specify where dolphins *.gmo files are located on each operating system
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
@ -334,14 +330,13 @@ void DolphinApp::InitLanguageSupport()
|
||||||
if (!m_locale->IsOk())
|
if (!m_locale->IsOk())
|
||||||
{
|
{
|
||||||
wxMessageBox(_("Error loading selected language. Falling back to system default."), _("Error"));
|
wxMessageBox(_("Error loading selected language. Falling back to system default."), _("Error"));
|
||||||
delete m_locale;
|
m_locale.reset(new wxLocale(wxLANGUAGE_DEFAULT));
|
||||||
m_locale = new wxLocale(wxLANGUAGE_DEFAULT);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
wxMessageBox(_("The selected language is not supported by your system. Falling back to system default."), _("Error"));
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -359,8 +354,6 @@ int DolphinApp::OnExit()
|
||||||
Core::Shutdown();
|
Core::Shutdown();
|
||||||
UICommon::Shutdown();
|
UICommon::Shutdown();
|
||||||
|
|
||||||
delete m_locale;
|
|
||||||
|
|
||||||
return wxApp::OnExit();
|
return wxApp::OnExit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
#include <wx/app.h>
|
#include <wx/app.h>
|
||||||
|
|
||||||
class CFrame;
|
class CFrame;
|
||||||
|
@ -20,22 +21,33 @@ public:
|
||||||
private:
|
private:
|
||||||
bool OnInit() override;
|
bool OnInit() override;
|
||||||
int OnExit() override;
|
int OnExit() override;
|
||||||
|
void OnInitCmdLine(wxCmdLineParser& parser) override;
|
||||||
|
bool OnCmdLineParsed(wxCmdLineParser& parser) override;
|
||||||
void OnFatalException() override;
|
void OnFatalException() override;
|
||||||
bool Initialize(int& c, wxChar **v) override;
|
bool Initialize(int& c, wxChar** v) override;
|
||||||
void InitLanguageSupport();
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
void MacOpenFile(const wxString &fileName) override;
|
void MacOpenFile(const wxString &fileName) override;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool BatchMode;
|
|
||||||
bool LoadFile;
|
|
||||||
bool playMovie;
|
|
||||||
wxString FileToLoad;
|
|
||||||
wxString movieFile;
|
|
||||||
wxLocale *m_locale;
|
|
||||||
|
|
||||||
void AfterInit();
|
|
||||||
void OnEndSession(wxCloseEvent& event);
|
void OnEndSession(wxCloseEvent& event);
|
||||||
|
void InitLanguageSupport();
|
||||||
|
void AfterInit();
|
||||||
|
static bool DolphinEmulatorDotComTextFileExists();
|
||||||
|
|
||||||
|
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;
|
||||||
|
std::unique_ptr<wxLocale> m_locale;
|
||||||
};
|
};
|
||||||
|
|
||||||
DECLARE_APP(DolphinApp);
|
DECLARE_APP(DolphinApp);
|
||||||
|
|
Loading…
Reference in New Issue