diff options
Diffstat (limited to 'src/yuzu')
-rw-r--r-- | src/yuzu/applets/qt_error.cpp | 12 | ||||
-rw-r--r-- | src/yuzu/configuration/configure_per_game.h | 2 | ||||
-rw-r--r-- | src/yuzu/configuration/configure_per_game_addons.cpp | 7 | ||||
-rw-r--r-- | src/yuzu/configuration/configure_per_game_addons.h | 2 | ||||
-rw-r--r-- | src/yuzu/configuration/configure_ringcon.cpp | 2 | ||||
-rw-r--r-- | src/yuzu/configuration/configure_system.cpp | 57 | ||||
-rw-r--r-- | src/yuzu/configuration/configure_system.h | 6 | ||||
-rw-r--r-- | src/yuzu/configuration/configure_vibration.cpp | 8 | ||||
-rw-r--r-- | src/yuzu/configuration/shared_translation.cpp | 4 | ||||
-rw-r--r-- | src/yuzu/debugger/console.h | 2 | ||||
-rw-r--r-- | src/yuzu/game_list_worker.cpp | 15 | ||||
-rw-r--r-- | src/yuzu/main.cpp | 436 | ||||
-rw-r--r-- | src/yuzu/main.h | 19 | ||||
-rw-r--r-- | src/yuzu/main.ui | 5 |
14 files changed, 163 insertions, 414 deletions
diff --git a/src/yuzu/applets/qt_error.cpp b/src/yuzu/applets/qt_error.cpp index 1dc4f0383..ad35f4126 100644 --- a/src/yuzu/applets/qt_error.cpp +++ b/src/yuzu/applets/qt_error.cpp @@ -25,8 +25,8 @@ void QtErrorDisplay::ShowError(Result error, FinishedCallback finished) const { callback = std::move(finished); emit MainWindowDisplayError( tr("Error Code: %1-%2 (0x%3)") - .arg(static_cast<u32>(error.module.Value()) + 2000, 4, 10, QChar::fromLatin1('0')) - .arg(error.description, 4, 10, QChar::fromLatin1('0')) + .arg(static_cast<u32>(error.GetModule()) + 2000, 4, 10, QChar::fromLatin1('0')) + .arg(error.GetDescription(), 4, 10, QChar::fromLatin1('0')) .arg(error.raw, 8, 16, QChar::fromLatin1('0')), tr("An error has occurred.\nPlease try again or contact the developer of the software.")); } @@ -38,8 +38,8 @@ void QtErrorDisplay::ShowErrorWithTimestamp(Result error, std::chrono::seconds t const QDateTime date_time = QDateTime::fromSecsSinceEpoch(time.count()); emit MainWindowDisplayError( tr("Error Code: %1-%2 (0x%3)") - .arg(static_cast<u32>(error.module.Value()) + 2000, 4, 10, QChar::fromLatin1('0')) - .arg(error.description, 4, 10, QChar::fromLatin1('0')) + .arg(static_cast<u32>(error.GetModule()) + 2000, 4, 10, QChar::fromLatin1('0')) + .arg(error.GetDescription(), 4, 10, QChar::fromLatin1('0')) .arg(error.raw, 8, 16, QChar::fromLatin1('0')), tr("An error occurred on %1 at %2.\nPlease try again or contact the developer of the " "software.") @@ -53,8 +53,8 @@ void QtErrorDisplay::ShowCustomErrorText(Result error, std::string dialog_text, callback = std::move(finished); emit MainWindowDisplayError( tr("Error Code: %1-%2 (0x%3)") - .arg(static_cast<u32>(error.module.Value()) + 2000, 4, 10, QChar::fromLatin1('0')) - .arg(error.description, 4, 10, QChar::fromLatin1('0')) + .arg(static_cast<u32>(error.GetModule()) + 2000, 4, 10, QChar::fromLatin1('0')) + .arg(error.GetDescription(), 4, 10, QChar::fromLatin1('0')) .arg(error.raw, 8, 16, QChar::fromLatin1('0')), tr("An error has occurred.\n\n%1\n\n%2") .arg(QString::fromStdString(dialog_text)) diff --git a/src/yuzu/configuration/configure_per_game.h b/src/yuzu/configuration/configure_per_game.h index c8ee46c04..9daae772c 100644 --- a/src/yuzu/configuration/configure_per_game.h +++ b/src/yuzu/configuration/configure_per_game.h @@ -11,7 +11,7 @@ #include <QList> #include "configuration/shared_widget.h" -#include "core/file_sys/vfs_types.h" +#include "core/file_sys/vfs/vfs_types.h" #include "frontend_common/config.h" #include "vk_device_info.h" #include "yuzu/configuration/configuration_shared.h" diff --git a/src/yuzu/configuration/configure_per_game_addons.cpp b/src/yuzu/configuration/configure_per_game_addons.cpp index 140a7fe5d..568775027 100644 --- a/src/yuzu/configuration/configure_per_game_addons.cpp +++ b/src/yuzu/configuration/configure_per_game_addons.cpp @@ -122,9 +122,8 @@ void ConfigurePerGameAddons::LoadConfiguration() { const auto& disabled = Settings::values.disabled_addons[title_id]; - for (const auto& patch : pm.GetPatchVersionNames(update_raw)) { - const auto name = - QString::fromStdString(patch.first).replace(QStringLiteral("[D] "), QString{}); + for (const auto& patch : pm.GetPatches(update_raw)) { + const auto name = QString::fromStdString(patch.name); auto* const first_item = new QStandardItem; first_item->setText(name); @@ -136,7 +135,7 @@ void ConfigurePerGameAddons::LoadConfiguration() { first_item->setCheckState(patch_disabled ? Qt::Unchecked : Qt::Checked); list_items.push_back(QList<QStandardItem*>{ - first_item, new QStandardItem{QString::fromStdString(patch.second)}}); + first_item, new QStandardItem{QString::fromStdString(patch.version)}}); item_model->appendRow(list_items.back()); } diff --git a/src/yuzu/configuration/configure_per_game_addons.h b/src/yuzu/configuration/configure_per_game_addons.h index 53db405c1..32dc5dde6 100644 --- a/src/yuzu/configuration/configure_per_game_addons.h +++ b/src/yuzu/configuration/configure_per_game_addons.h @@ -8,7 +8,7 @@ #include <QList> -#include "core/file_sys/vfs_types.h" +#include "core/file_sys/vfs/vfs_types.h" namespace Core { class System; diff --git a/src/yuzu/configuration/configure_ringcon.cpp b/src/yuzu/configuration/configure_ringcon.cpp index 3a7f6101d..9fd094ab6 100644 --- a/src/yuzu/configuration/configure_ringcon.cpp +++ b/src/yuzu/configuration/configure_ringcon.cpp @@ -494,4 +494,4 @@ QString ConfigureRingController::AnalogToText(const Common::ParamPackage& param, } return QObject::tr("[unknown]"); -}
\ No newline at end of file +} diff --git a/src/yuzu/configuration/configure_system.cpp b/src/yuzu/configuration/configure_system.cpp index b0b84f967..e193b5f95 100644 --- a/src/yuzu/configuration/configure_system.cpp +++ b/src/yuzu/configuration/configure_system.cpp @@ -12,9 +12,10 @@ #include <QGraphicsItem> #include <QLineEdit> #include <QMessageBox> +#include <QSpinBox> + #include "common/settings.h" #include "core/core.h" -#include "core/hle/service/time/time_manager.h" #include "ui_configure_system.h" #include "yuzu/configuration/configuration_shared.h" #include "yuzu/configuration/configure_system.h" @@ -49,6 +50,11 @@ ConfigureSystem::ConfigureSystem(Core::System& system_, : Tab(group_, parent), ui{std::make_unique<Ui::ConfigureSystem>()}, system{system_} { ui->setupUi(this); + const auto posix_time = std::chrono::system_clock::now().time_since_epoch(); + const auto current_time_s = + std::chrono::duration_cast<std::chrono::seconds>(posix_time).count(); + previous_time = current_time_s + Settings::values.custom_rtc_offset.GetValue(); + Setup(builder); const auto locale_check = [this]() { @@ -64,13 +70,28 @@ ConfigureSystem::ConfigureSystem(Core::System& system_, } }; + const auto update_date_offset = [this]() { + if (!checkbox_rtc->isChecked()) { + return; + } + auto offset = date_rtc_offset->value(); + offset += date_rtc->dateTime().toSecsSinceEpoch() - previous_time; + previous_time = date_rtc->dateTime().toSecsSinceEpoch(); + date_rtc_offset->setValue(offset); + }; + const auto update_rtc_date = [this]() { UpdateRtcTime(); }; + connect(combo_language, qOverload<int>(&QComboBox::currentIndexChanged), this, locale_check); connect(combo_region, qOverload<int>(&QComboBox::currentIndexChanged), this, locale_check); + connect(checkbox_rtc, qOverload<int>(&QCheckBox::stateChanged), this, update_rtc_date); + connect(date_rtc_offset, qOverload<int>(&QSpinBox::valueChanged), this, update_rtc_date); + connect(date_rtc, &QDateTimeEdit::dateTimeChanged, this, update_date_offset); ui->label_warn_invalid_locale->setVisible(false); locale_check(); SetConfiguration(); + UpdateRtcTime(); } ConfigureSystem::~ConfigureSystem() = default; @@ -120,14 +141,28 @@ void ConfigureSystem::Setup(const ConfigurationShared::Builder& builder) { continue; } + // Keep track of the region_index (and language_index) combobox to validate the selected + // settings if (setting->Id() == Settings::values.region_index.Id()) { - // Keep track of the region_index (and language_index) combobox to validate the selected - // settings combo_region = widget->combobox; - } else if (setting->Id() == Settings::values.language_index.Id()) { + } + + if (setting->Id() == Settings::values.language_index.Id()) { combo_language = widget->combobox; } + if (setting->Id() == Settings::values.custom_rtc.Id()) { + checkbox_rtc = widget->checkbox; + } + + if (setting->Id() == Settings::values.custom_rtc.Id()) { + date_rtc = widget->date_time_edit; + } + + if (setting->Id() == Settings::values.custom_rtc_offset.Id()) { + date_rtc_offset = widget->spinbox; + } + switch (setting->GetCategory()) { case Settings::Category::Core: core_hold.emplace(setting->Id(), widget); @@ -147,6 +182,19 @@ void ConfigureSystem::Setup(const ConfigurationShared::Builder& builder) { } } +void ConfigureSystem::UpdateRtcTime() { + const auto posix_time = std::chrono::system_clock::now().time_since_epoch(); + previous_time = std::chrono::duration_cast<std::chrono::seconds>(posix_time).count(); + date_rtc_offset->setEnabled(checkbox_rtc->isChecked()); + + if (checkbox_rtc->isChecked()) { + previous_time += date_rtc_offset->value(); + } + + const auto date = QDateTime::fromSecsSinceEpoch(previous_time); + date_rtc->setDateTime(date); +} + void ConfigureSystem::SetConfiguration() {} void ConfigureSystem::ApplyConfiguration() { @@ -154,4 +202,5 @@ void ConfigureSystem::ApplyConfiguration() { for (const auto& func : apply_funcs) { func(powered_on); } + UpdateRtcTime(); } diff --git a/src/yuzu/configuration/configure_system.h b/src/yuzu/configuration/configure_system.h index eab99a48a..4334211f9 100644 --- a/src/yuzu/configuration/configure_system.h +++ b/src/yuzu/configuration/configure_system.h @@ -43,6 +43,8 @@ private: void Setup(const ConfigurationShared::Builder& builder); + void UpdateRtcTime(); + std::vector<std::function<void(bool)>> apply_funcs{}; std::unique_ptr<Ui::ConfigureSystem> ui; @@ -52,4 +54,8 @@ private: QComboBox* combo_region; QComboBox* combo_language; + QCheckBox* checkbox_rtc; + QDateTimeEdit* date_rtc; + QSpinBox* date_rtc_offset; + u64 previous_time; }; diff --git a/src/yuzu/configuration/configure_vibration.cpp b/src/yuzu/configuration/configure_vibration.cpp index d898d8acc..6b1f4527b 100644 --- a/src/yuzu/configuration/configure_vibration.cpp +++ b/src/yuzu/configuration/configure_vibration.cpp @@ -116,8 +116,8 @@ void ConfigureVibration::VibrateController(Core::HID::ControllerTriggerType type .high_amplitude = 1.0f, .high_frequency = 320.0f, }; - controller->SetVibration(0, vibration); - controller->SetVibration(1, vibration); + controller->SetVibration(Core::HID::DeviceIndex::Left, vibration); + controller->SetVibration(Core::HID::DeviceIndex::Right, vibration); // Restore previous values player.vibration_enabled = old_vibration_enabled; @@ -127,7 +127,7 @@ void ConfigureVibration::VibrateController(Core::HID::ControllerTriggerType type void ConfigureVibration::StopVibrations() { for (std::size_t i = 0; i < NUM_PLAYERS; ++i) { auto controller = hid_core.GetEmulatedControllerByIndex(i); - controller->SetVibration(0, Core::HID::DEFAULT_VIBRATION_VALUE); - controller->SetVibration(1, Core::HID::DEFAULT_VIBRATION_VALUE); + controller->SetVibration(Core::HID::DeviceIndex::Left, Core::HID::DEFAULT_VIBRATION_VALUE); + controller->SetVibration(Core::HID::DeviceIndex::Right, Core::HID::DEFAULT_VIBRATION_VALUE); } } diff --git a/src/yuzu/configuration/shared_translation.cpp b/src/yuzu/configuration/shared_translation.cpp index 922eb1b1a..ed9c7d859 100644 --- a/src/yuzu/configuration/shared_translation.cpp +++ b/src/yuzu/configuration/shared_translation.cpp @@ -143,8 +143,10 @@ std::unique_ptr<TranslationMap> InitializeTranslations(QWidget* parent) { INSERT(Settings, rng_seed, tr("RNG Seed"), QStringLiteral()); INSERT(Settings, rng_seed_enabled, QStringLiteral(), QStringLiteral()); INSERT(Settings, device_name, tr("Device Name"), QStringLiteral()); - INSERT(Settings, custom_rtc, tr("Custom RTC"), QStringLiteral()); + INSERT(Settings, custom_rtc, tr("Custom RTC Date:"), QStringLiteral()); INSERT(Settings, custom_rtc_enabled, QStringLiteral(), QStringLiteral()); + INSERT(Settings, custom_rtc_offset, QStringLiteral(" "), + QStringLiteral("The number of seconds from the current unix time")); INSERT(Settings, language_index, tr("Language:"), tr("Note: this can be overridden when region setting is auto-select")); INSERT(Settings, region_index, tr("Region:"), QStringLiteral()); diff --git a/src/yuzu/debugger/console.h b/src/yuzu/debugger/console.h index fdb7d174c..2491d1ec1 100644 --- a/src/yuzu/debugger/console.h +++ b/src/yuzu/debugger/console.h @@ -10,4 +10,4 @@ namespace Debugger { * get a real qt logging window which would work for all platforms. */ void ToggleConsole(); -} // namespace Debugger
\ No newline at end of file +} // namespace Debugger diff --git a/src/yuzu/game_list_worker.cpp b/src/yuzu/game_list_worker.cpp index dc006832e..0cbf5f45e 100644 --- a/src/yuzu/game_list_worker.cpp +++ b/src/yuzu/game_list_worker.cpp @@ -17,7 +17,7 @@ #include "core/file_sys/card_image.h" #include "core/file_sys/content_archive.h" #include "core/file_sys/control_metadata.h" -#include "core/file_sys/mode.h" +#include "core/file_sys/fs_filesystem.h" #include "core/file_sys/nca_metadata.h" #include "core/file_sys/patch_manager.h" #include "core/file_sys/registered_cache.h" @@ -164,18 +164,19 @@ QString FormatPatchNameVersions(const FileSys::PatchManager& patch_manager, QString out; FileSys::VirtualFile update_raw; loader.ReadUpdateRaw(update_raw); - for (const auto& kv : patch_manager.GetPatchVersionNames(update_raw)) { - const bool is_update = kv.first == "Update" || kv.first == "[D] Update"; + for (const auto& patch : patch_manager.GetPatches(update_raw)) { + const bool is_update = patch.name == "Update"; if (!updatable && is_update) { continue; } - const QString type = QString::fromStdString(kv.first); + const QString type = + QString::fromStdString(patch.enabled ? patch.name : "[D] " + patch.name); - if (kv.second.empty()) { + if (patch.version.empty()) { out.append(QStringLiteral("%1\n").arg(type)); } else { - auto ver = kv.second; + auto ver = patch.version; // Display container name for packed updates if (is_update && ver == "PACKED") { @@ -346,7 +347,7 @@ void GameListWorker::ScanFileSystem(ScanTarget target, const std::string& dir_pa if (!is_dir && (HasSupportedFileExtension(physical_name) || IsExtractedNCAMain(physical_name))) { - const auto file = vfs->OpenFile(physical_name, FileSys::Mode::Read); + const auto file = vfs->OpenFile(physical_name, FileSys::OpenMode::Read); if (!file) { return true; } diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 3c562e3b2..782bcbb61 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -35,8 +35,8 @@ #include "configuration/configure_per_game.h" #include "configuration/configure_tas.h" #include "core/file_sys/romfs_factory.h" -#include "core/file_sys/vfs.h" -#include "core/file_sys/vfs_real.h" +#include "core/file_sys/vfs/vfs.h" +#include "core/file_sys/vfs/vfs_real.h" #include "core/frontend/applets/cabinet.h" #include "core/frontend/applets/controller.h" #include "core/frontend/applets/general_frontend.h" @@ -47,6 +47,7 @@ #include "core/hle/service/am/applet_oe.h" #include "core/hle/service/am/applets/applets.h" #include "core/hle/service/set/system_settings_server.h" +#include "frontend_common/content_manager.h" #include "hid_core/frontend/emulated_controller.h" #include "hid_core/hid_core.h" #include "yuzu/multiplayer/state.h" @@ -55,7 +56,7 @@ // These are wrappers to avoid the calls to CreateDirectory and CreateFile because of the Windows // defines. static FileSys::VirtualDir VfsFilesystemCreateDirectoryWrapper( - const FileSys::VirtualFilesystem& vfs, const std::string& path, FileSys::Mode mode) { + const FileSys::VirtualFilesystem& vfs, const std::string& path, FileSys::OpenMode mode) { return vfs->CreateDirectory(path, mode); } @@ -422,7 +423,7 @@ GMainWindow::GMainWindow(std::unique_ptr<QtConfig> config_, bool has_broken_vulk RemoveCachedContents(); // Gen keys if necessary - OnReinitializeKeys(ReinitializeKeyBehavior::NoWarning); + OnCheckFirmwareDecryption(); game_list->LoadCompatibilityList(); game_list->PopulateAsync(UISettings::values.game_dirs); @@ -1573,8 +1574,6 @@ void GMainWindow::ConnectMenuEvents() { connect(multiplayer_state, &MultiplayerState::SaveConfig, this, &GMainWindow::OnSaveConfig); // Tools - connect_menu(ui->action_Rederive, std::bind(&GMainWindow::OnReinitializeKeys, this, - ReinitializeKeyBehavior::Warning)); connect_menu(ui->action_Load_Album, &GMainWindow::OnAlbum); connect_menu(ui->action_Load_Cabinet_Nickname_Owner, [this]() { OnCabinet(Service::NFP::CabinetMode::StartNicknameAndOwnerSettings); }); @@ -1881,7 +1880,7 @@ bool GMainWindow::SelectAndSetCurrentUser( void GMainWindow::ConfigureFilesystemProvider(const std::string& filepath) { // Ensure all NCAs are registered before launching the game - const auto file = vfs->OpenFile(filepath, FileSys::Mode::Read); + const auto file = vfs->OpenFile(filepath, FileSys::OpenMode::Read); if (!file) { return; } @@ -2275,7 +2274,7 @@ void GMainWindow::OnGameListOpenFolder(u64 program_id, GameListOpenTarget target open_target = tr("Save Data"); const auto nand_dir = Common::FS::GetYuzuPath(Common::FS::YuzuPath::NANDDir); auto vfs_nand_dir = - vfs->OpenDirectory(Common::FS::PathToUTF8String(nand_dir), FileSys::Mode::Read); + vfs->OpenDirectory(Common::FS::PathToUTF8String(nand_dir), FileSys::OpenMode::Read); if (has_user_save) { // User save data @@ -2476,10 +2475,8 @@ void GMainWindow::OnGameListRemoveInstalledEntry(u64 program_id, InstalledEntryT } void GMainWindow::RemoveBaseContent(u64 program_id, InstalledEntryType type) { - const auto& fs_controller = system->GetFileSystemController(); - const auto res = fs_controller.GetUserNANDContents()->RemoveExistingEntry(program_id) || - fs_controller.GetSDMCContents()->RemoveExistingEntry(program_id); - + const auto res = + ContentManager::RemoveBaseContent(system->GetFileSystemController(), program_id); if (res) { QMessageBox::information(this, tr("Successfully Removed"), tr("Successfully removed the installed base game.")); @@ -2491,11 +2488,7 @@ void GMainWindow::RemoveBaseContent(u64 program_id, InstalledEntryType type) { } void GMainWindow::RemoveUpdateContent(u64 program_id, InstalledEntryType type) { - const auto update_id = program_id | 0x800; - const auto& fs_controller = system->GetFileSystemController(); - const auto res = fs_controller.GetUserNANDContents()->RemoveExistingEntry(update_id) || - fs_controller.GetSDMCContents()->RemoveExistingEntry(update_id); - + const auto res = ContentManager::RemoveUpdate(system->GetFileSystemController(), program_id); if (res) { QMessageBox::information(this, tr("Successfully Removed"), tr("Successfully removed the installed update.")); @@ -2506,22 +2499,7 @@ void GMainWindow::RemoveUpdateContent(u64 program_id, InstalledEntryType type) { } void GMainWindow::RemoveAddOnContent(u64 program_id, InstalledEntryType type) { - u32 count{}; - const auto& fs_controller = system->GetFileSystemController(); - const auto dlc_entries = system->GetContentProvider().ListEntriesFilter( - FileSys::TitleType::AOC, FileSys::ContentRecordType::Data); - - for (const auto& entry : dlc_entries) { - if (FileSys::GetBaseTitleID(entry.title_id) == program_id) { - const auto res = - fs_controller.GetUserNANDContents()->RemoveExistingEntry(entry.title_id) || - fs_controller.GetSDMCContents()->RemoveExistingEntry(entry.title_id); - if (res) { - ++count; - } - } - } - + const size_t count = ContentManager::RemoveAllDLC(*system, program_id); if (count == 0) { QMessageBox::warning(this, GetGameListErrorRemoving(type), tr("There are no DLC installed for this title.")); @@ -2675,7 +2653,7 @@ void GMainWindow::RemoveCustomConfiguration(u64 program_id, const std::string& g void GMainWindow::RemoveCacheStorage(u64 program_id) { const auto nand_dir = Common::FS::GetYuzuPath(Common::FS::YuzuPath::NANDDir); auto vfs_nand_dir = - vfs->OpenDirectory(Common::FS::PathToUTF8String(nand_dir), FileSys::Mode::Read); + vfs->OpenDirectory(Common::FS::PathToUTF8String(nand_dir), FileSys::OpenMode::Read); const auto cache_storage_path = FileSys::SaveDataFactory::GetFullPath( {}, vfs_nand_dir, FileSys::SaveDataSpaceId::NandUser, FileSys::SaveDataType::CacheStorage, @@ -2695,7 +2673,8 @@ void GMainWindow::OnGameListDumpRomFS(u64 program_id, const std::string& game_pa "cancelled the operation.")); }; - const auto loader = Loader::GetLoader(*system, vfs->OpenFile(game_path, FileSys::Mode::Read)); + const auto loader = + Loader::GetLoader(*system, vfs->OpenFile(game_path, FileSys::OpenMode::Read)); if (loader == nullptr) { failed(); return; @@ -2739,7 +2718,7 @@ void GMainWindow::OnGameListDumpRomFS(u64 program_id, const std::string& game_pa const FileSys::PatchManager pm{title_id, system->GetFileSystemController(), installed}; auto romfs = pm.PatchRomFS(base_nca.get(), base_romfs, type, packed_update_raw, false); - const auto out = VfsFilesystemCreateDirectoryWrapper(vfs, path, FileSys::Mode::ReadWrite); + const auto out = VfsFilesystemCreateDirectoryWrapper(vfs, path, FileSys::OpenMode::ReadWrite); if (out == nullptr) { failed(); @@ -2806,16 +2785,6 @@ void GMainWindow::OnGameListVerifyIntegrity(const std::string& game_path) { QMessageBox::warning(this, tr("Integrity verification couldn't be performed!"), tr("File contents were not checked for validity.")); }; - const auto Failed = [this] { - QMessageBox::critical(this, tr("Integrity verification failed!"), - tr("File contents may be corrupt.")); - }; - - const auto loader = Loader::GetLoader(*system, vfs->OpenFile(game_path, FileSys::Mode::Read)); - if (loader == nullptr) { - NotImplemented(); - return; - } QProgressDialog progress(tr("Verifying integrity..."), tr("Cancel"), 0, 100, this); progress.setWindowModality(Qt::WindowModal); @@ -2823,30 +2792,25 @@ void GMainWindow::OnGameListVerifyIntegrity(const std::string& game_path) { progress.setAutoClose(false); progress.setAutoReset(false); - const auto QtProgressCallback = [&](size_t processed_size, size_t total_size) { - if (progress.wasCanceled()) { - return false; - } - + const auto QtProgressCallback = [&](size_t total_size, size_t processed_size) { progress.setValue(static_cast<int>((processed_size * 100) / total_size)); - return true; + return progress.wasCanceled(); }; - const auto status = loader->VerifyIntegrity(QtProgressCallback); - if (progress.wasCanceled() || - status == Loader::ResultStatus::ErrorIntegrityVerificationNotImplemented) { + const auto result = ContentManager::VerifyGameContents(*system, game_path, QtProgressCallback); + progress.close(); + switch (result) { + case ContentManager::GameVerificationResult::Success: + QMessageBox::information(this, tr("Integrity verification succeeded!"), + tr("The operation completed successfully.")); + break; + case ContentManager::GameVerificationResult::Failed: + QMessageBox::critical(this, tr("Integrity verification failed!"), + tr("File contents may be corrupt.")); + break; + case ContentManager::GameVerificationResult::NotImplemented: NotImplemented(); - return; - } - - if (status == Loader::ResultStatus::ErrorIntegrityVerificationFailed) { - Failed(); - return; } - - progress.close(); - QMessageBox::information(this, tr("Integrity verification succeeded!"), - tr("The operation completed successfully.")); } void GMainWindow::OnGameListCopyTID(u64 program_id) { @@ -3052,7 +3016,7 @@ void GMainWindow::OnGameListCreateShortcut(u64 program_id, const std::string& ga system->GetContentProvider()}; const auto control = pm.GetControlMetadata(); const auto loader = - Loader::GetLoader(*system, vfs->OpenFile(game_path, FileSys::Mode::Read)); + Loader::GetLoader(*system, vfs->OpenFile(game_path, FileSys::OpenMode::Read)); game_title = fmt::format("{:016X}", program_id); if (control.first != nullptr) { game_title = control.first->GetApplicationName(); @@ -3290,12 +3254,21 @@ void GMainWindow::OnMenuInstallToNAND() { install_progress->setLabelText( tr("Installing file \"%1\"...").arg(QFileInfo(file).fileName())); - QFuture<InstallResult> future; - InstallResult result; + QFuture<ContentManager::InstallResult> future; + ContentManager::InstallResult result; if (file.endsWith(QStringLiteral("nsp"), Qt::CaseInsensitive)) { - - future = QtConcurrent::run([this, &file] { return InstallNSP(file); }); + const auto progress_callback = [this](size_t size, size_t progress) { + emit UpdateInstallProgress(); + if (install_progress->wasCanceled()) { + return true; + } + return false; + }; + future = QtConcurrent::run([this, &file, progress_callback] { + return ContentManager::InstallNSP(*system, *vfs, file.toStdString(), + progress_callback); + }); while (!future.isFinished()) { QCoreApplication::processEvents(); @@ -3311,16 +3284,16 @@ void GMainWindow::OnMenuInstallToNAND() { std::this_thread::sleep_for(std::chrono::milliseconds(10)); switch (result) { - case InstallResult::Success: + case ContentManager::InstallResult::Success: new_files.append(QFileInfo(file).fileName()); break; - case InstallResult::Overwrite: + case ContentManager::InstallResult::Overwrite: overwritten_files.append(QFileInfo(file).fileName()); break; - case InstallResult::Failure: + case ContentManager::InstallResult::Failure: failed_files.append(QFileInfo(file).fileName()); break; - case InstallResult::BaseInstallAttempted: + case ContentManager::InstallResult::BaseInstallAttempted: failed_files.append(QFileInfo(file).fileName()); detected_base_install = true; break; @@ -3354,96 +3327,7 @@ void GMainWindow::OnMenuInstallToNAND() { ui->action_Install_File_NAND->setEnabled(true); } -InstallResult GMainWindow::InstallNSP(const QString& filename) { - const auto qt_raw_copy = [this](const FileSys::VirtualFile& src, - const FileSys::VirtualFile& dest, std::size_t block_size) { - if (src == nullptr || dest == nullptr) { - return false; - } - if (!dest->Resize(src->GetSize())) { - return false; - } - - std::vector<u8> buffer(CopyBufferSize); - - for (std::size_t i = 0; i < src->GetSize(); i += buffer.size()) { - if (install_progress->wasCanceled()) { - dest->Resize(0); - return false; - } - - emit UpdateInstallProgress(); - - const auto read = src->Read(buffer.data(), buffer.size(), i); - dest->Write(buffer.data(), read, i); - } - return true; - }; - - std::shared_ptr<FileSys::NSP> nsp; - if (filename.endsWith(QStringLiteral("nsp"), Qt::CaseInsensitive)) { - nsp = std::make_shared<FileSys::NSP>( - vfs->OpenFile(filename.toStdString(), FileSys::Mode::Read)); - if (nsp->IsExtractedType()) { - return InstallResult::Failure; - } - } else { - return InstallResult::Failure; - } - - if (nsp->GetStatus() != Loader::ResultStatus::Success) { - return InstallResult::Failure; - } - const auto res = system->GetFileSystemController().GetUserNANDContents()->InstallEntry( - *nsp, true, qt_raw_copy); - switch (res) { - case FileSys::InstallResult::Success: - return InstallResult::Success; - case FileSys::InstallResult::OverwriteExisting: - return InstallResult::Overwrite; - case FileSys::InstallResult::ErrorBaseInstall: - return InstallResult::BaseInstallAttempted; - default: - return InstallResult::Failure; - } -} - -InstallResult GMainWindow::InstallNCA(const QString& filename) { - const auto qt_raw_copy = [this](const FileSys::VirtualFile& src, - const FileSys::VirtualFile& dest, std::size_t block_size) { - if (src == nullptr || dest == nullptr) { - return false; - } - if (!dest->Resize(src->GetSize())) { - return false; - } - - std::vector<u8> buffer(CopyBufferSize); - - for (std::size_t i = 0; i < src->GetSize(); i += buffer.size()) { - if (install_progress->wasCanceled()) { - dest->Resize(0); - return false; - } - - emit UpdateInstallProgress(); - - const auto read = src->Read(buffer.data(), buffer.size(), i); - dest->Write(buffer.data(), read, i); - } - return true; - }; - - const auto nca = - std::make_shared<FileSys::NCA>(vfs->OpenFile(filename.toStdString(), FileSys::Mode::Read)); - const auto id = nca->GetStatus(); - - // Game updates necessary are missing base RomFS - if (id != Loader::ResultStatus::Success && - id != Loader::ResultStatus::ErrorMissingBKTRBaseRomFS) { - return InstallResult::Failure; - } - +ContentManager::InstallResult GMainWindow::InstallNCA(const QString& filename) { const QStringList tt_options{tr("System Application"), tr("System Archive"), tr("System Application Update"), @@ -3464,7 +3348,7 @@ InstallResult GMainWindow::InstallNCA(const QString& filename) { if (!ok || index == -1) { QMessageBox::warning(this, tr("Failed to Install"), tr("The title type you selected for the NCA is invalid.")); - return InstallResult::Failure; + return ContentManager::InstallResult::Failure; } // If index is equal to or past Game, add the jump in TitleType. @@ -3478,15 +3362,15 @@ InstallResult GMainWindow::InstallNCA(const QString& filename) { auto* registered_cache = is_application ? fs_controller.GetUserNANDContents() : fs_controller.GetSystemNANDContents(); - const auto res = registered_cache->InstallEntry(*nca, static_cast<FileSys::TitleType>(index), - true, qt_raw_copy); - if (res == FileSys::InstallResult::Success) { - return InstallResult::Success; - } else if (res == FileSys::InstallResult::OverwriteExisting) { - return InstallResult::Overwrite; - } else { - return InstallResult::Failure; - } + const auto progress_callback = [this](size_t size, size_t progress) { + emit UpdateInstallProgress(); + if (install_progress->wasCanceled()) { + return true; + } + return false; + }; + return ContentManager::InstallNCA(*vfs, filename.toStdString(), *registered_cache, + static_cast<FileSys::TitleType>(index), progress_callback); } void GMainWindow::OnMenuRecentFile() { @@ -4221,10 +4105,6 @@ void GMainWindow::OnOpenYuzuFolder() { } void GMainWindow::OnVerifyInstalledContents() { - // Declare sizes. - size_t total_size = 0; - size_t processed_size = 0; - // Initialize a progress dialog. QProgressDialog progress(tr("Verifying integrity..."), tr("Cancel"), 0, 100, this); progress.setWindowModality(Qt::WindowModal); @@ -4232,93 +4112,25 @@ void GMainWindow::OnVerifyInstalledContents() { progress.setAutoClose(false); progress.setAutoReset(false); - // Declare a list of file names which failed to verify. - std::vector<std::string> failed; - // Declare progress callback. - auto QtProgressCallback = [&](size_t nca_processed, size_t nca_total) { - if (progress.wasCanceled()) { - return false; - } - progress.setValue(static_cast<int>(((processed_size + nca_processed) * 100) / total_size)); - return true; + auto QtProgressCallback = [&](size_t total_size, size_t processed_size) { + progress.setValue(static_cast<int>((processed_size * 100) / total_size)); + return progress.wasCanceled(); }; - // Get content registries. - auto bis_contents = system->GetFileSystemController().GetSystemNANDContents(); - auto user_contents = system->GetFileSystemController().GetUserNANDContents(); - - std::vector<FileSys::RegisteredCache*> content_providers; - if (bis_contents) { - content_providers.push_back(bis_contents); - } - if (user_contents) { - content_providers.push_back(user_contents); - } - - // Get associated NCA files. - std::vector<FileSys::VirtualFile> nca_files; - - // Get all installed IDs. - for (auto nca_provider : content_providers) { - const auto entries = nca_provider->ListEntriesFilter(); - - for (const auto& entry : entries) { - auto nca_file = nca_provider->GetEntryRaw(entry.title_id, entry.type); - if (!nca_file) { - continue; - } - - total_size += nca_file->GetSize(); - nca_files.push_back(std::move(nca_file)); - } - } - - // Using the NCA loader, determine if all NCAs are valid. - for (auto& nca_file : nca_files) { - Loader::AppLoader_NCA nca_loader(nca_file); - - auto status = nca_loader.VerifyIntegrity(QtProgressCallback); - if (progress.wasCanceled()) { - break; - } - if (status != Loader::ResultStatus::Success) { - FileSys::NCA nca(nca_file); - const auto title_id = nca.GetTitleId(); - std::string title_name = "unknown"; - - const auto control = provider->GetEntry(FileSys::GetBaseTitleID(title_id), - FileSys::ContentRecordType::Control); - if (control && control->GetStatus() == Loader::ResultStatus::Success) { - const FileSys::PatchManager pm{title_id, system->GetFileSystemController(), - *provider}; - const auto [nacp, logo] = pm.ParseControlNCA(*control); - if (nacp) { - title_name = nacp->GetApplicationName(); - } - } - - if (title_id > 0) { - failed.push_back( - fmt::format("{} ({:016X}) ({})", nca_file->GetName(), title_id, title_name)); - } else { - failed.push_back(fmt::format("{} (unknown)", nca_file->GetName())); - } - } - - processed_size += nca_file->GetSize(); - } - + const std::vector<std::string> result = + ContentManager::VerifyInstalledContents(*system, *provider, QtProgressCallback); progress.close(); - if (failed.size() > 0) { - auto failed_names = QString::fromStdString(fmt::format("{}", fmt::join(failed, "\n"))); + if (result.empty()) { + QMessageBox::information(this, tr("Integrity verification succeeded!"), + tr("The operation completed successfully.")); + } else { + const auto failed_names = + QString::fromStdString(fmt::format("{}", fmt::join(result, "\n"))); QMessageBox::critical( this, tr("Integrity verification failed!"), tr("Verification failed for the following files:\n\n%1").arg(failed_names)); - } else { - QMessageBox::information(this, tr("Integrity verification succeeded!"), - tr("The operation completed successfully.")); } } @@ -4737,122 +4549,20 @@ void GMainWindow::OnMouseActivity() { } } -void GMainWindow::OnReinitializeKeys(ReinitializeKeyBehavior behavior) { - if (behavior == ReinitializeKeyBehavior::Warning) { - const auto res = QMessageBox::information( - this, tr("Confirm Key Rederivation"), - tr("You are about to force rederive all of your keys. \nIf you do not know what " - "this " - "means or what you are doing, \nthis is a potentially destructive action. " - "\nPlease " - "make sure this is what you want \nand optionally make backups.\n\nThis will " - "delete " - "your autogenerated key files and re-run the key derivation module."), - QMessageBox::StandardButtons{QMessageBox::Ok, QMessageBox::Cancel}); - - if (res == QMessageBox::Cancel) - return; - - const auto keys_dir = Common::FS::GetYuzuPath(Common::FS::YuzuPath::KeysDir); - - Common::FS::RemoveFile(keys_dir / "prod.keys_autogenerated"); - Common::FS::RemoveFile(keys_dir / "console.keys_autogenerated"); - Common::FS::RemoveFile(keys_dir / "title.keys_autogenerated"); - } - - Core::Crypto::KeyManager& keys = Core::Crypto::KeyManager::Instance(); - bool all_keys_present{true}; - - if (keys.BaseDeriveNecessary()) { - Core::Crypto::PartitionDataManager pdm{vfs->OpenDirectory("", FileSys::Mode::Read)}; - - const auto function = [this, &keys, &pdm] { - keys.PopulateFromPartitionData(pdm); - - system->GetFileSystemController().CreateFactories(*vfs); - keys.DeriveETicket(pdm, system->GetContentProvider()); - }; - - QString errors; - if (!pdm.HasFuses()) { - errors += tr("Missing fuses"); - } - if (!pdm.HasBoot0()) { - errors += tr(" - Missing BOOT0"); - } - if (!pdm.HasPackage2()) { - errors += tr(" - Missing BCPKG2-1-Normal-Main"); - } - if (!pdm.HasProdInfo()) { - errors += tr(" - Missing PRODINFO"); - } - if (!errors.isEmpty()) { - all_keys_present = false; - QMessageBox::warning( - this, tr("Derivation Components Missing"), - tr("Encryption keys are missing. " - "<br>Please follow <a href='https://yuzu-emu.org/help/quickstart/'>the yuzu " - "quickstart guide</a> to get all your keys, firmware and " - "games.<br><br><small>(%1)</small>") - .arg(errors)); - } - - QProgressDialog prog(this); - prog.setRange(0, 0); - prog.setLabelText(tr("Deriving keys...\nThis may take up to a minute depending \non your " - "system's performance.")); - prog.setWindowTitle(tr("Deriving Keys")); - - prog.show(); - - auto future = QtConcurrent::run(function); - while (!future.isFinished()) { - QCoreApplication::processEvents(); - } - - prog.close(); - } - +void GMainWindow::OnCheckFirmwareDecryption() { system->GetFileSystemController().CreateFactories(*vfs); - - if (all_keys_present && !this->CheckSystemArchiveDecryption()) { - LOG_WARNING(Frontend, "Mii model decryption failed"); + if (!ContentManager::AreKeysPresent()) { QMessageBox::warning( - this, tr("System Archive Decryption Failed"), - tr("Encryption keys failed to decrypt firmware. " + this, tr("Derivation Components Missing"), + tr("Encryption keys are missing. " "<br>Please follow <a href='https://yuzu-emu.org/help/quickstart/'>the yuzu " "quickstart guide</a> to get all your keys, firmware and " "games.")); } - SetFirmwareVersion(); - - if (behavior == ReinitializeKeyBehavior::Warning) { - game_list->PopulateAsync(UISettings::values.game_dirs); - } - UpdateMenuState(); } -bool GMainWindow::CheckSystemArchiveDecryption() { - constexpr u64 MiiModelId = 0x0100000000000802; - - auto bis_system = system->GetFileSystemController().GetSystemNANDContents(); - if (!bis_system) { - // Not having system BIS files is not an error. - return true; - } - - auto mii_nca = bis_system->GetEntry(MiiModelId, FileSys::ContentRecordType::Data); - if (!mii_nca) { - // Not having the Mii model is not an error. - return true; - } - - // Return whether we are able to decrypt the RomFS of the Mii model. - return mii_nca->GetRomFS().get() != nullptr; -} - bool GMainWindow::CheckFirmwarePresence() { constexpr u64 MiiEditId = static_cast<u64>(Service::AM::Applets::AppletProgramId::MiiEdit); diff --git a/src/yuzu/main.h b/src/yuzu/main.h index f3276da64..6b72094ff 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h @@ -16,6 +16,7 @@ #include "common/announce_multiplayer_room.h" #include "common/common_types.h" #include "configuration/qt_config.h" +#include "frontend_common/content_manager.h" #include "input_common/drivers/tas_input.h" #include "yuzu/compatibility_list.h" #include "yuzu/hotkeys.h" @@ -124,18 +125,6 @@ enum class EmulatedDirectoryTarget { SDMC, }; -enum class InstallResult { - Success, - Overwrite, - Failure, - BaseInstallAttempted, -}; - -enum class ReinitializeKeyBehavior { - NoWarning, - Warning, -}; - namespace VkDeviceInfo { class Record; } @@ -406,7 +395,7 @@ private slots: void OnMiiEdit(); void OnOpenControllerMenu(); void OnCaptureScreenshot(); - void OnReinitializeKeys(ReinitializeKeyBehavior behavior); + void OnCheckFirmwareDecryption(); void OnLanguageChanged(const QString& locale); void OnMouseActivity(); bool OnShutdownBegin(); @@ -427,8 +416,7 @@ private: void RemoveCacheStorage(u64 program_id); bool SelectRomFSDumpTarget(const FileSys::ContentProvider&, u64 program_id, u64* selected_title_id, u8* selected_content_record_type); - InstallResult InstallNSP(const QString& filename); - InstallResult InstallNCA(const QString& filename); + ContentManager::InstallResult InstallNCA(const QString& filename); void MigrateConfigFiles(); void UpdateWindowTitle(std::string_view title_name = {}, std::string_view title_version = {}, std::string_view gpu_vendor = {}); @@ -448,7 +436,6 @@ private: void LoadTranslation(); void OpenPerGameConfiguration(u64 title_id, const std::string& file_name); bool CheckDarkMode(); - bool CheckSystemArchiveDecryption(); bool CheckFirmwarePresence(); void SetFirmwareVersion(); void ConfigureFilesystemProvider(const std::string& filepath); diff --git a/src/yuzu/main.ui b/src/yuzu/main.ui index e53f9951e..6a6b0821f 100644 --- a/src/yuzu/main.ui +++ b/src/yuzu/main.ui @@ -224,11 +224,6 @@ <string>&Stop</string> </property> </action> - <action name="action_Rederive"> - <property name="text"> - <string>&Reinitialize keys...</string> - </property> - </action> <action name="action_Verify_installed_contents"> <property name="text"> <string>&Verify Installed Contents</string> |