From 63d23835ef4445b3a010cc0e8b1e73ebe012ac08 Mon Sep 17 00:00:00 2001 From: lat9nq Date: Thu, 9 Jul 2020 22:42:09 -0400 Subject: configuration: implement per-game configurations (#4098) * Switch game settings to use a pointer In order to add full per-game settings, we need to be able to tell yuzu to switch to using either the global or game configuration. Using a pointer makes it easier to switch. * configuration: add new UI without changing existing funcitonality The new UI also adds General, System, Graphics, Advanced Graphics, and Audio tabs, but as yet they do nothing. This commit keeps yuzu to the same functionality as originally branched. * configuration: Rename files These weren't included in the last commit. Now they are. * configuration: setup global configuration checkbox Global config checkbox now enables/disables the appropriate tabs in the game properties dialog. The use global configuration setting is now saved to the config, defaulting to true. This also addresses some changes requested in the PR. * configuration: swap to per-game config memory for properties dialog Does not set memory going in-game. Swaps to game values when opening the properties dialog, then swaps back when closing it. Uses a `memcpy` to swap. Also implements saving config files, limited to certain groups of configurations so as to not risk setting unsafe configurations. * configuration: change config interfaces to use config-specific pointers When a game is booted, we need to be able to open the configuration dialogs without changing the settings pointer in the game's emualtion. A new pointer specific to just the configuration dialogs can be used to separate changes to just those config dialogs without affecting the emulation. * configuration: boot a game using per-game settings Swaps values where needed to boot a game. * configuration: user correct config during emulation Creates a new pointer specifically for modifying the configuration while emulation is in progress. Both the regular configuration dialog and the game properties dialog now use the pointer Settings::config_values to focus edits to the correct struct. * settings: split Settings::values into two different structs By splitting the settings into two mutually exclusive structs, it becomes easier, as a developer, to determine how to use the Settings structs after per-game configurations is merged. Other benefits include only duplicating the required settings in memory. * settings: move use_docked_mode to Controls group `use_docked_mode` is set in the input settings and cannot be accessed from the system settings. Grouping it with system settings causes it to be saved with per-game settings, which may make transferring configs more difficult later on, especially since docked mode cannot be set from within the game properties dialog. * configuration: Fix the other yuzu executables and a regression In main.cpp, we have to get the title ID before the ROM is loaded, else the renderer will reflect only the global settings and now the user's game specific settings. * settings: use a template to duplicate memory for each setting Replaces the type of each variable in the Settings::Values struct with a new class that allows basic data reading and writing. The new struct Settings::Setting duplicates the data in memory and can manage global overrides per each setting. * configuration: correct add-ons config and swap settings when apropriate Any add-ons interaction happens directly through the global values struct. Swapping bewteen structs now also includes copying the necessary global configs that cannot be changed nor saved in per-game settings. General and System config menus now update based on whether it is viewing the global or per-game settings. * settings: restore old values struct No longer needed with the Settings::Setting class template. * configuration: implement hierarchical game properties dialog This sets the apropriate global or local data in each setting. * clang format * clang format take 2 can the docker container save this? * address comments and style issues * config: read and write settings with global awareness Adds new functions to read and write settings while keeping the global state in focus. Files now generated per-game are much smaller since often they only need address the global state. * settings: restore global state when necessary Upon closing a game or the game properties dialog, we need to restore all global settings to the original global state so that we can properly open the configuration dialog or boot a different game. * configuration: guard setting values incorrectly This disables setting values while a game is running if the setting is overwritten by a per game setting. * config: don't write local settings in the global config Simple guards to prevent writing the wrong settings in the wrong files. * configuration: add comments, assume less, and clang format No longer assumes that a disabled UI element means the global state is turned off, instead opting to directly answer that question. Still however assumes a game is running if it is in that state. * configuration: fix a logic error Should not be negated * restore settings' global state regardless of accept/cancel Fixes loading a properties dialog and causing the global config dialog to show local settings. * fix more logic errors Fixed the frame limit would set the global setting from the game properties dialog. Also strengthened the Settings::Setting member variables and simplified the logic in config reading (ReadSettingGlobal). * fix another logic error In my efforts to guard RestoreGlobalState, I accidentally negated the IsPowered condition. * configure_audio: set toggle_stretched_audio to tristate * fixed custom rtc and rng seed overwriting the global value * clang format * rebased * clang format take 4 * address my own review Basically revert unintended changes * settings: literal instead of casting "No need to cast, use 1U instead" Thanks, Morph! Co-authored-by: Morph <39850852+Morph1984@users.noreply.github.com> * Revert "settings: literal instead of casting " This reverts commit 95e992a87c898f3e882ffdb415bb0ef9f80f613f. * main: fix status buttons reporting wrong settings after stop emulation * settings: Log UseDockedMode in the Controls group This should have happened when use_docked_mode was moved over to the controls group internally. This just reflects this in the log. * main: load settings if the file has a title id In other words, don't exit if the loader has trouble getting a title id. * use a zero * settings: initalize resolution factor with constructor instead of casting * Revert "settings: initalize resolution factor with constructor instead of casting" This reverts commit 54c35ecb46a29953842614620f9b7de1aa9d5dc8. * configure_graphics: guard device selector when Vulkan is global Prevents the user from editing the device selector if Vulkan is the global renderer backend. Also resets the vulkan_device variable when the users switches back-and-forth between global and Vulkan. * address reviewer concerns Changes function variables to const wherever they don't need to be changed. Sets Settings::Setting to final as it should not be inherited from. Sets ConfigurationShared::use_global_text to static. Co-Authored-By: VolcaEM * main: load per-game settings after LoadROM This prevents `Restart Emulation` from restoring the global settings *after* the per-game settings were applied. Thanks to BSoDGamingYT for finding this bug. * Revert "main: load per-game settings after LoadROM" This reverts commit 9d0d48c52d2dcf3bfb1806cc8fa7d5a271a8a804. * main: only restore global settings when necessary Loading the per-game settings cannot happen after the ROM is loaded, so we have to specify when to restore the global state. Again thanks to BSoD for finding the bug. * configuration_shared: address reviewer concerns except operator overrides Dropping operator override usage in next commit. Co-Authored-By: LC * settings: Drop operator overrides from Setting template Requires using GetValue and SetValue explicitly. Also reverts a change that broke title ID formatting in the game properties dialog. * complete rebase * configuration_shared: translate "Use global configuration" Uses ConfigurePerGame to do so, since its usage, at least as of now, corresponds with ConfigurationShared. * configure_per_game: address reviewer concern As far as I understand, it prevents the program from unnecessarily copying strings. Co-Authored-By: LC Co-authored-by: Morph <39850852+Morph1984@users.noreply.github.com> Co-authored-by: VolcaEM Co-authored-by: LC --- src/yuzu/main.cpp | 116 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 74 insertions(+), 42 deletions(-) (limited to 'src/yuzu/main.cpp') diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 9844e4764..4d501a8f9 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -16,7 +16,7 @@ #include "applets/software_keyboard.h" #include "applets/web_browser.h" #include "configuration/configure_input.h" -#include "configuration/configure_per_general.h" +#include "configuration/configure_per_game.h" #include "core/file_sys/vfs.h" #include "core/file_sys/vfs_real.h" #include "core/frontend/applets/general_frontend.h" @@ -534,15 +534,15 @@ void GMainWindow::InitializeWidgets() { if (emulation_running) { return; } - bool is_async = - !Settings::values.use_asynchronous_gpu_emulation || Settings::values.use_multi_core; - Settings::values.use_asynchronous_gpu_emulation = is_async; - async_status_button->setChecked(Settings::values.use_asynchronous_gpu_emulation); + bool is_async = !Settings::values.use_asynchronous_gpu_emulation.GetValue() || + Settings::values.use_multi_core.GetValue(); + Settings::values.use_asynchronous_gpu_emulation.SetValue(is_async); + async_status_button->setChecked(Settings::values.use_asynchronous_gpu_emulation.GetValue()); Settings::Apply(); }); async_status_button->setText(tr("ASYNC")); async_status_button->setCheckable(true); - async_status_button->setChecked(Settings::values.use_asynchronous_gpu_emulation); + async_status_button->setChecked(Settings::values.use_asynchronous_gpu_emulation.GetValue()); // Setup Multicore button multicore_status_button = new QPushButton(); @@ -552,17 +552,17 @@ void GMainWindow::InitializeWidgets() { if (emulation_running) { return; } - Settings::values.use_multi_core = !Settings::values.use_multi_core; - bool is_async = - Settings::values.use_asynchronous_gpu_emulation || Settings::values.use_multi_core; - Settings::values.use_asynchronous_gpu_emulation = is_async; - async_status_button->setChecked(Settings::values.use_asynchronous_gpu_emulation); - multicore_status_button->setChecked(Settings::values.use_multi_core); + Settings::values.use_multi_core.SetValue(!Settings::values.use_multi_core.GetValue()); + bool is_async = Settings::values.use_asynchronous_gpu_emulation.GetValue() || + Settings::values.use_multi_core.GetValue(); + Settings::values.use_asynchronous_gpu_emulation.SetValue(is_async); + async_status_button->setChecked(Settings::values.use_asynchronous_gpu_emulation.GetValue()); + multicore_status_button->setChecked(Settings::values.use_multi_core.GetValue()); Settings::Apply(); }); multicore_status_button->setText(tr("MULTICORE")); multicore_status_button->setCheckable(true); - multicore_status_button->setChecked(Settings::values.use_multi_core); + multicore_status_button->setChecked(Settings::values.use_multi_core.GetValue()); statusBar()->insertPermanentWidget(0, multicore_status_button); statusBar()->insertPermanentWidget(0, async_status_button); @@ -581,16 +581,16 @@ void GMainWindow::InitializeWidgets() { renderer_status_button->setCheckable(false); renderer_status_button->setDisabled(true); #else - renderer_status_button->setChecked(Settings::values.renderer_backend == + renderer_status_button->setChecked(Settings::values.renderer_backend.GetValue() == Settings::RendererBackend::Vulkan); connect(renderer_status_button, &QPushButton::clicked, [=] { if (emulation_running) { return; } if (renderer_status_button->isChecked()) { - Settings::values.renderer_backend = Settings::RendererBackend::Vulkan; + Settings::values.renderer_backend.SetValue(Settings::RendererBackend::Vulkan); } else { - Settings::values.renderer_backend = Settings::RendererBackend::OpenGL; + Settings::values.renderer_backend.SetValue(Settings::RendererBackend::OpenGL); } Settings::Apply(); @@ -727,21 +727,24 @@ void GMainWindow::InitializeHotkeys() { }); connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("Toggle Speed Limit"), this), &QShortcut::activated, this, [&] { - Settings::values.use_frame_limit = !Settings::values.use_frame_limit; + Settings::values.use_frame_limit.SetValue( + !Settings::values.use_frame_limit.GetValue()); UpdateStatusBar(); }); constexpr u16 SPEED_LIMIT_STEP = 5; connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("Increase Speed Limit"), this), &QShortcut::activated, this, [&] { - if (Settings::values.frame_limit < 9999 - SPEED_LIMIT_STEP) { - Settings::values.frame_limit += SPEED_LIMIT_STEP; + if (Settings::values.frame_limit.GetValue() < 9999 - SPEED_LIMIT_STEP) { + Settings::values.frame_limit.SetValue(SPEED_LIMIT_STEP + + Settings::values.frame_limit.GetValue()); UpdateStatusBar(); } }); connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("Decrease Speed Limit"), this), &QShortcut::activated, this, [&] { - if (Settings::values.frame_limit > SPEED_LIMIT_STEP) { - Settings::values.frame_limit -= SPEED_LIMIT_STEP; + if (Settings::values.frame_limit.GetValue() > SPEED_LIMIT_STEP) { + Settings::values.frame_limit.SetValue(Settings::values.frame_limit.GetValue() - + SPEED_LIMIT_STEP); UpdateStatusBar(); } }); @@ -1039,6 +1042,17 @@ void GMainWindow::BootGame(const QString& filename) { LOG_INFO(Frontend, "yuzu starting..."); StoreRecentFile(filename); // Put the filename on top of the list + u64 title_id{0}; + + const auto v_file = Core::GetGameFileFromPath(vfs, filename.toUtf8().constData()); + const auto loader = Loader::GetLoader(v_file); + if (!(loader == nullptr || loader->ReadProgramId(title_id) != Loader::ResultStatus::Success)) { + // Load per game settings + Config per_game_config(fmt::format("{:016X}.ini", title_id), false); + } + + Settings::LogSettings(); + if (UISettings::values.select_user_on_boot) { SelectAndSetCurrentUser(); } @@ -1063,6 +1077,7 @@ void GMainWindow::BootGame(const QString& filename) { &LoadingScreen::OnLoadProgress, Qt::QueuedConnection); // Update the GUI + UpdateStatusButtons(); if (ui.action_Single_Window_Mode->isChecked()) { game_list->hide(); game_list_placeholder->hide(); @@ -1078,8 +1093,6 @@ void GMainWindow::BootGame(const QString& filename) { ui.centralwidget->setMouseTracking(true); } - const u64 title_id = Core::System::GetInstance().CurrentProcess()->GetTitleID(); - std::string title_name; std::string title_version; const auto res = Core::System::GetInstance().GetGameName(title_name); @@ -1521,7 +1534,7 @@ void GMainWindow::OnGameListOpenPerGameProperties(const std::string& file) { return; } - ConfigurePerGameGeneral dialog(this, title_id); + ConfigurePerGame dialog(this, title_id); dialog.LoadFromFile(v_file); auto result = dialog.exec(); if (result == QDialog::Accepted) { @@ -1532,7 +1545,14 @@ void GMainWindow::OnGameListOpenPerGameProperties(const std::string& file) { game_list->PopulateAsync(UISettings::values.game_dirs); } - config->Save(); + // Do not cause the global config to write local settings into the config file + Settings::RestoreGlobalState(); + + if (!Core::System::GetInstance().IsPoweredOn()) { + config->Save(); + } + } else { + Settings::RestoreGlobalState(); } } @@ -1819,6 +1839,9 @@ void GMainWindow::OnStopGame() { } ShutdownGame(); + + Settings::RestoreGlobalState(); + UpdateStatusButtons(); } void GMainWindow::OnLoadComplete() { @@ -1926,7 +1949,7 @@ void GMainWindow::ToggleWindowMode() { void GMainWindow::ResetWindowSize() { const auto aspect_ratio = Layout::EmulationAspectRatio( - static_cast(Settings::values.aspect_ratio), + static_cast(Settings::values.aspect_ratio.GetValue()), static_cast(Layout::ScreenUndocked::Height) / Layout::ScreenUndocked::Width); if (!ui.action_Single_Window_Mode->isChecked()) { render_window->resize(Layout::ScreenUndocked::Height / aspect_ratio, @@ -1974,16 +1997,7 @@ void GMainWindow::OnConfigure() { ui.centralwidget->setMouseTracking(false); } - dock_status_button->setChecked(Settings::values.use_docked_mode); - multicore_status_button->setChecked(Settings::values.use_multi_core); - Settings::values.use_asynchronous_gpu_emulation = - Settings::values.use_asynchronous_gpu_emulation || Settings::values.use_multi_core; - async_status_button->setChecked(Settings::values.use_asynchronous_gpu_emulation); - -#ifdef HAS_VULKAN - renderer_status_button->setChecked(Settings::values.renderer_backend == - Settings::RendererBackend::Vulkan); -#endif + UpdateStatusButtons(); } void GMainWindow::OnLoadAmiibo() { @@ -2097,21 +2111,34 @@ void GMainWindow::UpdateStatusBar() { auto results = Core::System::GetInstance().GetAndResetPerfStats(); - if (Settings::values.use_frame_limit) { + if (Settings::values.use_frame_limit.GetValue()) { emu_speed_label->setText(tr("Speed: %1% / %2%") .arg(results.emulation_speed * 100.0, 0, 'f', 0) - .arg(Settings::values.frame_limit)); + .arg(Settings::values.frame_limit.GetValue())); } else { emu_speed_label->setText(tr("Speed: %1%").arg(results.emulation_speed * 100.0, 0, 'f', 0)); } game_fps_label->setText(tr("Game: %1 FPS").arg(results.game_fps, 0, 'f', 0)); emu_frametime_label->setText(tr("Frame: %1 ms").arg(results.frametime * 1000.0, 0, 'f', 2)); - emu_speed_label->setVisible(!Settings::values.use_multi_core); + emu_speed_label->setVisible(!Settings::values.use_multi_core.GetValue()); game_fps_label->setVisible(true); emu_frametime_label->setVisible(true); } +void GMainWindow::UpdateStatusButtons() { + dock_status_button->setChecked(Settings::values.use_docked_mode); + multicore_status_button->setChecked(Settings::values.use_multi_core.GetValue()); + Settings::values.use_asynchronous_gpu_emulation.SetValue( + Settings::values.use_asynchronous_gpu_emulation.GetValue() || + Settings::values.use_multi_core.GetValue()); + async_status_button->setChecked(Settings::values.use_asynchronous_gpu_emulation.GetValue()); +#ifdef HAS_VULKAN + renderer_status_button->setChecked(Settings::values.renderer_backend.GetValue() == + Settings::RendererBackend::Vulkan); +#endif +} + void GMainWindow::HideMouseCursor() { if (emu_thread == nullptr || UISettings::values.hide_mouse == false) { mouse_hide_timer.stop(); @@ -2195,6 +2222,9 @@ void GMainWindow::OnCoreError(Core::System::ResultStatus result, std::string det if (answer == QMessageBox::Yes) { if (emu_thread) { ShutdownGame(); + + Settings::RestoreGlobalState(); + UpdateStatusButtons(); } } else { // Only show the message if the game is still running. @@ -2357,9 +2387,13 @@ void GMainWindow::closeEvent(QCloseEvent* event) { hotkey_registry.SaveHotkeys(); // Shutdown session if the emu thread is active... - if (emu_thread != nullptr) + if (emu_thread != nullptr) { ShutdownGame(); + Settings::RestoreGlobalState(); + UpdateStatusButtons(); + } + render_window->close(); QWidget::closeEvent(event); @@ -2539,8 +2573,6 @@ int main(int argc, char* argv[]) { QObject::connect(&app, &QGuiApplication::applicationStateChanged, &main_window, &GMainWindow::OnAppFocusStateChanged); - Settings::LogSettings(); - int result = app.exec(); detached_tasks.WaitForAllTasks(); return result; -- cgit v1.2.3 From 4c269e5ced47765f35dbb58afa9fcac8138a1f7c Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Thu, 16 Apr 2020 23:27:38 -0400 Subject: Add support for batch install to NAND This adds support to batch install files to NAND --- src/yuzu/main.cpp | 295 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 174 insertions(+), 121 deletions(-) (limited to 'src/yuzu/main.cpp') diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 4d501a8f9..45ddc3baf 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -107,6 +107,7 @@ static FileSys::VirtualFile VfsDirectoryCreateFileWrapper(const FileSys::Virtual #include "yuzu/game_list.h" #include "yuzu/game_list_p.h" #include "yuzu/hotkeys.h" +#include "yuzu/install_dialog.h" #include "yuzu/loading_screen.h" #include "yuzu/main.h" #include "yuzu/uisettings.h" @@ -1596,38 +1597,67 @@ void GMainWindow::OnMenuLoadFolder() { void GMainWindow::OnMenuInstallToNAND() { const QString file_filter = tr("Installable Switch File (*.nca *.nsp *.xci);;Nintendo Content Archive " - "(*.nca);;Nintendo Submissions Package (*.nsp);;NX Cartridge " + "(*.nca);;Nintendo Submission Package (*.nsp);;NX Cartridge " "Image (*.xci)"); - QString filename = QFileDialog::getOpenFileName(this, tr("Install File"), - UISettings::values.roms_path, file_filter); + QStringList files = QFileDialog::getOpenFileNames(this, tr("Install Files"), + UISettings::values.roms_path, file_filter); - if (filename.isEmpty()) { + if (files.isEmpty()) { + return; + } + + InstallDialog installDialog(this, files); + if (installDialog.exec() == QDialog::Rejected) { return; } - const auto qt_raw_copy = [this](const FileSys::VirtualFile& src, - const FileSys::VirtualFile& dest, std::size_t block_size) { - if (src == nullptr || dest == nullptr) + const QStringList filenames = installDialog.GetFilenames(); + const bool overwrite_files = installDialog.ShouldOverwriteFiles(); + + int count = 0; + int total_count = filenames.size(); + bool is_progressdialog_created = false; + + const auto qt_raw_copy = [this, &count, &total_count, &is_progressdialog_created]( + 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())) + } + if (!dest->Resize(src->GetSize())) { return false; + } std::array buffer{}; const int progress_maximum = static_cast(src->GetSize() / buffer.size()); - QProgressDialog progress( - tr("Installing file \"%1\"...").arg(QString::fromStdString(src->GetName())), - tr("Cancel"), 0, progress_maximum, this); - progress.setWindowModality(Qt::WindowModal); + if (!is_progressdialog_created) { + ui.action_Install_File_NAND->setEnabled(false); + install_progress = new QProgressDialog( + tr("Installing file \"%1\"...").arg(QString::fromStdString(src->GetName())), + tr("Cancel"), 0, progress_maximum, this); + install_progress->setWindowTitle( + tr("%n file(s) remaining", "", total_count - count - 1)); + install_progress->setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint & + ~Qt::WindowMaximizeButtonHint); + install_progress->setAutoClose(false); + is_progressdialog_created = true; + } else { + install_progress->setWindowTitle( + tr("%n file(s) remaining", "", total_count - count - 1)); + install_progress->setLabelText( + tr("Installing file \"%1\"...").arg(QString::fromStdString(src->GetName()))); + install_progress->setMaximum(progress_maximum); + } for (std::size_t i = 0; i < src->GetSize(); i += buffer.size()) { - if (progress.wasCanceled()) { + if (install_progress->wasCanceled()) { dest->Resize(0); return false; } const int progress_value = static_cast(i / buffer.size()); - progress.setValue(progress_value); + install_progress->setValue(progress_value); const auto read = src->Read(buffer.data(), buffer.size(), i); dest->Write(buffer.data(), read, i); @@ -1636,143 +1666,166 @@ void GMainWindow::OnMenuInstallToNAND() { return true; }; - const auto success = [this]() { + const auto success = [this, &count, &is_progressdialog_created]() { + if (is_progressdialog_created) { + install_progress->close(); + } QMessageBox::information(this, tr("Successfully Installed"), - tr("The file was successfully installed.")); + tr("%n file(s) successfully installed", "", count)); game_list->PopulateAsync(UISettings::values.game_dirs); FileUtil::DeleteDirRecursively(FileUtil::GetUserPath(FileUtil::UserPath::CacheDir) + DIR_SEP + "game_list"); + ui.action_Install_File_NAND->setEnabled(true); }; - const auto failed = [this]() { + const auto failed = [this, &is_progressdialog_created](const QString& file) { + if (is_progressdialog_created) { + install_progress->close(); + } QMessageBox::warning( - this, tr("Failed to Install"), + this, tr("Failed to Install %1").arg(QFileInfo(file).fileName()), tr("There was an error while attempting to install the provided file. It " "could have an incorrect format or be missing metadata. Please " "double-check your file and try again.")); + game_list->PopulateAsync(UISettings::values.game_dirs); + ui.action_Install_File_NAND->setEnabled(true); }; - const auto overwrite = [this]() { - return QMessageBox::question(this, tr("Failed to Install"), - tr("The file you are attempting to install already exists " - "in the cache. Would you like to overwrite it?")) == - QMessageBox::Yes; + const auto overwrite = [this](const QString& file) { + return QMessageBox::question( + this, tr("Failed to Install %1").arg(QFileInfo(file).fileName()), + tr("The file you are attempting to install already exists " + "in the cache. Would you like to overwrite it?")) == QMessageBox::Yes; }; - if (filename.endsWith(QStringLiteral("xci"), Qt::CaseInsensitive) || - filename.endsWith(QStringLiteral("nsp"), Qt::CaseInsensitive)) { - std::shared_ptr nsp; - if (filename.endsWith(QStringLiteral("nsp"), Qt::CaseInsensitive)) { - nsp = std::make_shared( - vfs->OpenFile(filename.toStdString(), FileSys::Mode::Read)); - if (nsp->IsExtractedType()) - failed(); - } else { - const auto xci = std::make_shared( - vfs->OpenFile(filename.toStdString(), FileSys::Mode::Read)); - nsp = xci->GetSecurePartitionNSP(); - } + for (const QString& filename : filenames) { + if (filename.endsWith(QStringLiteral("xci"), Qt::CaseInsensitive) || + filename.endsWith(QStringLiteral("nsp"), Qt::CaseInsensitive)) { + std::shared_ptr nsp; + if (filename.endsWith(QStringLiteral("nsp"), Qt::CaseInsensitive)) { + nsp = std::make_shared( + vfs->OpenFile(filename.toStdString(), FileSys::Mode::Read)); + if (nsp->IsExtractedType()) { + failed(filename); + break; + } + } else { + const auto xci = std::make_shared( + vfs->OpenFile(filename.toStdString(), FileSys::Mode::Read)); + nsp = xci->GetSecurePartitionNSP(); + } - if (nsp->GetStatus() != Loader::ResultStatus::Success) { - failed(); - return; - } - const auto res = Core::System::GetInstance() - .GetFileSystemController() - .GetUserNANDContents() - ->InstallEntry(*nsp, false, qt_raw_copy); - if (res == FileSys::InstallResult::Success) { - success(); - } else { - if (res == FileSys::InstallResult::ErrorAlreadyExists) { - if (overwrite()) { + if (nsp->GetStatus() != Loader::ResultStatus::Success) { + failed(filename); + break; + } + const auto res = Core::System::GetInstance() + .GetFileSystemController() + .GetUserNANDContents() + ->InstallEntry(*nsp, false, qt_raw_copy); + if (res == FileSys::InstallResult::Success) { + ++count; + } else if (res == FileSys::InstallResult::ErrorAlreadyExists) { + if (overwrite_files && overwrite(filename)) { const auto res2 = Core::System::GetInstance() .GetFileSystemController() .GetUserNANDContents() ->InstallEntry(*nsp, true, qt_raw_copy); - if (res2 == FileSys::InstallResult::Success) { - success(); - } else { - failed(); + if (res2 != FileSys::InstallResult::Success) { + failed(filename); + break; } + ++count; + } else { + --total_count; } } else { - failed(); + failed(filename); + break; } - } - } else { - const auto nca = std::make_shared( - 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) { - failed(); - return; - } + } else { + const auto nca = std::make_shared( + vfs->OpenFile(filename.toStdString(), FileSys::Mode::Read)); + const auto id = nca->GetStatus(); - const QStringList tt_options{tr("System Application"), - tr("System Archive"), - tr("System Application Update"), - tr("Firmware Package (Type A)"), - tr("Firmware Package (Type B)"), - tr("Game"), - tr("Game Update"), - tr("Game DLC"), - tr("Delta Title")}; - bool ok; - const auto item = QInputDialog::getItem( - this, tr("Select NCA Install Type..."), - tr("Please select the type of title you would like to install this NCA as:\n(In " - "most instances, the default 'Game' is fine.)"), - tt_options, 5, false, &ok); - - auto index = tt_options.indexOf(item); - if (!ok || index == -1) { - QMessageBox::warning(this, tr("Failed to Install"), - tr("The title type you selected for the NCA is invalid.")); - return; - } + // Game updates necessary are missing base RomFS + if (id != Loader::ResultStatus::Success && + id != Loader::ResultStatus::ErrorMissingBKTRBaseRomFS) { + failed(filename); + break; + } - // If index is equal to or past Game, add the jump in TitleType. - if (index >= 5) { - index += static_cast(FileSys::TitleType::Application) - - static_cast(FileSys::TitleType::FirmwarePackageB); - } + const QStringList tt_options{tr("System Application"), + tr("System Archive"), + tr("System Application Update"), + tr("Firmware Package (Type A)"), + tr("Firmware Package (Type B)"), + tr("Game"), + tr("Game Update"), + tr("Game DLC"), + tr("Delta Title")}; + bool ok; + const auto item = QInputDialog::getItem( + this, tr("Select NCA Install Type..."), + tr("Please select the type of title you would like to install this NCA as:\n(In " + "most instances, the default 'Game' is fine.)"), + tt_options, 5, false, &ok); + + auto index = tt_options.indexOf(item); + if (!ok || index == -1) { + QMessageBox::warning(this, tr("Failed to Install"), + tr("The title type you selected for the NCA is invalid.")); + break; + } - FileSys::InstallResult res; - if (index >= static_cast(FileSys::TitleType::Application)) { - res = Core::System::GetInstance() - .GetFileSystemController() - .GetUserNANDContents() - ->InstallEntry(*nca, static_cast(index), false, - qt_raw_copy); - } else { - res = Core::System::GetInstance() - .GetFileSystemController() - .GetSystemNANDContents() - ->InstallEntry(*nca, static_cast(index), false, - qt_raw_copy); - } + // If index is equal to or past Game, add the jump in TitleType. + if (index >= 5) { + index += static_cast(FileSys::TitleType::Application) - + static_cast(FileSys::TitleType::FirmwarePackageB); + } - if (res == FileSys::InstallResult::Success) { - success(); - } else if (res == FileSys::InstallResult::ErrorAlreadyExists) { - if (overwrite()) { - const auto res2 = Core::System::GetInstance() - .GetFileSystemController() - .GetUserNANDContents() - ->InstallEntry(*nca, static_cast(index), - true, qt_raw_copy); - if (res2 == FileSys::InstallResult::Success) { - success(); + FileSys::InstallResult res; + if (index >= static_cast(FileSys::TitleType::Application)) { + res = Core::System::GetInstance() + .GetFileSystemController() + .GetUserNANDContents() + ->InstallEntry(*nca, static_cast(index), false, + qt_raw_copy); + } else { + res = Core::System::GetInstance() + .GetFileSystemController() + .GetSystemNANDContents() + ->InstallEntry(*nca, static_cast(index), false, + qt_raw_copy); + } + + if (res == FileSys::InstallResult::Success) { + ++count; + } else if (res == FileSys::InstallResult::ErrorAlreadyExists) { + if (overwrite_files && overwrite(filename)) { + const auto res2 = + Core::System::GetInstance() + .GetFileSystemController() + .GetUserNANDContents() + ->InstallEntry(*nca, static_cast(index), true, + qt_raw_copy); + if (res2 != FileSys::InstallResult::Success) { + failed(filename); + break; + } + ++count; } else { - failed(); + --total_count; } + } else { + failed(filename); + break; } - } else { - failed(); + } + + // Return success only on the last file + if (filename == filenames.last()) { + success(); } } } -- cgit v1.2.3 From 7f4d96d87332824643d7a8d3ff0fab7ea771b798 Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Wed, 1 Jul 2020 16:15:57 -0400 Subject: Refactor batch installing files Key issues fixed: - Progress dialog showing up as white/hanging/getting stuck/unresponsive. Key changes: - Progress dialog now shows progress as a function of all files instead of per nca within a file. - Overwrite existing files will overwrite all files in the selection. --- src/yuzu/main.cpp | 399 +++++++++++++++++++++++++++++------------------------- 1 file changed, 214 insertions(+), 185 deletions(-) (limited to 'src/yuzu/main.cpp') diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 45ddc3baf..4539cbe0d 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -1599,28 +1599,107 @@ void GMainWindow::OnMenuInstallToNAND() { tr("Installable Switch File (*.nca *.nsp *.xci);;Nintendo Content Archive " "(*.nca);;Nintendo Submission Package (*.nsp);;NX Cartridge " "Image (*.xci)"); - QStringList files = QFileDialog::getOpenFileNames(this, tr("Install Files"), - UISettings::values.roms_path, file_filter); - if (files.isEmpty()) { + QStringList filenames = QFileDialog::getOpenFileNames( + this, tr("Install Files"), UISettings::values.roms_path, file_filter); + + if (filenames.isEmpty()) { return; } - InstallDialog installDialog(this, files); + InstallDialog installDialog(this, filenames); if (installDialog.exec() == QDialog::Rejected) { return; } - const QStringList filenames = installDialog.GetFilenames(); + const QStringList files = installDialog.GetFiles(); const bool overwrite_files = installDialog.ShouldOverwriteFiles(); int count = 0; - int total_count = filenames.size(); - bool is_progressdialog_created = false; + const int total_count = filenames.size(); + + QStringList new_files{}; // Newly installed files that do not yet exist in the NAND + QStringList overwritten_files{}; // Files that overwrote those existing in the NAND + QStringList existing_files{}; // Files that were not installed as they already exist in the NAND + QStringList failed_files{}; // Files that failed to install due to errors + + ui.action_Install_File_NAND->setEnabled(false); + + QProgressDialog install_progress(QStringLiteral(""), tr("Cancel"), 0, total_count, this); + install_progress.setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint & + ~Qt::WindowMaximizeButtonHint); + install_progress.setAutoClose(false); + install_progress.setFixedWidth(installDialog.GetMinimumWidth()); + install_progress.show(); + + for (const QString& file : files) { + install_progress.setWindowTitle(tr("%n file(s) remaining", "", total_count - count)); + install_progress.setLabelText( + tr("Installing file \"%1\"...").arg(QFileInfo(file).fileName())); + + QFuture future; + InstallResult result; + + if (file.endsWith(QStringLiteral("xci"), Qt::CaseInsensitive) || + file.endsWith(QStringLiteral("nsp"), Qt::CaseInsensitive)) { + future = QtConcurrent::run([this, &file, &overwrite_files, &install_progress] { + return InstallNSPXCI(file, overwrite_files, install_progress); + }); + + while (!future.isFinished()) { + QCoreApplication::processEvents(); + } + + result = future.result(); + } else { + result = InstallNCA(file, overwrite_files, install_progress); + } - const auto qt_raw_copy = [this, &count, &total_count, &is_progressdialog_created]( - const FileSys::VirtualFile& src, const FileSys::VirtualFile& dest, - std::size_t block_size) { + switch (result) { + case InstallResult::Success: + new_files.append(QFileInfo(file).fileName()); + break; + case InstallResult::Overwrite: + overwritten_files.append(QFileInfo(file).fileName()); + break; + case InstallResult::AlreadyExists: + existing_files.append(QFileInfo(file).fileName()); + break; + case InstallResult::Failure: + failed_files.append(QFileInfo(file).fileName()); + break; + } + + install_progress.setValue(++count); + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + } + + install_progress.close(); + + const QString install_results = + (new_files.isEmpty() ? QStringLiteral("") + : tr("%n file(s) were newly installed\n", "", new_files.size())) + + (overwritten_files.isEmpty() + ? QStringLiteral("") + : tr("%n file(s) were overwritten\n", "", overwritten_files.size())) + + (existing_files.isEmpty() + ? QStringLiteral("") + : tr("%n file(s) already exist in NAND\n", "", existing_files.size())) + + (failed_files.isEmpty() ? QStringLiteral("") + : tr("%n file(s) failed to install\n", "", failed_files.size())); + + QMessageBox::information(this, tr("Install Results"), install_results); + game_list->PopulateAsync(UISettings::values.game_dirs); + FileUtil::DeleteDirRecursively(FileUtil::GetUserPath(FileUtil::UserPath::CacheDir) + DIR_SEP + + "game_list"); + ui.action_Install_File_NAND->setEnabled(true); +} + +InstallResult GMainWindow::InstallNSPXCI(const QString& filename, bool overwrite_files, + QProgressDialog& install_progress) { + const auto qt_raw_copy = [this, &install_progress](const FileSys::VirtualFile& src, + const FileSys::VirtualFile& dest, + std::size_t block_size) { if (src == nullptr || dest == nullptr) { return false; } @@ -1629,204 +1708,154 @@ void GMainWindow::OnMenuInstallToNAND() { } std::array buffer{}; - const int progress_maximum = static_cast(src->GetSize() / buffer.size()); - - if (!is_progressdialog_created) { - ui.action_Install_File_NAND->setEnabled(false); - install_progress = new QProgressDialog( - tr("Installing file \"%1\"...").arg(QString::fromStdString(src->GetName())), - tr("Cancel"), 0, progress_maximum, this); - install_progress->setWindowTitle( - tr("%n file(s) remaining", "", total_count - count - 1)); - install_progress->setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint & - ~Qt::WindowMaximizeButtonHint); - install_progress->setAutoClose(false); - is_progressdialog_created = true; - } else { - install_progress->setWindowTitle( - tr("%n file(s) remaining", "", total_count - count - 1)); - install_progress->setLabelText( - tr("Installing file \"%1\"...").arg(QString::fromStdString(src->GetName()))); - install_progress->setMaximum(progress_maximum); - } for (std::size_t i = 0; i < src->GetSize(); i += buffer.size()) { - if (install_progress->wasCanceled()) { + if (install_progress.wasCanceled()) { dest->Resize(0); return false; } - const int progress_value = static_cast(i / buffer.size()); - install_progress->setValue(progress_value); - const auto read = src->Read(buffer.data(), buffer.size(), i); dest->Write(buffer.data(), read, i); } - return true; }; - const auto success = [this, &count, &is_progressdialog_created]() { - if (is_progressdialog_created) { - install_progress->close(); - } - QMessageBox::information(this, tr("Successfully Installed"), - tr("%n file(s) successfully installed", "", count)); - game_list->PopulateAsync(UISettings::values.game_dirs); - FileUtil::DeleteDirRecursively(FileUtil::GetUserPath(FileUtil::UserPath::CacheDir) + - DIR_SEP + "game_list"); - ui.action_Install_File_NAND->setEnabled(true); - }; - - const auto failed = [this, &is_progressdialog_created](const QString& file) { - if (is_progressdialog_created) { - install_progress->close(); + std::shared_ptr nsp; + if (filename.endsWith(QStringLiteral("nsp"), Qt::CaseInsensitive)) { + nsp = std::make_shared( + vfs->OpenFile(filename.toStdString(), FileSys::Mode::Read)); + if (nsp->IsExtractedType()) { + return InstallResult::Failure; } - QMessageBox::warning( - this, tr("Failed to Install %1").arg(QFileInfo(file).fileName()), - tr("There was an error while attempting to install the provided file. It " - "could have an incorrect format or be missing metadata. Please " - "double-check your file and try again.")); - game_list->PopulateAsync(UISettings::values.game_dirs); - ui.action_Install_File_NAND->setEnabled(true); - }; - - const auto overwrite = [this](const QString& file) { - return QMessageBox::question( - this, tr("Failed to Install %1").arg(QFileInfo(file).fileName()), - tr("The file you are attempting to install already exists " - "in the cache. Would you like to overwrite it?")) == QMessageBox::Yes; - }; - - for (const QString& filename : filenames) { - if (filename.endsWith(QStringLiteral("xci"), Qt::CaseInsensitive) || - filename.endsWith(QStringLiteral("nsp"), Qt::CaseInsensitive)) { - std::shared_ptr nsp; - if (filename.endsWith(QStringLiteral("nsp"), Qt::CaseInsensitive)) { - nsp = std::make_shared( - vfs->OpenFile(filename.toStdString(), FileSys::Mode::Read)); - if (nsp->IsExtractedType()) { - failed(filename); - break; - } - } else { - const auto xci = std::make_shared( - vfs->OpenFile(filename.toStdString(), FileSys::Mode::Read)); - nsp = xci->GetSecurePartitionNSP(); - } - - if (nsp->GetStatus() != Loader::ResultStatus::Success) { - failed(filename); - break; - } - const auto res = Core::System::GetInstance() - .GetFileSystemController() - .GetUserNANDContents() - ->InstallEntry(*nsp, false, qt_raw_copy); - if (res == FileSys::InstallResult::Success) { - ++count; - } else if (res == FileSys::InstallResult::ErrorAlreadyExists) { - if (overwrite_files && overwrite(filename)) { - const auto res2 = Core::System::GetInstance() - .GetFileSystemController() - .GetUserNANDContents() - ->InstallEntry(*nsp, true, qt_raw_copy); - if (res2 != FileSys::InstallResult::Success) { - failed(filename); - break; - } - ++count; - } else { - --total_count; - } - } else { - failed(filename); - break; + } else { + const auto xci = std::make_shared( + vfs->OpenFile(filename.toStdString(), FileSys::Mode::Read)); + nsp = xci->GetSecurePartitionNSP(); + } + + if (nsp->GetStatus() != Loader::ResultStatus::Success) { + return InstallResult::Failure; + } + const auto res = + Core::System::GetInstance().GetFileSystemController().GetUserNANDContents()->InstallEntry( + *nsp, false, qt_raw_copy); + if (res == FileSys::InstallResult::Success) { + return InstallResult::Success; + } else if (res == FileSys::InstallResult::ErrorAlreadyExists) { + if (overwrite_files) { + const auto res2 = Core::System::GetInstance() + .GetFileSystemController() + .GetUserNANDContents() + ->InstallEntry(*nsp, true, qt_raw_copy); + if (res2 != FileSys::InstallResult::Success) { + return InstallResult::Failure; } + return InstallResult::Overwrite; } else { - const auto nca = std::make_shared( - 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) { - failed(filename); - break; - } + return InstallResult::AlreadyExists; + } + } else { + return InstallResult::Failure; + } +} - const QStringList tt_options{tr("System Application"), - tr("System Archive"), - tr("System Application Update"), - tr("Firmware Package (Type A)"), - tr("Firmware Package (Type B)"), - tr("Game"), - tr("Game Update"), - tr("Game DLC"), - tr("Delta Title")}; - bool ok; - const auto item = QInputDialog::getItem( - this, tr("Select NCA Install Type..."), - tr("Please select the type of title you would like to install this NCA as:\n(In " - "most instances, the default 'Game' is fine.)"), - tt_options, 5, false, &ok); - - auto index = tt_options.indexOf(item); - if (!ok || index == -1) { - QMessageBox::warning(this, tr("Failed to Install"), - tr("The title type you selected for the NCA is invalid.")); - break; - } +InstallResult GMainWindow::InstallNCA(const QString& filename, bool overwrite_files, + QProgressDialog& install_progress) { + const auto qt_raw_copy = [this, &install_progress](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; + } - // If index is equal to or past Game, add the jump in TitleType. - if (index >= 5) { - index += static_cast(FileSys::TitleType::Application) - - static_cast(FileSys::TitleType::FirmwarePackageB); - } + std::array buffer{}; - FileSys::InstallResult res; - if (index >= static_cast(FileSys::TitleType::Application)) { - res = Core::System::GetInstance() - .GetFileSystemController() - .GetUserNANDContents() - ->InstallEntry(*nca, static_cast(index), false, - qt_raw_copy); - } else { - res = Core::System::GetInstance() - .GetFileSystemController() - .GetSystemNANDContents() - ->InstallEntry(*nca, static_cast(index), false, - qt_raw_copy); + for (std::size_t i = 0; i < src->GetSize(); i += buffer.size()) { + if (install_progress.wasCanceled()) { + dest->Resize(0); + return false; } - if (res == FileSys::InstallResult::Success) { - ++count; - } else if (res == FileSys::InstallResult::ErrorAlreadyExists) { - if (overwrite_files && overwrite(filename)) { - const auto res2 = - Core::System::GetInstance() - .GetFileSystemController() - .GetUserNANDContents() - ->InstallEntry(*nca, static_cast(index), true, - qt_raw_copy); - if (res2 != FileSys::InstallResult::Success) { - failed(filename); - break; - } - ++count; - } else { - --total_count; - } - } else { - failed(filename); - break; - } + const auto read = src->Read(buffer.data(), buffer.size(), i); + dest->Write(buffer.data(), read, i); } + return true; + }; - // Return success only on the last file - if (filename == filenames.last()) { - success(); + const auto nca = + std::make_shared(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; + } + + const QStringList tt_options{tr("System Application"), + tr("System Archive"), + tr("System Application Update"), + tr("Firmware Package (Type A)"), + tr("Firmware Package (Type B)"), + tr("Game"), + tr("Game Update"), + tr("Game DLC"), + tr("Delta Title")}; + bool ok; + const auto item = QInputDialog::getItem( + this, tr("Select NCA Install Type..."), + tr("Please select the type of title you would like to install this NCA as:\n(In " + "most instances, the default 'Game' is fine.)"), + tt_options, 5, false, &ok); + + auto index = tt_options.indexOf(item); + 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; + } + + // If index is equal to or past Game, add the jump in TitleType. + if (index >= 5) { + index += static_cast(FileSys::TitleType::Application) - + static_cast(FileSys::TitleType::FirmwarePackageB); + } + + FileSys::InstallResult res; + if (index >= static_cast(FileSys::TitleType::Application)) { + res = Core::System::GetInstance() + .GetFileSystemController() + .GetUserNANDContents() + ->InstallEntry(*nca, static_cast(index), false, qt_raw_copy); + } else { + res = Core::System::GetInstance() + .GetFileSystemController() + .GetSystemNANDContents() + ->InstallEntry(*nca, static_cast(index), false, qt_raw_copy); + } + + if (res == FileSys::InstallResult::Success) { + return InstallResult::Success; + } else if (res == FileSys::InstallResult::ErrorAlreadyExists) { + if (overwrite_files) { + const auto res2 = + Core::System::GetInstance() + .GetFileSystemController() + .GetUserNANDContents() + ->InstallEntry(*nca, static_cast(index), true, qt_raw_copy); + if (res2 != FileSys::InstallResult::Success) { + return InstallResult::Failure; + } + return InstallResult::Overwrite; + } else { + return InstallResult::AlreadyExists; } + } else { + return InstallResult::Failure; } } -- cgit v1.2.3 From 6d8d7ebc66d9deb5adb4edb246590481b1236bbc Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Sun, 5 Jul 2020 09:29:39 -0400 Subject: Update the install and progress dialogs - Remove the overwrite files checkbox, it will always overwrite - The progressbar now reflects the progress in terms of data transferred. --- src/yuzu/main.cpp | 118 ++++++++++++++++++++++++------------------------------ 1 file changed, 52 insertions(+), 66 deletions(-) (limited to 'src/yuzu/main.cpp') diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 4539cbe0d..8a57e34c7 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -848,6 +848,9 @@ void GMainWindow::ConnectWidgetEvents() { connect(game_list, &GameList::OpenPerGameGeneralRequested, this, &GMainWindow::OnGameListOpenPerGameProperties); + connect(this, &GMainWindow::UpdateInstallProgress, this, + &GMainWindow::IncrementInstallProgress); + connect(this, &GMainWindow::EmulationStarting, render_window, &GRenderWindow::OnEmulationStarting); connect(this, &GMainWindow::EmulationStopping, render_window, @@ -1594,6 +1597,10 @@ void GMainWindow::OnMenuLoadFolder() { } } +void GMainWindow::IncrementInstallProgress() { + install_progress->setValue(install_progress->value() + 1); +} + void GMainWindow::OnMenuInstallToNAND() { const QString file_filter = tr("Installable Switch File (*.nca *.nsp *.xci);;Nintendo Content Archive " @@ -1613,28 +1620,35 @@ void GMainWindow::OnMenuInstallToNAND() { } const QStringList files = installDialog.GetFiles(); - const bool overwrite_files = installDialog.ShouldOverwriteFiles(); - int count = 0; - const int total_count = filenames.size(); + int remaining = filenames.size(); + + // This would only overflow above 2^43 bytes (8.796 TB) + int total_size = 0; + for (const QString& file : files) { + total_size += static_cast(QFile(file).size() / 0x1000); + } + if (total_size < 0) { + LOG_CRITICAL(Frontend, "Attempting to install too many files, aborting."); + return; + } QStringList new_files{}; // Newly installed files that do not yet exist in the NAND QStringList overwritten_files{}; // Files that overwrote those existing in the NAND - QStringList existing_files{}; // Files that were not installed as they already exist in the NAND - QStringList failed_files{}; // Files that failed to install due to errors + QStringList failed_files{}; // Files that failed to install due to errors ui.action_Install_File_NAND->setEnabled(false); - QProgressDialog install_progress(QStringLiteral(""), tr("Cancel"), 0, total_count, this); - install_progress.setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint & - ~Qt::WindowMaximizeButtonHint); - install_progress.setAutoClose(false); - install_progress.setFixedWidth(installDialog.GetMinimumWidth()); - install_progress.show(); + install_progress = new QProgressDialog(QStringLiteral(""), tr("Cancel"), 0, total_size, this); + install_progress->setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint & + ~Qt::WindowMaximizeButtonHint); + install_progress->setAttribute(Qt::WA_DeleteOnClose, true); + install_progress->setFixedWidth(installDialog.GetMinimumWidth() + 40); + install_progress->show(); for (const QString& file : files) { - install_progress.setWindowTitle(tr("%n file(s) remaining", "", total_count - count)); - install_progress.setLabelText( + install_progress->setWindowTitle(tr("%n file(s) remaining", "", remaining)); + install_progress->setLabelText( tr("Installing file \"%1\"...").arg(QFileInfo(file).fileName())); QFuture future; @@ -1642,19 +1656,21 @@ void GMainWindow::OnMenuInstallToNAND() { if (file.endsWith(QStringLiteral("xci"), Qt::CaseInsensitive) || file.endsWith(QStringLiteral("nsp"), Qt::CaseInsensitive)) { - future = QtConcurrent::run([this, &file, &overwrite_files, &install_progress] { - return InstallNSPXCI(file, overwrite_files, install_progress); - }); + + future = QtConcurrent::run([this, &file] { return InstallNSPXCI(file); }); while (!future.isFinished()) { QCoreApplication::processEvents(); } result = future.result(); + } else { - result = InstallNCA(file, overwrite_files, install_progress); + result = InstallNCA(file); } + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + switch (result) { case InstallResult::Success: new_files.append(QFileInfo(file).fileName()); @@ -1662,19 +1678,15 @@ void GMainWindow::OnMenuInstallToNAND() { case InstallResult::Overwrite: overwritten_files.append(QFileInfo(file).fileName()); break; - case InstallResult::AlreadyExists: - existing_files.append(QFileInfo(file).fileName()); - break; case InstallResult::Failure: failed_files.append(QFileInfo(file).fileName()); break; } - install_progress.setValue(++count); - std::this_thread::sleep_for(std::chrono::milliseconds(10)); + --remaining; } - install_progress.close(); + install_progress->close(); const QString install_results = (new_files.isEmpty() ? QStringLiteral("") @@ -1682,9 +1694,6 @@ void GMainWindow::OnMenuInstallToNAND() { (overwritten_files.isEmpty() ? QStringLiteral("") : tr("%n file(s) were overwritten\n", "", overwritten_files.size())) + - (existing_files.isEmpty() - ? QStringLiteral("") - : tr("%n file(s) already exist in NAND\n", "", existing_files.size())) + (failed_files.isEmpty() ? QStringLiteral("") : tr("%n file(s) failed to install\n", "", failed_files.size())); @@ -1695,11 +1704,9 @@ void GMainWindow::OnMenuInstallToNAND() { ui.action_Install_File_NAND->setEnabled(true); } -InstallResult GMainWindow::InstallNSPXCI(const QString& filename, bool overwrite_files, - QProgressDialog& install_progress) { - const auto qt_raw_copy = [this, &install_progress](const FileSys::VirtualFile& src, - const FileSys::VirtualFile& dest, - std::size_t block_size) { +InstallResult GMainWindow::InstallNSPXCI(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; } @@ -1710,11 +1717,13 @@ InstallResult GMainWindow::InstallNSPXCI(const QString& filename, bool overwrite std::array buffer{}; for (std::size_t i = 0; i < src->GetSize(); i += buffer.size()) { - if (install_progress.wasCanceled()) { + 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); } @@ -1739,32 +1748,19 @@ InstallResult GMainWindow::InstallNSPXCI(const QString& filename, bool overwrite } const auto res = Core::System::GetInstance().GetFileSystemController().GetUserNANDContents()->InstallEntry( - *nsp, false, qt_raw_copy); + *nsp, true, qt_raw_copy); if (res == FileSys::InstallResult::Success) { return InstallResult::Success; } else if (res == FileSys::InstallResult::ErrorAlreadyExists) { - if (overwrite_files) { - const auto res2 = Core::System::GetInstance() - .GetFileSystemController() - .GetUserNANDContents() - ->InstallEntry(*nsp, true, qt_raw_copy); - if (res2 != FileSys::InstallResult::Success) { - return InstallResult::Failure; - } - return InstallResult::Overwrite; - } else { - return InstallResult::AlreadyExists; - } + return InstallResult::Overwrite; } else { return InstallResult::Failure; } } -InstallResult GMainWindow::InstallNCA(const QString& filename, bool overwrite_files, - QProgressDialog& install_progress) { - const auto qt_raw_copy = [this, &install_progress](const FileSys::VirtualFile& src, - const FileSys::VirtualFile& dest, - std::size_t block_size) { +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; } @@ -1775,11 +1771,13 @@ InstallResult GMainWindow::InstallNCA(const QString& filename, bool overwrite_fi std::array buffer{}; for (std::size_t i = 0; i < src->GetSize(); i += buffer.size()) { - if (install_progress.wasCanceled()) { + 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); } @@ -1830,30 +1828,18 @@ InstallResult GMainWindow::InstallNCA(const QString& filename, bool overwrite_fi res = Core::System::GetInstance() .GetFileSystemController() .GetUserNANDContents() - ->InstallEntry(*nca, static_cast(index), false, qt_raw_copy); + ->InstallEntry(*nca, static_cast(index), true, qt_raw_copy); } else { res = Core::System::GetInstance() .GetFileSystemController() .GetSystemNANDContents() - ->InstallEntry(*nca, static_cast(index), false, qt_raw_copy); + ->InstallEntry(*nca, static_cast(index), true, qt_raw_copy); } if (res == FileSys::InstallResult::Success) { return InstallResult::Success; } else if (res == FileSys::InstallResult::ErrorAlreadyExists) { - if (overwrite_files) { - const auto res2 = - Core::System::GetInstance() - .GetFileSystemController() - .GetUserNANDContents() - ->InstallEntry(*nca, static_cast(index), true, qt_raw_copy); - if (res2 != FileSys::InstallResult::Success) { - return InstallResult::Failure; - } - return InstallResult::Overwrite; - } else { - return InstallResult::AlreadyExists; - } + return InstallResult::Overwrite; } else { return InstallResult::Failure; } -- cgit v1.2.3 From 75a01475d174a8dbea7dcf41002cb53abce1d8bb Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Wed, 8 Jul 2020 13:01:25 -0400 Subject: Add additional empty check for the QStringList returned by the InstallDialog --- src/yuzu/main.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/yuzu/main.cpp') diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 8a57e34c7..432379705 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -1621,6 +1621,10 @@ void GMainWindow::OnMenuInstallToNAND() { const QStringList files = installDialog.GetFiles(); + if (files.isEmpty()) { + return; + } + int remaining = filenames.size(); // This would only overflow above 2^43 bytes (8.796 TB) -- cgit v1.2.3