mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-10-05 15:49:01 +00:00
# Conflicts: # CMakeLists.txt # CMakeSettings.json # Data/Sys/GameSettings/GLR.ini # Data/Sys/GameSettings/HA9.ini # Data/Sys/GameSettings/MB3.ini # Data/Sys/GameSettings/MBA.ini # Data/Sys/GameSettings/MCV.ini # Data/Sys/GameSettings/MCY.ini # Data/Sys/GameSettings/NAK.ini # Data/Sys/GameSettings/NAL.ini # Data/Sys/GameSettings/NAT.ini # Data/Sys/GameSettings/R8P.ini # Data/Sys/GameSettings/R9I.ini # Data/Sys/GameSettings/REF.ini # Data/Sys/GameSettings/RES.ini # Data/Sys/GameSettings/RMHE08.ini # Data/Sys/GameSettings/RMHP08.ini # Data/Sys/GameSettings/SE2.ini # Data/Sys/GameSettings/WW2.ini # Data/Sys/GameSettings/WW3.ini # Data/Sys/GameSettings/WWI.ini # Externals/Bochs_disasm/Bochs_disasm.vcxproj # Externals/FreeSurround/FreeSurround.vcxproj # Externals/LZO/LZO.vcxproj # Externals/SFML/build/vc2010/SFML_Network.vcxproj # Externals/bzip2/bzip2.vcxproj # Externals/cpp-optparse/cpp-optparse.vcxproj # Externals/cubeb/msvc/cubeb.vcxproj # Externals/curl/curl.vcxproj # Externals/curl/lib/CMakeLists.txt # Externals/discord-rpc/src/discord-rpc.vcxproj # Externals/ed25519/ed25519.vcxproj # Externals/enet/enet.vcxproj # Externals/glslang/glslang.vcxproj # Externals/imgui/imgui.vcxproj # Externals/liblzma/liblzma.vcxproj # Externals/libpng/png/png.vcxproj # Externals/libusb/libusb_static_2013.vcxproj # Externals/mbedtls/mbedTLS.vcxproj # Externals/miniupnpc/miniupnpc.vcxproj # Externals/minizip/minizip.vcxproj # Externals/picojson/picojson.vcxproj # Externals/pugixml/pugixml.vcxproj # Externals/soundtouch/SoundTouch.vcxproj # Externals/xxhash/xxhash.vcxproj # Externals/zlib/zlib.vcxproj # Externals/zstd/zstd.vcxproj # Languages/Languages.vcxproj # Source/Android/jni/MainAndroid.cpp # Source/Core/AudioCommon/AudioCommon.vcxproj # Source/Core/Common/Common.vcxproj # Source/Core/Common/Common.vcxproj.filters # Source/Core/Common/Logging/Log.h # Source/Core/Common/StringUtil.cpp # Source/Core/Core/CMakeLists.txt # Source/Core/Core/ConfigManager.cpp # Source/Core/Core/ConfigManager.h # Source/Core/Core/Core.vcxproj # Source/Core/Core/Core.vcxproj.filters # Source/Core/Core/HotkeyManager.cpp # Source/Core/Core/State.cpp # Source/Core/DiscIO/DiscIO.vcxproj # Source/Core/DolphinNoGUI/DolphinNoGUI.vcxproj # Source/Core/DolphinQt/Config/Graphics/GeneralWidget.cpp # Source/Core/DolphinQt/DolphinQt.vcxproj # Source/Core/InputCommon/InputCommon.vcxproj # Source/Core/InputCommon/InputCommon.vcxproj.filters # Source/Core/UICommon/UICommon.vcxproj # Source/Core/UpdaterCommon/UpdaterCommon.vcxproj # Source/Core/VideoBackends/D3D/D3D.vcxproj # Source/Core/VideoBackends/D3D12/D3D12.vcxproj # Source/Core/VideoBackends/D3DCommon/D3DCommon.vcxproj # Source/Core/VideoBackends/Null/Null.vcxproj # Source/Core/VideoBackends/OGL/OGL.vcxproj # Source/Core/VideoBackends/Software/Software.vcxproj # Source/Core/VideoBackends/Vulkan/Vulkan.vcxproj # Source/Core/VideoCommon/OnScreenDisplay.cpp # Source/Core/VideoCommon/OnScreenDisplay.h # Source/Core/VideoCommon/VideoCommon.vcxproj # Source/Core/WinUpdater/WinUpdater.vcxproj # Source/DSPTool/DSPTool.vcxproj # Source/PCH/pch.vcxproj # Source/UnitTests/UnitTests.vcxproj
299 lines
9.9 KiB
C++
299 lines
9.9 KiB
C++
// Copyright 2015 Dolphin Emulator Project
|
|
// Licensed under GPLv2+
|
|
// Refer to the license.txt file included.
|
|
|
|
#ifdef _WIN32
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include <Windows.h>
|
|
#include <cstdio>
|
|
#endif
|
|
|
|
|
|
#include <OptionParser.h>
|
|
#include <QAbstractEventDispatcher>
|
|
#include <QApplication>
|
|
#include <QObject>
|
|
#include <QPushButton>
|
|
#include <QWidget>
|
|
|
|
#include "Common/Config/Config.h"
|
|
#include "Common/MsgHandler.h"
|
|
#include "Common/ScopeGuard.h"
|
|
|
|
#include "Core/Analytics.h"
|
|
#include "Core/Boot/Boot.h"
|
|
#include "Core/Config/MainSettings.h"
|
|
#include "Core/Core.h"
|
|
|
|
#include "DolphinQt/Host.h"
|
|
#include "DolphinQt/MainWindow.h"
|
|
#include "DolphinQt/QtUtils/ModalMessageBox.h"
|
|
#include "DolphinQt/QtUtils/RunOnObject.h"
|
|
#include "DolphinQt/Resources.h"
|
|
#include "DolphinQt/Settings.h"
|
|
#include "DolphinQt/Translation.h"
|
|
#include "DolphinQt/Updater.h"
|
|
|
|
#include "UICommon/CommandLineParse.h"
|
|
#include "UICommon/UICommon.h"
|
|
|
|
static bool QtMsgAlertHandler(const char* caption, const char* text, bool yes_no,
|
|
Common::MsgType style)
|
|
{
|
|
const bool called_from_cpu_thread = Core::IsCPUThread();
|
|
|
|
std::optional<bool> r = RunOnObject(QApplication::instance(), [&] {
|
|
Common::ScopeGuard scope_guard(&Core::UndeclareAsCPUThread);
|
|
if (called_from_cpu_thread)
|
|
{
|
|
// Temporarily declare this as the CPU thread to avoid getting a deadlock if any DolphinQt
|
|
// code calls RunAsCPUThread while the CPU thread is blocked on this function returning.
|
|
// Notably, if the panic alert steals focus from RenderWidget, Host::SetRenderFocus gets
|
|
// called, which can attempt to use RunAsCPUThread to get us out of exclusive fullscreen.
|
|
Core::DeclareAsCPUThread();
|
|
}
|
|
else
|
|
{
|
|
scope_guard.Dismiss();
|
|
}
|
|
|
|
ModalMessageBox message_box(QApplication::activeWindow(), Qt::ApplicationModal);
|
|
message_box.setWindowTitle(QString::fromUtf8(caption));
|
|
message_box.setText(QString::fromUtf8(text));
|
|
|
|
message_box.setStandardButtons(yes_no ? QMessageBox::Yes | QMessageBox::No : QMessageBox::Ok);
|
|
if (style == Common::MsgType::Warning)
|
|
message_box.addButton(QMessageBox::Ignore)->setText(QObject::tr("Ignore for this session"));
|
|
|
|
message_box.setIcon([&] {
|
|
switch (style)
|
|
{
|
|
case Common::MsgType::Information:
|
|
return QMessageBox::Information;
|
|
case Common::MsgType::Question:
|
|
return QMessageBox::Question;
|
|
case Common::MsgType::Warning:
|
|
return QMessageBox::Warning;
|
|
case Common::MsgType::Critical:
|
|
return QMessageBox::Critical;
|
|
}
|
|
// appease MSVC
|
|
return QMessageBox::NoIcon;
|
|
}());
|
|
|
|
const int button = message_box.exec();
|
|
if (button == QMessageBox::Yes)
|
|
return true;
|
|
|
|
if (button == QMessageBox::Ignore)
|
|
{
|
|
Common::SetEnableAlert(false);
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
});
|
|
if (r.has_value())
|
|
return *r;
|
|
return false;
|
|
}
|
|
|
|
#ifndef _WIN32
|
|
int main(int argc, char* argv[])
|
|
{
|
|
#else
|
|
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
|
|
{
|
|
std::vector<std::string> utf8_args = CommandLineToUtf8Argv(GetCommandLineW());
|
|
const int utf8_argc = static_cast<int>(utf8_args.size());
|
|
std::vector<char*> utf8_argv(utf8_args.size());
|
|
for (size_t i = 0; i < utf8_args.size(); ++i)
|
|
utf8_argv[i] = utf8_args[i].data();
|
|
|
|
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
|
|
|
|
#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
|
|
|
|
auto parser = CommandLineParse::CreateParser(CommandLineParse::ParserOptions::IncludeGUIOptions);
|
|
const optparse::Values& options =
|
|
#ifdef _WIN32
|
|
CommandLineParse::ParseArguments(parser.get(), utf8_argc, utf8_argv.data());
|
|
#else
|
|
CommandLineParse::ParseArguments(parser.get(), argc, argv);
|
|
#endif
|
|
const std::vector<std::string> args = parser->args();
|
|
|
|
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
|
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
|
QCoreApplication::setOrganizationName(QStringLiteral("Dolphin Emulator"));
|
|
QCoreApplication::setOrganizationDomain(QStringLiteral("dolphin-emu.org"));
|
|
QCoreApplication::setApplicationName(QStringLiteral("dolphin-emu"));
|
|
|
|
#ifdef _WIN32
|
|
QApplication app(__argc, __argv);
|
|
#else
|
|
QApplication app(argc, argv);
|
|
#endif
|
|
|
|
#ifdef _WIN32
|
|
// On Windows, Qt 5's default system font (MS Shell Dlg 2) is outdated.
|
|
// Interestingly, the QMenu font is correct and comes from lfMenuFont
|
|
// (Segoe UI on English computers).
|
|
// So use it for the entire application.
|
|
// This code will become unnecessary and obsolete once we switch to Qt 6.
|
|
QApplication::setFont(QApplication::font("QMenu"));
|
|
#endif
|
|
|
|
#ifdef _WIN32
|
|
FreeConsole();
|
|
#endif
|
|
|
|
UICommon::SetUserDirectory(static_cast<const char*>(options.get("user")));
|
|
UICommon::CreateDirectories();
|
|
UICommon::Init();
|
|
Resources::Init();
|
|
Settings::Instance().SetBatchModeEnabled(options.is_set("batch"));
|
|
Settings::Instance().SetSlippiInputFile(static_cast<const char*>(options.get("slippi_input")));
|
|
|
|
// Hook up alerts from core
|
|
Common::RegisterMsgAlertHandler(QtMsgAlertHandler);
|
|
|
|
// Hook up translations
|
|
Translation::Initialize();
|
|
|
|
// 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);
|
|
|
|
std::optional<std::string> save_state_path;
|
|
if (options.is_set("save_state"))
|
|
{
|
|
save_state_path = static_cast<const char*>(options.get("save_state"));
|
|
}
|
|
|
|
std::unique_ptr<BootParameters> boot;
|
|
bool game_specified = false;
|
|
if (options.is_set("exec"))
|
|
{
|
|
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, save_state_path);
|
|
game_specified = true;
|
|
}
|
|
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);
|
|
boot = std::make_unique<BootParameters>(BootParameters::NANDTitle{title_id});
|
|
}
|
|
else
|
|
{
|
|
ModalMessageBox::critical(nullptr, QObject::tr("Error"), QObject::tr("Invalid title ID."));
|
|
}
|
|
game_specified = true;
|
|
}
|
|
else if (!args.empty())
|
|
{
|
|
boot = BootParameters::GenerateFromFile(args.front(), save_state_path);
|
|
game_specified = true;
|
|
}
|
|
|
|
int retval;
|
|
|
|
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)
|
|
{
|
|
ModalMessageBox::critical(
|
|
nullptr, QObject::tr("Error"),
|
|
QObject::tr("Batch mode cannot be used without specifying a game to launch."));
|
|
retval = 1;
|
|
}
|
|
else if (!boot && (Settings::Instance().IsBatchModeEnabled() || save_state_path))
|
|
{
|
|
// 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
|
|
{
|
|
DolphinAnalytics::Instance().ReportDolphinStart("qt");
|
|
|
|
MainWindow win{std::move(boot), static_cast<const char*>(options.get("movie"))};
|
|
if (options.is_set("debugger"))
|
|
Settings::Instance().SetDebugModeEnabled(true);
|
|
win.Show();
|
|
|
|
#if defined(USE_ANALYTICS) && USE_ANALYTICS
|
|
if (!Config::Get(Config::MAIN_ANALYTICS_PERMISSION_ASKED))
|
|
{
|
|
ModalMessageBox analytics_prompt(&win);
|
|
|
|
analytics_prompt.setIcon(QMessageBox::Question);
|
|
analytics_prompt.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
|
analytics_prompt.setWindowTitle(QObject::tr("Allow Usage Statistics Reporting"));
|
|
analytics_prompt.setText(
|
|
QObject::tr("Do you authorize Dolphin to report information to Dolphin's developers?"));
|
|
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 "
|
|
"settings."));
|
|
|
|
const int answer = analytics_prompt.exec();
|
|
|
|
Config::SetBase(Config::MAIN_ANALYTICS_PERMISSION_ASKED, true);
|
|
Settings::Instance().SetAnalyticsEnabled(answer == QMessageBox::Yes);
|
|
|
|
DolphinAnalytics::Instance().ReloadConfig();
|
|
}
|
|
#endif
|
|
|
|
if (!Settings::Instance().IsBatchModeEnabled())
|
|
{
|
|
auto* updater = new Updater(&win);
|
|
updater->start();
|
|
}
|
|
|
|
retval = app.exec();
|
|
}
|
|
|
|
Core::Shutdown();
|
|
UICommon::Shutdown();
|
|
Host::GetInstance()->deleteLater();
|
|
|
|
return retval;
|
|
}
|