2015-11-27 08:33:07 +00:00
|
|
|
// Copyright 2015 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2017-06-14 12:31:30 +00:00
|
|
|
#include <OptionParser.h>
|
2016-05-12 01:18:30 +00:00
|
|
|
#include <QAbstractEventDispatcher>
|
2015-11-27 08:33:07 +00:00
|
|
|
#include <QApplication>
|
2017-05-20 21:41:02 +00:00
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QObject>
|
2015-11-27 08:33:07 +00:00
|
|
|
|
2017-07-26 04:11:47 +00:00
|
|
|
#include "Common/MsgHandler.h"
|
2017-05-20 21:41:02 +00:00
|
|
|
#include "Core/Analytics.h"
|
2017-10-01 22:09:07 +00:00
|
|
|
#include "Core/Boot/Boot.h"
|
2015-11-27 08:33:07 +00:00
|
|
|
#include "Core/BootManager.h"
|
|
|
|
#include "Core/Core.h"
|
|
|
|
#include "DolphinQt2/Host.h"
|
2016-07-13 05:52:45 +00:00
|
|
|
#include "DolphinQt2/InDevelopmentWarning.h"
|
2015-11-27 08:33:07 +00:00
|
|
|
#include "DolphinQt2/MainWindow.h"
|
2017-07-26 04:11:47 +00:00
|
|
|
#include "DolphinQt2/QtUtils/RunOnObject.h"
|
2015-11-27 08:33:07 +00:00
|
|
|
#include "DolphinQt2/Resources.h"
|
2016-07-13 05:52:45 +00:00
|
|
|
#include "DolphinQt2/Settings.h"
|
2017-07-17 21:50:40 +00:00
|
|
|
#include "DolphinQt2/Translation.h"
|
2017-06-14 12:31:30 +00:00
|
|
|
#include "UICommon/CommandLineParse.h"
|
2015-11-27 08:33:07 +00:00
|
|
|
#include "UICommon/UICommon.h"
|
|
|
|
|
2017-09-07 18:35:17 +00:00
|
|
|
static bool QtMsgAlertHandler(const char* caption, const char* text, bool yes_no, MsgType style)
|
2017-07-26 04:11:47 +00:00
|
|
|
{
|
|
|
|
return RunOnObject(QApplication::instance(), [&] {
|
|
|
|
QMessageBox message_box(QApplication::activeWindow());
|
|
|
|
message_box.setWindowTitle(QString::fromUtf8(caption));
|
|
|
|
message_box.setText(QString::fromUtf8(text));
|
|
|
|
message_box.setStandardButtons(yes_no ? QMessageBox::Yes | QMessageBox::No : QMessageBox::Ok);
|
|
|
|
message_box.setIcon([&] {
|
|
|
|
switch (style)
|
|
|
|
{
|
|
|
|
case MsgType::Information:
|
|
|
|
return QMessageBox::Information;
|
|
|
|
case MsgType::Question:
|
|
|
|
return QMessageBox::Question;
|
|
|
|
case MsgType::Warning:
|
|
|
|
return QMessageBox::Warning;
|
|
|
|
case MsgType::Critical:
|
|
|
|
return QMessageBox::Critical;
|
|
|
|
}
|
|
|
|
// appease MSVC
|
|
|
|
return QMessageBox::NoIcon;
|
|
|
|
}());
|
|
|
|
|
|
|
|
return message_box.exec() == QMessageBox::Yes;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-06-23 07:40:55 +00:00
|
|
|
// N.B. On Windows, this should be called from WinMain. Link against qtmain and specify
|
|
|
|
// /SubSystem:Windows
|
2015-11-27 08:33:07 +00:00
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
2017-09-02 21:38:02 +00:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
|
2017-05-30 20:42:21 +00:00
|
|
|
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
2017-09-02 21:38:02 +00:00
|
|
|
#endif
|
|
|
|
|
2017-05-30 20:42:21 +00:00
|
|
|
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
2017-07-06 00:35:47 +00:00
|
|
|
QCoreApplication::setOrganizationName(QStringLiteral("Dolphin Emulator"));
|
|
|
|
QCoreApplication::setOrganizationDomain(QStringLiteral("dolphin-emu.org"));
|
2018-01-01 12:31:53 +00:00
|
|
|
QCoreApplication::setApplicationName(QStringLiteral("dolphin-emu"));
|
2017-05-30 20:42:21 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
QApplication app(argc, argv);
|
2015-11-27 08:33:07 +00:00
|
|
|
|
2017-06-14 12:31:30 +00:00
|
|
|
auto parser = CommandLineParse::CreateParser(CommandLineParse::ParserOptions::IncludeGUIOptions);
|
|
|
|
const optparse::Values& options = CommandLineParse::ParseArguments(parser.get(), argc, argv);
|
|
|
|
const std::vector<std::string> args = parser->args();
|
|
|
|
|
|
|
|
UICommon::SetUserDirectory(static_cast<const char*>(options.get("user")));
|
2016-06-24 08:43:46 +00:00
|
|
|
UICommon::CreateDirectories();
|
|
|
|
UICommon::Init();
|
|
|
|
Resources::Init();
|
2017-09-19 12:14:45 +00:00
|
|
|
Settings::Instance().SetDebugModeEnabled(options.is_set("debugger"));
|
2015-11-27 08:33:07 +00:00
|
|
|
|
2017-07-26 04:11:47 +00:00
|
|
|
// Hook up alerts from core
|
|
|
|
RegisterMsgAlertHandler(QtMsgAlertHandler);
|
|
|
|
|
2017-07-17 21:50:40 +00:00
|
|
|
// Hook up translations
|
|
|
|
Translation::Initialize();
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// Whenever the event loop is about to go to sleep, dispatch the jobs
|
|
|
|
// queued in the Core first.
|
|
|
|
QObject::connect(QAbstractEventDispatcher::instance(), &QAbstractEventDispatcher::aboutToBlock,
|
|
|
|
&app, &Core::HostDispatchJobs);
|
2016-05-12 01:18:30 +00:00
|
|
|
|
2017-10-01 22:09:07 +00:00
|
|
|
std::unique_ptr<BootParameters> boot;
|
2017-11-26 17:32:28 +00:00
|
|
|
if (options.is_set("exec"))
|
|
|
|
{
|
|
|
|
boot = BootParameters::GenerateFromFile(static_cast<const char*>(options.get("exec")));
|
|
|
|
}
|
|
|
|
else if (options.is_set("nand_title"))
|
2017-10-01 22:09:07 +00:00
|
|
|
{
|
|
|
|
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."));
|
|
|
|
}
|
|
|
|
}
|
2018-03-16 08:14:24 +00:00
|
|
|
else if (!args.empty())
|
|
|
|
{
|
|
|
|
boot = BootParameters::GenerateFromFile(args.front());
|
|
|
|
}
|
2017-10-01 22:09:07 +00:00
|
|
|
|
2016-07-13 05:52:45 +00:00
|
|
|
int retval = 0;
|
2017-06-22 22:11:53 +00:00
|
|
|
|
|
|
|
if (SConfig::GetInstance().m_show_development_warning)
|
2016-07-13 05:52:45 +00:00
|
|
|
{
|
|
|
|
InDevelopmentWarning warning_box;
|
|
|
|
retval = warning_box.exec() == QDialog::Rejected;
|
|
|
|
}
|
|
|
|
if (!retval)
|
|
|
|
{
|
2017-05-20 21:41:02 +00:00
|
|
|
DolphinAnalytics::Instance()->ReportDolphinStart("qt");
|
|
|
|
|
2017-10-01 22:09:07 +00:00
|
|
|
MainWindow win{std::move(boot)};
|
2016-07-13 05:52:45 +00:00
|
|
|
win.show();
|
2017-05-20 21:41:02 +00:00
|
|
|
|
|
|
|
#if defined(USE_ANALYTICS) && USE_ANALYTICS
|
2017-06-22 22:11:53 +00:00
|
|
|
if (!SConfig::GetInstance().m_analytics_permission_asked)
|
2017-05-20 21:41:02 +00:00
|
|
|
{
|
|
|
|
QMessageBox analytics_prompt(&win);
|
|
|
|
|
|
|
|
analytics_prompt.setIcon(QMessageBox::Question);
|
|
|
|
analytics_prompt.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
2017-07-23 09:41:39 +00:00
|
|
|
analytics_prompt.setText(
|
|
|
|
QObject::tr("Do you authorize Dolphin to report information to Dolphin's developers?"));
|
2017-05-20 21:41:02 +00:00
|
|
|
analytics_prompt.setInformativeText(
|
|
|
|
QObject::tr("If authorized, Dolphin can collect data on its performance, "
|
|
|
|
"feature usage, and configuration, as well as data on your system's "
|
|
|
|
"hardware and operating system.\n\n"
|
|
|
|
"No private data is ever collected. This data helps us understand "
|
|
|
|
"how people and emulated games use Dolphin and prioritize our "
|
|
|
|
"efforts. It also helps us identify rare configurations that are "
|
|
|
|
"causing bugs, performance and stability issues.\n"
|
|
|
|
"This authorization can be revoked at any time through Dolphin's "
|
2017-07-23 09:41:39 +00:00
|
|
|
"settings."));
|
2017-05-20 21:41:02 +00:00
|
|
|
|
|
|
|
const int answer = analytics_prompt.exec();
|
|
|
|
|
2017-06-22 22:11:53 +00:00
|
|
|
SConfig::GetInstance().m_analytics_permission_asked = true;
|
|
|
|
SConfig::GetInstance().m_analytics_enabled = (answer == QMessageBox::Yes);
|
2017-05-20 21:41:02 +00:00
|
|
|
|
|
|
|
DolphinAnalytics::Instance()->ReloadConfig();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-07-13 05:52:45 +00:00
|
|
|
retval = app.exec();
|
|
|
|
}
|
2015-11-27 08:33:07 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
BootManager::Stop();
|
|
|
|
Core::Shutdown();
|
|
|
|
UICommon::Shutdown();
|
|
|
|
Host::GetInstance()->deleteLater();
|
2015-11-27 08:33:07 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
return retval;
|
2015-11-27 08:33:07 +00:00
|
|
|
}
|