2015-11-27 08:33:07 +00:00
|
|
|
// Copyright 2015 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2015-11-27 08:33:07 +00:00
|
|
|
|
2018-04-29 20:20:03 +00:00
|
|
|
#ifdef _WIN32
|
2023-07-30 22:27:48 +00:00
|
|
|
#include <cstdio>
|
2020-09-21 09:23:06 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2018-04-29 20:20:03 +00:00
|
|
|
#include <Windows.h>
|
|
|
|
#endif
|
|
|
|
|
2023-01-20 07:50:39 +00:00
|
|
|
#ifdef __linux__
|
|
|
|
#include <cstdlib>
|
|
|
|
#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
|
|
|
|
2020-07-20 09:22:53 +00:00
|
|
|
#include "Common/Config/Config.h"
|
2017-07-26 04:11:47 +00:00
|
|
|
#include "Common/MsgHandler.h"
|
2020-03-31 18:51:34 +00:00
|
|
|
#include "Common/ScopeGuard.h"
|
2019-03-04 19:49:00 +00:00
|
|
|
|
2017-10-01 22:09:07 +00:00
|
|
|
#include "Core/Boot/Boot.h"
|
2020-07-20 09:22:53 +00:00
|
|
|
#include "Core/Config/MainSettings.h"
|
2015-11-27 08:33:07 +00:00
|
|
|
#include "Core/Core.h"
|
2020-09-15 10:13:10 +00:00
|
|
|
#include "Core/DolphinAnalytics.h"
|
2024-03-18 08:35:42 +00:00
|
|
|
#include "Core/System.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"
|
2023-07-30 22:42:15 +00:00
|
|
|
#include "DolphinQt/QtUtils/SetWindowDecorations.h"
|
2018-07-06 22:40:15 +00:00
|
|
|
#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
|
|
|
{
|
2020-03-31 18:51:34 +00:00
|
|
|
const bool called_from_cpu_thread = Core::IsCPUThread();
|
2020-04-24 22:26:51 +00:00
|
|
|
const bool called_from_gpu_thread = Core::IsGPUThread();
|
2020-03-31 18:51:34 +00:00
|
|
|
|
2018-05-21 22:27:12 +00:00
|
|
|
std::optional<bool> r = RunOnObject(QApplication::instance(), [&] {
|
2020-04-25 08:35:14 +00:00
|
|
|
// If we were called from the CPU/GPU thread, set us as the CPU/GPU thread.
|
|
|
|
// This information is used in order to avoid deadlocks when calling e.g.
|
2024-03-22 07:43:04 +00:00
|
|
|
// Host::SetRenderFocus or Core::CPUThreadGuard. (Host::SetRenderFocus
|
2020-04-25 08:35:14 +00:00
|
|
|
// can get called automatically when a dialog steals the focus.)
|
|
|
|
|
2020-04-24 22:26:51 +00:00
|
|
|
Common::ScopeGuard cpu_scope_guard(&Core::UndeclareAsCPUThread);
|
|
|
|
Common::ScopeGuard gpu_scope_guard(&Core::UndeclareAsGPUThread);
|
|
|
|
|
|
|
|
if (!called_from_cpu_thread)
|
|
|
|
cpu_scope_guard.Dismiss();
|
|
|
|
if (!called_from_gpu_thread)
|
|
|
|
gpu_scope_guard.Dismiss();
|
|
|
|
|
2020-03-31 18:51:34 +00:00
|
|
|
if (called_from_cpu_thread)
|
|
|
|
Core::DeclareAsCPUThread();
|
2020-04-24 22:26:51 +00:00
|
|
|
if (called_from_gpu_thread)
|
|
|
|
Core::DeclareAsGPUThread();
|
2020-03-31 18:51:34 +00:00
|
|
|
|
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;
|
|
|
|
}());
|
|
|
|
|
2023-07-30 22:42:15 +00:00
|
|
|
SetQWidgetWindowDecorations(&message_box);
|
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
|
|
|
{
|
2022-09-24 11:03:45 +00:00
|
|
|
Config::SetCurrent(Config::MAIN_USE_PANIC_HANDLERS, 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
|
|
|
}
|
|
|
|
|
2022-03-08 07:22:35 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#define main app_main
|
|
|
|
#endif
|
|
|
|
|
2015-11-27 08:33:07 +00:00
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
2022-03-08 07:22:35 +00:00
|
|
|
#ifdef _WIN32
|
2018-04-29 20:20:03 +00:00
|
|
|
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
|
|
|
|
|
2023-06-02 16:00:51 +00:00
|
|
|
Core::DeclareAsHostThread();
|
2021-05-20 22:33:38 +00:00
|
|
|
|
2020-08-04 19:18:32 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
// On macOS, a command line option matching the format "-psn_X_XXXXXX" is passed when
|
|
|
|
// the application is launched for the first time. This is to set the "ProcessSerialNumber",
|
|
|
|
// something used by the legacy Process Manager from Carbon. optparse will fail if it finds
|
|
|
|
// this as it isn't a valid Dolphin command line option, so pretend like it doesn't exist
|
|
|
|
// if found.
|
|
|
|
if (strncmp(argv[argc - 1], "-psn", 4) == 0)
|
|
|
|
{
|
|
|
|
argc--;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-01-20 07:50:39 +00:00
|
|
|
#ifdef __linux__
|
|
|
|
// Qt 6.3+ has a bug which causes mouse inputs to not be registered in our XInput2 code.
|
|
|
|
// If we define QT_XCB_NO_XI2, Qt's xcb platform plugin no longer initializes its XInput
|
|
|
|
// code, which makes mouse inputs work again.
|
|
|
|
// For more information: https://bugs.dolphin-emu.org/issues/12913
|
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(6, 3, 0))
|
2023-03-23 16:17:49 +00:00
|
|
|
setenv("QT_XCB_NO_XI2", "1", true);
|
2023-01-20 07:50:39 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
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
|
|
|
|
2023-04-19 16:40:12 +00:00
|
|
|
// QApplication will parse arguments and remove any it recognizes as targeting Qt
|
2015-11-27 08:33:07 +00:00
|
|
|
QApplication app(argc, argv);
|
2023-04-19 16:40:12 +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();
|
2015-11-27 08:33:07 +00:00
|
|
|
|
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")));
|
2015-11-27 08:33:07 +00:00
|
|
|
UICommon::CreateDirectories();
|
|
|
|
UICommon::Init();
|
|
|
|
Resources::Init();
|
2019-10-27 18:03:10 +00:00
|
|
|
Settings::Instance().SetBatchModeEnabled(options.is_set("batch"));
|
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-05-12 01:18:30 +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,
|
2024-03-18 08:35:42 +00:00
|
|
|
&app, [] { Core::HostDispatchJobs(Core::System::GetInstance()); });
|
2016-05-12 01:18:30 +00:00
|
|
|
|
2020-05-07 03:10:30 +00:00
|
|
|
std::optional<std::string> save_state_path;
|
|
|
|
if (options.is_set("save_state"))
|
|
|
|
{
|
|
|
|
save_state_path = static_cast<const char*>(options.get("save_state"));
|
|
|
|
}
|
|
|
|
|
2017-10-01 22:09:07 +00:00
|
|
|
std::unique_ptr<BootParameters> boot;
|
2019-10-27 18:03:10 +00:00
|
|
|
bool game_specified = false;
|
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))};
|
2021-11-20 18:38:09 +00:00
|
|
|
boot = BootParameters::GenerateFromFile(
|
|
|
|
paths, BootSessionData(save_state_path, DeleteSavestateAfterBoot::No));
|
2019-10-27 18:03:10 +00:00
|
|
|
game_specified = true;
|
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
|
|
|
}
|
2019-10-27 18:03:10 +00:00
|
|
|
game_specified = true;
|
2017-10-01 22:09:07 +00:00
|
|
|
}
|
2018-03-16 08:14:24 +00:00
|
|
|
else if (!args.empty())
|
|
|
|
{
|
2021-11-20 18:38:09 +00:00
|
|
|
boot = BootParameters::GenerateFromFile(
|
|
|
|
args.front(), BootSessionData(save_state_path, DeleteSavestateAfterBoot::No));
|
2019-10-27 18:03:10 +00:00
|
|
|
game_specified = true;
|
2018-03-16 08:14:24 +00:00
|
|
|
}
|
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
|
|
|
|
2020-05-07 03:10:30 +00:00
|
|
|
if (save_state_path && !game_specified)
|
|
|
|
{
|
|
|
|
ModalMessageBox::critical(
|
|
|
|
nullptr, QObject::tr("Error"),
|
|
|
|
QObject::tr("A save state cannot be loaded without specifying a game to launch."));
|
|
|
|
retval = 1;
|
|
|
|
}
|
|
|
|
else if (Settings::Instance().IsBatchModeEnabled() && !game_specified)
|
2019-10-27 18:03:10 +00:00
|
|
|
{
|
|
|
|
ModalMessageBox::critical(
|
|
|
|
nullptr, QObject::tr("Error"),
|
|
|
|
QObject::tr("Batch mode cannot be used without specifying a game to launch."));
|
|
|
|
retval = 1;
|
|
|
|
}
|
2020-05-07 03:10:30 +00:00
|
|
|
else if (!boot && (Settings::Instance().IsBatchModeEnabled() || save_state_path))
|
2019-10-27 18:03:10 +00:00
|
|
|
{
|
|
|
|
// A game to launch was specified, but it was invalid.
|
|
|
|
// An error has already been shown by code above, so exit without showing another error.
|
|
|
|
retval = 1;
|
|
|
|
}
|
|
|
|
else
|
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
|
|
|
|
2023-08-01 17:52:36 +00:00
|
|
|
Settings::Instance().InitDefaultPalette();
|
2023-07-31 21:22:53 +00:00
|
|
|
Settings::Instance().UpdateSystemDark();
|
2023-11-04 16:56:43 +00:00
|
|
|
Settings::Instance().ApplyStyle();
|
2023-08-01 18:14:03 +00:00
|
|
|
|
|
|
|
MainWindow win{std::move(boot), static_cast<const char*>(options.get("movie"))};
|
2017-05-20 21:41:02 +00:00
|
|
|
|
|
|
|
#if defined(USE_ANALYTICS) && USE_ANALYTICS
|
2020-07-20 09:22:53 +00:00
|
|
|
if (!Config::Get(Config::MAIN_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
|
|
|
|
2023-07-30 22:42:15 +00:00
|
|
|
SetQWidgetWindowDecorations(&analytics_prompt);
|
2017-05-20 21:41:02 +00:00
|
|
|
const int answer = analytics_prompt.exec();
|
|
|
|
|
2020-07-20 09:22:53 +00:00
|
|
|
Config::SetBase(Config::MAIN_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())
|
|
|
|
{
|
2021-12-27 18:09:47 +00:00
|
|
|
auto* updater = new Updater(&win, Config::Get(Config::MAIN_AUTOUPDATE_UPDATE_TRACK),
|
|
|
|
Config::Get(Config::MAIN_AUTOUPDATE_HASH_OVERRIDE));
|
2019-08-11 18:58:04 +00:00
|
|
|
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
|
|
|
|
2024-03-18 08:35:42 +00:00
|
|
|
Core::Shutdown(Core::System::GetInstance());
|
2015-11-27 08:33:07 +00:00
|
|
|
UICommon::Shutdown();
|
|
|
|
Host::GetInstance()->deleteLater();
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
2022-03-08 07:22:35 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
int WINAPI wWinMain(_In_ HINSTANCE, _In_opt_ HINSTANCE, _In_ LPWSTR, _In_ int)
|
|
|
|
{
|
2023-05-16 18:23:21 +00:00
|
|
|
std::vector<std::string> args = Common::CommandLineToUtf8Argv(GetCommandLineW());
|
2022-03-08 07:22:35 +00:00
|
|
|
const int argc = static_cast<int>(args.size());
|
|
|
|
std::vector<char*> argv(args.size());
|
|
|
|
for (size_t i = 0; i < args.size(); ++i)
|
|
|
|
argv[i] = args[i].data();
|
|
|
|
|
|
|
|
return main(argc, argv.data());
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef main
|
|
|
|
#endif
|