2015-11-27 08:33:07 +00:00
|
|
|
// Copyright 2015 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2018-04-29 20:20:03 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include <Windows.h>
|
|
|
|
#include <cstdio>
|
2018-05-05 23:23:13 +00:00
|
|
|
|
|
|
|
#include "Common/StringUtil.h"
|
2018-04-29 20:20:03 +00:00
|
|
|
#endif
|
|
|
|
|
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 <QObject>
|
2017-10-05 16:20:18 +00:00
|
|
|
#include <QPushButton>
|
2018-03-18 00:22:05 +00:00
|
|
|
#include <QWidget>
|
2015-11-27 08:33:07 +00:00
|
|
|
|
2017-07-26 04:11:47 +00:00
|
|
|
#include "Common/MsgHandler.h"
|
2019-03-04 19:49:00 +00:00
|
|
|
|
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"
|
2018-07-15 03:07:23 +00:00
|
|
|
#include "Core/ConfigManager.h"
|
2015-11-27 08:33:07 +00:00
|
|
|
#include "Core/Core.h"
|
2019-03-04 19:49:00 +00:00
|
|
|
|
2018-07-06 22:40:15 +00:00
|
|
|
#include "DolphinQt/Host.h"
|
|
|
|
#include "DolphinQt/MainWindow.h"
|
2019-03-04 19:49:00 +00:00
|
|
|
#include "DolphinQt/QtUtils/ModalMessageBox.h"
|
2018-07-06 22:40:15 +00:00
|
|
|
#include "DolphinQt/QtUtils/RunOnObject.h"
|
|
|
|
#include "DolphinQt/Resources.h"
|
|
|
|
#include "DolphinQt/Settings.h"
|
|
|
|
#include "DolphinQt/Translation.h"
|
|
|
|
#include "DolphinQt/Updater.h"
|
2019-03-04 19:49:00 +00:00
|
|
|
|
2017-06-14 12:31:30 +00:00
|
|
|
#include "UICommon/CommandLineParse.h"
|
2015-11-27 08:33:07 +00:00
|
|
|
#include "UICommon/UICommon.h"
|
|
|
|
|
2019-06-17 03:45:37 +00:00
|
|
|
static bool QtMsgAlertHandler(const char* caption, const char* text, bool yes_no,
|
|
|
|
Common::MsgType style)
|
2017-07-26 04:11:47 +00:00
|
|
|
{
|
2018-05-21 22:27:12 +00:00
|
|
|
std::optional<bool> r = RunOnObject(QApplication::instance(), [&] {
|
2019-08-01 17:52:28 +00:00
|
|
|
ModalMessageBox message_box(QApplication::activeWindow(), Qt::ApplicationModal);
|
2017-07-26 04:11:47 +00:00
|
|
|
message_box.setWindowTitle(QString::fromUtf8(caption));
|
|
|
|
message_box.setText(QString::fromUtf8(text));
|
2017-10-05 16:20:18 +00:00
|
|
|
|
2017-07-26 04:11:47 +00:00
|
|
|
message_box.setStandardButtons(yes_no ? QMessageBox::Yes | QMessageBox::No : QMessageBox::Ok);
|
2019-06-17 03:45:37 +00:00
|
|
|
if (style == Common::MsgType::Warning)
|
2017-10-05 16:20:18 +00:00
|
|
|
message_box.addButton(QMessageBox::Ignore)->setText(QObject::tr("Ignore for this session"));
|
|
|
|
|
2017-07-26 04:11:47 +00:00
|
|
|
message_box.setIcon([&] {
|
|
|
|
switch (style)
|
|
|
|
{
|
2019-06-17 03:45:37 +00:00
|
|
|
case Common::MsgType::Information:
|
2017-07-26 04:11:47 +00:00
|
|
|
return QMessageBox::Information;
|
2019-06-17 03:45:37 +00:00
|
|
|
case Common::MsgType::Question:
|
2017-07-26 04:11:47 +00:00
|
|
|
return QMessageBox::Question;
|
2019-06-17 03:45:37 +00:00
|
|
|
case Common::MsgType::Warning:
|
2017-07-26 04:11:47 +00:00
|
|
|
return QMessageBox::Warning;
|
2019-06-17 03:45:37 +00:00
|
|
|
case Common::MsgType::Critical:
|
2017-07-26 04:11:47 +00:00
|
|
|
return QMessageBox::Critical;
|
|
|
|
}
|
|
|
|
// appease MSVC
|
|
|
|
return QMessageBox::NoIcon;
|
|
|
|
}());
|
|
|
|
|
2017-10-05 16:20:18 +00:00
|
|
|
const int button = message_box.exec();
|
|
|
|
if (button == QMessageBox::Yes)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (button == QMessageBox::Ignore)
|
2019-07-20 19:04:27 +00:00
|
|
|
{
|
2019-06-17 03:45:37 +00:00
|
|
|
Common::SetEnableAlert(false);
|
2019-07-20 19:04:27 +00:00
|
|
|
return true;
|
|
|
|
}
|
2017-10-05 16:20:18 +00:00
|
|
|
|
|
|
|
return false;
|
2017-07-26 04:11:47 +00:00
|
|
|
});
|
2018-05-21 22:27:12 +00:00
|
|
|
if (r.has_value())
|
|
|
|
return *r;
|
|
|
|
return false;
|
2017-07-26 04:11:47 +00:00
|
|
|
}
|
|
|
|
|
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[])
|
|
|
|
{
|
2018-04-29 20:20:03 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
const bool console_attached = AttachConsole(ATTACH_PARENT_PROCESS) != FALSE;
|
|
|
|
HANDLE stdout_handle = ::GetStdHandle(STD_OUTPUT_HANDLE);
|
|
|
|
if (console_attached && stdout_handle)
|
|
|
|
{
|
|
|
|
freopen("CONOUT$", "w", stdout);
|
|
|
|
freopen("CONOUT$", "w", stderr);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-05-30 20:42:21 +00:00
|
|
|
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
|
|
|
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
|
|
|
|
2018-05-05 09:56:42 +00:00
|
|
|
#ifdef _WIN32
|
2018-05-05 23:23:13 +00:00
|
|
|
// Get the default system font because Qt's way of obtaining it is outdated
|
|
|
|
NONCLIENTMETRICS metrics = {};
|
2018-05-10 11:40:53 +00:00
|
|
|
LOGFONT& logfont = metrics.lfMenuFont;
|
2018-05-05 23:23:13 +00:00
|
|
|
metrics.cbSize = sizeof(NONCLIENTMETRICS);
|
2018-05-05 09:56:42 +00:00
|
|
|
|
2018-05-05 23:23:13 +00:00
|
|
|
if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(metrics), &metrics, 0))
|
|
|
|
{
|
|
|
|
// Sadly Qt 5 doesn't support turning a native font handle into a QFont so this is the next best
|
|
|
|
// thing
|
|
|
|
QFont font = QApplication::font();
|
|
|
|
font.setFamily(QString::fromStdString(UTF16ToUTF8(logfont.lfFaceName)));
|
2018-05-10 11:40:53 +00:00
|
|
|
|
2018-05-05 23:23:13 +00:00
|
|
|
font.setItalic(logfont.lfItalic);
|
|
|
|
font.setStrikeOut(logfont.lfStrikeOut);
|
|
|
|
font.setUnderline(logfont.lfUnderline);
|
|
|
|
|
|
|
|
// The default font size is a bit too small
|
|
|
|
font.setPointSize(QFontInfo(font).pointSize() * 1.2);
|
|
|
|
|
|
|
|
QApplication::setFont(font);
|
|
|
|
}
|
2018-05-05 09:56:42 +00:00
|
|
|
#endif
|
|
|
|
|
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();
|
|
|
|
|
2018-04-29 20:20:03 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
FreeConsole();
|
|
|
|
#endif
|
|
|
|
|
2017-06-14 12:31:30 +00:00
|
|
|
UICommon::SetUserDirectory(static_cast<const char*>(options.get("user")));
|
2016-06-24 08:43:46 +00:00
|
|
|
UICommon::CreateDirectories();
|
|
|
|
UICommon::Init();
|
|
|
|
Resources::Init();
|
2019-08-11 18:58:04 +00:00
|
|
|
Settings::Instance().SetBatchModeEnabled(options.is_set("batch") && options.is_set("exec"));
|
2015-11-27 08:33:07 +00:00
|
|
|
|
2017-07-26 04:11:47 +00:00
|
|
|
// Hook up alerts from core
|
2019-06-17 03:45:37 +00:00
|
|
|
Common::RegisterMsgAlertHandler(QtMsgAlertHandler);
|
2017-07-26 04:11:47 +00:00
|
|
|
|
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"))
|
|
|
|
{
|
2018-11-05 18:20:45 +00:00
|
|
|
const std::list<std::string> paths_list = options.all("exec");
|
|
|
|
const std::vector<std::string> paths{std::make_move_iterator(std::begin(paths_list)),
|
|
|
|
std::make_move_iterator(std::end(paths_list))};
|
|
|
|
boot = BootParameters::GenerateFromFile(paths);
|
2017-11-26 17:32:28 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
|
{
|
2019-03-04 19:49:00 +00:00
|
|
|
ModalMessageBox::critical(nullptr, QObject::tr("Error"), QObject::tr("Invalid title ID."));
|
2017-10-01 22:09:07 +00:00
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
2018-03-20 06:41:47 +00:00
|
|
|
int retval;
|
2017-06-22 22:11:53 +00:00
|
|
|
|
2016-07-13 05:52:45 +00:00
|
|
|
{
|
2019-06-23 17:26:07 +00:00
|
|
|
DolphinAnalytics::Instance().ReportDolphinStart("qt");
|
2017-05-20 21:41:02 +00:00
|
|
|
|
2019-03-27 13:26:17 +00:00
|
|
|
MainWindow win{std::move(boot), static_cast<const char*>(options.get("movie"))};
|
2018-05-04 08:02:05 +00:00
|
|
|
if (options.is_set("debugger"))
|
|
|
|
Settings::Instance().SetDebugModeEnabled(true);
|
2018-05-13 13:03:48 +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
|
|
|
{
|
2019-03-04 19:49:00 +00:00
|
|
|
ModalMessageBox analytics_prompt(&win);
|
2017-05-20 21:41:02 +00:00
|
|
|
|
|
|
|
analytics_prompt.setIcon(QMessageBox::Question);
|
|
|
|
analytics_prompt.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
2018-09-08 13:19:01 +00:00
|
|
|
analytics_prompt.setWindowTitle(QObject::tr("Allow Usage Statistics Reporting"));
|
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;
|
2018-03-23 22:25:17 +00:00
|
|
|
Settings::Instance().SetAnalyticsEnabled(answer == QMessageBox::Yes);
|
2017-05-20 21:41:02 +00:00
|
|
|
|
2019-06-23 17:26:07 +00:00
|
|
|
DolphinAnalytics::Instance().ReloadConfig();
|
2017-05-20 21:41:02 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-08-11 18:58:04 +00:00
|
|
|
if (!Settings::Instance().IsBatchModeEnabled())
|
|
|
|
{
|
|
|
|
auto* updater = new Updater(&win);
|
|
|
|
updater->start();
|
|
|
|
}
|
2018-03-18 00:22:05 +00:00
|
|
|
|
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
|
|
|
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
|
|
|
}
|