main.cpp 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265
  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. #include <fmt/ostream.h>
  9. #include <glad/glad.h>
  10. #define QT_NO_OPENGL
  11. #include <QDesktopWidget>
  12. #include <QDialogButtonBox>
  13. #include <QFileDialog>
  14. #include <QMessageBox>
  15. #include <QtGui>
  16. #include <QtWidgets>
  17. #include <fmt/format.h>
  18. #include "common/common_paths.h"
  19. #include "common/logging/backend.h"
  20. #include "common/logging/filter.h"
  21. #include "common/logging/log.h"
  22. #include "common/microprofile.h"
  23. #include "common/scm_rev.h"
  24. #include "common/scope_exit.h"
  25. #include "common/string_util.h"
  26. #include "common/telemetry.h"
  27. #include "core/core.h"
  28. #include "core/crypto/key_manager.h"
  29. #include "core/file_sys/card_image.h"
  30. #include "core/file_sys/registered_cache.h"
  31. #include "core/file_sys/savedata_factory.h"
  32. #include "core/file_sys/vfs_real.h"
  33. #include "core/hle/service/filesystem/filesystem.h"
  34. #include "core/loader/loader.h"
  35. #include "core/perf_stats.h"
  36. #include "core/settings.h"
  37. #include "core/telemetry_session.h"
  38. #include "video_core/debug_utils/debug_utils.h"
  39. #include "yuzu/about_dialog.h"
  40. #include "yuzu/bootmanager.h"
  41. #include "yuzu/configuration/config.h"
  42. #include "yuzu/configuration/configure_dialog.h"
  43. #include "yuzu/debugger/console.h"
  44. #include "yuzu/debugger/graphics/graphics_breakpoints.h"
  45. #include "yuzu/debugger/graphics/graphics_surface.h"
  46. #include "yuzu/debugger/profiler.h"
  47. #include "yuzu/debugger/wait_tree.h"
  48. #include "yuzu/game_list.h"
  49. #include "yuzu/game_list_p.h"
  50. #include "yuzu/hotkeys.h"
  51. #include "yuzu/main.h"
  52. #include "yuzu/ui_settings.h"
  53. #ifdef QT_STATICPLUGIN
  54. Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin);
  55. #endif
  56. #ifdef _WIN32
  57. extern "C" {
  58. // tells Nvidia and AMD drivers to use the dedicated GPU by default on laptops with switchable
  59. // graphics
  60. __declspec(dllexport) unsigned long NvOptimusEnablement = 0x00000001;
  61. __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
  62. }
  63. #endif
  64. /**
  65. * "Callouts" are one-time instructional messages shown to the user. In the config settings, there
  66. * is a bitfield "callout_flags" options, used to track if a message has already been shown to the
  67. * user. This is 32-bits - if we have more than 32 callouts, we should retire and recyle old ones.
  68. */
  69. enum class CalloutFlag : uint32_t {
  70. Telemetry = 0x1,
  71. };
  72. static void ShowCalloutMessage(const QString& message, CalloutFlag flag) {
  73. if (UISettings::values.callout_flags & static_cast<uint32_t>(flag)) {
  74. return;
  75. }
  76. UISettings::values.callout_flags |= static_cast<uint32_t>(flag);
  77. QMessageBox msg;
  78. msg.setText(message);
  79. msg.setStandardButtons(QMessageBox::Ok);
  80. msg.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
  81. msg.setStyleSheet("QLabel{min-width: 900px;}");
  82. msg.exec();
  83. }
  84. void GMainWindow::ShowCallouts() {}
  85. const int GMainWindow::max_recent_files_item;
  86. static void InitializeLogging() {
  87. Log::Filter log_filter;
  88. log_filter.ParseFilterString(Settings::values.log_filter);
  89. Log::SetGlobalFilter(log_filter);
  90. const std::string& log_dir = FileUtil::GetUserPath(FileUtil::UserPath::LogDir);
  91. FileUtil::CreateFullPath(log_dir);
  92. Log::AddBackend(std::make_unique<Log::FileBackend>(log_dir + LOG_FILE));
  93. }
  94. GMainWindow::GMainWindow()
  95. : config(new Config()), emu_thread(nullptr),
  96. vfs(std::make_shared<FileSys::RealVfsFilesystem>()) {
  97. InitializeLogging();
  98. debug_context = Tegra::DebugContext::Construct();
  99. setAcceptDrops(true);
  100. ui.setupUi(this);
  101. statusBar()->hide();
  102. default_theme_paths = QIcon::themeSearchPaths();
  103. UpdateUITheme();
  104. InitializeWidgets();
  105. InitializeDebugWidgets();
  106. InitializeRecentFileMenuActions();
  107. InitializeHotkeys();
  108. SetDefaultUIGeometry();
  109. RestoreUIState();
  110. ConnectMenuEvents();
  111. ConnectWidgetEvents();
  112. LOG_INFO(Frontend, "yuzu Version: {} | {}-{}", Common::g_build_name, Common::g_scm_branch,
  113. Common::g_scm_desc);
  114. setWindowTitle(QString("yuzu %1| %2-%3")
  115. .arg(Common::g_build_name, Common::g_scm_branch, Common::g_scm_desc));
  116. show();
  117. // Necessary to load titles from nand in gamelist.
  118. Service::FileSystem::CreateFactories(vfs);
  119. game_list->LoadCompatibilityList();
  120. game_list->PopulateAsync(UISettings::values.gamedir, UISettings::values.gamedir_deepscan);
  121. // Show one-time "callout" messages to the user
  122. ShowCallouts();
  123. QStringList args = QApplication::arguments();
  124. if (args.length() >= 2) {
  125. BootGame(args[1]);
  126. }
  127. }
  128. GMainWindow::~GMainWindow() {
  129. // will get automatically deleted otherwise
  130. if (render_window->parent() == nullptr)
  131. delete render_window;
  132. }
  133. void GMainWindow::InitializeWidgets() {
  134. render_window = new GRenderWindow(this, emu_thread.get());
  135. render_window->hide();
  136. game_list = new GameList(vfs, this);
  137. ui.horizontalLayout->addWidget(game_list);
  138. // Create status bar
  139. message_label = new QLabel();
  140. // Configured separately for left alignment
  141. message_label->setVisible(false);
  142. message_label->setFrameStyle(QFrame::NoFrame);
  143. message_label->setContentsMargins(4, 0, 4, 0);
  144. message_label->setAlignment(Qt::AlignLeft);
  145. statusBar()->addPermanentWidget(message_label, 1);
  146. emu_speed_label = new QLabel();
  147. emu_speed_label->setToolTip(
  148. tr("Current emulation speed. Values higher or lower than 100% "
  149. "indicate emulation is running faster or slower than a Switch."));
  150. game_fps_label = new QLabel();
  151. game_fps_label->setToolTip(tr("How many frames per second the game is currently displaying. "
  152. "This will vary from game to game and scene to scene."));
  153. emu_frametime_label = new QLabel();
  154. emu_frametime_label->setToolTip(
  155. tr("Time taken to emulate a Switch frame, not counting framelimiting or v-sync. For "
  156. "full-speed emulation this should be at most 16.67 ms."));
  157. for (auto& label : {emu_speed_label, game_fps_label, emu_frametime_label}) {
  158. label->setVisible(false);
  159. label->setFrameStyle(QFrame::NoFrame);
  160. label->setContentsMargins(4, 0, 4, 0);
  161. statusBar()->addPermanentWidget(label, 0);
  162. }
  163. statusBar()->setVisible(true);
  164. setStyleSheet("QStatusBar::item{border: none;}");
  165. }
  166. void GMainWindow::InitializeDebugWidgets() {
  167. QMenu* debug_menu = ui.menu_View_Debugging;
  168. #if MICROPROFILE_ENABLED
  169. microProfileDialog = new MicroProfileDialog(this);
  170. microProfileDialog->hide();
  171. debug_menu->addAction(microProfileDialog->toggleViewAction());
  172. #endif
  173. graphicsBreakpointsWidget = new GraphicsBreakPointsWidget(debug_context, this);
  174. addDockWidget(Qt::RightDockWidgetArea, graphicsBreakpointsWidget);
  175. graphicsBreakpointsWidget->hide();
  176. debug_menu->addAction(graphicsBreakpointsWidget->toggleViewAction());
  177. graphicsSurfaceWidget = new GraphicsSurfaceWidget(debug_context, this);
  178. addDockWidget(Qt::RightDockWidgetArea, graphicsSurfaceWidget);
  179. graphicsSurfaceWidget->hide();
  180. debug_menu->addAction(graphicsSurfaceWidget->toggleViewAction());
  181. waitTreeWidget = new WaitTreeWidget(this);
  182. addDockWidget(Qt::LeftDockWidgetArea, waitTreeWidget);
  183. waitTreeWidget->hide();
  184. debug_menu->addAction(waitTreeWidget->toggleViewAction());
  185. connect(this, &GMainWindow::EmulationStarting, waitTreeWidget,
  186. &WaitTreeWidget::OnEmulationStarting);
  187. connect(this, &GMainWindow::EmulationStopping, waitTreeWidget,
  188. &WaitTreeWidget::OnEmulationStopping);
  189. }
  190. void GMainWindow::InitializeRecentFileMenuActions() {
  191. for (int i = 0; i < max_recent_files_item; ++i) {
  192. actions_recent_files[i] = new QAction(this);
  193. actions_recent_files[i]->setVisible(false);
  194. connect(actions_recent_files[i], &QAction::triggered, this, &GMainWindow::OnMenuRecentFile);
  195. ui.menu_recent_files->addAction(actions_recent_files[i]);
  196. }
  197. ui.menu_recent_files->addSeparator();
  198. QAction* action_clear_recent_files = new QAction(this);
  199. action_clear_recent_files->setText(tr("Clear Recent Files"));
  200. connect(action_clear_recent_files, &QAction::triggered, this, [this] {
  201. UISettings::values.recent_files.clear();
  202. UpdateRecentFiles();
  203. });
  204. ui.menu_recent_files->addAction(action_clear_recent_files);
  205. UpdateRecentFiles();
  206. }
  207. void GMainWindow::InitializeHotkeys() {
  208. hotkey_registry.RegisterHotkey("Main Window", "Load File", QKeySequence::Open);
  209. hotkey_registry.RegisterHotkey("Main Window", "Start Emulation");
  210. hotkey_registry.RegisterHotkey("Main Window", "Continue/Pause", QKeySequence(Qt::Key_F4));
  211. hotkey_registry.RegisterHotkey("Main Window", "Restart", QKeySequence(Qt::Key_F5));
  212. hotkey_registry.RegisterHotkey("Main Window", "Fullscreen", QKeySequence::FullScreen);
  213. hotkey_registry.RegisterHotkey("Main Window", "Exit Fullscreen", QKeySequence(Qt::Key_Escape),
  214. Qt::ApplicationShortcut);
  215. hotkey_registry.RegisterHotkey("Main Window", "Toggle Speed Limit", QKeySequence("CTRL+Z"),
  216. Qt::ApplicationShortcut);
  217. hotkey_registry.RegisterHotkey("Main Window", "Increase Speed Limit", QKeySequence("+"),
  218. Qt::ApplicationShortcut);
  219. hotkey_registry.RegisterHotkey("Main Window", "Decrease Speed Limit", QKeySequence("-"),
  220. Qt::ApplicationShortcut);
  221. hotkey_registry.LoadHotkeys();
  222. connect(hotkey_registry.GetHotkey("Main Window", "Load File", this), &QShortcut::activated,
  223. this, &GMainWindow::OnMenuLoadFile);
  224. connect(hotkey_registry.GetHotkey("Main Window", "Start Emulation", this),
  225. &QShortcut::activated, this, &GMainWindow::OnStartGame);
  226. connect(hotkey_registry.GetHotkey("Main Window", "Continue/Pause", this), &QShortcut::activated,
  227. this, [&] {
  228. if (emulation_running) {
  229. if (emu_thread->IsRunning()) {
  230. OnPauseGame();
  231. } else {
  232. OnStartGame();
  233. }
  234. }
  235. });
  236. connect(hotkey_registry.GetHotkey("Main Window", "Restart", this), &QShortcut::activated, this,
  237. [this] {
  238. if (!Core::System::GetInstance().IsPoweredOn())
  239. return;
  240. BootGame(QString(game_path));
  241. });
  242. connect(hotkey_registry.GetHotkey("Main Window", "Fullscreen", render_window),
  243. &QShortcut::activated, ui.action_Fullscreen, &QAction::trigger);
  244. connect(hotkey_registry.GetHotkey("Main Window", "Fullscreen", render_window),
  245. &QShortcut::activatedAmbiguously, ui.action_Fullscreen, &QAction::trigger);
  246. connect(hotkey_registry.GetHotkey("Main Window", "Exit Fullscreen", this),
  247. &QShortcut::activated, this, [&] {
  248. if (emulation_running) {
  249. ui.action_Fullscreen->setChecked(false);
  250. ToggleFullscreen();
  251. }
  252. });
  253. connect(hotkey_registry.GetHotkey("Main Window", "Toggle Speed Limit", this),
  254. &QShortcut::activated, this, [&] {
  255. Settings::values.use_frame_limit = !Settings::values.use_frame_limit;
  256. UpdateStatusBar();
  257. });
  258. constexpr u16 SPEED_LIMIT_STEP = 5;
  259. connect(hotkey_registry.GetHotkey("Main Window", "Increase Speed Limit", this),
  260. &QShortcut::activated, this, [&] {
  261. if (Settings::values.frame_limit < 9999 - SPEED_LIMIT_STEP) {
  262. Settings::values.frame_limit += SPEED_LIMIT_STEP;
  263. UpdateStatusBar();
  264. }
  265. });
  266. connect(hotkey_registry.GetHotkey("Main Window", "Decrease Speed Limit", this),
  267. &QShortcut::activated, this, [&] {
  268. if (Settings::values.frame_limit > SPEED_LIMIT_STEP) {
  269. Settings::values.frame_limit -= SPEED_LIMIT_STEP;
  270. UpdateStatusBar();
  271. }
  272. });
  273. }
  274. void GMainWindow::SetDefaultUIGeometry() {
  275. // geometry: 55% of the window contents are in the upper screen half, 45% in the lower half
  276. const QRect screenRect = QApplication::desktop()->screenGeometry(this);
  277. const int w = screenRect.width() * 2 / 3;
  278. const int h = screenRect.height() / 2;
  279. const int x = (screenRect.x() + screenRect.width()) / 2 - w / 2;
  280. const int y = (screenRect.y() + screenRect.height()) / 2 - h * 55 / 100;
  281. setGeometry(x, y, w, h);
  282. }
  283. void GMainWindow::RestoreUIState() {
  284. restoreGeometry(UISettings::values.geometry);
  285. restoreState(UISettings::values.state);
  286. render_window->restoreGeometry(UISettings::values.renderwindow_geometry);
  287. #if MICROPROFILE_ENABLED
  288. microProfileDialog->restoreGeometry(UISettings::values.microprofile_geometry);
  289. microProfileDialog->setVisible(UISettings::values.microprofile_visible);
  290. #endif
  291. game_list->LoadInterfaceLayout();
  292. ui.action_Single_Window_Mode->setChecked(UISettings::values.single_window_mode);
  293. ToggleWindowMode();
  294. ui.action_Fullscreen->setChecked(UISettings::values.fullscreen);
  295. ui.action_Display_Dock_Widget_Headers->setChecked(UISettings::values.display_titlebar);
  296. OnDisplayTitleBars(ui.action_Display_Dock_Widget_Headers->isChecked());
  297. ui.action_Show_Filter_Bar->setChecked(UISettings::values.show_filter_bar);
  298. game_list->setFilterVisible(ui.action_Show_Filter_Bar->isChecked());
  299. ui.action_Show_Status_Bar->setChecked(UISettings::values.show_status_bar);
  300. statusBar()->setVisible(ui.action_Show_Status_Bar->isChecked());
  301. Debugger::ToggleConsole();
  302. }
  303. void GMainWindow::ConnectWidgetEvents() {
  304. connect(game_list, &GameList::GameChosen, this, &GMainWindow::OnGameListLoadFile);
  305. connect(game_list, &GameList::OpenFolderRequested, this, &GMainWindow::OnGameListOpenFolder);
  306. connect(game_list, &GameList::NavigateToGamedbEntryRequested, this,
  307. &GMainWindow::OnGameListNavigateToGamedbEntry);
  308. connect(this, &GMainWindow::EmulationStarting, render_window,
  309. &GRenderWindow::OnEmulationStarting);
  310. connect(this, &GMainWindow::EmulationStopping, render_window,
  311. &GRenderWindow::OnEmulationStopping);
  312. connect(&status_bar_update_timer, &QTimer::timeout, this, &GMainWindow::UpdateStatusBar);
  313. }
  314. void GMainWindow::ConnectMenuEvents() {
  315. // File
  316. connect(ui.action_Load_File, &QAction::triggered, this, &GMainWindow::OnMenuLoadFile);
  317. connect(ui.action_Load_Folder, &QAction::triggered, this, &GMainWindow::OnMenuLoadFolder);
  318. connect(ui.action_Install_File_NAND, &QAction::triggered, this,
  319. &GMainWindow::OnMenuInstallToNAND);
  320. connect(ui.action_Select_Game_List_Root, &QAction::triggered, this,
  321. &GMainWindow::OnMenuSelectGameListRoot);
  322. connect(ui.action_Select_NAND_Directory, &QAction::triggered, this,
  323. [this] { OnMenuSelectEmulatedDirectory(EmulatedDirectoryTarget::NAND); });
  324. connect(ui.action_Select_SDMC_Directory, &QAction::triggered, this,
  325. [this] { OnMenuSelectEmulatedDirectory(EmulatedDirectoryTarget::SDMC); });
  326. connect(ui.action_Exit, &QAction::triggered, this, &QMainWindow::close);
  327. // Emulation
  328. connect(ui.action_Start, &QAction::triggered, this, &GMainWindow::OnStartGame);
  329. connect(ui.action_Pause, &QAction::triggered, this, &GMainWindow::OnPauseGame);
  330. connect(ui.action_Stop, &QAction::triggered, this, &GMainWindow::OnStopGame);
  331. connect(ui.action_Restart, &QAction::triggered, this, [this] { BootGame(QString(game_path)); });
  332. connect(ui.action_Configure, &QAction::triggered, this, &GMainWindow::OnConfigure);
  333. // View
  334. connect(ui.action_Single_Window_Mode, &QAction::triggered, this,
  335. &GMainWindow::ToggleWindowMode);
  336. connect(ui.action_Display_Dock_Widget_Headers, &QAction::triggered, this,
  337. &GMainWindow::OnDisplayTitleBars);
  338. ui.action_Show_Filter_Bar->setShortcut(tr("CTRL+F"));
  339. connect(ui.action_Show_Filter_Bar, &QAction::triggered, this, &GMainWindow::OnToggleFilterBar);
  340. connect(ui.action_Show_Status_Bar, &QAction::triggered, statusBar(), &QStatusBar::setVisible);
  341. // Fullscreen
  342. ui.action_Fullscreen->setShortcut(
  343. hotkey_registry.GetHotkey("Main Window", "Fullscreen", this)->key());
  344. connect(ui.action_Fullscreen, &QAction::triggered, this, &GMainWindow::ToggleFullscreen);
  345. // Help
  346. connect(ui.action_About, &QAction::triggered, this, &GMainWindow::OnAbout);
  347. }
  348. void GMainWindow::OnDisplayTitleBars(bool show) {
  349. QList<QDockWidget*> widgets = findChildren<QDockWidget*>();
  350. if (show) {
  351. for (QDockWidget* widget : widgets) {
  352. QWidget* old = widget->titleBarWidget();
  353. widget->setTitleBarWidget(nullptr);
  354. if (old != nullptr)
  355. delete old;
  356. }
  357. } else {
  358. for (QDockWidget* widget : widgets) {
  359. QWidget* old = widget->titleBarWidget();
  360. widget->setTitleBarWidget(new QWidget());
  361. if (old != nullptr)
  362. delete old;
  363. }
  364. }
  365. }
  366. QStringList GMainWindow::GetUnsupportedGLExtensions() {
  367. QStringList unsupported_ext;
  368. if (!GLAD_GL_ARB_program_interface_query)
  369. unsupported_ext.append("ARB_program_interface_query");
  370. if (!GLAD_GL_ARB_separate_shader_objects)
  371. unsupported_ext.append("ARB_separate_shader_objects");
  372. if (!GLAD_GL_ARB_vertex_attrib_binding)
  373. unsupported_ext.append("ARB_vertex_attrib_binding");
  374. if (!GLAD_GL_ARB_vertex_type_10f_11f_11f_rev)
  375. unsupported_ext.append("ARB_vertex_type_10f_11f_11f_rev");
  376. if (!GLAD_GL_ARB_texture_mirror_clamp_to_edge)
  377. unsupported_ext.append("ARB_texture_mirror_clamp_to_edge");
  378. // Extensions required to support some texture formats.
  379. if (!GLAD_GL_EXT_texture_compression_s3tc)
  380. unsupported_ext.append("EXT_texture_compression_s3tc");
  381. if (!GLAD_GL_ARB_texture_compression_rgtc)
  382. unsupported_ext.append("ARB_texture_compression_rgtc");
  383. if (!GLAD_GL_ARB_texture_compression_bptc)
  384. unsupported_ext.append("ARB_texture_compression_bptc");
  385. if (!GLAD_GL_ARB_depth_buffer_float)
  386. unsupported_ext.append("ARB_depth_buffer_float");
  387. for (const QString& ext : unsupported_ext)
  388. LOG_CRITICAL(Frontend, "Unsupported GL extension: {}", ext.toStdString());
  389. return unsupported_ext;
  390. }
  391. bool GMainWindow::LoadROM(const QString& filename) {
  392. // Shutdown previous session if the emu thread is still active...
  393. if (emu_thread != nullptr)
  394. ShutdownGame();
  395. render_window->InitRenderTarget();
  396. render_window->MakeCurrent();
  397. if (!gladLoadGL()) {
  398. QMessageBox::critical(this, tr("Error while initializing OpenGL 3.3 Core!"),
  399. tr("Your GPU may not support OpenGL 3.3, or you do not "
  400. "have the latest graphics driver."));
  401. return false;
  402. }
  403. QStringList unsupported_gl_extensions = GetUnsupportedGLExtensions();
  404. if (!unsupported_gl_extensions.empty()) {
  405. QMessageBox::critical(this, tr("Error while initializing OpenGL Core!"),
  406. tr("Your GPU may not support one or more required OpenGL"
  407. "extensions. Please ensure you have the latest graphics "
  408. "driver.<br><br>Unsupported extensions:<br>") +
  409. unsupported_gl_extensions.join("<br>"));
  410. return false;
  411. }
  412. Core::System& system{Core::System::GetInstance()};
  413. system.SetFilesystem(vfs);
  414. system.SetGPUDebugContext(debug_context);
  415. const Core::System::ResultStatus result{system.Load(*render_window, filename.toStdString())};
  416. render_window->DoneCurrent();
  417. if (result != Core::System::ResultStatus::Success) {
  418. switch (result) {
  419. case Core::System::ResultStatus::ErrorGetLoader:
  420. LOG_CRITICAL(Frontend, "Failed to obtain loader for {}!", filename.toStdString());
  421. QMessageBox::critical(this, tr("Error while loading ROM!"),
  422. tr("The ROM format is not supported."));
  423. break;
  424. case Core::System::ResultStatus::ErrorSystemMode:
  425. LOG_CRITICAL(Frontend, "Failed to load ROM!");
  426. QMessageBox::critical(this, tr("Error while loading ROM!"),
  427. tr("Could not determine the system mode."));
  428. break;
  429. case Core::System::ResultStatus::ErrorVideoCore:
  430. QMessageBox::critical(
  431. this, tr("An error occurred initializing the video core."),
  432. tr("yuzu has encountered an error while running the video core, please see the "
  433. "log for more details."
  434. "For more information on accessing the log, please see the following page: "
  435. "<a href='https://community.citra-emu.org/t/how-to-upload-the-log-file/296'>How "
  436. "to "
  437. "Upload the Log File</a>."
  438. "Ensure that you have the latest graphics drivers for your GPU."));
  439. break;
  440. default:
  441. if (static_cast<u32>(result) >
  442. static_cast<u32>(Core::System::ResultStatus::ErrorLoader)) {
  443. LOG_CRITICAL(Frontend, "Failed to load ROM!");
  444. const u16 loader_id = static_cast<u16>(Core::System::ResultStatus::ErrorLoader);
  445. const u16 error_id = static_cast<u16>(result) - loader_id;
  446. QMessageBox::critical(
  447. this, tr("Error while loading ROM!"),
  448. QString::fromStdString(fmt::format(
  449. "While attempting to load the ROM requested, an error occured. Please "
  450. "refer to the yuzu wiki for more information or the yuzu discord for "
  451. "additional help.\n\nError Code: {:04X}-{:04X}\nError Description: {}",
  452. loader_id, error_id, static_cast<Loader::ResultStatus>(error_id))));
  453. } else {
  454. QMessageBox::critical(
  455. this, tr("Error while loading ROM!"),
  456. tr("An unknown error occurred. Please see the log for more details."));
  457. }
  458. break;
  459. }
  460. return false;
  461. }
  462. game_path = filename;
  463. Core::Telemetry().AddField(Telemetry::FieldType::App, "Frontend", "Qt");
  464. return true;
  465. }
  466. void GMainWindow::BootGame(const QString& filename) {
  467. LOG_INFO(Frontend, "yuzu starting...");
  468. StoreRecentFile(filename); // Put the filename on top of the list
  469. if (!LoadROM(filename))
  470. return;
  471. // Create and start the emulation thread
  472. emu_thread = std::make_unique<EmuThread>(render_window);
  473. emit EmulationStarting(emu_thread.get());
  474. render_window->moveContext();
  475. emu_thread->start();
  476. connect(render_window, &GRenderWindow::Closed, this, &GMainWindow::OnStopGame);
  477. // BlockingQueuedConnection is important here, it makes sure we've finished refreshing our views
  478. // before the CPU continues
  479. connect(emu_thread.get(), &EmuThread::DebugModeEntered, waitTreeWidget,
  480. &WaitTreeWidget::OnDebugModeEntered, Qt::BlockingQueuedConnection);
  481. connect(emu_thread.get(), &EmuThread::DebugModeLeft, waitTreeWidget,
  482. &WaitTreeWidget::OnDebugModeLeft, Qt::BlockingQueuedConnection);
  483. // Update the GUI
  484. if (ui.action_Single_Window_Mode->isChecked()) {
  485. game_list->hide();
  486. }
  487. status_bar_update_timer.start(2000);
  488. std::string title_name;
  489. const auto res = Core::System::GetInstance().GetGameName(title_name);
  490. if (res != Loader::ResultStatus::Success)
  491. title_name = FileUtil::GetFilename(filename.toStdString());
  492. setWindowTitle(QString("yuzu %1| %4 | %2-%3")
  493. .arg(Common::g_build_name, Common::g_scm_branch, Common::g_scm_desc,
  494. QString::fromStdString(title_name)));
  495. render_window->show();
  496. render_window->setFocus();
  497. emulation_running = true;
  498. if (ui.action_Fullscreen->isChecked()) {
  499. ShowFullscreen();
  500. }
  501. OnStartGame();
  502. }
  503. void GMainWindow::ShutdownGame() {
  504. emu_thread->RequestStop();
  505. emit EmulationStopping();
  506. // Wait for emulation thread to complete and delete it
  507. emu_thread->wait();
  508. emu_thread = nullptr;
  509. // The emulation is stopped, so closing the window or not does not matter anymore
  510. disconnect(render_window, &GRenderWindow::Closed, this, &GMainWindow::OnStopGame);
  511. // Update the GUI
  512. ui.action_Start->setEnabled(false);
  513. ui.action_Start->setText(tr("Start"));
  514. ui.action_Pause->setEnabled(false);
  515. ui.action_Stop->setEnabled(false);
  516. ui.action_Restart->setEnabled(false);
  517. render_window->hide();
  518. game_list->show();
  519. game_list->setFilterFocus();
  520. setWindowTitle(QString("yuzu %1| %2-%3")
  521. .arg(Common::g_build_name, Common::g_scm_branch, Common::g_scm_desc));
  522. // Disable status bar updates
  523. status_bar_update_timer.stop();
  524. message_label->setVisible(false);
  525. emu_speed_label->setVisible(false);
  526. game_fps_label->setVisible(false);
  527. emu_frametime_label->setVisible(false);
  528. emulation_running = false;
  529. game_path.clear();
  530. }
  531. void GMainWindow::StoreRecentFile(const QString& filename) {
  532. UISettings::values.recent_files.prepend(filename);
  533. UISettings::values.recent_files.removeDuplicates();
  534. while (UISettings::values.recent_files.size() > max_recent_files_item) {
  535. UISettings::values.recent_files.removeLast();
  536. }
  537. UpdateRecentFiles();
  538. }
  539. void GMainWindow::UpdateRecentFiles() {
  540. const int num_recent_files =
  541. std::min(UISettings::values.recent_files.size(), max_recent_files_item);
  542. for (int i = 0; i < num_recent_files; i++) {
  543. const QString text = QString("&%1. %2").arg(i + 1).arg(
  544. QFileInfo(UISettings::values.recent_files[i]).fileName());
  545. actions_recent_files[i]->setText(text);
  546. actions_recent_files[i]->setData(UISettings::values.recent_files[i]);
  547. actions_recent_files[i]->setToolTip(UISettings::values.recent_files[i]);
  548. actions_recent_files[i]->setVisible(true);
  549. }
  550. for (int j = num_recent_files; j < max_recent_files_item; ++j) {
  551. actions_recent_files[j]->setVisible(false);
  552. }
  553. // Enable the recent files menu if the list isn't empty
  554. ui.menu_recent_files->setEnabled(num_recent_files != 0);
  555. }
  556. void GMainWindow::OnGameListLoadFile(QString game_path) {
  557. BootGame(game_path);
  558. }
  559. void GMainWindow::OnGameListOpenFolder(u64 program_id, GameListOpenTarget target) {
  560. std::string path;
  561. std::string open_target;
  562. switch (target) {
  563. case GameListOpenTarget::SaveData: {
  564. open_target = "Save Data";
  565. const std::string nand_dir = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir);
  566. ASSERT(program_id != 0);
  567. // TODO(tech4me): Update this to work with arbitrary user profile
  568. // Refer to core/hle/service/acc/profile_manager.cpp ProfileManager constructor
  569. constexpr u128 user_id = {1, 0};
  570. path = nand_dir + FileSys::SaveDataFactory::GetFullPath(FileSys::SaveDataSpaceId::NandUser,
  571. FileSys::SaveDataType::SaveData,
  572. program_id, user_id, 0);
  573. break;
  574. }
  575. default:
  576. UNIMPLEMENTED();
  577. }
  578. const QString qpath = QString::fromStdString(path);
  579. const QDir dir(qpath);
  580. if (!dir.exists()) {
  581. QMessageBox::warning(this,
  582. tr("Error Opening %1 Folder").arg(QString::fromStdString(open_target)),
  583. tr("Folder does not exist!"));
  584. return;
  585. }
  586. LOG_INFO(Frontend, "Opening {} path for program_id={:016x}", open_target, program_id);
  587. QDesktopServices::openUrl(QUrl::fromLocalFile(qpath));
  588. }
  589. void GMainWindow::OnGameListNavigateToGamedbEntry(
  590. u64 program_id,
  591. std::unordered_map<std::string, std::pair<QString, QString>>& compatibility_list) {
  592. auto it = FindMatchingCompatibilityEntry(compatibility_list, program_id);
  593. QString directory;
  594. if (it != compatibility_list.end())
  595. directory = it->second.second;
  596. QDesktopServices::openUrl(QUrl("https://yuzu-emu.org/game/" + directory));
  597. }
  598. void GMainWindow::OnMenuLoadFile() {
  599. QString extensions;
  600. for (const auto& piece : game_list->supported_file_extensions)
  601. extensions += "*." + piece + " ";
  602. extensions += "main ";
  603. QString file_filter = tr("Switch Executable") + " (" + extensions + ")";
  604. file_filter += ";;" + tr("All Files (*.*)");
  605. QString filename = QFileDialog::getOpenFileName(this, tr("Load File"),
  606. UISettings::values.roms_path, file_filter);
  607. if (!filename.isEmpty()) {
  608. UISettings::values.roms_path = QFileInfo(filename).path();
  609. BootGame(filename);
  610. }
  611. }
  612. void GMainWindow::OnMenuLoadFolder() {
  613. const QString dir_path =
  614. QFileDialog::getExistingDirectory(this, tr("Open Extracted ROM Directory"));
  615. if (dir_path.isNull()) {
  616. return;
  617. }
  618. const QDir dir{dir_path};
  619. const QStringList matching_main = dir.entryList(QStringList("main"), QDir::Files);
  620. if (matching_main.size() == 1) {
  621. BootGame(dir.path() + DIR_SEP + matching_main[0]);
  622. } else {
  623. QMessageBox::warning(this, tr("Invalid Directory Selected"),
  624. tr("The directory you have selected does not contain a 'main' file."));
  625. }
  626. }
  627. void GMainWindow::OnMenuInstallToNAND() {
  628. const QString file_filter =
  629. tr("Installable Switch File (*.nca *.xci);;Nintendo Content Archive (*.nca);;NX Cartridge "
  630. "Image (*.xci)");
  631. QString filename = QFileDialog::getOpenFileName(this, tr("Install File"),
  632. UISettings::values.roms_path, file_filter);
  633. if (filename.isEmpty()) {
  634. return;
  635. }
  636. const auto qt_raw_copy = [this](FileSys::VirtualFile src, FileSys::VirtualFile dest) {
  637. if (src == nullptr || dest == nullptr)
  638. return false;
  639. if (!dest->Resize(src->GetSize()))
  640. return false;
  641. std::array<u8, 0x1000> buffer{};
  642. const int progress_maximum = static_cast<int>(src->GetSize() / buffer.size());
  643. QProgressDialog progress(
  644. tr("Installing file \"%1\"...").arg(QString::fromStdString(src->GetName())),
  645. tr("Cancel"), 0, progress_maximum, this);
  646. progress.setWindowModality(Qt::WindowModal);
  647. for (size_t i = 0; i < src->GetSize(); i += buffer.size()) {
  648. if (progress.wasCanceled()) {
  649. dest->Resize(0);
  650. return false;
  651. }
  652. const int progress_value = static_cast<int>(i / buffer.size());
  653. progress.setValue(progress_value);
  654. const auto read = src->Read(buffer.data(), buffer.size(), i);
  655. dest->Write(buffer.data(), read, i);
  656. }
  657. return true;
  658. };
  659. const auto success = [this]() {
  660. QMessageBox::information(this, tr("Successfully Installed"),
  661. tr("The file was successfully installed."));
  662. game_list->PopulateAsync(UISettings::values.gamedir, UISettings::values.gamedir_deepscan);
  663. };
  664. const auto failed = [this]() {
  665. QMessageBox::warning(
  666. this, tr("Failed to Install"),
  667. tr("There was an error while attempting to install the provided file. It "
  668. "could have an incorrect format or be missing metadata. Please "
  669. "double-check your file and try again."));
  670. };
  671. const auto overwrite = [this]() {
  672. return QMessageBox::question(this, tr("Failed to Install"),
  673. tr("The file you are attempting to install already exists "
  674. "in the cache. Would you like to overwrite it?")) ==
  675. QMessageBox::Yes;
  676. };
  677. if (filename.endsWith("xci", Qt::CaseInsensitive)) {
  678. const auto xci = std::make_shared<FileSys::XCI>(
  679. vfs->OpenFile(filename.toStdString(), FileSys::Mode::Read));
  680. if (xci->GetStatus() != Loader::ResultStatus::Success) {
  681. failed();
  682. return;
  683. }
  684. const auto res =
  685. Service::FileSystem::GetUserNANDContents()->InstallEntry(xci, false, qt_raw_copy);
  686. if (res == FileSys::InstallResult::Success) {
  687. success();
  688. } else {
  689. if (res == FileSys::InstallResult::ErrorAlreadyExists) {
  690. if (overwrite()) {
  691. const auto res2 = Service::FileSystem::GetUserNANDContents()->InstallEntry(
  692. xci, true, qt_raw_copy);
  693. if (res2 == FileSys::InstallResult::Success) {
  694. success();
  695. } else {
  696. failed();
  697. }
  698. }
  699. } else {
  700. failed();
  701. }
  702. }
  703. } else {
  704. const auto nca = std::make_shared<FileSys::NCA>(
  705. vfs->OpenFile(filename.toStdString(), FileSys::Mode::Read));
  706. if (nca->GetStatus() != Loader::ResultStatus::Success) {
  707. failed();
  708. return;
  709. }
  710. const QStringList tt_options{tr("System Application"),
  711. tr("System Archive"),
  712. tr("System Application Update"),
  713. tr("Firmware Package (Type A)"),
  714. tr("Firmware Package (Type B)"),
  715. tr("Game"),
  716. tr("Game Update"),
  717. tr("Game DLC"),
  718. tr("Delta Title")};
  719. bool ok;
  720. const auto item = QInputDialog::getItem(
  721. this, tr("Select NCA Install Type..."),
  722. tr("Please select the type of title you would like to install this NCA as:\n(In "
  723. "most instances, the default 'Game' is fine.)"),
  724. tt_options, 5, false, &ok);
  725. auto index = tt_options.indexOf(item);
  726. if (!ok || index == -1) {
  727. QMessageBox::warning(this, tr("Failed to Install"),
  728. tr("The title type you selected for the NCA is invalid."));
  729. return;
  730. }
  731. if (index >= 5)
  732. index += 0x7B;
  733. const auto res = Service::FileSystem::GetUserNANDContents()->InstallEntry(
  734. nca, static_cast<FileSys::TitleType>(index), false, qt_raw_copy);
  735. if (res == FileSys::InstallResult::Success) {
  736. success();
  737. } else if (res == FileSys::InstallResult::ErrorAlreadyExists) {
  738. if (overwrite()) {
  739. const auto res2 = Service::FileSystem::GetUserNANDContents()->InstallEntry(
  740. nca, static_cast<FileSys::TitleType>(index), true, qt_raw_copy);
  741. if (res2 == FileSys::InstallResult::Success) {
  742. success();
  743. } else {
  744. failed();
  745. }
  746. }
  747. } else {
  748. failed();
  749. }
  750. }
  751. }
  752. void GMainWindow::OnMenuSelectGameListRoot() {
  753. QString dir_path = QFileDialog::getExistingDirectory(this, tr("Select Directory"));
  754. if (!dir_path.isEmpty()) {
  755. UISettings::values.gamedir = dir_path;
  756. game_list->PopulateAsync(dir_path, UISettings::values.gamedir_deepscan);
  757. }
  758. }
  759. void GMainWindow::OnMenuSelectEmulatedDirectory(EmulatedDirectoryTarget target) {
  760. const auto res = QMessageBox::information(
  761. this, tr("Changing Emulated Directory"),
  762. tr("You are about to change the emulated %1 directory of the system. Please note "
  763. "that this does not also move the contents of the previous directory to the "
  764. "new one and you will have to do that yourself.")
  765. .arg(target == EmulatedDirectoryTarget::SDMC ? tr("SD card") : tr("NAND")),
  766. QMessageBox::StandardButtons{QMessageBox::Ok, QMessageBox::Cancel});
  767. if (res == QMessageBox::Cancel)
  768. return;
  769. QString dir_path = QFileDialog::getExistingDirectory(this, tr("Select Directory"));
  770. if (!dir_path.isEmpty()) {
  771. FileUtil::GetUserPath(target == EmulatedDirectoryTarget::SDMC ? FileUtil::UserPath::SDMCDir
  772. : FileUtil::UserPath::NANDDir,
  773. dir_path.toStdString());
  774. Service::FileSystem::CreateFactories(vfs);
  775. game_list->PopulateAsync(UISettings::values.gamedir, UISettings::values.gamedir_deepscan);
  776. }
  777. }
  778. void GMainWindow::OnMenuRecentFile() {
  779. QAction* action = qobject_cast<QAction*>(sender());
  780. assert(action);
  781. const QString filename = action->data().toString();
  782. if (QFileInfo::exists(filename)) {
  783. BootGame(filename);
  784. } else {
  785. // Display an error message and remove the file from the list.
  786. QMessageBox::information(this, tr("File not found"),
  787. tr("File \"%1\" not found").arg(filename));
  788. UISettings::values.recent_files.removeOne(filename);
  789. UpdateRecentFiles();
  790. }
  791. }
  792. void GMainWindow::OnStartGame() {
  793. emu_thread->SetRunning(true);
  794. qRegisterMetaType<Core::System::ResultStatus>("Core::System::ResultStatus");
  795. qRegisterMetaType<std::string>("std::string");
  796. connect(emu_thread.get(), &EmuThread::ErrorThrown, this, &GMainWindow::OnCoreError);
  797. ui.action_Start->setEnabled(false);
  798. ui.action_Start->setText(tr("Continue"));
  799. ui.action_Pause->setEnabled(true);
  800. ui.action_Stop->setEnabled(true);
  801. ui.action_Restart->setEnabled(true);
  802. }
  803. void GMainWindow::OnPauseGame() {
  804. emu_thread->SetRunning(false);
  805. ui.action_Start->setEnabled(true);
  806. ui.action_Pause->setEnabled(false);
  807. ui.action_Stop->setEnabled(true);
  808. }
  809. void GMainWindow::OnStopGame() {
  810. ShutdownGame();
  811. }
  812. void GMainWindow::ToggleFullscreen() {
  813. if (!emulation_running) {
  814. return;
  815. }
  816. if (ui.action_Fullscreen->isChecked()) {
  817. ShowFullscreen();
  818. } else {
  819. HideFullscreen();
  820. }
  821. }
  822. void GMainWindow::ShowFullscreen() {
  823. if (ui.action_Single_Window_Mode->isChecked()) {
  824. UISettings::values.geometry = saveGeometry();
  825. ui.menubar->hide();
  826. statusBar()->hide();
  827. showFullScreen();
  828. } else {
  829. UISettings::values.renderwindow_geometry = render_window->saveGeometry();
  830. render_window->showFullScreen();
  831. }
  832. }
  833. void GMainWindow::HideFullscreen() {
  834. if (ui.action_Single_Window_Mode->isChecked()) {
  835. statusBar()->setVisible(ui.action_Show_Status_Bar->isChecked());
  836. ui.menubar->show();
  837. showNormal();
  838. restoreGeometry(UISettings::values.geometry);
  839. } else {
  840. render_window->showNormal();
  841. render_window->restoreGeometry(UISettings::values.renderwindow_geometry);
  842. }
  843. }
  844. void GMainWindow::ToggleWindowMode() {
  845. if (ui.action_Single_Window_Mode->isChecked()) {
  846. // Render in the main window...
  847. render_window->BackupGeometry();
  848. ui.horizontalLayout->addWidget(render_window);
  849. render_window->setFocusPolicy(Qt::ClickFocus);
  850. if (emulation_running) {
  851. render_window->setVisible(true);
  852. render_window->setFocus();
  853. game_list->hide();
  854. }
  855. } else {
  856. // Render in a separate window...
  857. ui.horizontalLayout->removeWidget(render_window);
  858. render_window->setParent(nullptr);
  859. render_window->setFocusPolicy(Qt::NoFocus);
  860. if (emulation_running) {
  861. render_window->setVisible(true);
  862. render_window->RestoreGeometry();
  863. game_list->show();
  864. }
  865. }
  866. }
  867. void GMainWindow::OnConfigure() {
  868. ConfigureDialog configureDialog(this, hotkey_registry);
  869. auto old_theme = UISettings::values.theme;
  870. auto result = configureDialog.exec();
  871. if (result == QDialog::Accepted) {
  872. configureDialog.applyConfiguration();
  873. if (UISettings::values.theme != old_theme)
  874. UpdateUITheme();
  875. game_list->PopulateAsync(UISettings::values.gamedir, UISettings::values.gamedir_deepscan);
  876. config->Save();
  877. }
  878. }
  879. void GMainWindow::OnAbout() {
  880. AboutDialog aboutDialog(this);
  881. aboutDialog.exec();
  882. }
  883. void GMainWindow::OnToggleFilterBar() {
  884. game_list->setFilterVisible(ui.action_Show_Filter_Bar->isChecked());
  885. if (ui.action_Show_Filter_Bar->isChecked()) {
  886. game_list->setFilterFocus();
  887. } else {
  888. game_list->clearFilter();
  889. }
  890. }
  891. void GMainWindow::UpdateStatusBar() {
  892. if (emu_thread == nullptr) {
  893. status_bar_update_timer.stop();
  894. return;
  895. }
  896. auto results = Core::System::GetInstance().GetAndResetPerfStats();
  897. if (Settings::values.use_frame_limit) {
  898. emu_speed_label->setText(tr("Speed: %1% / %2%")
  899. .arg(results.emulation_speed * 100.0, 0, 'f', 0)
  900. .arg(Settings::values.frame_limit));
  901. } else {
  902. emu_speed_label->setText(tr("Speed: %1%").arg(results.emulation_speed * 100.0, 0, 'f', 0));
  903. }
  904. game_fps_label->setText(tr("Game: %1 FPS").arg(results.game_fps, 0, 'f', 0));
  905. emu_frametime_label->setText(tr("Frame: %1 ms").arg(results.frametime * 1000.0, 0, 'f', 2));
  906. emu_speed_label->setVisible(true);
  907. game_fps_label->setVisible(true);
  908. emu_frametime_label->setVisible(true);
  909. }
  910. void GMainWindow::OnCoreError(Core::System::ResultStatus result, std::string details) {
  911. QMessageBox::StandardButton answer;
  912. QString status_message;
  913. const QString common_message = tr(
  914. "The game you are trying to load requires additional files from your Switch to be dumped "
  915. "before playing.<br/><br/>For more information on dumping these files, please see the "
  916. "following wiki page: <a "
  917. "href='https://yuzu-emu.org/wiki/"
  918. "dumping-system-archives-and-the-shared-fonts-from-a-switch-console/'>Dumping System "
  919. "Archives and the Shared Fonts from a Switch Console</a>.<br/><br/>Would you like to quit "
  920. "back to the game list? Continuing emulation may result in crashes, corrupted save "
  921. "data, or other bugs.");
  922. switch (result) {
  923. case Core::System::ResultStatus::ErrorSystemFiles: {
  924. QString message = "yuzu was unable to locate a Switch system archive";
  925. if (!details.empty()) {
  926. message.append(tr(": %1. ").arg(details.c_str()));
  927. } else {
  928. message.append(". ");
  929. }
  930. message.append(common_message);
  931. answer = QMessageBox::question(this, tr("System Archive Not Found"), message,
  932. QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
  933. status_message = "System Archive Missing";
  934. break;
  935. }
  936. case Core::System::ResultStatus::ErrorSharedFont: {
  937. QString message = tr("yuzu was unable to locate the Switch shared fonts. ");
  938. message.append(common_message);
  939. answer = QMessageBox::question(this, tr("Shared Fonts Not Found"), message,
  940. QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
  941. status_message = "Shared Font Missing";
  942. break;
  943. }
  944. default:
  945. answer = QMessageBox::question(
  946. this, tr("Fatal Error"),
  947. tr("yuzu has encountered a fatal error, please see the log for more details. "
  948. "For more information on accessing the log, please see the following page: "
  949. "<a href='https://community.citra-emu.org/t/how-to-upload-the-log-file/296'>How to "
  950. "Upload the Log File</a>.<br/><br/>Would you like to quit back to the game list? "
  951. "Continuing emulation may result in crashes, corrupted save data, or other bugs."),
  952. QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
  953. status_message = "Fatal Error encountered";
  954. break;
  955. }
  956. if (answer == QMessageBox::Yes) {
  957. if (emu_thread) {
  958. ShutdownGame();
  959. }
  960. } else {
  961. // Only show the message if the game is still running.
  962. if (emu_thread) {
  963. emu_thread->SetRunning(true);
  964. message_label->setText(status_message);
  965. message_label->setVisible(true);
  966. }
  967. }
  968. }
  969. bool GMainWindow::ConfirmClose() {
  970. if (emu_thread == nullptr || !UISettings::values.confirm_before_closing)
  971. return true;
  972. QMessageBox::StandardButton answer =
  973. QMessageBox::question(this, tr("yuzu"), tr("Are you sure you want to close yuzu?"),
  974. QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
  975. return answer != QMessageBox::No;
  976. }
  977. void GMainWindow::closeEvent(QCloseEvent* event) {
  978. if (!ConfirmClose()) {
  979. event->ignore();
  980. return;
  981. }
  982. if (ui.action_Fullscreen->isChecked()) {
  983. UISettings::values.geometry = saveGeometry();
  984. UISettings::values.renderwindow_geometry = render_window->saveGeometry();
  985. }
  986. UISettings::values.state = saveState();
  987. #if MICROPROFILE_ENABLED
  988. UISettings::values.microprofile_geometry = microProfileDialog->saveGeometry();
  989. UISettings::values.microprofile_visible = microProfileDialog->isVisible();
  990. #endif
  991. UISettings::values.single_window_mode = ui.action_Single_Window_Mode->isChecked();
  992. UISettings::values.fullscreen = ui.action_Fullscreen->isChecked();
  993. UISettings::values.display_titlebar = ui.action_Display_Dock_Widget_Headers->isChecked();
  994. UISettings::values.show_filter_bar = ui.action_Show_Filter_Bar->isChecked();
  995. UISettings::values.show_status_bar = ui.action_Show_Status_Bar->isChecked();
  996. UISettings::values.first_start = false;
  997. game_list->SaveInterfaceLayout();
  998. hotkey_registry.SaveHotkeys();
  999. // Shutdown session if the emu thread is active...
  1000. if (emu_thread != nullptr)
  1001. ShutdownGame();
  1002. render_window->close();
  1003. QWidget::closeEvent(event);
  1004. }
  1005. static bool IsSingleFileDropEvent(QDropEvent* event) {
  1006. const QMimeData* mimeData = event->mimeData();
  1007. return mimeData->hasUrls() && mimeData->urls().length() == 1;
  1008. }
  1009. void GMainWindow::dropEvent(QDropEvent* event) {
  1010. if (IsSingleFileDropEvent(event) && ConfirmChangeGame()) {
  1011. const QMimeData* mimeData = event->mimeData();
  1012. QString filename = mimeData->urls().at(0).toLocalFile();
  1013. BootGame(filename);
  1014. }
  1015. }
  1016. void GMainWindow::dragEnterEvent(QDragEnterEvent* event) {
  1017. if (IsSingleFileDropEvent(event)) {
  1018. event->acceptProposedAction();
  1019. }
  1020. }
  1021. void GMainWindow::dragMoveEvent(QDragMoveEvent* event) {
  1022. event->acceptProposedAction();
  1023. }
  1024. bool GMainWindow::ConfirmChangeGame() {
  1025. if (emu_thread == nullptr)
  1026. return true;
  1027. auto answer = QMessageBox::question(
  1028. this, tr("yuzu"),
  1029. tr("Are you sure you want to stop the emulation? Any unsaved progress will be lost."),
  1030. QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
  1031. return answer != QMessageBox::No;
  1032. }
  1033. void GMainWindow::filterBarSetChecked(bool state) {
  1034. ui.action_Show_Filter_Bar->setChecked(state);
  1035. emit(OnToggleFilterBar());
  1036. }
  1037. void GMainWindow::UpdateUITheme() {
  1038. QStringList theme_paths(default_theme_paths);
  1039. if (UISettings::values.theme != UISettings::themes[0].second &&
  1040. !UISettings::values.theme.isEmpty()) {
  1041. const QString theme_uri(":" + UISettings::values.theme + "/style.qss");
  1042. QFile f(theme_uri);
  1043. if (f.open(QFile::ReadOnly | QFile::Text)) {
  1044. QTextStream ts(&f);
  1045. qApp->setStyleSheet(ts.readAll());
  1046. GMainWindow::setStyleSheet(ts.readAll());
  1047. } else {
  1048. LOG_ERROR(Frontend, "Unable to set style, stylesheet file not found");
  1049. }
  1050. theme_paths.append(QStringList{":/icons/default", ":/icons/" + UISettings::values.theme});
  1051. QIcon::setThemeName(":/icons/" + UISettings::values.theme);
  1052. } else {
  1053. qApp->setStyleSheet("");
  1054. GMainWindow::setStyleSheet("");
  1055. theme_paths.append(QStringList{":/icons/default"});
  1056. QIcon::setThemeName(":/icons/default");
  1057. }
  1058. QIcon::setThemeSearchPaths(theme_paths);
  1059. emit UpdateThemedIcons();
  1060. }
  1061. #ifdef main
  1062. #undef main
  1063. #endif
  1064. int main(int argc, char* argv[]) {
  1065. MicroProfileOnThreadCreate("Frontend");
  1066. SCOPE_EXIT({ MicroProfileShutdown(); });
  1067. // Init settings params
  1068. QCoreApplication::setOrganizationName("yuzu team");
  1069. QCoreApplication::setApplicationName("yuzu");
  1070. QApplication::setAttribute(Qt::AA_DontCheckOpenGLContextThreadAffinity);
  1071. QApplication app(argc, argv);
  1072. // Qt changes the locale and causes issues in float conversion using std::to_string() when
  1073. // generating shaders
  1074. setlocale(LC_ALL, "C");
  1075. GMainWindow main_window;
  1076. // After settings have been loaded by GMainWindow, apply the filter
  1077. main_window.show();
  1078. return app.exec();
  1079. }