| 1 | // Copyright 2022 Dolphin Emulator Project |
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | |
| 4 | #include "DolphinQt/NANDRepairDialog.h" |
| 5 | |
| 6 | #include <QApplication> |
| 7 | #include <QDialog> |
| 8 | #include <QDialogButtonBox> |
| 9 | #include <QHBoxLayout> |
| 10 | #include <QIcon> |
| 11 | #include <QLabel> |
| 12 | #include <QPlainTextEdit> |
| 13 | #include <QPushButton> |
| 14 | #include <QStyle> |
| 15 | #include <QVBoxLayout> |
| 16 | |
| 17 | #include <fmt/format.h> |
| 18 | |
| 19 | #include "Common/StringUtil.h" |
| 20 | #include "Core/ConfigManager.h" |
| 21 | #include "Core/TitleDatabase.h" |
| 22 | #include "Core/WiiUtils.h" |
| 23 | #include "DiscIO/WiiSaveBanner.h" |
| 24 | #include "DolphinQt/Resources.h" |
| 25 | |
| 26 | NANDRepairDialog::NANDRepairDialog(const WiiUtils::NANDCheckResult& result, QWidget* parent) |
| 27 | : QDialog(parent) |
| 28 | { |
| 29 | setWindowTitle(tr("NAND Check")); |
| 30 | setWindowIcon(Resources::GetAppIcon()); |
| 31 | |
| 32 | QVBoxLayout* main_layout = new QVBoxLayout(); |
| 33 | |
| 34 | QLabel* damaged_label = |
| 35 | new QLabel(tr("The emulated NAND is damaged. System titles such as the Wii Menu and " |
| 36 | "the Wii Shop Channel may not work correctly.")); |
| 37 | damaged_label->setWordWrap(true); |
| 38 | main_layout->addWidget(damaged_label); |
| 39 | |
| 40 | if (!result.titles_to_remove.empty()) |
| 41 | { |
| 42 | QLabel* warning_label = |
| 43 | new QLabel(tr("WARNING: Fixing this NAND requires the deletion of titles that have " |
| 44 | "incomplete data on the NAND, including all associated save data. " |
| 45 | "By continuing, the following title(s) will be removed:")); |
| 46 | warning_label->setWordWrap(true); |
| 47 | main_layout->addWidget(warning_label); |
| 48 | |
| 49 | std::string title_listings; |
| 50 | Core::TitleDatabase title_db; |
| 51 | const DiscIO::Language language = SConfig::GetInstance().GetCurrentLanguage(true); |
| 52 | for (const u64 title_id : result.titles_to_remove) |
| 53 | { |
| 54 | title_listings += fmt::format("{:016x}", title_id); |
| 55 | |
| 56 | const std::string database_name = title_db.GetChannelName(title_id, language); |
| 57 | if (!database_name.empty()) |
| 58 | { |
| 59 | title_listings += " - " + database_name; |
| 60 | } |
| 61 | else |
| 62 | { |
| 63 | DiscIO::WiiSaveBanner banner(title_id); |
| 64 | if (banner.IsValid()) |
| 65 | { |
| 66 | title_listings += " - " + banner.GetName(); |
| 67 | const std::string description = banner.GetDescription(); |
| 68 | if (!StripWhitespace(description).empty()) |
| 69 | title_listings += " - " + description; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | title_listings += "\n"; |
| 74 | } |
| 75 | |
| 76 | QPlainTextEdit* title_box = new QPlainTextEdit(QString::fromStdString(title_listings)); |
| 77 | title_box->setReadOnly(true); |
| 78 | main_layout->addWidget(title_box); |
| 79 | |
| 80 | QLabel* maybe_fix_label = new QLabel(tr("Launching these titles may also fix the issues.")); |
| 81 | maybe_fix_label->setWordWrap(true); |
| 82 | main_layout->addWidget(maybe_fix_label); |
| 83 | } |
| 84 | |
| 85 | QLabel* question_label = new QLabel(tr("Do you want to try to repair the NAND?")); |
| 86 | question_label->setWordWrap(true); |
| 87 | main_layout->addWidget(question_label); |
| 88 | |
| 89 | QDialogButtonBox* button_box = new QDialogButtonBox(QDialogButtonBox::Yes | QDialogButtonBox::No); |
| 90 | main_layout->addWidget(button_box); |
| 91 | |
| 92 | QHBoxLayout* top_layout = new QHBoxLayout(); |
| 93 | |
| 94 | QIcon icon = QApplication::style()->standardIcon(QStyle::SP_MessageBoxWarning); |
| 95 | QLabel* icon_label = new QLabel; |
| 96 | icon_label->setPixmap(icon.pixmap(100)); |
| 97 | icon_label->setAlignment(Qt::AlignTop); |
| 98 | top_layout->addWidget(icon_label); |
| 99 | top_layout->addSpacing(10); |
| 100 | |
| 101 | top_layout->addLayout(main_layout); |
| 102 | |
| 103 | setLayout(top_layout); |
| 104 | resize(600, 400); |
| 105 | |
| 106 | connect(button_box->button(QDialogButtonBox::Yes), &QPushButton::clicked, this, &QDialog::accept); |
| 107 | connect(button_box->button(QDialogButtonBox::No), &QPushButton::clicked, this, &QDialog::reject); |
| 108 | } |