summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar bunnei2018-08-17 00:19:05 -0400
committerGravatar GitHub2018-08-17 00:19:05 -0400
commit1db7839f1105cdda21c8efb7a5ca4067ded59bb2 (patch)
treef5da9623d45a8c98790dde170ef1169e107ec462 /src
parentMerge pull request #1093 from greggameplayer/GetDefaultDisplayResolutionChang... (diff)
parentqt/main: Unindent code in OnMenuInstallToNAND() (diff)
downloadyuzu-1db7839f1105cdda21c8efb7a5ca4067ded59bb2.tar.gz
yuzu-1db7839f1105cdda21c8efb7a5ca4067ded59bb2.tar.xz
yuzu-1db7839f1105cdda21c8efb7a5ca4067ded59bb2.zip
Merge pull request #1091 from lioncash/warning
qt/main: Get rid of compilation warnings
Diffstat (limited to 'src')
-rw-r--r--src/yuzu/main.cpp161
1 files changed, 83 insertions, 78 deletions
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index f7eee7769..2df65023a 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -628,24 +628,33 @@ void GMainWindow::OnMenuInstallToNAND() {
628 QString filename = QFileDialog::getOpenFileName(this, tr("Install File"), 628 QString filename = QFileDialog::getOpenFileName(this, tr("Install File"),
629 UISettings::values.roms_path, file_filter); 629 UISettings::values.roms_path, file_filter);
630 630
631 if (filename.isEmpty()) {
632 return;
633 }
634
631 const auto qt_raw_copy = [this](FileSys::VirtualFile src, FileSys::VirtualFile dest) { 635 const auto qt_raw_copy = [this](FileSys::VirtualFile src, FileSys::VirtualFile dest) {
632 if (src == nullptr || dest == nullptr) 636 if (src == nullptr || dest == nullptr)
633 return false; 637 return false;
634 if (!dest->Resize(src->GetSize())) 638 if (!dest->Resize(src->GetSize()))
635 return false; 639 return false;
636 640
637 QProgressDialog progress(fmt::format("Installing file \"{}\"...", src->GetName()).c_str(), 641 std::array<u8, 0x1000> buffer{};
638 "Cancel", 0, src->GetSize() / 0x1000, this); 642 const int progress_maximum = static_cast<int>(src->GetSize() / buffer.size());
643
644 QProgressDialog progress(
645 tr("Installing file \"%1\"...").arg(QString::fromStdString(src->GetName())),
646 tr("Cancel"), 0, progress_maximum, this);
639 progress.setWindowModality(Qt::WindowModal); 647 progress.setWindowModality(Qt::WindowModal);
640 648
641 std::array<u8, 0x1000> buffer{}; 649 for (size_t i = 0; i < src->GetSize(); i += buffer.size()) {
642 for (size_t i = 0; i < src->GetSize(); i += 0x1000) {
643 if (progress.wasCanceled()) { 650 if (progress.wasCanceled()) {
644 dest->Resize(0); 651 dest->Resize(0);
645 return false; 652 return false;
646 } 653 }
647 654
648 progress.setValue(i / 0x1000); 655 const int progress_value = static_cast<int>(i / buffer.size());
656 progress.setValue(progress_value);
657
649 const auto read = src->Read(buffer.data(), buffer.size(), i); 658 const auto read = src->Read(buffer.data(), buffer.size(), i);
650 dest->Write(buffer.data(), read, i); 659 dest->Write(buffer.data(), read, i);
651 } 660 }
@@ -668,92 +677,88 @@ void GMainWindow::OnMenuInstallToNAND() {
668 }; 677 };
669 678
670 const auto overwrite = [this]() { 679 const auto overwrite = [this]() {
671 return QMessageBox::question(this, "Failed to Install", 680 return QMessageBox::question(this, tr("Failed to Install"),
672 "The file you are attempting to install already exists " 681 tr("The file you are attempting to install already exists "
673 "in the cache. Would you like to overwrite it?") == 682 "in the cache. Would you like to overwrite it?")) ==
674 QMessageBox::Yes; 683 QMessageBox::Yes;
675 }; 684 };
676 685
677 if (!filename.isEmpty()) { 686 if (filename.endsWith("xci", Qt::CaseInsensitive)) {
678 if (filename.endsWith("xci", Qt::CaseInsensitive)) { 687 const auto xci = std::make_shared<FileSys::XCI>(
679 const auto xci = std::make_shared<FileSys::XCI>( 688 vfs->OpenFile(filename.toStdString(), FileSys::Mode::Read));
680 vfs->OpenFile(filename.toStdString(), FileSys::Mode::Read)); 689 if (xci->GetStatus() != Loader::ResultStatus::Success) {
681 if (xci->GetStatus() != Loader::ResultStatus::Success) { 690 failed();
682 failed(); 691 return;
683 return; 692 }
684 } 693 const auto res =
685 const auto res = 694 Service::FileSystem::GetUserNANDContents()->InstallEntry(xci, false, qt_raw_copy);
686 Service::FileSystem::GetUserNANDContents()->InstallEntry(xci, false, qt_raw_copy); 695 if (res == FileSys::InstallResult::Success) {
687 if (res == FileSys::InstallResult::Success) { 696 success();
688 success(); 697 } else {
689 } else { 698 if (res == FileSys::InstallResult::ErrorAlreadyExists) {
690 if (res == FileSys::InstallResult::ErrorAlreadyExists) { 699 if (overwrite()) {
691 if (overwrite()) { 700 const auto res2 = Service::FileSystem::GetUserNANDContents()->InstallEntry(
692 const auto res2 = Service::FileSystem::GetUserNANDContents()->InstallEntry( 701 xci, true, qt_raw_copy);
693 xci, true, qt_raw_copy); 702 if (res2 == FileSys::InstallResult::Success) {
694 if (res2 == FileSys::InstallResult::Success) { 703 success();
695 success(); 704 } else {
696 } else { 705 failed();
697 failed();
698 }
699 } 706 }
700 } else {
701 failed();
702 } 707 }
703 } 708 } else {
704 } else {
705 const auto nca = std::make_shared<FileSys::NCA>(
706 vfs->OpenFile(filename.toStdString(), FileSys::Mode::Read));
707 if (nca->GetStatus() != Loader::ResultStatus::Success) {
708 failed(); 709 failed();
709 return;
710 }
711
712 static const QStringList tt_options{"System Application",
713 "System Archive",
714 "System Application Update",
715 "Firmware Package (Type A)",
716 "Firmware Package (Type B)",
717 "Game",
718 "Game Update",
719 "Game DLC",
720 "Delta Title"};
721 bool ok;
722 const auto item = QInputDialog::getItem(
723 this, tr("Select NCA Install Type..."),
724 tr("Please select the type of title you would like to install this NCA as:\n(In "
725 "most instances, the default 'Game' is fine.)"),
726 tt_options, 5, false, &ok);
727
728 auto index = tt_options.indexOf(item);
729 if (!ok || index == -1) {
730 QMessageBox::warning(this, tr("Failed to Install"),
731 tr("The title type you selected for the NCA is invalid."));
732 return;
733 } 710 }
711 }
712 } else {
713 const auto nca = std::make_shared<FileSys::NCA>(
714 vfs->OpenFile(filename.toStdString(), FileSys::Mode::Read));
715 if (nca->GetStatus() != Loader::ResultStatus::Success) {
716 failed();
717 return;
718 }
734 719
735 if (index >= 5) 720 const QStringList tt_options{tr("System Application"),
736 index += 0x7B; 721 tr("System Archive"),
722 tr("System Application Update"),
723 tr("Firmware Package (Type A)"),
724 tr("Firmware Package (Type B)"),
725 tr("Game"),
726 tr("Game Update"),
727 tr("Game DLC"),
728 tr("Delta Title")};
729 bool ok;
730 const auto item = QInputDialog::getItem(
731 this, tr("Select NCA Install Type..."),
732 tr("Please select the type of title you would like to install this NCA as:\n(In "
733 "most instances, the default 'Game' is fine.)"),
734 tt_options, 5, false, &ok);
735
736 auto index = tt_options.indexOf(item);
737 if (!ok || index == -1) {
738 QMessageBox::warning(this, tr("Failed to Install"),
739 tr("The title type you selected for the NCA is invalid."));
740 return;
741 }
737 742
738 const auto res = Service::FileSystem::GetUserNANDContents()->InstallEntry( 743 if (index >= 5)
739 nca, static_cast<FileSys::TitleType>(index), false, qt_raw_copy); 744 index += 0x7B;
740 if (res == FileSys::InstallResult::Success) { 745
741 success(); 746 const auto res = Service::FileSystem::GetUserNANDContents()->InstallEntry(
742 } else { 747 nca, static_cast<FileSys::TitleType>(index), false, qt_raw_copy);
743 if (res == FileSys::InstallResult::ErrorAlreadyExists) { 748 if (res == FileSys::InstallResult::Success) {
744 if (overwrite()) { 749 success();
745 const auto res2 = Service::FileSystem::GetUserNANDContents()->InstallEntry( 750 } else if (res == FileSys::InstallResult::ErrorAlreadyExists) {
746 nca, static_cast<FileSys::TitleType>(index), true, qt_raw_copy); 751 if (overwrite()) {
747 if (res2 == FileSys::InstallResult::Success) { 752 const auto res2 = Service::FileSystem::GetUserNANDContents()->InstallEntry(
748 success(); 753 nca, static_cast<FileSys::TitleType>(index), true, qt_raw_copy);
749 } else { 754 if (res2 == FileSys::InstallResult::Success) {
750 failed(); 755 success();
751 }
752 }
753 } else { 756 } else {
754 failed(); 757 failed();
755 } 758 }
756 } 759 }
760 } else {
761 failed();
757 } 762 }
758 } 763 }
759} 764}