From 57616f9758a23bbb9d1f7c5797c2831926004e49 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 25 Sep 2018 17:56:14 -0400 Subject: vfs/etc: Append std:: to size_t usages Given we just recently had a patch backport this from citra, let's try and keep the convention uniform. --- src/yuzu/main.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/yuzu/main.cpp') diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index dc8b5407d..1455edc89 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -760,7 +760,7 @@ void GMainWindow::OnGameListDumpRomFS(u64 program_id, const std::string& game_pa const auto path = fmt::format("{}{:016X}/romfs", FileUtil::GetUserPath(FileUtil::UserPath::DumpDir), program_id); - auto failed = [this, &path]() { + const auto failed = [this, &path] { QMessageBox::warning(this, tr("RomFS Extraction Failed!"), tr("There was an error copying the RomFS files or the user " "cancelled the operation.")); @@ -809,9 +809,9 @@ void GMainWindow::OnGameListDumpRomFS(u64 program_id, const std::string& game_pa const auto full = res == "Full"; - const static std::function calculate_entry_size = + static const std::function calculate_entry_size = [](const FileSys::VirtualDir& dir, bool full) { - size_t out = 0; + 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; @@ -822,10 +822,10 @@ void GMainWindow::OnGameListDumpRomFS(u64 program_id, const std::string& game_pa progress.setWindowModality(Qt::WindowModal); progress.setMinimumDuration(100); - const static std::function + static const std::function qt_raw_copy = [](QProgressDialog& dialog, const FileSys::VirtualDir& src, - const FileSys::VirtualDir& dest, size_t block_size, bool full) { + 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()) @@ -931,7 +931,7 @@ void GMainWindow::OnMenuInstallToNAND() { } const auto qt_raw_copy = [this](const FileSys::VirtualFile& src, - const FileSys::VirtualFile& dest, size_t block_size) { + const FileSys::VirtualFile& dest, std::size_t block_size) { if (src == nullptr || dest == nullptr) return false; if (!dest->Resize(src->GetSize())) -- cgit v1.2.3 From cbb146069a7b20d5687d5d163fd1400af3151485 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 25 Sep 2018 18:04:22 -0400 Subject: 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(-) (limited to 'src/yuzu/main.cpp') 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.")); -- cgit v1.2.3 From f646ca874d8589f4be4a7e6bcce69301e60b24f3 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 25 Sep 2018 18:06:35 -0400 Subject: yuzu/main: Resolve precedence bug within CalculateRomFSEntrySize() Ternary operators have a lower precedence than arithmetic operators, so what was actually occurring here is "return (out + full) ? x : y" which most definitely isn't intended, given we calculate out recursively above. We were essentially doing a lot of work for nothing. --- src/yuzu/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/yuzu/main.cpp') diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 1b125cbd3..d74489935 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -763,7 +763,7 @@ static std::size_t CalculateRomFSEntrySize(const FileSys::VirtualDir& dir, bool out += 1 + CalculateRomFSEntrySize(subdir, full); } - return out + full ? dir->GetFiles().size() : 0; + return out + (full ? dir->GetFiles().size() : 0); } static bool RomFSRawCopy(QProgressDialog& dialog, const FileSys::VirtualDir& src, -- cgit v1.2.3