From aac807fd3a79432480f46520f228dd38ac97b54d Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 16 Aug 2018 10:28:03 -0400 Subject: [PATCH 1/3] qt/main: Get rid of compilation warnings Gets rid of truncation warnings about conversion to int. While we're at it, we can also de-hardcode the buffer size being used. --- src/yuzu/main.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index f7eee7769..2e62135f4 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -634,18 +634,22 @@ void GMainWindow::OnMenuInstallToNAND() { if (!dest->Resize(src->GetSize())) return false; + std::array buffer{}; + const int progress_maximum = static_cast(src->GetSize() / buffer.size()); + QProgressDialog progress(fmt::format("Installing file \"{}\"...", src->GetName()).c_str(), - "Cancel", 0, src->GetSize() / 0x1000, this); + "Cancel", 0, progress_maximum, this); progress.setWindowModality(Qt::WindowModal); - std::array buffer{}; - for (size_t i = 0; i < src->GetSize(); i += 0x1000) { + for (size_t i = 0; i < src->GetSize(); i += buffer.size()) { if (progress.wasCanceled()) { dest->Resize(0); return false; } - progress.setValue(i / 0x1000); + const int progress_value = static_cast(i / buffer.size()); + progress.setValue(progress_value); + const auto read = src->Read(buffer.data(), buffer.size(), i); dest->Write(buffer.data(), read, i); } From 2a3d7128d14133e8a2ae7f4559ed97bc7c843b8d Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 16 Aug 2018 10:30:41 -0400 Subject: [PATCH 2/3] qt/main: Make installation dialog text within OnMenuInstallToNAND() translatable This is user-facing text, so it should be marked as translatable by Qt. --- src/yuzu/main.cpp | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 2e62135f4..b8fc7d514 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -637,8 +637,9 @@ void GMainWindow::OnMenuInstallToNAND() { std::array buffer{}; const int progress_maximum = static_cast(src->GetSize() / buffer.size()); - QProgressDialog progress(fmt::format("Installing file \"{}\"...", src->GetName()).c_str(), - "Cancel", 0, progress_maximum, this); + QProgressDialog progress( + tr("Installing file \"%1\"...").arg(QString::fromStdString(src->GetName())), + tr("Cancel"), 0, progress_maximum, this); progress.setWindowModality(Qt::WindowModal); for (size_t i = 0; i < src->GetSize(); i += buffer.size()) { @@ -672,9 +673,9 @@ void GMainWindow::OnMenuInstallToNAND() { }; const auto overwrite = [this]() { - return QMessageBox::question(this, "Failed to Install", - "The file you are attempting to install already exists " - "in the cache. Would you like to overwrite it?") == + 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; }; @@ -713,15 +714,15 @@ void GMainWindow::OnMenuInstallToNAND() { return; } - static const QStringList tt_options{"System Application", - "System Archive", - "System Application Update", - "Firmware Package (Type A)", - "Firmware Package (Type B)", - "Game", - "Game Update", - "Game DLC", - "Delta Title"}; + 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..."), From 9791f0d5905ac29cf87756f4344ed3b6d3ac9a86 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 16 Aug 2018 10:37:56 -0400 Subject: [PATCH 3/3] qt/main: Unindent code in OnMenuInstallToNAND() We can change this into an early-return if the filename is empty. There's no need to include all of the code within the if statement. --- src/yuzu/main.cpp | 148 +++++++++++++++++++++++----------------------- 1 file changed, 74 insertions(+), 74 deletions(-) diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index b8fc7d514..2df65023a 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -628,6 +628,10 @@ void GMainWindow::OnMenuInstallToNAND() { QString filename = QFileDialog::getOpenFileName(this, tr("Install File"), UISettings::values.roms_path, file_filter); + if (filename.isEmpty()) { + return; + } + const auto qt_raw_copy = [this](FileSys::VirtualFile src, FileSys::VirtualFile dest) { if (src == nullptr || dest == nullptr) return false; @@ -679,86 +683,82 @@ void GMainWindow::OnMenuInstallToNAND() { QMessageBox::Yes; }; - if (!filename.isEmpty()) { - if (filename.endsWith("xci", Qt::CaseInsensitive)) { - const auto xci = std::make_shared( - vfs->OpenFile(filename.toStdString(), FileSys::Mode::Read)); - if (xci->GetStatus() != Loader::ResultStatus::Success) { - failed(); - return; - } - const auto res = - Service::FileSystem::GetUserNANDContents()->InstallEntry(xci, false, qt_raw_copy); - if (res == FileSys::InstallResult::Success) { - success(); - } else { - if (res == FileSys::InstallResult::ErrorAlreadyExists) { - if (overwrite()) { - const auto res2 = Service::FileSystem::GetUserNANDContents()->InstallEntry( - xci, true, qt_raw_copy); - if (res2 == FileSys::InstallResult::Success) { - success(); - } else { - failed(); - } + if (filename.endsWith("xci", Qt::CaseInsensitive)) { + const auto xci = std::make_shared( + vfs->OpenFile(filename.toStdString(), FileSys::Mode::Read)); + if (xci->GetStatus() != Loader::ResultStatus::Success) { + failed(); + return; + } + const auto res = + Service::FileSystem::GetUserNANDContents()->InstallEntry(xci, false, qt_raw_copy); + if (res == FileSys::InstallResult::Success) { + success(); + } else { + if (res == FileSys::InstallResult::ErrorAlreadyExists) { + if (overwrite()) { + const auto res2 = Service::FileSystem::GetUserNANDContents()->InstallEntry( + xci, true, qt_raw_copy); + if (res2 == FileSys::InstallResult::Success) { + success(); + } else { + failed(); } + } + } else { + failed(); + } + } + } else { + const auto nca = std::make_shared( + vfs->OpenFile(filename.toStdString(), FileSys::Mode::Read)); + if (nca->GetStatus() != Loader::ResultStatus::Success) { + failed(); + return; + } + + 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; + } + + if (index >= 5) + index += 0x7B; + + const auto res = Service::FileSystem::GetUserNANDContents()->InstallEntry( + nca, static_cast(index), false, qt_raw_copy); + if (res == FileSys::InstallResult::Success) { + success(); + } else if (res == FileSys::InstallResult::ErrorAlreadyExists) { + if (overwrite()) { + const auto res2 = Service::FileSystem::GetUserNANDContents()->InstallEntry( + nca, static_cast(index), true, qt_raw_copy); + if (res2 == FileSys::InstallResult::Success) { + success(); } else { failed(); } } } else { - const auto nca = std::make_shared( - vfs->OpenFile(filename.toStdString(), FileSys::Mode::Read)); - if (nca->GetStatus() != Loader::ResultStatus::Success) { - failed(); - return; - } - - 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; - } - - if (index >= 5) - index += 0x7B; - - const auto res = Service::FileSystem::GetUserNANDContents()->InstallEntry( - nca, static_cast(index), false, qt_raw_copy); - if (res == FileSys::InstallResult::Success) { - success(); - } else { - if (res == FileSys::InstallResult::ErrorAlreadyExists) { - if (overwrite()) { - const auto res2 = Service::FileSystem::GetUserNANDContents()->InstallEntry( - nca, static_cast(index), true, qt_raw_copy); - if (res2 == FileSys::InstallResult::Success) { - success(); - } else { - failed(); - } - } - } else { - failed(); - } - } + failed(); } } }