diff options
| author | 2018-09-25 18:04:22 -0400 | |
|---|---|---|
| committer | 2018-09-25 20:06:21 -0400 | |
| commit | cbb146069a7b20d5687d5d163fd1400af3151485 (patch) | |
| tree | 09f317f648af4402121d9cd86e92ac8c54b8517a /src | |
| parent | vfs/etc: Append std:: to size_t usages (diff) | |
| download | yuzu-cbb146069a7b20d5687d5d163fd1400af3151485.tar.gz yuzu-cbb146069a7b20d5687d5d163fd1400af3151485.tar.xz yuzu-cbb146069a7b20d5687d5d163fd1400af3151485.zip | |
yuzu/main: Move functions stored into static std::function instances out of OnGameListDumpRomFS()
This can cause warnings about static constructors, and is also not ideal
performance-wise due to the indirection through std::function. This also
keeps the behavior itself separate from the surrounding code, which can
make it nicer to read, due to the size of the code.
Diffstat (limited to 'src')
| -rw-r--r-- | src/yuzu/main.cpp | 84 |
1 files changed, 42 insertions, 42 deletions
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 1455edc89..1b125cbd3 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp | |||
| @@ -756,6 +756,46 @@ void GMainWindow::OnGameListOpenFolder(u64 program_id, GameListOpenTarget target | |||
| 756 | QDesktopServices::openUrl(QUrl::fromLocalFile(qpath)); | 756 | QDesktopServices::openUrl(QUrl::fromLocalFile(qpath)); |
| 757 | } | 757 | } |
| 758 | 758 | ||
| 759 | static std::size_t CalculateRomFSEntrySize(const FileSys::VirtualDir& dir, bool full) { | ||
| 760 | std::size_t out = 0; | ||
| 761 | |||
| 762 | for (const auto& subdir : dir->GetSubdirectories()) { | ||
| 763 | out += 1 + CalculateRomFSEntrySize(subdir, full); | ||
| 764 | } | ||
| 765 | |||
| 766 | return out + full ? dir->GetFiles().size() : 0; | ||
| 767 | } | ||
| 768 | |||
| 769 | static bool RomFSRawCopy(QProgressDialog& dialog, const FileSys::VirtualDir& src, | ||
| 770 | const FileSys::VirtualDir& dest, std::size_t block_size, bool full) { | ||
| 771 | if (src == nullptr || dest == nullptr || !src->IsReadable() || !dest->IsWritable()) | ||
| 772 | return false; | ||
| 773 | if (dialog.wasCanceled()) | ||
| 774 | return false; | ||
| 775 | |||
| 776 | if (full) { | ||
| 777 | for (const auto& file : src->GetFiles()) { | ||
| 778 | const auto out = VfsDirectoryCreateFileWrapper(dest, file->GetName()); | ||
| 779 | if (!FileSys::VfsRawCopy(file, out, block_size)) | ||
| 780 | return false; | ||
| 781 | dialog.setValue(dialog.value() + 1); | ||
| 782 | if (dialog.wasCanceled()) | ||
| 783 | return false; | ||
| 784 | } | ||
| 785 | } | ||
| 786 | |||
| 787 | for (const auto& dir : src->GetSubdirectories()) { | ||
| 788 | const auto out = dest->CreateSubdirectory(dir->GetName()); | ||
| 789 | if (!RomFSRawCopy(dialog, dir, out, block_size, full)) | ||
| 790 | return false; | ||
| 791 | dialog.setValue(dialog.value() + 1); | ||
| 792 | if (dialog.wasCanceled()) | ||
| 793 | return false; | ||
| 794 | } | ||
| 795 | |||
| 796 | return true; | ||
| 797 | } | ||
| 798 | |||
| 759 | void GMainWindow::OnGameListDumpRomFS(u64 program_id, const std::string& game_path) { | 799 | void GMainWindow::OnGameListDumpRomFS(u64 program_id, const std::string& game_path) { |
| 760 | const auto path = fmt::format("{}{:016X}/romfs", | 800 | const auto path = fmt::format("{}{:016X}/romfs", |
| 761 | FileUtil::GetUserPath(FileUtil::UserPath::DumpDir), program_id); | 801 | FileUtil::GetUserPath(FileUtil::UserPath::DumpDir), program_id); |
| @@ -808,53 +848,13 @@ void GMainWindow::OnGameListDumpRomFS(u64 program_id, const std::string& game_pa | |||
| 808 | failed(); | 848 | failed(); |
| 809 | 849 | ||
| 810 | const auto full = res == "Full"; | 850 | const auto full = res == "Full"; |
| 811 | 851 | const auto entry_size = CalculateRomFSEntrySize(extracted, full); | |
| 812 | static const std::function<std::size_t(const FileSys::VirtualDir&, bool)> calculate_entry_size = | ||
| 813 | [](const FileSys::VirtualDir& dir, bool full) { | ||
| 814 | std::size_t out = 0; | ||
| 815 | for (const auto& subdir : dir->GetSubdirectories()) | ||
| 816 | out += 1 + calculate_entry_size(subdir, full); | ||
| 817 | return out + full ? dir->GetFiles().size() : 0; | ||
| 818 | }; | ||
| 819 | const auto entry_size = calculate_entry_size(extracted, full); | ||
| 820 | 852 | ||
| 821 | QProgressDialog progress(tr("Extracting RomFS..."), tr("Cancel"), 0, entry_size, this); | 853 | QProgressDialog progress(tr("Extracting RomFS..."), tr("Cancel"), 0, entry_size, this); |
| 822 | progress.setWindowModality(Qt::WindowModal); | 854 | progress.setWindowModality(Qt::WindowModal); |
| 823 | progress.setMinimumDuration(100); | 855 | progress.setMinimumDuration(100); |
| 824 | 856 | ||
| 825 | static const std::function<bool(QProgressDialog&, const FileSys::VirtualDir&, | 857 | if (RomFSRawCopy(progress, extracted, out, 0x400000, full)) { |
| 826 | const FileSys::VirtualDir&, std::size_t, bool)> | ||
| 827 | qt_raw_copy = [](QProgressDialog& dialog, const FileSys::VirtualDir& src, | ||
| 828 | const FileSys::VirtualDir& dest, std::size_t block_size, bool full) { | ||
| 829 | if (src == nullptr || dest == nullptr || !src->IsReadable() || !dest->IsWritable()) | ||
| 830 | return false; | ||
| 831 | if (dialog.wasCanceled()) | ||
| 832 | return false; | ||
| 833 | |||
| 834 | if (full) { | ||
| 835 | for (const auto& file : src->GetFiles()) { | ||
| 836 | const auto out = VfsDirectoryCreateFileWrapper(dest, file->GetName()); | ||
| 837 | if (!FileSys::VfsRawCopy(file, out, block_size)) | ||
| 838 | return false; | ||
| 839 | dialog.setValue(dialog.value() + 1); | ||
| 840 | if (dialog.wasCanceled()) | ||
| 841 | return false; | ||
| 842 | } | ||
| 843 | } | ||
| 844 | |||
| 845 | for (const auto& dir : src->GetSubdirectories()) { | ||
| 846 | const auto out = dest->CreateSubdirectory(dir->GetName()); | ||
| 847 | if (!qt_raw_copy(dialog, dir, out, block_size, full)) | ||
| 848 | return false; | ||
| 849 | dialog.setValue(dialog.value() + 1); | ||
| 850 | if (dialog.wasCanceled()) | ||
| 851 | return false; | ||
| 852 | } | ||
| 853 | |||
| 854 | return true; | ||
| 855 | }; | ||
| 856 | |||
| 857 | if (qt_raw_copy(progress, extracted, out, 0x400000, full)) { | ||
| 858 | progress.close(); | 858 | progress.close(); |
| 859 | QMessageBox::information(this, tr("RomFS Extraction Succeeded!"), | 859 | QMessageBox::information(this, tr("RomFS Extraction Succeeded!"), |
| 860 | tr("The operation completed successfully.")); | 860 | tr("The operation completed successfully.")); |