Move DolphinWX over to command command line parsing.

This commit is contained in:
Ryan Houdek 2016-01-17 05:15:03 -06:00 committed by Léo Lam
parent 36a9479c17
commit c2d5fe3ec9
2 changed files with 40 additions and 53 deletions

View File

@ -2,6 +2,7 @@
// Licensed under GPLv2+ // Licensed under GPLv2+
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <OptionParser.h>
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
#include <mutex> #include <mutex>
@ -47,6 +48,7 @@
#include "DolphinWX/VideoConfigDiag.h" #include "DolphinWX/VideoConfigDiag.h"
#include "DolphinWX/WxUtils.h" #include "DolphinWX/WxUtils.h"
#include "UICommon/CommandLineParse.h"
#include "UICommon/UICommon.h" #include "UICommon/UICommon.h"
#include "VideoCommon/VideoBackendBase.h" #include "VideoCommon/VideoBackendBase.h"
@ -77,6 +79,11 @@ bool DolphinApp::Initialize(int& c, wxChar** v)
// The 'main program' equivalent that creates the main window and return the main frame // The 'main program' equivalent that creates the main window and return the main frame
void DolphinApp::OnInitCmdLine(wxCmdLineParser& parser)
{
parser.SetCmdLine("");
}
bool DolphinApp::OnInit() bool DolphinApp::OnInit()
{ {
std::lock_guard<std::mutex> lk(s_init_mutex); std::lock_guard<std::mutex> lk(s_init_mutex);
@ -96,6 +103,8 @@ bool DolphinApp::OnInit()
wxHandleFatalExceptions(true); wxHandleFatalExceptions(true);
#endif #endif
ParseCommandLine();
UICommon::SetUserDirectory(m_user_path.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
@ -130,60 +139,41 @@ bool DolphinApp::OnInit()
return true; return true;
} }
void DolphinApp::OnInitCmdLine(wxCmdLineParser& parser) void DolphinApp::ParseCommandLine()
{ {
static const wxCmdLineEntryDesc desc[] = { auto parser = CommandLineParse::CreateParser(CommandLineParse::ParserOptions::IncludeGUIOptions);
{wxCMD_LINE_SWITCH, "h", "help", "Show this help message", wxCMD_LINE_VAL_NONE, optparse::Values& options = CommandLineParse::ParseArguments(parser.get(), argc, argv);
wxCMD_LINE_OPTION_HELP}, std::vector<std::string> args = parser->args();
{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, TGC, 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, "c", "confirm", "Set Confirm on Stop", wxCMD_LINE_VAL_STRING,
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); if (options.is_set("exec"))
}
bool DolphinApp::OnCmdLineParsed(wxCmdLineParser& parser)
{
if (argc == 2 && File::Exists(argv[1].ToUTF8().data()))
{ {
m_load_file = true; m_load_file = true;
m_file_to_load = argv[1]; m_file_to_load = static_cast<const char*>(options.get("exec"));
} }
else if (parser.Parse() != 0) else if (args.size())
{ {
return false; m_load_file = true;
m_file_to_load = args.front();
args.erase(args.begin());
} }
if (!m_load_file) m_use_debugger = options.is_set("debugger");
m_load_file = parser.Found("exec", &m_file_to_load); m_use_logger = options.is_set("logger");
m_batch_mode = options.is_set("batch");
m_use_debugger = parser.Found("debugger"); m_confirm_stop = options.is_set("confirm");
m_use_logger = parser.Found("logger"); m_confirm_setting = options.get("confirm");
m_batch_mode = parser.Found("batch");
m_confirm_stop = parser.Found("confirm", &m_confirm_setting);
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; m_select_video_backend = options.is_set("video_backend");
m_video_backend_name = static_cast<const char*>(options.get("video_backend"));
m_select_audio_emulation = options.is_set("audio_emulation");
m_audio_emulation_name = static_cast<const char*>(options.get("audio_emulation"));
m_play_movie = options.is_set("movie");
m_movie_file = static_cast<const char*>(options.get("movie"));
m_user_path = static_cast<const char*>(options.get("user"));
} }
#ifdef __APPLE__ #ifdef __APPLE__
@ -224,12 +214,7 @@ void DolphinApp::AfterInit()
} }
if (m_confirm_stop) if (m_confirm_stop)
{ SConfig::GetInstance().bConfirmStop = m_confirm_setting;
if (m_confirm_setting.Upper() == "TRUE")
SConfig::GetInstance().bConfirmStop = true;
else if (m_confirm_setting.Upper() == "FALSE")
SConfig::GetInstance().bConfirmStop = false;
}
if (m_play_movie && !m_movie_file.empty()) if (m_play_movie && !m_movie_file.empty())
{ {

View File

@ -8,6 +8,7 @@
#include <wx/app.h> #include <wx/app.h>
class CFrame; class CFrame;
class wxCmdLineParser;
class wxLocale; class wxLocale;
extern CFrame* main_frame; extern CFrame* main_frame;
@ -21,9 +22,8 @@ public:
private: private:
bool OnInit() override; bool OnInit() override;
int OnExit() override;
void OnInitCmdLine(wxCmdLineParser& parser) override; void OnInitCmdLine(wxCmdLineParser& parser) override;
bool OnCmdLineParsed(wxCmdLineParser& parser) override; int OnExit() override;
void OnFatalException() override; void OnFatalException() override;
bool Initialize(int& c, wxChar** v) override; bool Initialize(int& c, wxChar** v) override;
@ -37,6 +37,8 @@ private:
void OnActivate(wxActivateEvent& ev); void OnActivate(wxActivateEvent& ev);
void OnIdle(wxIdleEvent&); void OnIdle(wxIdleEvent&);
void ParseCommandLine();
bool m_batch_mode = false; bool m_batch_mode = false;
bool m_confirm_stop = false; bool m_confirm_stop = false;
bool m_is_active = true; bool m_is_active = true;
@ -46,7 +48,7 @@ private:
bool m_use_logger = false; bool m_use_logger = false;
bool m_select_video_backend = false; bool m_select_video_backend = false;
bool m_select_audio_emulation = false; bool m_select_audio_emulation = false;
wxString m_confirm_setting; bool m_confirm_setting;
wxString m_video_backend_name; wxString m_video_backend_name;
wxString m_audio_emulation_name; wxString m_audio_emulation_name;
wxString m_user_path; wxString m_user_path;