void MainWindow::OnImportNANDBackup() { auto response = QMessageBox::question( this, tr("Question"), tr("Merging a new NAND over your currently selected NAND will overwrite any channels " "and savegames that already exist. This process is not reversible, so it is " "recommended that you keep backups of both NANDs. Are you sure you want to " "continue?")); if (response == QMessageBox::No) return; QString file = QFileDialog::getOpenFileName(this, tr("Select the save file"), QDir::currentPath(), tr("BootMii NAND backup file (*.bin);;" "All Files (*)")); if (file.isEmpty()) return; QProgressDialog* dialog = new QProgressDialog(this); dialog->setMinimum(0); dialog->setMaximum(0); dialog->setLabelText(tr("Importing NAND backup")); dialog->setCancelButton(nullptr); auto beginning = QDateTime::currentDateTime().toMSecsSinceEpoch(); auto result = std::async(std::launch::async, [&] { DiscIO::NANDImporter().ImportNANDBin( file.toStdString(), [&dialog, beginning] { QueueOnObject(dialog, [&dialog, beginning] { dialog->setLabelText( tr("Importing NAND backup\n Time elapsed: %1s") .arg((QDateTime::currentDateTime().toMSecsSinceEpoch() - beginning) / 1000)); }); }, [this] { return RunOnObject(this, [this] { return QFileDialog::getOpenFileName(this, tr("Select the keys file (OTP/SEEPROM dump)"), QDir::currentPath(), tr("BootMii keys file (*.bin);;" "All Files (*)")) .toStdString(); }); }); QueueOnObject(dialog, &QProgressDialog::close); }); dialog->exec(); result.wait(); m_menu_bar->UpdateToolsMenu(Core::IsRunning()); }
static bool QtMsgAlertHandler(const char* caption, const char* text, bool yes_no, MsgType style) { std::optional<bool> r = RunOnObject(QApplication::instance(), [&] { QMessageBox message_box(QApplication::activeWindow()); message_box.setWindowTitle(QString::fromUtf8(caption)); message_box.setText(QString::fromUtf8(text)); message_box.setStandardButtons(yes_no ? QMessageBox::Yes | QMessageBox::No : QMessageBox::Ok); if (style == MsgType::Warning) message_box.addButton(QMessageBox::Ignore)->setText(QObject::tr("Ignore for this session")); message_box.setIcon([&] { switch (style) { case MsgType::Information: return QMessageBox::Information; case MsgType::Question: return QMessageBox::Question; case MsgType::Warning: return QMessageBox::Warning; case MsgType::Critical: return QMessageBox::Critical; } // appease MSVC return QMessageBox::NoIcon; }()); const int button = message_box.exec(); if (button == QMessageBox::Yes) return true; if (button == QMessageBox::Ignore) SetEnableAlert(false); return false; }); if (r.has_value()) return *r; return false; }