UI: Implement a command line option to boot NAND title

This commit is contained in:
Léo Lam 2017-10-02 00:09:07 +02:00
parent 8e0869aff6
commit 4b4a9a6486
8 changed files with 69 additions and 26 deletions

View File

@ -360,14 +360,26 @@ int main(int argc, char* argv[])
optparse::Values& options = CommandLineParse::ParseArguments(parser.get(), argc, argv); optparse::Values& options = CommandLineParse::ParseArguments(parser.get(), argc, argv);
std::vector<std::string> args = parser->args(); std::vector<std::string> args = parser->args();
std::string boot_filename; std::unique_ptr<BootParameters> boot;
if (options.is_set("exec")) if (options.is_set("exec"))
{ {
boot_filename = static_cast<const char*>(options.get("exec")); boot = BootParameters::GenerateFromFile(static_cast<const char*>(options.get("exec")));
}
else if (options.is_set("nand_title"))
{
const std::string hex_string = static_cast<const char*>(options.get("nand_title"));
if (hex_string.length() != 16)
{
fprintf(stderr, "Invalid title ID\n");
parser->print_help();
return 1;
}
const u64 title_id = std::stoull(hex_string, nullptr, 16);
boot = std::make_unique<BootParameters>(BootParameters::NANDTitle{title_id});
} }
else if (args.size()) else if (args.size())
{ {
boot_filename = args.front(); boot = BootParameters::GenerateFromFile(args.front());
args.erase(args.begin()); args.erase(args.begin());
} }
else else
@ -408,9 +420,9 @@ int main(int argc, char* argv[])
DolphinAnalytics::Instance()->ReportDolphinStart("nogui"); DolphinAnalytics::Instance()->ReportDolphinStart("nogui");
if (!BootManager::BootCore(BootParameters::GenerateFromFile(boot_filename))) if (!BootManager::BootCore(std::move(boot)))
{ {
fprintf(stderr, "Could not boot %s\n", boot_filename.c_str()); fprintf(stderr, "Could not boot the specified file\n");
return 1; return 1;
} }

View File

