2021-01-31 06:10:50 +00:00
|
|
|
#include "common/crash_handler.h"
|
2019-12-31 06:17:17 +00:00
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "qthostinterface.h"
|
2020-08-29 12:19:28 +00:00
|
|
|
#include "qtutils.h"
|
2019-12-31 06:17:17 +00:00
|
|
|
#include <QtWidgets/QApplication>
|
2020-04-05 12:59:06 +00:00
|
|
|
#include <QtWidgets/QMessageBox>
|
2021-02-28 09:55:26 +00:00
|
|
|
#include <csignal>
|
2021-02-28 09:00:54 +00:00
|
|
|
#include <cstdio>
|
2020-04-13 12:13:46 +00:00
|
|
|
#include <cstdlib>
|
2019-12-31 06:17:17 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2021-01-09 02:02:33 +00:00
|
|
|
static bool ParseCommandLineParameters(QApplication& app, QtHostInterface* host_interface,
|
|
|
|
std::unique_ptr<SystemBootParameters>* boot_params)
|
|
|
|
{
|
|
|
|
const QStringList args(app.arguments());
|
|
|
|
std::vector<std::string> converted_args;
|
|
|
|
std::vector<char*> converted_argv;
|
|
|
|
converted_args.reserve(args.size());
|
|
|
|
converted_argv.reserve(args.size());
|
|
|
|
|
|
|
|
for (const QString& arg : args)
|
|
|
|
converted_args.push_back(arg.toStdString());
|
|
|
|
|
|
|
|
for (std::string& arg : converted_args)
|
|
|
|
converted_argv.push_back(arg.data());
|
|
|
|
|
|
|
|
return host_interface->ParseCommandLineParameters(args.size(), converted_argv.data(), boot_params);
|
|
|
|
}
|
|
|
|
|
2021-02-28 09:00:54 +00:00
|
|
|
static void SignalHandler(int signal)
|
|
|
|
{
|
|
|
|
// First try the normal (graceful) shutdown/exit.
|
|
|
|
static bool graceful_shutdown_attempted = false;
|
|
|
|
if (!graceful_shutdown_attempted)
|
|
|
|
{
|
|
|
|
std::fprintf(stderr, "Received CTRL+C, attempting graceful shutdown. Press CTRL+C again to force.\n");
|
|
|
|
graceful_shutdown_attempted = true;
|
|
|
|
QtHostInterface::GetInstance()->requestExit();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::signal(signal, SIG_DFL);
|
2021-02-28 09:55:26 +00:00
|
|
|
|
|
|
|
// MacOS is missing std::quick_exit() despite it being C++11...
|
|
|
|
#ifndef __APPLE__
|
2021-02-28 09:00:54 +00:00
|
|
|
std::quick_exit(1);
|
2021-02-28 09:55:26 +00:00
|
|
|
#else
|
|
|
|
_Exit(1);
|
|
|
|
#endif
|
2021-02-28 09:00:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void HookSignals()
|
|
|
|
{
|
|
|
|
std::signal(SIGINT, SignalHandler);
|
|
|
|
std::signal(SIGTERM, SignalHandler);
|
|
|
|
}
|
|
|
|
|
2019-12-31 06:17:17 +00:00
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
2021-01-31 06:10:50 +00:00
|
|
|
CrashHandler::Install();
|
|
|
|
|
2020-08-29 12:19:28 +00:00
|
|
|
// Register any standard types we need elsewhere
|
|
|
|
qRegisterMetaType<std::optional<bool>>();
|
2020-10-19 15:14:49 +00:00
|
|
|
qRegisterMetaType<std::function<void()>>();
|
2020-08-29 12:19:28 +00:00
|
|
|
|
2020-01-07 04:27:48 +00:00
|
|
|
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
2020-09-09 14:07:52 +00:00
|
|
|
QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
2020-01-07 04:27:48 +00:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
|
|
|
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
|
|
|
#endif
|
2020-01-03 07:51:42 +00:00
|
|
|
|
2019-12-31 06:17:17 +00:00
|
|
|
QApplication app(argc, argv);
|
|
|
|
|
2020-03-22 12:40:29 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
// Use Segoe UI on Windows rather than MS Shell Dlg 2, courtesy of Dolphin.
|
|
|
|
// Can be removed once switched to Qt 6.
|
|
|
|
QApplication::setFont(QApplication::font("QMenu"));
|
|
|
|
#endif
|
|
|
|
|
2019-12-31 06:17:17 +00:00
|
|
|
std::unique_ptr<QtHostInterface> host_interface = std::make_unique<QtHostInterface>();
|
2020-04-13 12:13:46 +00:00
|
|
|
std::unique_ptr<SystemBootParameters> boot_params;
|
2021-01-09 02:02:33 +00:00
|
|
|
if (!ParseCommandLineParameters(app, host_interface.get(), &boot_params))
|
2020-04-13 12:13:46 +00:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
2020-12-29 06:29:14 +00:00
|
|
|
std::unique_ptr<MainWindow> window = std::make_unique<MainWindow>(host_interface.get());
|
|
|
|
|
2020-04-05 12:59:06 +00:00
|
|
|
if (!host_interface->Initialize())
|
|
|
|
{
|
|
|
|
host_interface->Shutdown();
|
|
|
|
QMessageBox::critical(nullptr, QObject::tr("DuckStation Error"),
|
|
|
|
QObject::tr("Failed to initialize host interface. Cannot continue."), QMessageBox::Ok);
|
2020-04-13 12:13:46 +00:00
|
|
|
return EXIT_FAILURE;
|
2020-04-05 12:59:06 +00:00
|
|
|
}
|
2019-12-31 06:17:17 +00:00
|
|
|
|
2020-12-29 06:29:14 +00:00
|
|
|
window->initializeAndShow();
|
2021-02-28 09:00:54 +00:00
|
|
|
HookSignals();
|
2019-12-31 06:17:17 +00:00
|
|
|
|
2020-04-13 12:13:46 +00:00
|
|
|
// if we're in batch mode, don't bother refreshing the game list as it won't be used
|
|
|
|
if (!host_interface->inBatchMode())
|
|
|
|
host_interface->refreshGameList();
|
|
|
|
|
|
|
|
if (boot_params)
|
|
|
|
{
|
2020-09-12 20:01:08 +00:00
|
|
|
host_interface->bootSystem(std::move(boot_params));
|
2020-04-13 12:13:46 +00:00
|
|
|
}
|
2020-08-06 12:08:22 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
window->startupUpdateCheck();
|
|
|
|
}
|
2020-03-12 05:32:34 +00:00
|
|
|
|
2020-04-05 12:59:06 +00:00
|
|
|
int result = app.exec();
|
|
|
|
|
|
|
|
window.reset();
|
|
|
|
host_interface->Shutdown();
|
|
|
|
return result;
|
2019-12-31 06:17:17 +00:00
|
|
|
}
|