diff options
Diffstat (limited to 'src/citra_qt/main.cpp')
-rw-r--r-- | src/citra_qt/main.cpp | 89 |
1 files changed, 81 insertions, 8 deletions
diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index d6c27f0df..57adbc136 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include <clocale> #include <thread> #include <QDesktopWidget> @@ -171,6 +172,8 @@ GMainWindow::GMainWindow() : emu_thread(nullptr) } UpdateRecentFiles(); + confirm_before_closing = settings.value("confirmClose", true).toBool(); + // Setup connections connect(game_list, SIGNAL(GameChosen(QString)), this, SLOT(OnGameListLoadFile(QString))); connect(ui.action_Load_File, SIGNAL(triggered()), this, SLOT(OnMenuLoadFile())); @@ -208,7 +211,7 @@ GMainWindow::GMainWindow() : emu_thread(nullptr) show(); - game_list->PopulateAsync(settings.value("gameListRootDir").toString(), settings.value("gameListDeepScan").toBool()); + game_list->PopulateAsync(settings.value("gameListRootDir", ".").toString(), settings.value("gameListDeepScan", false).toBool()); QStringList args = QApplication::arguments(); if (args.length() >= 2) { @@ -246,22 +249,73 @@ void GMainWindow::OnDisplayTitleBars(bool show) } } -void GMainWindow::BootGame(const std::string& filename) { - LOG_INFO(Frontend, "Citra starting..."); - +bool GMainWindow::InitializeSystem() { // Shutdown previous session if the emu thread is still active... if (emu_thread != nullptr) ShutdownGame(); // Initialize the core emulation - System::Init(render_window); + System::Result system_result = System::Init(render_window); + if (System::Result::Success != system_result) { + switch (system_result) { + case System::Result::ErrorInitVideoCore: + QMessageBox::critical(this, tr("Error while starting Citra!"), + tr("Failed to initialize the video core!\n\n" + "Please ensure that your GPU supports OpenGL 3.3 and that you have the latest graphics driver.")); + break; + + default: + QMessageBox::critical(this, tr("Error while starting Citra!"), + tr("Unknown error (please check the log)!")); + break; + } + return false; + } + return true; +} - // Load the game - if (Loader::ResultStatus::Success != Loader::LoadFile(filename)) { +bool GMainWindow::LoadROM(const std::string& filename) { + Loader::ResultStatus result = Loader::LoadFile(filename); + if (Loader::ResultStatus::Success != result) { LOG_CRITICAL(Frontend, "Failed to load ROM!"); System::Shutdown(); - return; + + switch (result) { + case Loader::ResultStatus::ErrorEncrypted: { + // Build the MessageBox ourselves to have clickable link + QMessageBox popup_error; + popup_error.setTextFormat(Qt::RichText); + popup_error.setWindowTitle(tr("Error while loading ROM!")); + popup_error.setText(tr("The game that you are trying to load must be decrypted before being used with Citra.<br/><br/>" + "For more information on dumping and decrypting games, please see: <a href='https://citra-emu.org/wiki/Dumping-Game-Cartridges'>https://citra-emu.org/wiki/Dumping-Game-Cartridges</a>")); + popup_error.setIcon(QMessageBox::Critical); + popup_error.exec(); + break; + } + case Loader::ResultStatus::ErrorInvalidFormat: + QMessageBox::critical(this, tr("Error while loading ROM!"), + tr("The ROM format is not supported.")); + break; + case Loader::ResultStatus::Error: + + default: + QMessageBox::critical(this, tr("Error while loading ROM!"), + tr("Unknown error!")); + break; + } + return false; } + return true; +} + +void GMainWindow::BootGame(const std::string& filename) { + LOG_INFO(Frontend, "Citra starting..."); + + if (!InitializeSystem()) + return; + + if (!LoadROM(filename)) + return; // Create and start the emulation thread emu_thread = Common::make_unique<EmuThread>(render_window); @@ -497,7 +551,22 @@ void GMainWindow::OnConfigure() { //GControllerConfigDialog* dialog = new GControllerConfigDialog(controller_ports, this); } +bool GMainWindow::ConfirmClose() { + if (emu_thread == nullptr || !confirm_before_closing) + return true; + + auto answer = QMessageBox::question(this, tr("Citra"), + tr("Are you sure you want to close Citra?"), + QMessageBox::Yes | QMessageBox::No, QMessageBox::No); + return answer != QMessageBox::No; +} + void GMainWindow::closeEvent(QCloseEvent* event) { + if (!ConfirmClose()) { + event->ignore(); + return; + } + // Save window layout QSettings settings(QSettings::IniFormat, QSettings::UserScope, "Citra team", "Citra"); @@ -512,6 +581,7 @@ void GMainWindow::closeEvent(QCloseEvent* event) { settings.setValue("singleWindowMode", ui.action_Single_Window_Mode->isChecked()); settings.setValue("displayTitleBars", ui.actionDisplay_widget_title_bars->isChecked()); settings.setValue("firstStart", false); + settings.setValue("confirmClose", confirm_before_closing); game_list->SaveInterfaceLayout(settings); SaveHotkeys(settings); @@ -545,6 +615,9 @@ int main(int argc, char* argv[]) { QApplication::setAttribute(Qt::AA_X11InitThreads); QApplication app(argc, argv); + // Qt changes the locale and causes issues in float conversion using std::to_string() when generating shaders + setlocale(LC_ALL, "C"); + GMainWindow main_window; // After settings have been loaded by GMainWindow, apply the filter log_filter.ParseFilterString(Settings::values.log_filter); |