2
1
Fork 0
mirror of https://github.com/yuzu-emu/yuzu.git synced 2024-07-04 23:31:19 +01:00

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.
This commit is contained in:
Lioncash 2018-09-25 18:04:22 -04:00
parent 57616f9758
commit cbb146069a

View file

@ -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<std::size_t(const FileSys::VirtualDir&, bool)> 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<bool(QProgressDialog&, const FileSys::VirtualDir&,
const FileSys::VirtualDir&, std::size_t, bool)>
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."));