diff options
author | Zach Hilman <zachhilman@gmail.com> | 2018-08-11 23:01:38 -0400 |
---|---|---|
committer | Zach Hilman <zachhilman@gmail.com> | 2018-08-11 23:01:42 -0400 |
commit | 6b76b774007020befdaa8d7475a9a4edd6d0a0a4 (patch) | |
tree | 2df8544c20f22914520ea397524d3a91159131a5 /src/yuzu/main.cpp | |
parent | fdf27bf39022d8a96c0386cc92b6670953471089 (diff) |
registration: Add support for force overwrite of installed
Diffstat (limited to 'src/yuzu/main.cpp')
-rw-r--r-- | src/yuzu/main.cpp | 88 |
1 files changed, 58 insertions, 30 deletions
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index e8254c30f6..b5f97f3327 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -650,37 +650,59 @@ void GMainWindow::OnMenuInstallToNAND() { return true; }; + const auto success = [this]() { + QMessageBox::information(this, tr("Successfully Installed"), + tr("The file was successfully installed.")); + game_list->PopulateAsync(UISettings::values.gamedir, UISettings::values.gamedir_deepscan); + }; + + const auto failed = [this]() { + QMessageBox::warning( + this, tr("Failed to Install"), + 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.")); + }; + + 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?") == + QMessageBox::Yes; + }; + if (!filename.isEmpty()) { if (filename.endsWith("xci", Qt::CaseInsensitive)) { const auto xci = std::make_shared<FileSys::XCI>( vfs->OpenFile(filename.toStdString(), FileSys::Mode::Read)); if (xci->GetStatus() != Loader::ResultStatus::Success) { - QMessageBox::warning( - this, tr("Failed to Install XCI"), - tr("The XCI file you provided is invalid. Please double-check your encryption " - "keys and the file and try again.")); + failed(); return; } - if (Service::FileSystem::GetUserNANDContents()->InstallEntry(xci, qt_raw_copy)) { - QMessageBox::information(this, tr("Successfully Installed XCI"), - tr("The file was successfully installed.")); - game_list->PopulateAsync(UISettings::values.gamedir, - UISettings::values.gamedir_deepscan); + const auto res = + Service::FileSystem::GetUserNANDContents()->InstallEntry(xci, false, qt_raw_copy); + if (res == FileSys::InstallResult::Success) { + success(); } else { - QMessageBox::warning( - this, tr("Failed to Install XCI"), - tr("There was an error while attempting to install the provided XCI file. It " - "could have an incorrect format or be missing a metadata entry. Please " - "double-check your file and try again.")); + 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<FileSys::NCA>( vfs->OpenFile(filename.toStdString(), FileSys::Mode::Read)); if (nca->GetStatus() != Loader::ResultStatus::Success) { - QMessageBox::warning( - this, tr("Failed to Install NCA"), - tr("The NCA file you provided is invalid. Please double-check your encryption " - "keys and the file and try again.")); + failed(); return; } @@ -702,7 +724,7 @@ void GMainWindow::OnMenuInstallToNAND() { auto index = tt_options.indexOf(item); if (!ok || index == -1) { - QMessageBox::warning(this, tr("Failed to Install NCA"), + QMessageBox::warning(this, tr("Failed to Install"), tr("The title type you selected for the NCA is invalid.")); return; } @@ -710,18 +732,24 @@ void GMainWindow::OnMenuInstallToNAND() { if (index >= 5) index += 0x7B; - if (Service::FileSystem::GetUserNANDContents()->InstallEntry( - nca, static_cast<FileSys::TitleType>(index), qt_raw_copy)) { - QMessageBox::information(this, tr("Successfully Installed NCA"), - tr("The file was successfully installed.")); - game_list->PopulateAsync(UISettings::values.gamedir, - UISettings::values.gamedir_deepscan); + const auto res = Service::FileSystem::GetUserNANDContents()->InstallEntry( + nca, static_cast<FileSys::TitleType>(index), false, qt_raw_copy); + if (res == FileSys::InstallResult::Success) { + success(); } else { - QMessageBox::warning(this, tr("Failed to Install NCA"), - tr("There was an error while attempting to install the " - "provided NCA file. An error might have occured creating " - "the metadata file or parsing the NCA. Please " - "double-check your file and try again.")); + if (res == FileSys::InstallResult::ErrorAlreadyExists) { + if (overwrite()) { + const auto res2 = Service::FileSystem::GetUserNANDContents()->InstallEntry( + nca, static_cast<FileSys::TitleType>(index), true, qt_raw_copy); + if (res2 == FileSys::InstallResult::Success) { + success(); + } else { + failed(); + } + } + } else { + failed(); + } } } } |