mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-12-26 16:40:06 +00: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:
parent
57616f9758
commit
cbb146069a
@ -756,6 +756,46 @@ void GMainWindow::OnGameListOpenFolder(u64 program_id, GameListOpenTarget target
|
|||||||
QDesktopServices::openUrl(QUrl::fromLocalFile(qpath));
|
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) {
|
void GMainWindow::OnGameListDumpRomFS(u64 program_id, const std::string& game_path) {
|
||||||
const auto path = fmt::format("{}{:016X}/romfs",
|
const auto path = fmt::format("{}{:016X}/romfs",
|
||||||
FileUtil::GetUserPath(FileUtil::UserPath::DumpDir), program_id);
|
FileUtil::GetUserPath(FileUtil::UserPath::DumpDir), program_id);
|
||||||
@ -808,53 +848,13 @@ void GMainWindow::OnGameListDumpRomFS(u64 program_id, const std::string& game_pa
|
|||||||
failed();
|
failed();
|
||||||
|
|
||||||
const auto full = res == "Full";
|
const auto full = res == "Full";
|
||||||
|
const auto entry_size = CalculateRomFSEntrySize(extracted, 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);
|
|
||||||
|
|
||||||
QProgressDialog progress(tr("Extracting RomFS..."), tr("Cancel"), 0, entry_size, this);
|
QProgressDialog progress(tr("Extracting RomFS..."), tr("Cancel"), 0, entry_size, this);
|
||||||
progress.setWindowModality(Qt::WindowModal);
|
progress.setWindowModality(Qt::WindowModal);
|
||||||
progress.setMinimumDuration(100);
|
progress.setMinimumDuration(100);
|
||||||
|
|
||||||
static const std::function<bool(QProgressDialog&, const FileSys::VirtualDir&,
|
if (RomFSRawCopy(progress, extracted, out, 0x400000, full)) {
|
||||||
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)) {
|
|
||||||
progress.close();
|
progress.close();
|
||||||
QMessageBox::information(this, tr("RomFS Extraction Succeeded!"),
|
QMessageBox::information(this, tr("RomFS Extraction Succeeded!"),
|
||||||
tr("The operation completed successfully."));
|
tr("The operation completed successfully."));
|
||||||
|
Loading…
Reference in New Issue
Block a user