main.cpp 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <cinttypes>
  5. #include <clocale>
  6. #include <memory>
  7. #include <thread>
  8. // VFS includes must be before glad as they will conflict with Windows file api, which uses defines.
  9. #include "core/file_sys/vfs.h"
  10. #include "core/file_sys/vfs_real.h"
  11. // These are wrappers to avoid the calls to CreateDirectory and CreateFile becuase of the Windows
  12. // defines.
  13. static FileSys::VirtualDir VfsFilesystemCreateDirectoryWrapper(
  14. const FileSys::VirtualFilesystem& vfs, const std::string& path, FileSys::Mode mode) {
  15. return vfs->CreateDirectory(path, mode);
  16. }
  17. static FileSys::VirtualFile VfsDirectoryCreateFileWrapper(const FileSys::VirtualDir& dir,
  18. const std::string& path) {
  19. return dir->CreateFile(path);
  20. }
  21. #include <fmt/ostream.h>
  22. #include <glad/glad.h>
  23. #define QT_NO_OPENGL
  24. #include <QDesktopWidget>
  25. #include <QDialogButtonBox>
  26. #include <QFileDialog>
  27. #include <QMessageBox>
  28. #include <QtConcurrent/QtConcurrent>
  29. #include <QtGui>
  30. #include <QtWidgets>
  31. #include <fmt/format.h>
  32. #include "common/common_paths.h"
  33. #include "common/detached_tasks.h"
  34. #include "common/file_util.h"
  35. #include "common/logging/backend.h"
  36. #include "common/logging/filter.h"
  37. #include "common/logging/log.h"
  38. #include "common/microprofile.h"
  39. #include "common/scm_rev.h"
  40. #include "common/scope_exit.h"
  41. #include "common/string_util.h"
  42. #include "common/telemetry.h"
  43. #include "core/core.h"
  44. #include "core/crypto/key_manager.h"
  45. #include "core/file_sys/bis_factory.h"
  46. #include "core/file_sys/card_image.h"
  47. #include "core/file_sys/content_archive.h"
  48. #include "core/file_sys/control_metadata.h"
  49. #include "core/file_sys/patch_manager.h"
  50. #include "core/file_sys/registered_cache.h"
  51. #include "core/file_sys/romfs.h"
  52. #include "core/file_sys/savedata_factory.h"
  53. #include "core/file_sys/submission_package.h"
  54. #include "core/hle/kernel/process.h"
  55. #include "core/hle/service/filesystem/filesystem.h"
  56. #include "core/hle/service/filesystem/fsp_ldr.h"
  57. #include "core/loader/loader.h"
  58. #include "core/perf_stats.h"
  59. #include "core/settings.h"
  60. #include "core/telemetry_session.h"
  61. #include "video_core/debug_utils/debug_utils.h"
  62. #include "yuzu/about_dialog.h"
  63. #include "yuzu/bootmanager.h"
  64. #include "yuzu/compatdb.h"
  65. #include "yuzu/compatibility_list.h"
  66. #include "yuzu/configuration/config.h"
  67. #include "yuzu/configuration/configure_dialog.h"
  68. #include "yuzu/debugger/console.h"
  69. #include "yuzu/debugger/graphics/graphics_breakpoints.h"
  70. #include "yuzu/debugger/graphics/graphics_surface.h"
  71. #include "yuzu/debugger/profiler.h"
  72. #include "yuzu/debugger/wait_tree.h"
  73. #include "yuzu/discord.h"
  74. #include "yuzu/game_list.h"
  75. #include "yuzu/game_list_p.h"
  76. #include "yuzu/hotkeys.h"
  77. #include "yuzu/main.h"
  78. #include "yuzu/ui_settings.h"
  79. #ifdef USE_DISCORD_PRESENCE
  80. #include "yuzu/discord_impl.h"
  81. #endif
  82. #ifdef QT_STATICPLUGIN
  83. Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin);
  84. #endif
  85. #ifdef _WIN32
  86. extern "C" {
  87. // tells Nvidia and AMD drivers to use the dedicated GPU by default on laptops with switchable
  88. // graphics
  89. __declspec(dllexport) unsigned long NvOptimusEnablement = 0x00000001;
  90. __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
  91. }
  92. #endif
  93. /**
  94. * "Callouts" are one-time instructional messages shown to the user. In the config settings, there
  95. * is a bitfield "callout_flags" options, used to track if a message has already been shown to the
  96. * user. This is 32-bits - if we have more than 32 callouts, we should retire and recyle old ones.
  97. */
  98. enum class CalloutFlag : uint32_t {
  99. Telemetry = 0x1,
  100. DRDDeprecation = 0x2,
  101. };
  102. void GMainWindow::ShowTelemetryCallout() {
  103. if (UISettings::values.callout_flags & static_cast<uint32_t>(CalloutFlag::Telemetry)) {
  104. return;
  105. }
  106. UISettings::values.callout_flags |= static_cast<uint32_t>(CalloutFlag::Telemetry);
  107. const QString telemetry_message =
  108. tr("<a href='https://yuzu-emu.org/help/feature/telemetry/'>Anonymous "
  109. "data is collected</a> to help improve yuzu. "
  110. "<br/><br/>Would you like to share your usage data with us?");
  111. if (QMessageBox::question(this, tr("Telemetry"), telemetry_message) != QMessageBox::Yes) {
  112. Settings::values.enable_telemetry = false;
  113. Settings::Apply();
  114. }
  115. }
  116. const int GMainWindow::max_recent_files_item;
  117. static void InitializeLogging() {
  118. Log::Filter log_filter;
  119. log_filter.ParseFilterString(Settings::values.log_filter);
  120. Log::SetGlobalFilter(log_filter);
  121. const std::string& log_dir = FileUtil::GetUserPath(FileUtil::UserPath::LogDir);
  122. FileUtil::CreateFullPath(log_dir);
  123. Log::AddBackend(std::make_unique<Log::FileBackend>(log_dir + LOG_FILE));
  124. }
  125. GMainWindow::GMainWindow()
  126. : config(new Config()), emu_thread(nullptr),
  127. vfs(std::make_shared<FileSys::RealVfsFilesystem>()) {
  128. InitializeLogging();
  129. debug_context = Tegra::DebugContext::Construct();
  130. setAcceptDrops(true);
  131. ui.setupUi(this);
  132. statusBar()->hide();
  133. default_theme_paths = QIcon::themeSearchPaths();
  134. UpdateUITheme();
  135. SetDiscordEnabled(UISettings::values.enable_discord_presence);
  136. discord_rpc->Update();
  137. InitializeWidgets();
  138. InitializeDebugWidgets();
  139. InitializeRecentFileMenuActions();
  140. InitializeHotkeys();
  141. SetDefaultUIGeometry();
  142. RestoreUIState();
  143. ConnectMenuEvents();
  144. ConnectWidgetEvents();
  145. LOG_INFO(Frontend, "yuzu Version: {} | {}-{}", Common::g_build_fullname, Common::g_scm_branch,
  146. Common::g_scm_desc);
  147. setWindowTitle(QString("yuzu %1| %2-%3")
  148. .arg(Common::g_build_fullname, Common::g_scm_branch, Common::g_scm_desc));
  149. show();
  150. // Gen keys if necessary
  151. OnReinitializeKeys(ReinitializeKeyBehavior::NoWarning);
  152. // Necessary to load titles from nand in gamelist.
  153. Service::FileSystem::CreateFactories(*vfs);
  154. game_list->LoadCompatibilityList();
  155. game_list->PopulateAsync(UISettings::values.gamedir, UISettings::values.gamedir_deepscan);
  156. // Show one-time "callout" messages to the user
  157. ShowTelemetryCallout();
  158. QStringList args = QApplication::arguments();
  159. if (args.length() >= 2) {
  160. BootGame(args[1]);
  161. }
  162. }
  163. GMainWindow::~GMainWindow() {
  164. // will get automatically deleted otherwise
  165. if (render_window->parent() == nullptr)
  166. delete render_window;
  167. }
  168. void GMainWindow::InitializeWidgets() {
  169. #ifdef YUZU_ENABLE_COMPATIBILITY_REPORTING
  170. ui.action_Report_Compatibility->setVisible(true);
  171. #endif
  172. render_window = new GRenderWindow(this, emu_thread.get());
  173. render_window->hide();
  174. game_list = new GameList(vfs, this);
  175. ui.horizontalLayout->addWidget(game_list);
  176. // Create status bar
  177. message_label = new QLabel();
  178. // Configured separately for left alignment
  179. message_label->setVisible(false);
  180. message_label->setFrameStyle(QFrame::NoFrame);
  181. message_label->setContentsMargins(4, 0, 4, 0);
  182. message_label->setAlignment(Qt::AlignLeft);
  183. statusBar()->addPermanentWidget(message_label, 1);
  184. emu_speed_label = new QLabel();
  185. emu_speed_label->setToolTip(
  186. tr("Current emulation speed. Values higher or lower than 100% "
  187. "indicate emulation is running faster or slower than a Switch."));
  188. game_fps_label = new QLabel();
  189. game_fps_label->setToolTip(tr("How many frames per second the game is currently displaying. "
  190. "This will vary from game to game and scene to scene."));
  191. emu_frametime_label = new QLabel();
  192. emu_frametime_label->setToolTip(
  193. tr("Time taken to emulate a Switch frame, not counting framelimiting or v-sync. For "
  194. "full-speed emulation this should be at most 16.67 ms."));
  195. for (auto& label : {emu_speed_label, game_fps_label, emu_frametime_label}) {
  196. label->setVisible(false);
  197. label->setFrameStyle(QFrame::NoFrame);
  198. label->setContentsMargins(4, 0, 4, 0);
  199. statusBar()->addPermanentWidget(label, 0);
  200. }
  201. statusBar()->setVisible(true);
  202. setStyleSheet("QStatusBar::item{border: none;}");
  203. }
  204. void GMainWindow::InitializeDebugWidgets() {
  205. QMenu* debug_menu = ui.menu_View_Debugging;
  206. #if MICROPROFILE_ENABLED
  207. microProfileDialog = new MicroProfileDialog(this);
  208. microProfileDialog->hide();
  209. debug_menu->addAction(microProfileDialog->toggleViewAction());
  210. #endif
  211. graphicsBreakpointsWidget = new GraphicsBreakPointsWidget(debug_context, this);
  212. addDockWidget(Qt::RightDockWidgetArea, graphicsBreakpointsWidget);
  213. graphicsBreakpointsWidget->hide();
  214. debug_menu->addAction(graphicsBreakpointsWidget->toggleViewAction());
  215. graphicsSurfaceWidget = new GraphicsSurfaceWidget(debug_context, this);
  216. addDockWidget(Qt::RightDockWidgetArea, graphicsSurfaceWidget);
  217. graphicsSurfaceWidget->hide();
  218. debug_menu->addAction(graphicsSurfaceWidget->toggleViewAction());
  219. waitTreeWidget = new WaitTreeWidget(this);
  220. addDockWidget(Qt::LeftDockWidgetArea, waitTreeWidget);
  221. waitTreeWidget->hide();
  222. debug_menu->addAction(waitTreeWidget->toggleViewAction());
  223. connect(this, &GMainWindow::EmulationStarting, waitTreeWidget,
  224. &WaitTreeWidget::OnEmulationStarting);
  225. connect(this, &GMainWindow::EmulationStopping, waitTreeWidget,
  226. &WaitTreeWidget::OnEmulationStopping);
  227. }
  228. void GMainWindow::InitializeRecentFileMenuActions() {
  229. for (int i = 0; i < max_recent_files_item; ++i) {
  230. actions_recent_files[i] = new QAction(this);
  231. actions_recent_files[i]->setVisible(false);
  232. connect(actions_recent_files[i], &QAction::triggered, this, &GMainWindow::OnMenuRecentFile);
  233. ui.menu_recent_files->addAction(actions_recent_files[i]);
  234. }
  235. ui.menu_recent_files->addSeparator();
  236. QAction* action_clear_recent_files = new QAction(this);
  237. action_clear_recent_files->setText(tr("Clear Recent Files"));
  238. connect(action_clear_recent_files, &QAction::triggered, this, [this] {
  239. UISettings::values.recent_files.clear();
  240. UpdateRecentFiles();
  241. });
  242. ui.menu_recent_files->addAction(action_clear_recent_files);
  243. UpdateRecentFiles();
  244. }
  245. void GMainWindow::InitializeHotkeys() {
  246. hotkey_registry.RegisterHotkey("Main Window", "Load File", QKeySequence::Open);
  247. hotkey_registry.RegisterHotkey("Main Window", "Start Emulation");
  248. hotkey_registry.RegisterHotkey("Main Window", "Continue/Pause", QKeySequence(Qt::Key_F4));
  249. hotkey_registry.RegisterHotkey("Main Window", "Restart", QKeySequence(Qt::Key_F5));
  250. hotkey_registry.RegisterHotkey("Main Window", "Fullscreen", QKeySequence::FullScreen);
  251. hotkey_registry.RegisterHotkey("Main Window", "Exit Fullscreen", QKeySequence(Qt::Key_Escape),
  252. Qt::ApplicationShortcut);
  253. hotkey_registry.RegisterHotkey("Main Window", "Toggle Speed Limit", QKeySequence("CTRL+Z"),
  254. Qt::ApplicationShortcut);
  255. hotkey_registry.RegisterHotkey("Main Window", "Increase Speed Limit", QKeySequence("+"),
  256. Qt::ApplicationShortcut);
  257. hotkey_registry.RegisterHotkey("Main Window", "Decrease Speed Limit", QKeySequence("-"),
  258. Qt::ApplicationShortcut);
  259. hotkey_registry.LoadHotkeys();
  260. connect(hotkey_registry.GetHotkey("Main Window", "Load File", this), &QShortcut::activated,
  261. this, &GMainWindow::OnMenuLoadFile);
  262. connect(hotkey_registry.GetHotkey("Main Window", "Start Emulation", this),
  263. &QShortcut::activated, this, &GMainWindow::OnStartGame);
  264. connect(hotkey_registry.GetHotkey("Main Window", "Continue/Pause", this), &QShortcut::activated,
  265. this, [&] {
  266. if (emulation_running) {
  267. if (emu_thread->IsRunning()) {
  268. OnPauseGame();
  269. } else {
  270. OnStartGame();
  271. }
  272. }
  273. });
  274. connect(hotkey_registry.GetHotkey("Main Window", "Restart", this), &QShortcut::activated, this,
  275. [this] {
  276. if (!Core::System::GetInstance().IsPoweredOn())
  277. return;
  278. BootGame(QString(game_path));
  279. });
  280. connect(hotkey_registry.GetHotkey("Main Window", "Fullscreen", render_window),
  281. &QShortcut::activated, ui.action_Fullscreen, &QAction::trigger);
  282. connect(hotkey_registry.GetHotkey("Main Window", "Fullscreen", render_window),
  283. &QShortcut::activatedAmbiguously, ui.action_Fullscreen, &QAction::trigger);
  284. connect(hotkey_registry.GetHotkey("Main Window", "Exit Fullscreen", this),
  285. &QShortcut::activated, this, [&] {
  286. if (emulation_running) {
  287. ui.action_Fullscreen->setChecked(false);
  288. ToggleFullscreen();
  289. }
  290. });
  291. connect(hotkey_registry.GetHotkey("Main Window", "Toggle Speed Limit", this),
  292. &QShortcut::activated, this, [&] {
  293. Settings::values.use_frame_limit = !Settings::values.use_frame_limit;
  294. UpdateStatusBar();
  295. });
  296. constexpr u16 SPEED_LIMIT_STEP = 5;
  297. connect(hotkey_registry.GetHotkey("Main Window", "Increase Speed Limit", this),
  298. &QShortcut::activated, this, [&] {
  299. if (Settings::values.frame_limit < 9999 - SPEED_LIMIT_STEP) {
  300. Settings::values.frame_limit += SPEED_LIMIT_STEP;
  301. UpdateStatusBar();
  302. }
  303. });
  304. connect(hotkey_registry.GetHotkey("Main Window", "Decrease Speed Limit", this),
  305. &QShortcut::activated, this, [&] {
  306. if (Settings::values.frame_limit > SPEED_LIMIT_STEP) {
  307. Settings::values.frame_limit -= SPEED_LIMIT_STEP;
  308. UpdateStatusBar();
  309. }
  310. });
  311. }
  312. void GMainWindow::SetDefaultUIGeometry() {
  313. // geometry: 55% of the window contents are in the upper screen half, 45% in the lower half
  314. const QRect screenRect = QApplication::desktop()->screenGeometry(this);
  315. const int w = screenRect.width() * 2 / 3;
  316. const int h = screenRect.height() / 2;
  317. const int x = (screenRect.x() + screenRect.width()) / 2 - w / 2;
  318. const int y = (screenRect.y() + screenRect.height()) / 2 - h * 55 / 100;
  319. setGeometry(x, y, w, h);
  320. }
  321. void GMainWindow::RestoreUIState() {
  322. restoreGeometry(UISettings::values.geometry);
  323. restoreState(UISettings::values.state);
  324. render_window->restoreGeometry(UISettings::values.renderwindow_geometry);
  325. #if MICROPROFILE_ENABLED
  326. microProfileDialog->restoreGeometry(UISettings::values.microprofile_geometry);
  327. microProfileDialog->setVisible(UISettings::values.microprofile_visible);
  328. #endif
  329. game_list->LoadInterfaceLayout();
  330. ui.action_Single_Window_Mode->setChecked(UISettings::values.single_window_mode);
  331. ToggleWindowMode();
  332. ui.action_Fullscreen->setChecked(UISettings::values.fullscreen);
  333. ui.action_Display_Dock_Widget_Headers->setChecked(UISettings::values.display_titlebar);
  334. OnDisplayTitleBars(ui.action_Display_Dock_Widget_Headers->isChecked());
  335. ui.action_Show_Filter_Bar->setChecked(UISettings::values.show_filter_bar);
  336. game_list->setFilterVisible(ui.action_Show_Filter_Bar->isChecked());
  337. ui.action_Show_Status_Bar->setChecked(UISettings::values.show_status_bar);
  338. statusBar()->setVisible(ui.action_Show_Status_Bar->isChecked());
  339. Debugger::ToggleConsole();
  340. }
  341. void GMainWindow::ConnectWidgetEvents() {
  342. connect(game_list, &GameList::GameChosen, this, &GMainWindow::OnGameListLoadFile);
  343. connect(game_list, &GameList::OpenFolderRequested, this, &GMainWindow::OnGameListOpenFolder);
  344. connect(game_list, &GameList::DumpRomFSRequested, this, &GMainWindow::OnGameListDumpRomFS);
  345. connect(game_list, &GameList::CopyTIDRequested, this, &GMainWindow::OnGameListCopyTID);
  346. connect(game_list, &GameList::NavigateToGamedbEntryRequested, this,
  347. &GMainWindow::OnGameListNavigateToGamedbEntry);
  348. connect(this, &GMainWindow::EmulationStarting, render_window,
  349. &GRenderWindow::OnEmulationStarting);
  350. connect(this, &GMainWindow::EmulationStopping, render_window,
  351. &GRenderWindow::OnEmulationStopping);
  352. connect(&status_bar_update_timer, &QTimer::timeout, this, &GMainWindow::UpdateStatusBar);
  353. }
  354. void GMainWindow::ConnectMenuEvents() {
  355. // File
  356. connect(ui.action_Load_File, &QAction::triggered, this, &GMainWindow::OnMenuLoadFile);
  357. connect(ui.action_Load_Folder, &QAction::triggered, this, &GMainWindow::OnMenuLoadFolder);
  358. connect(ui.action_Install_File_NAND, &QAction::triggered, this,
  359. &GMainWindow::OnMenuInstallToNAND);
  360. connect(ui.action_Select_Game_List_Root, &QAction::triggered, this,
  361. &GMainWindow::OnMenuSelectGameListRoot);
  362. connect(ui.action_Select_NAND_Directory, &QAction::triggered, this,
  363. [this] { OnMenuSelectEmulatedDirectory(EmulatedDirectoryTarget::NAND); });
  364. connect(ui.action_Select_SDMC_Directory, &QAction::triggered, this,
  365. [this] { OnMenuSelectEmulatedDirectory(EmulatedDirectoryTarget::SDMC); });
  366. connect(ui.action_Exit, &QAction::triggered, this, &QMainWindow::close);
  367. // Emulation
  368. connect(ui.action_Start, &QAction::triggered, this, &GMainWindow::OnStartGame);
  369. connect(ui.action_Pause, &QAction::triggered, this, &GMainWindow::OnPauseGame);
  370. connect(ui.action_Stop, &QAction::triggered, this, &GMainWindow::OnStopGame);
  371. connect(ui.action_Report_Compatibility, &QAction::triggered, this,
  372. &GMainWindow::OnMenuReportCompatibility);
  373. connect(ui.action_Restart, &QAction::triggered, this, [this] { BootGame(QString(game_path)); });
  374. connect(ui.action_Configure, &QAction::triggered, this, &GMainWindow::OnConfigure);
  375. // View
  376. connect(ui.action_Single_Window_Mode, &QAction::triggered, this,
  377. &GMainWindow::ToggleWindowMode);
  378. connect(ui.action_Display_Dock_Widget_Headers, &QAction::triggered, this,
  379. &GMainWindow::OnDisplayTitleBars);
  380. ui.action_Show_Filter_Bar->setShortcut(tr("CTRL+F"));
  381. connect(ui.action_Show_Filter_Bar, &QAction::triggered, this, &GMainWindow::OnToggleFilterBar);
  382. connect(ui.action_Show_Status_Bar, &QAction::triggered, statusBar(), &QStatusBar::setVisible);
  383. // Fullscreen
  384. ui.action_Fullscreen->setShortcut(
  385. hotkey_registry.GetHotkey("Main Window", "Fullscreen", this)->key());
  386. connect(ui.action_Fullscreen, &QAction::triggered, this, &GMainWindow::ToggleFullscreen);
  387. // Help
  388. connect(ui.action_Rederive, &QAction::triggered, this,
  389. std::bind(&GMainWindow::OnReinitializeKeys, this, ReinitializeKeyBehavior::Warning));
  390. connect(ui.action_About, &QAction::triggered, this, &GMainWindow::OnAbout);
  391. }
  392. void GMainWindow::OnDisplayTitleBars(bool show) {
  393. QList<QDockWidget*> widgets = findChildren<QDockWidget*>();
  394. if (show) {
  395. for (QDockWidget* widget : widgets) {
  396. QWidget* old = widget->titleBarWidget();
  397. widget->setTitleBarWidget(nullptr);
  398. if (old != nullptr)
  399. delete old;
  400. }
  401. } else {
  402. for (QDockWidget* widget : widgets) {
  403. QWidget* old = widget->titleBarWidget();
  404. widget->setTitleBarWidget(new QWidget());
  405. if (old != nullptr)
  406. delete old;
  407. }
  408. }
  409. }
  410. QStringList GMainWindow::GetUnsupportedGLExtensions() {
  411. QStringList unsupported_ext;
  412. if (!GLAD_GL_ARB_program_interface_query)
  413. unsupported_ext.append("ARB_program_interface_query");
  414. if (!GLAD_GL_ARB_separate_shader_objects)
  415. unsupported_ext.append("ARB_separate_shader_objects");
  416. if (!GLAD_GL_ARB_vertex_attrib_binding)
  417. unsupported_ext.append("ARB_vertex_attrib_binding");
  418. if (!GLAD_GL_ARB_vertex_type_10f_11f_11f_rev)
  419. unsupported_ext.append("ARB_vertex_type_10f_11f_11f_rev");
  420. if (!GLAD_GL_ARB_texture_mirror_clamp_to_edge)
  421. unsupported_ext.append("ARB_texture_mirror_clamp_to_edge");
  422. if (!GLAD_GL_ARB_base_instance)
  423. unsupported_ext.append("ARB_base_instance");
  424. if (!GLAD_GL_ARB_texture_storage)
  425. unsupported_ext.append("ARB_texture_storage");
  426. if (!GLAD_GL_ARB_multi_bind)
  427. unsupported_ext.append("ARB_multi_bind");
  428. if (!GLAD_GL_ARB_copy_image)
  429. unsupported_ext.append("ARB_copy_image");
  430. // Extensions required to support some texture formats.
  431. if (!GLAD_GL_EXT_texture_compression_s3tc)
  432. unsupported_ext.append("EXT_texture_compression_s3tc");
  433. if (!GLAD_GL_ARB_texture_compression_rgtc)
  434. unsupported_ext.append("ARB_texture_compression_rgtc");
  435. if (!GLAD_GL_ARB_texture_compression_bptc)
  436. unsupported_ext.append("ARB_texture_compression_bptc");
  437. if (!GLAD_GL_ARB_depth_buffer_float)
  438. unsupported_ext.append("ARB_depth_buffer_float");
  439. for (const QString& ext : unsupported_ext)
  440. LOG_CRITICAL(Frontend, "Unsupported GL extension: {}", ext.toStdString());
  441. return unsupported_ext;
  442. }
  443. bool GMainWindow::LoadROM(const QString& filename) {
  444. // Shutdown previous session if the emu thread is still active...
  445. if (emu_thread != nullptr)
  446. ShutdownGame();
  447. render_window->InitRenderTarget();
  448. render_window->MakeCurrent();
  449. if (!gladLoadGL()) {
  450. QMessageBox::critical(this, tr("Error while initializing OpenGL 3.3 Core!"),
  451. tr("Your GPU may not support OpenGL 3.3, or you do not "
  452. "have the latest graphics driver."));
  453. return false;
  454. }
  455. QStringList unsupported_gl_extensions = GetUnsupportedGLExtensions();
  456. if (!unsupported_gl_extensions.empty()) {
  457. QMessageBox::critical(this, tr("Error while initializing OpenGL Core!"),
  458. tr("Your GPU may not support one or more required OpenGL"
  459. "extensions. Please ensure you have the latest graphics "
  460. "driver.<br><br>Unsupported extensions:<br>") +
  461. unsupported_gl_extensions.join("<br>"));
  462. return false;
  463. }
  464. Core::System& system{Core::System::GetInstance()};
  465. system.SetFilesystem(vfs);
  466. system.SetGPUDebugContext(debug_context);
  467. const Core::System::ResultStatus result{system.Load(*render_window, filename.toStdString())};
  468. const auto drd_callout =
  469. (UISettings::values.callout_flags & static_cast<u32>(CalloutFlag::DRDDeprecation)) == 0;
  470. if (result == Core::System::ResultStatus::Success &&
  471. system.GetAppLoader().GetFileType() == Loader::FileType::DeconstructedRomDirectory &&
  472. drd_callout) {
  473. UISettings::values.callout_flags |= static_cast<u32>(CalloutFlag::DRDDeprecation);
  474. QMessageBox::warning(
  475. this, tr("Warning Outdated Game Format"),
  476. tr("You are using the deconstructed ROM directory format for this game, which is an "
  477. "outdated format that has been superseded by others such as NCA, NAX, XCI, or "
  478. "NSP. Deconstructed ROM directories lack icons, metadata, and update "
  479. "support.<br><br>For an explanation of the various Switch formats yuzu supports, <a "
  480. "href='https://yuzu-emu.org/wiki/overview-of-switch-game-formats'>check out our "
  481. "wiki</a>. This message will not be shown again."));
  482. }
  483. render_window->DoneCurrent();
  484. if (result != Core::System::ResultStatus::Success) {
  485. switch (result) {
  486. case Core::System::ResultStatus::ErrorGetLoader:
  487. LOG_CRITICAL(Frontend, "Failed to obtain loader for {}!", filename.toStdString());
  488. QMessageBox::critical(this, tr("Error while loading ROM!"),
  489. tr("The ROM format is not supported."));
  490. break;
  491. case Core::System::ResultStatus::ErrorSystemMode:
  492. LOG_CRITICAL(Frontend, "Failed to load ROM!");
  493. QMessageBox::critical(this, tr("Error while loading ROM!"),
  494. tr("Could not determine the system mode."));
  495. break;
  496. case Core::System::ResultStatus::ErrorVideoCore:
  497. QMessageBox::critical(
  498. this, tr("An error occurred initializing the video core."),
  499. tr("yuzu has encountered an error while running the video core, please see the "
  500. "log for more details."
  501. "For more information on accessing the log, please see the following page: "
  502. "<a href='https://community.citra-emu.org/t/how-to-upload-the-log-file/296'>How "
  503. "to "
  504. "Upload the Log File</a>."
  505. "Ensure that you have the latest graphics drivers for your GPU."));
  506. break;
  507. default:
  508. if (static_cast<u32>(result) >
  509. static_cast<u32>(Core::System::ResultStatus::ErrorLoader)) {
  510. LOG_CRITICAL(Frontend, "Failed to load ROM!");
  511. const u16 loader_id = static_cast<u16>(Core::System::ResultStatus::ErrorLoader);
  512. const u16 error_id = static_cast<u16>(result) - loader_id;
  513. QMessageBox::critical(
  514. this, tr("Error while loading ROM!"),
  515. QString::fromStdString(fmt::format(
  516. "While attempting to load the ROM requested, an error occured. Please "
  517. "refer to the yuzu wiki for more information or the yuzu discord for "
  518. "additional help.\n\nError Code: {:04X}-{:04X}\nError Description: {}",
  519. loader_id, error_id, static_cast<Loader::ResultStatus>(error_id))));
  520. } else {
  521. QMessageBox::critical(
  522. this, tr("Error while loading ROM!"),
  523. tr("An unknown error occurred. Please see the log for more details."));
  524. }
  525. break;
  526. }
  527. return false;
  528. }
  529. game_path = filename;
  530. Core::Telemetry().AddField(Telemetry::FieldType::App, "Frontend", "Qt");
  531. return true;
  532. }
  533. void GMainWindow::BootGame(const QString& filename) {
  534. LOG_INFO(Frontend, "yuzu starting...");
  535. StoreRecentFile(filename); // Put the filename on top of the list
  536. if (!LoadROM(filename))
  537. return;
  538. // Create and start the emulation thread
  539. emu_thread = std::make_unique<EmuThread>(render_window);
  540. emit EmulationStarting(emu_thread.get());
  541. render_window->moveContext();
  542. emu_thread->start();
  543. connect(render_window, &GRenderWindow::Closed, this, &GMainWindow::OnStopGame);
  544. // BlockingQueuedConnection is important here, it makes sure we've finished refreshing our views
  545. // before the CPU continues
  546. connect(emu_thread.get(), &EmuThread::DebugModeEntered, waitTreeWidget,
  547. &WaitTreeWidget::OnDebugModeEntered, Qt::BlockingQueuedConnection);
  548. connect(emu_thread.get(), &EmuThread::DebugModeLeft, waitTreeWidget,
  549. &WaitTreeWidget::OnDebugModeLeft, Qt::BlockingQueuedConnection);
  550. // Update the GUI
  551. if (ui.action_Single_Window_Mode->isChecked()) {
  552. game_list->hide();
  553. }
  554. status_bar_update_timer.start(2000);
  555. std::string title_name;
  556. const auto res = Core::System::GetInstance().GetGameName(title_name);
  557. if (res != Loader::ResultStatus::Success) {
  558. const u64 title_id = Core::System::GetInstance().CurrentProcess()->GetTitleID();
  559. const auto [nacp, icon_file] = FileSys::PatchManager(title_id).GetControlMetadata();
  560. if (nacp != nullptr)
  561. title_name = nacp->GetApplicationName();
  562. if (title_name.empty())
  563. title_name = FileUtil::GetFilename(filename.toStdString());
  564. }
  565. setWindowTitle(QString("yuzu %1| %4 | %2-%3")
  566. .arg(Common::g_build_fullname, Common::g_scm_branch, Common::g_scm_desc,
  567. QString::fromStdString(title_name)));
  568. render_window->show();
  569. render_window->setFocus();
  570. emulation_running = true;
  571. if (ui.action_Fullscreen->isChecked()) {
  572. ShowFullscreen();
  573. }
  574. OnStartGame();
  575. }
  576. void GMainWindow::ShutdownGame() {
  577. discord_rpc->Pause();
  578. emu_thread->RequestStop();
  579. emit EmulationStopping();
  580. // Wait for emulation thread to complete and delete it
  581. emu_thread->wait();
  582. emu_thread = nullptr;
  583. discord_rpc->Update();
  584. // The emulation is stopped, so closing the window or not does not matter anymore
  585. disconnect(render_window, &GRenderWindow::Closed, this, &GMainWindow::OnStopGame);
  586. // Update the GUI
  587. ui.action_Start->setEnabled(false);
  588. ui.action_Start->setText(tr("Start"));
  589. ui.action_Pause->setEnabled(false);
  590. ui.action_Stop->setEnabled(false);
  591. ui.action_Restart->setEnabled(false);
  592. ui.action_Report_Compatibility->setEnabled(false);
  593. render_window->hide();
  594. game_list->show();
  595. game_list->setFilterFocus();
  596. setWindowTitle(QString("yuzu %1| %2-%3")
  597. .arg(Common::g_build_fullname, Common::g_scm_branch, Common::g_scm_desc));
  598. // Disable status bar updates
  599. status_bar_update_timer.stop();
  600. message_label->setVisible(false);
  601. emu_speed_label->setVisible(false);
  602. game_fps_label->setVisible(false);
  603. emu_frametime_label->setVisible(false);
  604. emulation_running = false;
  605. game_path.clear();
  606. }
  607. void GMainWindow::StoreRecentFile(const QString& filename) {
  608. UISettings::values.recent_files.prepend(filename);
  609. UISettings::values.recent_files.removeDuplicates();
  610. while (UISettings::values.recent_files.size() > max_recent_files_item) {
  611. UISettings::values.recent_files.removeLast();
  612. }
  613. UpdateRecentFiles();
  614. }
  615. void GMainWindow::UpdateRecentFiles() {
  616. const int num_recent_files =
  617. std::min(UISettings::values.recent_files.size(), max_recent_files_item);
  618. for (int i = 0; i < num_recent_files; i++) {
  619. const QString text = QString("&%1. %2").arg(i + 1).arg(
  620. QFileInfo(UISettings::values.recent_files[i]).fileName());
  621. actions_recent_files[i]->setText(text);
  622. actions_recent_files[i]->setData(UISettings::values.recent_files[i]);
  623. actions_recent_files[i]->setToolTip(UISettings::values.recent_files[i]);
  624. actions_recent_files[i]->setVisible(true);
  625. }
  626. for (int j = num_recent_files; j < max_recent_files_item; ++j) {
  627. actions_recent_files[j]->setVisible(false);
  628. }
  629. // Enable the recent files menu if the list isn't empty
  630. ui.menu_recent_files->setEnabled(num_recent_files != 0);
  631. }
  632. void GMainWindow::OnGameListLoadFile(QString game_path) {
  633. BootGame(game_path);
  634. }
  635. void GMainWindow::OnGameListOpenFolder(u64 program_id, GameListOpenTarget target) {
  636. std::string path;
  637. std::string open_target;
  638. switch (target) {
  639. case GameListOpenTarget::SaveData: {
  640. open_target = "Save Data";
  641. const std::string nand_dir = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir);
  642. ASSERT(program_id != 0);
  643. // TODO(tech4me): Update this to work with arbitrary user profile
  644. // Refer to core/hle/service/acc/profile_manager.cpp ProfileManager constructor
  645. constexpr u128 user_id = {1, 0};
  646. path = nand_dir + FileSys::SaveDataFactory::GetFullPath(FileSys::SaveDataSpaceId::NandUser,
  647. FileSys::SaveDataType::SaveData,
  648. program_id, user_id, 0);
  649. break;
  650. }
  651. case GameListOpenTarget::ModData: {
  652. open_target = "Mod Data";
  653. const auto load_dir = FileUtil::GetUserPath(FileUtil::UserPath::LoadDir);
  654. path = fmt::format("{}{:016X}", load_dir, program_id);
  655. break;
  656. }
  657. default:
  658. UNIMPLEMENTED();
  659. }
  660. const QString qpath = QString::fromStdString(path);
  661. const QDir dir(qpath);
  662. if (!dir.exists()) {
  663. QMessageBox::warning(this,
  664. tr("Error Opening %1 Folder").arg(QString::fromStdString(open_target)),
  665. tr("Folder does not exist!"));
  666. return;
  667. }
  668. LOG_INFO(Frontend, "Opening {} path for program_id={:016x}", open_target, program_id);
  669. QDesktopServices::openUrl(QUrl::fromLocalFile(qpath));
  670. }
  671. static std::size_t CalculateRomFSEntrySize(const FileSys::VirtualDir& dir, bool full) {
  672. std::size_t out = 0;
  673. for (const auto& subdir : dir->GetSubdirectories()) {
  674. out += 1 + CalculateRomFSEntrySize(subdir, full);
  675. }
  676. return out + (full ? dir->GetFiles().size() : 0);
  677. }
  678. static bool RomFSRawCopy(QProgressDialog& dialog, const FileSys::VirtualDir& src,
  679. const FileSys::VirtualDir& dest, std::size_t block_size, bool full) {
  680. if (src == nullptr || dest == nullptr || !src->IsReadable() || !dest->IsWritable())
  681. return false;
  682. if (dialog.wasCanceled())
  683. return false;
  684. if (full) {
  685. for (const auto& file : src->GetFiles()) {
  686. const auto out = VfsDirectoryCreateFileWrapper(dest, file->GetName());
  687. if (!FileSys::VfsRawCopy(file, out, block_size))
  688. return false;
  689. dialog.setValue(dialog.value() + 1);
  690. if (dialog.wasCanceled())
  691. return false;
  692. }
  693. }
  694. for (const auto& dir : src->GetSubdirectories()) {
  695. const auto out = dest->CreateSubdirectory(dir->GetName());
  696. if (!RomFSRawCopy(dialog, dir, out, block_size, full))
  697. return false;
  698. dialog.setValue(dialog.value() + 1);
  699. if (dialog.wasCanceled())
  700. return false;
  701. }
  702. return true;
  703. }
  704. void GMainWindow::OnGameListDumpRomFS(u64 program_id, const std::string& game_path) {
  705. const auto path = fmt::format("{}{:016X}/romfs",
  706. FileUtil::GetUserPath(FileUtil::UserPath::DumpDir), program_id);
  707. const auto failed = [this, &path] {
  708. QMessageBox::warning(this, tr("RomFS Extraction Failed!"),
  709. tr("There was an error copying the RomFS files or the user "
  710. "cancelled the operation."));
  711. vfs->DeleteDirectory(path);
  712. };
  713. const auto loader = Loader::GetLoader(vfs->OpenFile(game_path, FileSys::Mode::Read));
  714. if (loader == nullptr) {
  715. failed();
  716. return;
  717. }
  718. FileSys::VirtualFile file;
  719. if (loader->ReadRomFS(file) != Loader::ResultStatus::Success) {
  720. failed();
  721. return;
  722. }
  723. const auto romfs =
  724. loader->IsRomFSUpdatable()
  725. ? FileSys::PatchManager(program_id).PatchRomFS(file, loader->ReadRomFSIVFCOffset())
  726. : file;
  727. const auto extracted = FileSys::ExtractRomFS(romfs, FileSys::RomFSExtractionType::Full);
  728. if (extracted == nullptr) {
  729. failed();
  730. return;
  731. }
  732. const auto out = VfsFilesystemCreateDirectoryWrapper(vfs, path, FileSys::Mode::ReadWrite);
  733. if (out == nullptr) {
  734. failed();
  735. return;
  736. }
  737. bool ok;
  738. const auto res = QInputDialog::getItem(
  739. this, tr("Select RomFS Dump Mode"),
  740. tr("Please select the how you would like the RomFS dumped.<br>Full will copy all of the "
  741. "files into the new directory while <br>skeleton will only create the directory "
  742. "structure."),
  743. {"Full", "Skeleton"}, 0, false, &ok);
  744. if (!ok)
  745. failed();
  746. const auto full = res == "Full";
  747. const auto entry_size = CalculateRomFSEntrySize(extracted, full);
  748. QProgressDialog progress(tr("Extracting RomFS..."), tr("Cancel"), 0, entry_size, this);
  749. progress.setWindowModality(Qt::WindowModal);
  750. progress.setMinimumDuration(100);
  751. if (RomFSRawCopy(progress, extracted, out, 0x400000, full)) {
  752. progress.close();
  753. QMessageBox::information(this, tr("RomFS Extraction Succeeded!"),
  754. tr("The operation completed successfully."));
  755. QDesktopServices::openUrl(QUrl::fromLocalFile(QString::fromStdString(path)));
  756. } else {
  757. progress.close();
  758. failed();
  759. }
  760. }
  761. void GMainWindow::OnGameListCopyTID(u64 program_id) {
  762. QClipboard* clipboard = QGuiApplication::clipboard();
  763. clipboard->setText(QString::fromStdString(fmt::format("{:016X}", program_id)));
  764. }
  765. void GMainWindow::OnGameListNavigateToGamedbEntry(u64 program_id,
  766. const CompatibilityList& compatibility_list) {
  767. const auto it = FindMatchingCompatibilityEntry(compatibility_list, program_id);
  768. QString directory;
  769. if (it != compatibility_list.end())
  770. directory = it->second.second;
  771. QDesktopServices::openUrl(QUrl("https://yuzu-emu.org/game/" + directory));
  772. }
  773. void GMainWindow::OnMenuLoadFile() {
  774. const QString extensions =
  775. QString("*.").append(GameList::supported_file_extensions.join(" *.")).append(" main");
  776. const QString file_filter = tr("Switch Executable (%1);;All Files (*.*)",
  777. "%1 is an identifier for the Switch executable file extensions.")
  778. .arg(extensions);
  779. const QString filename = QFileDialog::getOpenFileName(
  780. this, tr("Load File"), UISettings::values.roms_path, file_filter);
  781. if (filename.isEmpty()) {
  782. return;
  783. }
  784. UISettings::values.roms_path = QFileInfo(filename).path();
  785. BootGame(filename);
  786. }
  787. void GMainWindow::OnMenuLoadFolder() {
  788. const QString dir_path =
  789. QFileDialog::getExistingDirectory(this, tr("Open Extracted ROM Directory"));
  790. if (dir_path.isNull()) {
  791. return;
  792. }
  793. const QDir dir{dir_path};
  794. const QStringList matching_main = dir.entryList(QStringList("main"), QDir::Files);
  795. if (matching_main.size() == 1) {
  796. BootGame(dir.path() + DIR_SEP + matching_main[0]);
  797. } else {
  798. QMessageBox::warning(this, tr("Invalid Directory Selected"),
  799. tr("The directory you have selected does not contain a 'main' file."));
  800. }
  801. }
  802. void GMainWindow::OnMenuInstallToNAND() {
  803. const QString file_filter =
  804. tr("Installable Switch File (*.nca *.nsp *.xci);;Nintendo Content Archive "
  805. "(*.nca);;Nintendo Submissions Package (*.nsp);;NX Cartridge "
  806. "Image (*.xci)");
  807. QString filename = QFileDialog::getOpenFileName(this, tr("Install File"),
  808. UISettings::values.roms_path, file_filter);
  809. if (filename.isEmpty()) {
  810. return;
  811. }
  812. const auto qt_raw_copy = [this](const FileSys::VirtualFile& src,
  813. const FileSys::VirtualFile& dest, std::size_t block_size) {
  814. if (src == nullptr || dest == nullptr)
  815. return false;
  816. if (!dest->Resize(src->GetSize()))
  817. return false;
  818. std::array<u8, 0x1000> buffer{};
  819. const int progress_maximum = static_cast<int>(src->GetSize() / buffer.size());
  820. QProgressDialog progress(
  821. tr("Installing file \"%1\"...").arg(QString::fromStdString(src->GetName())),
  822. tr("Cancel"), 0, progress_maximum, this);
  823. progress.setWindowModality(Qt::WindowModal);
  824. for (std::size_t i = 0; i < src->GetSize(); i += buffer.size()) {
  825. if (progress.wasCanceled()) {
  826. dest->Resize(0);
  827. return false;
  828. }
  829. const int progress_value = static_cast<int>(i / buffer.size());
  830. progress.setValue(progress_value);
  831. const auto read = src->Read(buffer.data(), buffer.size(), i);
  832. dest->Write(buffer.data(), read, i);
  833. }
  834. return true;
  835. };
  836. const auto success = [this]() {
  837. QMessageBox::information(this, tr("Successfully Installed"),
  838. tr("The file was successfully installed."));
  839. game_list->PopulateAsync(UISettings::values.gamedir, UISettings::values.gamedir_deepscan);
  840. };
  841. const auto failed = [this]() {
  842. QMessageBox::warning(
  843. this, tr("Failed to Install"),
  844. tr("There was an error while attempting to install the provided file. It "
  845. "could have an incorrect format or be missing metadata. Please "
  846. "double-check your file and try again."));
  847. };
  848. const auto overwrite = [this]() {
  849. return QMessageBox::question(this, tr("Failed to Install"),
  850. tr("The file you are attempting to install already exists "
  851. "in the cache. Would you like to overwrite it?")) ==
  852. QMessageBox::Yes;
  853. };
  854. if (filename.endsWith("xci", Qt::CaseInsensitive) ||
  855. filename.endsWith("nsp", Qt::CaseInsensitive)) {
  856. std::shared_ptr<FileSys::NSP> nsp;
  857. if (filename.endsWith("nsp", Qt::CaseInsensitive)) {
  858. nsp = std::make_shared<FileSys::NSP>(
  859. vfs->OpenFile(filename.toStdString(), FileSys::Mode::Read));
  860. if (nsp->IsExtractedType())
  861. failed();
  862. } else {
  863. const auto xci = std::make_shared<FileSys::XCI>(
  864. vfs->OpenFile(filename.toStdString(), FileSys::Mode::Read));
  865. nsp = xci->GetSecurePartitionNSP();
  866. }
  867. if (nsp->GetStatus() != Loader::ResultStatus::Success) {
  868. failed();
  869. return;
  870. }
  871. const auto res =
  872. Service::FileSystem::GetUserNANDContents()->InstallEntry(nsp, false, qt_raw_copy);
  873. if (res == FileSys::InstallResult::Success) {
  874. success();
  875. } else {
  876. if (res == FileSys::InstallResult::ErrorAlreadyExists) {
  877. if (overwrite()) {
  878. const auto res2 = Service::FileSystem::GetUserNANDContents()->InstallEntry(
  879. nsp, true, qt_raw_copy);
  880. if (res2 == FileSys::InstallResult::Success) {
  881. success();
  882. } else {
  883. failed();
  884. }
  885. }
  886. } else {
  887. failed();
  888. }
  889. }
  890. } else {
  891. const auto nca = std::make_shared<FileSys::NCA>(
  892. vfs->OpenFile(filename.toStdString(), FileSys::Mode::Read));
  893. const auto id = nca->GetStatus();
  894. // Game updates necessary are missing base RomFS
  895. if (id != Loader::ResultStatus::Success &&
  896. id != Loader::ResultStatus::ErrorMissingBKTRBaseRomFS) {
  897. failed();
  898. return;
  899. }
  900. const QStringList tt_options{tr("System Application"),
  901. tr("System Archive"),
  902. tr("System Application Update"),
  903. tr("Firmware Package (Type A)"),
  904. tr("Firmware Package (Type B)"),
  905. tr("Game"),
  906. tr("Game Update"),
  907. tr("Game DLC"),
  908. tr("Delta Title")};
  909. bool ok;
  910. const auto item = QInputDialog::getItem(
  911. this, tr("Select NCA Install Type..."),
  912. tr("Please select the type of title you would like to install this NCA as:\n(In "
  913. "most instances, the default 'Game' is fine.)"),
  914. tt_options, 5, false, &ok);
  915. auto index = tt_options.indexOf(item);
  916. if (!ok || index == -1) {
  917. QMessageBox::warning(this, tr("Failed to Install"),
  918. tr("The title type you selected for the NCA is invalid."));
  919. return;
  920. }
  921. // If index is equal to or past Game, add the jump in TitleType.
  922. if (index >= 5) {
  923. index += static_cast<size_t>(FileSys::TitleType::Application) -
  924. static_cast<size_t>(FileSys::TitleType::FirmwarePackageB);
  925. }
  926. FileSys::InstallResult res;
  927. if (index >= static_cast<size_t>(FileSys::TitleType::Application)) {
  928. res = Service::FileSystem::GetUserNANDContents()->InstallEntry(
  929. nca, static_cast<FileSys::TitleType>(index), false, qt_raw_copy);
  930. } else {
  931. res = Service::FileSystem::GetSystemNANDContents()->InstallEntry(
  932. nca, static_cast<FileSys::TitleType>(index), false, qt_raw_copy);
  933. }
  934. if (res == FileSys::InstallResult::Success) {
  935. success();
  936. } else if (res == FileSys::InstallResult::ErrorAlreadyExists) {
  937. if (overwrite()) {
  938. const auto res2 = Service::FileSystem::GetUserNANDContents()->InstallEntry(
  939. nca, static_cast<FileSys::TitleType>(index), true, qt_raw_copy);
  940. if (res2 == FileSys::InstallResult::Success) {
  941. success();
  942. } else {
  943. failed();
  944. }
  945. }
  946. } else {
  947. failed();
  948. }
  949. }
  950. }
  951. void GMainWindow::OnMenuSelectGameListRoot() {
  952. QString dir_path = QFileDialog::getExistingDirectory(this, tr("Select Directory"));
  953. if (!dir_path.isEmpty()) {
  954. UISettings::values.gamedir = dir_path;
  955. game_list->PopulateAsync(dir_path, UISettings::values.gamedir_deepscan);
  956. }
  957. }
  958. void GMainWindow::OnMenuSelectEmulatedDirectory(EmulatedDirectoryTarget target) {
  959. const auto res = QMessageBox::information(
  960. this, tr("Changing Emulated Directory"),
  961. tr("You are about to change the emulated %1 directory of the system. Please note "
  962. "that this does not also move the contents of the previous directory to the "
  963. "new one and you will have to do that yourself.")
  964. .arg(target == EmulatedDirectoryTarget::SDMC ? tr("SD card") : tr("NAND")),
  965. QMessageBox::StandardButtons{QMessageBox::Ok, QMessageBox::Cancel});
  966. if (res == QMessageBox::Cancel)
  967. return;
  968. QString dir_path = QFileDialog::getExistingDirectory(this, tr("Select Directory"));
  969. if (!dir_path.isEmpty()) {
  970. FileUtil::GetUserPath(target == EmulatedDirectoryTarget::SDMC ? FileUtil::UserPath::SDMCDir
  971. : FileUtil::UserPath::NANDDir,
  972. dir_path.toStdString());
  973. Service::FileSystem::CreateFactories(*vfs);
  974. game_list->PopulateAsync(UISettings::values.gamedir, UISettings::values.gamedir_deepscan);
  975. }
  976. }
  977. void GMainWindow::OnMenuRecentFile() {
  978. QAction* action = qobject_cast<QAction*>(sender());
  979. assert(action);
  980. const QString filename = action->data().toString();
  981. if (QFileInfo::exists(filename)) {
  982. BootGame(filename);
  983. } else {
  984. // Display an error message and remove the file from the list.
  985. QMessageBox::information(this, tr("File not found"),
  986. tr("File \"%1\" not found").arg(filename));
  987. UISettings::values.recent_files.removeOne(filename);
  988. UpdateRecentFiles();
  989. }
  990. }
  991. void GMainWindow::OnStartGame() {
  992. emu_thread->SetRunning(true);
  993. qRegisterMetaType<Core::System::ResultStatus>("Core::System::ResultStatus");
  994. qRegisterMetaType<std::string>("std::string");
  995. connect(emu_thread.get(), &EmuThread::ErrorThrown, this, &GMainWindow::OnCoreError);
  996. ui.action_Start->setEnabled(false);
  997. ui.action_Start->setText(tr("Continue"));
  998. ui.action_Pause->setEnabled(true);
  999. ui.action_Stop->setEnabled(true);
  1000. ui.action_Restart->setEnabled(true);
  1001. ui.action_Report_Compatibility->setEnabled(true);
  1002. discord_rpc->Update();
  1003. }
  1004. void GMainWindow::OnPauseGame() {
  1005. emu_thread->SetRunning(false);
  1006. ui.action_Start->setEnabled(true);
  1007. ui.action_Pause->setEnabled(false);
  1008. ui.action_Stop->setEnabled(true);
  1009. }
  1010. void GMainWindow::OnStopGame() {
  1011. ShutdownGame();
  1012. }
  1013. void GMainWindow::OnMenuReportCompatibility() {
  1014. if (!Settings::values.yuzu_token.empty() && !Settings::values.yuzu_username.empty()) {
  1015. CompatDB compatdb{this};
  1016. compatdb.exec();
  1017. } else {
  1018. QMessageBox::critical(
  1019. this, tr("Missing yuzu Account"),
  1020. tr("In order to submit a game compatibility test case, you must link your yuzu "
  1021. "account.<br><br/>To link your yuzu account, go to Emulation &gt; Configuration "
  1022. "&gt; "
  1023. "Web."));
  1024. }
  1025. }
  1026. void GMainWindow::ToggleFullscreen() {
  1027. if (!emulation_running) {
  1028. return;
  1029. }
  1030. if (ui.action_Fullscreen->isChecked()) {
  1031. ShowFullscreen();
  1032. } else {
  1033. HideFullscreen();
  1034. }
  1035. }
  1036. void GMainWindow::ShowFullscreen() {
  1037. if (ui.action_Single_Window_Mode->isChecked()) {
  1038. UISettings::values.geometry = saveGeometry();
  1039. ui.menubar->hide();
  1040. statusBar()->hide();
  1041. showFullScreen();
  1042. } else {
  1043. UISettings::values.renderwindow_geometry = render_window->saveGeometry();
  1044. render_window->showFullScreen();
  1045. }
  1046. }
  1047. void GMainWindow::HideFullscreen() {
  1048. if (ui.action_Single_Window_Mode->isChecked()) {
  1049. statusBar()->setVisible(ui.action_Show_Status_Bar->isChecked());
  1050. ui.menubar->show();
  1051. showNormal();
  1052. restoreGeometry(UISettings::values.geometry);
  1053. } else {
  1054. render_window->showNormal();
  1055. render_window->restoreGeometry(UISettings::values.renderwindow_geometry);
  1056. }
  1057. }
  1058. void GMainWindow::ToggleWindowMode() {
  1059. if (ui.action_Single_Window_Mode->isChecked()) {
  1060. // Render in the main window...
  1061. render_window->BackupGeometry();
  1062. ui.horizontalLayout->addWidget(render_window);
  1063. render_window->setFocusPolicy(Qt::ClickFocus);
  1064. if (emulation_running) {
  1065. render_window->setVisible(true);
  1066. render_window->setFocus();
  1067. game_list->hide();
  1068. }
  1069. } else {
  1070. // Render in a separate window...
  1071. ui.horizontalLayout->removeWidget(render_window);
  1072. render_window->setParent(nullptr);
  1073. render_window->setFocusPolicy(Qt::NoFocus);
  1074. if (emulation_running) {
  1075. render_window->setVisible(true);
  1076. render_window->RestoreGeometry();
  1077. game_list->show();
  1078. }
  1079. }
  1080. }
  1081. void GMainWindow::OnConfigure() {
  1082. ConfigureDialog configureDialog(this, hotkey_registry);
  1083. auto old_theme = UISettings::values.theme;
  1084. const bool old_discord_presence = UISettings::values.enable_discord_presence;
  1085. auto result = configureDialog.exec();
  1086. if (result == QDialog::Accepted) {
  1087. configureDialog.applyConfiguration();
  1088. if (UISettings::values.theme != old_theme)
  1089. UpdateUITheme();
  1090. if (UISettings::values.enable_discord_presence != old_discord_presence)
  1091. SetDiscordEnabled(UISettings::values.enable_discord_presence);
  1092. game_list->PopulateAsync(UISettings::values.gamedir, UISettings::values.gamedir_deepscan);
  1093. config->Save();
  1094. }
  1095. }
  1096. void GMainWindow::OnAbout() {
  1097. AboutDialog aboutDialog(this);
  1098. aboutDialog.exec();
  1099. }
  1100. void GMainWindow::OnToggleFilterBar() {
  1101. game_list->setFilterVisible(ui.action_Show_Filter_Bar->isChecked());
  1102. if (ui.action_Show_Filter_Bar->isChecked()) {
  1103. game_list->setFilterFocus();
  1104. } else {
  1105. game_list->clearFilter();
  1106. }
  1107. }
  1108. void GMainWindow::UpdateStatusBar() {
  1109. if (emu_thread == nullptr) {
  1110. status_bar_update_timer.stop();
  1111. return;
  1112. }
  1113. auto results = Core::System::GetInstance().GetAndResetPerfStats();
  1114. if (Settings::values.use_frame_limit) {
  1115. emu_speed_label->setText(tr("Speed: %1% / %2%")
  1116. .arg(results.emulation_speed * 100.0, 0, 'f', 0)
  1117. .arg(Settings::values.frame_limit));
  1118. } else {
  1119. emu_speed_label->setText(tr("Speed: %1%").arg(results.emulation_speed * 100.0, 0, 'f', 0));
  1120. }
  1121. game_fps_label->setText(tr("Game: %1 FPS").arg(results.game_fps, 0, 'f', 0));
  1122. emu_frametime_label->setText(tr("Frame: %1 ms").arg(results.frametime * 1000.0, 0, 'f', 2));
  1123. emu_speed_label->setVisible(true);
  1124. game_fps_label->setVisible(true);
  1125. emu_frametime_label->setVisible(true);
  1126. }
  1127. void GMainWindow::OnCoreError(Core::System::ResultStatus result, std::string details) {
  1128. QMessageBox::StandardButton answer;
  1129. QString status_message;
  1130. const QString common_message = tr(
  1131. "The game you are trying to load requires additional files from your Switch to be dumped "
  1132. "before playing.<br/><br/>For more information on dumping these files, please see the "
  1133. "following wiki page: <a "
  1134. "href='https://yuzu-emu.org/wiki/"
  1135. "dumping-system-archives-and-the-shared-fonts-from-a-switch-console/'>Dumping System "
  1136. "Archives and the Shared Fonts from a Switch Console</a>.<br/><br/>Would you like to quit "
  1137. "back to the game list? Continuing emulation may result in crashes, corrupted save "
  1138. "data, or other bugs.");
  1139. switch (result) {
  1140. case Core::System::ResultStatus::ErrorSystemFiles: {
  1141. QString message = "yuzu was unable to locate a Switch system archive";
  1142. if (!details.empty()) {
  1143. message.append(tr(": %1. ").arg(details.c_str()));
  1144. } else {
  1145. message.append(". ");
  1146. }
  1147. message.append(common_message);
  1148. answer = QMessageBox::question(this, tr("System Archive Not Found"), message,
  1149. QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
  1150. status_message = "System Archive Missing";
  1151. break;
  1152. }
  1153. case Core::System::ResultStatus::ErrorSharedFont: {
  1154. QString message = tr("yuzu was unable to locate the Switch shared fonts. ");
  1155. message.append(common_message);
  1156. answer = QMessageBox::question(this, tr("Shared Fonts Not Found"), message,
  1157. QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
  1158. status_message = "Shared Font Missing";
  1159. break;
  1160. }
  1161. default:
  1162. answer = QMessageBox::question(
  1163. this, tr("Fatal Error"),
  1164. tr("yuzu has encountered a fatal error, please see the log for more details. "
  1165. "For more information on accessing the log, please see the following page: "
  1166. "<a href='https://community.citra-emu.org/t/how-to-upload-the-log-file/296'>How to "
  1167. "Upload the Log File</a>.<br/><br/>Would you like to quit back to the game list? "
  1168. "Continuing emulation may result in crashes, corrupted save data, or other bugs."),
  1169. QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
  1170. status_message = "Fatal Error encountered";
  1171. break;
  1172. }
  1173. if (answer == QMessageBox::Yes) {
  1174. if (emu_thread) {
  1175. ShutdownGame();
  1176. }
  1177. } else {
  1178. // Only show the message if the game is still running.
  1179. if (emu_thread) {
  1180. emu_thread->SetRunning(true);
  1181. message_label->setText(status_message);
  1182. message_label->setVisible(true);
  1183. }
  1184. }
  1185. }
  1186. void GMainWindow::OnReinitializeKeys(ReinitializeKeyBehavior behavior) {
  1187. if (behavior == ReinitializeKeyBehavior::Warning) {
  1188. const auto res = QMessageBox::information(
  1189. this, tr("Confirm Key Rederivation"),
  1190. tr("You are about to force rederive all of your keys. \nIf you do not know what this "
  1191. "means or what you are doing, \nthis is a potentially destructive action. \nPlease "
  1192. "make "
  1193. "sure this is what you want \nand optionally make backups.\n\nThis will delete your "
  1194. "autogenerated key files and re-run the key derivation module."),
  1195. QMessageBox::StandardButtons{QMessageBox::Ok, QMessageBox::Cancel});
  1196. if (res == QMessageBox::Cancel)
  1197. return;
  1198. FileUtil::Delete(FileUtil::GetUserPath(FileUtil::UserPath::KeysDir) +
  1199. "prod.keys_autogenerated");
  1200. FileUtil::Delete(FileUtil::GetUserPath(FileUtil::UserPath::KeysDir) +
  1201. "console.keys_autogenerated");
  1202. FileUtil::Delete(FileUtil::GetUserPath(FileUtil::UserPath::KeysDir) +
  1203. "title.keys_autogenerated");
  1204. }
  1205. Core::Crypto::KeyManager keys{};
  1206. if (keys.BaseDeriveNecessary()) {
  1207. Core::Crypto::PartitionDataManager pdm{vfs->OpenDirectory(
  1208. FileUtil::GetUserPath(FileUtil::UserPath::SysDataDir), FileSys::Mode::Read)};
  1209. const auto function = [this, &keys, &pdm] {
  1210. keys.PopulateFromPartitionData(pdm);
  1211. Service::FileSystem::CreateFactories(*vfs);
  1212. keys.DeriveETicket(pdm);
  1213. };
  1214. QString errors;
  1215. if (!pdm.HasFuses())
  1216. errors += tr("- Missing fuses - Cannot derive SBK\n");
  1217. if (!pdm.HasBoot0())
  1218. errors += tr("- Missing BOOT0 - Cannot derive master keys\n");
  1219. if (!pdm.HasPackage2())
  1220. errors += tr("- Missing BCPKG2-1-Normal-Main - Cannot derive general keys\n");
  1221. if (!pdm.HasProdInfo())
  1222. errors += tr("- Missing PRODINFO - Cannot derive title keys\n");
  1223. if (!errors.isEmpty()) {
  1224. QMessageBox::warning(
  1225. this, tr("Warning Missing Derivation Components"),
  1226. tr("The following are missing from your configuration that may hinder key "
  1227. "derivation. It will be attempted but may not complete.<br><br>") +
  1228. errors +
  1229. tr("<br><br>You can get all of these and dump all of your games easily by "
  1230. "following <a href='https://yuzu-emu.org/help/quickstart/quickstart/'>the "
  1231. "quickstart guide</a>. Alternatively, you can use another method of dumping "
  1232. "to obtain all of your keys."));
  1233. }
  1234. QProgressDialog prog;
  1235. prog.setRange(0, 0);
  1236. prog.setLabelText(tr("Deriving keys...\nThis may take up to a minute depending \non your "
  1237. "system's performance."));
  1238. prog.setWindowTitle(tr("Deriving Keys"));
  1239. prog.show();
  1240. auto future = QtConcurrent::run(function);
  1241. while (!future.isFinished()) {
  1242. QCoreApplication::processEvents();
  1243. }
  1244. prog.close();
  1245. }
  1246. Service::FileSystem::CreateFactories(*vfs);
  1247. if (behavior == ReinitializeKeyBehavior::Warning) {
  1248. game_list->PopulateAsync(UISettings::values.gamedir, UISettings::values.gamedir_deepscan);
  1249. }
  1250. }
  1251. bool GMainWindow::ConfirmClose() {
  1252. if (emu_thread == nullptr || !UISettings::values.confirm_before_closing)
  1253. return true;
  1254. QMessageBox::StandardButton answer =
  1255. QMessageBox::question(this, tr("yuzu"), tr("Are you sure you want to close yuzu?"),
  1256. QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
  1257. return answer != QMessageBox::No;
  1258. }
  1259. void GMainWindow::closeEvent(QCloseEvent* event) {
  1260. if (!ConfirmClose()) {
  1261. event->ignore();
  1262. return;
  1263. }
  1264. if (ui.action_Fullscreen->isChecked()) {
  1265. UISettings::values.geometry = saveGeometry();
  1266. UISettings::values.renderwindow_geometry = render_window->saveGeometry();
  1267. }
  1268. UISettings::values.state = saveState();
  1269. #if MICROPROFILE_ENABLED
  1270. UISettings::values.microprofile_geometry = microProfileDialog->saveGeometry();
  1271. UISettings::values.microprofile_visible = microProfileDialog->isVisible();
  1272. #endif
  1273. UISettings::values.single_window_mode = ui.action_Single_Window_Mode->isChecked();
  1274. UISettings::values.fullscreen = ui.action_Fullscreen->isChecked();
  1275. UISettings::values.display_titlebar = ui.action_Display_Dock_Widget_Headers->isChecked();
  1276. UISettings::values.show_filter_bar = ui.action_Show_Filter_Bar->isChecked();
  1277. UISettings::values.show_status_bar = ui.action_Show_Status_Bar->isChecked();
  1278. UISettings::values.first_start = false;
  1279. game_list->SaveInterfaceLayout();
  1280. hotkey_registry.SaveHotkeys();
  1281. // Shutdown session if the emu thread is active...
  1282. if (emu_thread != nullptr)
  1283. ShutdownGame();
  1284. render_window->close();
  1285. QWidget::closeEvent(event);
  1286. }
  1287. static bool IsSingleFileDropEvent(QDropEvent* event) {
  1288. const QMimeData* mimeData = event->mimeData();
  1289. return mimeData->hasUrls() && mimeData->urls().length() == 1;
  1290. }
  1291. void GMainWindow::dropEvent(QDropEvent* event) {
  1292. if (IsSingleFileDropEvent(event) && ConfirmChangeGame()) {
  1293. const QMimeData* mimeData = event->mimeData();
  1294. QString filename = mimeData->urls().at(0).toLocalFile();
  1295. BootGame(filename);
  1296. }
  1297. }
  1298. void GMainWindow::dragEnterEvent(QDragEnterEvent* event) {
  1299. if (IsSingleFileDropEvent(event)) {
  1300. event->acceptProposedAction();
  1301. }
  1302. }
  1303. void GMainWindow::dragMoveEvent(QDragMoveEvent* event) {
  1304. event->acceptProposedAction();
  1305. }
  1306. bool GMainWindow::ConfirmChangeGame() {
  1307. if (emu_thread == nullptr)
  1308. return true;
  1309. auto answer = QMessageBox::question(
  1310. this, tr("yuzu"),
  1311. tr("Are you sure you want to stop the emulation? Any unsaved progress will be lost."),
  1312. QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
  1313. return answer != QMessageBox::No;
  1314. }
  1315. void GMainWindow::filterBarSetChecked(bool state) {
  1316. ui.action_Show_Filter_Bar->setChecked(state);
  1317. emit(OnToggleFilterBar());
  1318. }
  1319. void GMainWindow::UpdateUITheme() {
  1320. QStringList theme_paths(default_theme_paths);
  1321. if (UISettings::values.theme != UISettings::themes[0].second &&
  1322. !UISettings::values.theme.isEmpty()) {
  1323. const QString theme_uri(":" + UISettings::values.theme + "/style.qss");
  1324. QFile f(theme_uri);
  1325. if (f.open(QFile::ReadOnly | QFile::Text)) {
  1326. QTextStream ts(&f);
  1327. qApp->setStyleSheet(ts.readAll());
  1328. GMainWindow::setStyleSheet(ts.readAll());
  1329. } else {
  1330. LOG_ERROR(Frontend, "Unable to set style, stylesheet file not found");
  1331. }
  1332. theme_paths.append(QStringList{":/icons/default", ":/icons/" + UISettings::values.theme});
  1333. QIcon::setThemeName(":/icons/" + UISettings::values.theme);
  1334. } else {
  1335. qApp->setStyleSheet("");
  1336. GMainWindow::setStyleSheet("");
  1337. theme_paths.append(QStringList{":/icons/default"});
  1338. QIcon::setThemeName(":/icons/default");
  1339. }
  1340. QIcon::setThemeSearchPaths(theme_paths);
  1341. emit UpdateThemedIcons();
  1342. }
  1343. void GMainWindow::SetDiscordEnabled(bool state) {
  1344. #ifdef USE_DISCORD_PRESENCE
  1345. if (state) {
  1346. discord_rpc = std::make_unique<DiscordRPC::DiscordImpl>();
  1347. } else {
  1348. discord_rpc = std::make_unique<DiscordRPC::NullImpl>();
  1349. }
  1350. #else
  1351. discord_rpc = std::make_unique<DiscordRPC::NullImpl>();
  1352. #endif
  1353. discord_rpc->Update();
  1354. }
  1355. #ifdef main
  1356. #undef main
  1357. #endif
  1358. int main(int argc, char* argv[]) {
  1359. Common::DetachedTasks detached_tasks;
  1360. MicroProfileOnThreadCreate("Frontend");
  1361. SCOPE_EXIT({ MicroProfileShutdown(); });
  1362. // Init settings params
  1363. QCoreApplication::setOrganizationName("yuzu team");
  1364. QCoreApplication::setApplicationName("yuzu");
  1365. QApplication::setAttribute(Qt::AA_DontCheckOpenGLContextThreadAffinity);
  1366. QApplication app(argc, argv);
  1367. // Qt changes the locale and causes issues in float conversion using std::to_string() when
  1368. // generating shaders
  1369. setlocale(LC_ALL, "C");
  1370. GMainWindow main_window;
  1371. // After settings have been loaded by GMainWindow, apply the filter
  1372. main_window.show();
  1373. int result = app.exec();
  1374. detached_tasks.WaitForAllTasks();
  1375. return result;
  1376. }