Main: Move commandline parsing handling to appropriate override functions

This commit is contained in:
Lioncash 2015-08-27 06:59:23 -04:00
parent d9b18862f3
commit aafae49d24
2 changed files with 129 additions and 125 deletions

View File

@ -96,96 +96,12 @@ bool DolphinApp::Initialize(int& c, wxChar **v)
bool DolphinApp::OnInit() bool DolphinApp::OnInit()
{ {
if (!wxApp::OnInit())
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
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 // Register message box and translation handlers
RegisterMsgAlertHandler(&wxMsgAlert); RegisterMsgAlertHandler(&wxMsgAlert);
RegisterStringTranslator(&wxStringTranslator); RegisterStringTranslator(&wxStringTranslator);
@ -194,22 +110,16 @@ bool DolphinApp::OnInit()
wxHandleFatalExceptions(true); wxHandleFatalExceptions(true);
#endif #endif
UICommon::SetUserDirectory(userPath.ToStdString()); UICommon::SetUserDirectory(m_user_path.ToStdString());
UICommon::CreateDirectories(); UICommon::CreateDirectories();
InitLanguageSupport(); // The language setting is loaded from the user directory InitLanguageSupport(); // The language setting is loaded from the user directory
UICommon::Init(); UICommon::Init();
if (selectVideoBackend && videoBackendName != wxEmptyString) if (m_select_video_backend && !m_video_backend_name.empty())
SConfig::GetInstance().m_strVideoBackend = SConfig::GetInstance().m_strVideoBackend = WxStrToStr(m_video_backend_name);
WxStrToStr(videoBackendName);
if (selectAudioEmulation) if (m_select_audio_emulation)
{ SConfig::GetInstance().bDSPHLE = (m_audio_emulation_name.Upper() == "HLE");
if (audioEmulationName == "HLE")
SConfig::GetInstance().bDSPHLE = true;
else if (audioEmulationName == "LLE")
SConfig::GetInstance().bDSPHLE = false;
}
VideoBackend::ActivateBackend(SConfig::GetInstance().m_strVideoBackend); VideoBackend::ActivateBackend(SConfig::GetInstance().m_strVideoBackend);
@ -251,9 +161,10 @@ bool DolphinApp::OnInit()
#endif #endif
main_frame = new CFrame(nullptr, wxID_ANY, main_frame = new CFrame(nullptr, wxID_ANY,
StrToWxStr(scm_rev_str), StrToWxStr(scm_rev_str),
wxPoint(x, y), wxSize(w, h), wxPoint(x, y), wxSize(w, h),
UseDebugger, BatchMode, UseLogger); m_use_debugger, m_batch_mode, m_use_logger);
SetTopWindow(main_frame); SetTopWindow(main_frame);
main_frame->SetMinSize(wxSize(400, 300)); main_frame->SetMinSize(wxSize(400, 300));
@ -262,27 +173,111 @@ bool DolphinApp::OnInit()
return true; return true;
} }
#ifdef __APPLE__ void DolphinApp::OnInitCmdLine(wxCmdLineParser& parser)
void DolphinApp::MacOpenFile(const wxString &fileName)
{ {
FileToLoad = fileName; static const wxCmdLineEntryDesc desc[] =
LoadFile = true; {
main_frame->BootGame(WxStrToStr(FileToLoad)); {
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 #endif
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 +285,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

View File

@ -20,22 +20,32 @@ 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();
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); DECLARE_APP(DolphinApp);