From cbb146069a7b20d5687d5d163fd1400af3151485 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 25 Sep 2018 18:04:22 -0400 Subject: [PATCH] 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. --- src/yuzu/main.cpp | 84 +++++++++++++++++++++++------------------------ 1 file 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 QDesktopServices::openUrl(QUrl::fromLocalFile(qpath)); } +static std::size_t CalculateRomFSEntrySize(const FileSys::VirtualDir& dir, bool full) { + std::size_t out = 0; + + for (const auto& subdir : dir->GetSubdirectories()) { + out += 1 + CalculateRomFSEntrySize(subdir, full); + } + + return out + full ? dir->GetFiles().size() : 0; +} + +static bool RomFSRawCopy(QProgressDialog& dialog, const FileSys::VirtualDir& src, + const FileSys::VirtualDir& dest, std::size_t block_size, bool full) { + if (src == nullptr || dest == nullptr || !src->IsReadable() || !dest->IsWritable()) + return false; + if (dialog.wasCanceled()) + return false; + + if (full) { + for (const auto& file : src->GetFiles()) { + const auto out = VfsDirectoryCreateFileWrapper(dest, file->GetName()); + if (!FileSys::VfsRawCopy(file, out, block_size)) + return false; + dialog.setValue(dialog.value() + 1); + if (dialog.wasCanceled()) + return false; + } + } + + for (const auto& dir : src->GetSubdirectories()) { + const auto out = dest->CreateSubdirectory(dir->GetName()); + if (!RomFSRawCopy(dialog, dir, out, block_size, full)) + return false; + dialog.setValue(dialog.value() + 1); + if (dialog.wasCanceled()) + return false; + } + + return true; +} + void GMainWindow::OnGameListDumpRomFS(u64 program_id, const std::string& game_path) { const auto path = fmt::format("{}{:016X}/romfs", FileUtil::GetUserPath(FileUtil::UserPath::DumpDir), program_id); @@ -808,53 +848,13 @@ void GMainWindow::OnGameListDumpRomFS(u64 program_id, const std::string& game_pa failed(); const auto full = res == "Full"; - - static const std::function calculate_entry_size = - [](const FileSys::VirtualDir& dir, bool full) { - std::size_t out = 0; - for (const auto& subdir : dir->GetSubdirectories()) - out += 1 + calculate_entry_size(subdir, full); - return out + full ? dir->GetFiles().size() : 0; - }; - const auto entry_size = calculate_entry_size(extracted, full); + const auto entry_size = CalculateRomFSEntrySize(extracted, full); QProgressDialog progress(tr("Extracting RomFS..."), tr("Cancel"), 0, entry_size, this); progress.setWindowModality(Qt::WindowModal); progress.setMinimumDuration(100); - static const std::function - qt_raw_copy = [](QProgressDialog& dialog, const FileSys::VirtualDir& src, - const FileSys::VirtualDir& dest, std::size_t block_size, bool full) { - if (src == nullptr || dest == nullptr || !src->IsReadable() || !dest->IsWritable()) - return false; - if (dialog.wasCanceled()) - return false; - - if (full) { - for (const auto& file : src->GetFiles()) { - const auto out = VfsDirectoryCreateFileWrapper(dest, file->GetName()); - if (!FileSys::VfsRawCopy(file, out, block_size)) - return false; - dialog.setValue(dialog.value() + 1); - if (dialog.wasCanceled()) - return false; - } - } - - for (const auto& dir : src->GetSubdirectories()) { - const auto out = dest->CreateSubdirectory(dir->GetName()); - if (!qt_raw_copy(dialog, dir, out, block_size, full)) - return false; - dialog.setValue(dialog.value() + 1); - if (dialog.wasCanceled()) - return false; - } - - return true; - }; - - if (qt_raw_copy(progress, extracted, out, 0x400000, full)) { + if (RomFSRawCopy(progress, extracted, out, 0x400000, full)) { progress.close(); QMessageBox::information(this, tr("RomFS Extraction Succeeded!"), tr("The operation completed successfully."));