@ -10,6 +10,7 @@
#include "Common/MsgHandler.h" #include "Common/MsgHandler.h"
#include "Core/Analytics.h" #include "Core/Analytics.h"
#include "Core/Boot/Boot.h"
#include "Core/BootManager.h" #include "Core/BootManager.h"
#include "Core/Core.h" #include "Core/Core.h"
#include "DolphinQt2/Host.h" #include "DolphinQt2/Host.h"
@ -84,6 +85,21 @@ int main(int argc, char* argv[])
QObject::connect(QAbstractEventDispatcher::instance(), &QAbstractEventDispatcher::aboutToBlock, QObject::connect(QAbstractEventDispatcher::instance(), &QAbstractEventDispatcher::aboutToBlock,
&app, &Core::HostDispatchJobs); &app, &Core::HostDispatchJobs);
std::unique_ptr<BootParameters> boot;
if (options.is_set("nand_title"))
{
const std::string hex_string = static_cast<const char*>(options.get("nand_title"));
if (hex_string.length() == 16)
{
const u64 title_id = std::stoull(hex_string, nullptr, 16);
boot = std::make_unique<BootParameters>(BootParameters::NANDTitle{title_id});
}
else
{
QMessageBox::critical(nullptr, QObject::tr("Error"), QObject::tr("Invalid title ID."));
}
}
int retval = 0; int retval = 0;
if (SConfig::GetInstance().m_show_development_warning) if (SConfig::GetInstance().m_show_development_warning)
@ -95,7 +111,7 @@ int main(int argc, char* argv[])
{ {
DolphinAnalytics::Instance()->ReportDolphinStart("qt"); DolphinAnalytics::Instance()->ReportDolphinStart("qt");
MainWindow win; MainWindow win{std::move(boot)};
win.show(); win.show();
#if defined(USE_ANALYTICS) && USE_ANALYTICS #if defined(USE_ANALYTICS) && USE_ANALYTICS

View File

@ -65,7 +65,7 @@
#include "UICommon/X11Utils.h" #include "UICommon/X11Utils.h"
#endif #endif
MainWindow::MainWindow() : QMainWindow(nullptr) MainWindow::MainWindow(std::unique_ptr<BootParameters> boot_parameters) : QMainWindow(nullptr)
{ {
setWindowTitle(QString::fromStdString(Common::scm_rev_str)); setWindowTitle(QString::fromStdString(Common::scm_rev_str));
setWindowIcon(QIcon(Resources::GetMisc(Resources::LOGO_SMALL))); setWindowIcon(QIcon(Resources::GetMisc(Resources::LOGO_SMALL)));
@ -84,6 +84,9 @@ MainWindow::MainWindow() : QMainWindow(nullptr)
InitCoreCallbacks(); InitCoreCallbacks();
NetPlayInit(); NetPlayInit();
if (boot_parameters)
StartGame(std::move(boot_parameters));
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()

View File

@ -35,7 +35,7 @@ class MainWindow final : public QMainWindow
Q_OBJECT Q_OBJECT
public: public:
explicit MainWindow(); explicit MainWindow(std::unique_ptr<BootParameters> boot_parameters);
~MainWindow(); ~MainWindow();
bool eventFilter(QObject* object, QEvent* event) override; bool eventFilter(QObject* object, QEvent* event) override;

View File

@ -106,6 +106,7 @@ public:
void StatusBarMessage(const char* format, ...); void StatusBarMessage(const char* format, ...);
void ClearStatusBar(); void ClearStatusBar();
void BootGame(const std::string& filename); void BootGame(const std::string& filename);
void StartGame(std::unique_ptr<BootParameters> boot);
bool RendererHasFocus(); bool RendererHasFocus();
bool RendererIsFullscreen(); bool RendererIsFullscreen();
void OpenGeneralConfiguration(wxWindowID tab_id = wxID_ANY); void OpenGeneralConfiguration(wxWindowID tab_id = wxID_ANY);
@ -193,7 +194,6 @@ private:
void InitializeTASDialogs(); void InitializeTASDialogs();
void InitializeCoreCallbacks(); void InitializeCoreCallbacks();
void StartGame(std::unique_ptr<BootParameters> boot);
void SetDebuggerStartupParameters() const; void SetDebuggerStartupParameters() const;
// Utility // Utility

View File

@ -34,6 +34,7 @@
#include "Common/Version.h" #include "Common/Version.h"
#include "Core/Analytics.h" #include "Core/Analytics.h"
#include "Core/Boot/Boot.h"
#include "Core/ConfigManager.h" #include "Core/ConfigManager.h"
#include "Core/Core.h" #include "Core/Core.h"
#include "Core/HW/Wiimote.h" #include "Core/HW/Wiimote.h"
@ -169,13 +170,24 @@ void DolphinApp::ParseCommandLine()
if (options.is_set("exec")) if (options.is_set("exec"))
{ {
m_load_file = true; m_boot = BootParameters::GenerateFromFile(static_cast<const char*>(options.get("exec")));
m_file_to_load = static_cast<const char*>(options.get("exec")); }
else if (options.is_set("nand_title"))
{
const std::string hex_string = static_cast<const char*>(options.get("nand_title"));
if (hex_string.length() == 16)
{
const u64 title_id = std::stoull(hex_string, nullptr, 16);
m_boot = std::make_unique<BootParameters>(BootParameters::NANDTitle{title_id});
}
else
{
WxUtils::ShowErrorDialog(_("The title ID is invalid."));
}
} }
else if (args.size()) else if (args.size())
{ {
m_load_file = true; m_boot = BootParameters::GenerateFromFile(args.front());
m_file_to_load = args.front();
args.erase(args.begin()); args.erase(args.begin());
} }
@ -201,9 +213,7 @@ void DolphinApp::ParseCommandLine()
#ifdef __APPLE__ #ifdef __APPLE__
void DolphinApp::MacOpenFile(const wxString& fileName) void DolphinApp::MacOpenFile(const wxString& fileName)
{ {
m_file_to_load = fileName; main_frame->StartGame(BootParameters::GenerateFromFile(fileName.ToStdString()));
m_load_file = true;
main_frame->BootGame(WxStrToStr(m_file_to_load));
} }
#endif #endif
@ -241,20 +251,16 @@ void DolphinApp::AfterInit()
{ {
if (Movie::PlayInput(WxStrToStr(m_movie_file))) if (Movie::PlayInput(WxStrToStr(m_movie_file)))
{ {
if (m_load_file && !m_file_to_load.empty()) if (m_boot)
{ main_frame->StartGame(std::move(m_boot));
main_frame->BootGame(WxStrToStr(m_file_to_load));
}
else else
{
main_frame->BootGame(""); main_frame->BootGame("");
}
} }
} }
// First check if we have an exec command line. // First check if we have an exec command line.
else if (m_load_file && !m_file_to_load.empty()) else if (m_boot)
{ {
main_frame->BootGame(WxStrToStr(m_file_to_load)); main_frame->StartGame(std::move(m_boot));
} }
// 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

@ -13,6 +13,8 @@ class wxLocale;
extern CFrame* main_frame; extern CFrame* main_frame;
struct BootParameters;
// Define a new application // Define a new application
class DolphinApp : public wxApp class DolphinApp : public wxApp
{ {
@ -43,7 +45,6 @@ private:
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;
bool m_load_file = false;
bool m_play_movie = false; bool m_play_movie = false;
bool m_use_debugger = false; bool m_use_debugger = false;
bool m_use_logger = false; bool m_use_logger = false;
@ -53,7 +54,7 @@ private:
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;
wxString m_file_to_load; std::unique_ptr<BootParameters> m_boot;
wxString m_movie_file; wxString m_movie_file;
std::unique_ptr<wxLocale> m_locale; std::unique_ptr<wxLocale> m_locale;
}; };

View File

@ -73,6 +73,11 @@ std::unique_ptr<optparse::OptionParser> CreateParser(ParserOptions options)
.metavar("<file>") .metavar("<file>")
.type("string") .type("string")
.help("Load the specified file"); .help("Load the specified file");
parser->add_option("-n", "--nand_title")
.action("store")
.metavar("<16-character ASCII title ID>")
.type("string")
.help("Launch a NAND title");
parser->add_option("-C", "--config") parser->add_option("-C", "--config")
.action("append") .action("append")
.metavar("<System>.<Section>.<Key>=<Value>") .metavar("<System>.<Section>.<Key>=<Value>")