From 66f7e9641369aeca436d7cbb4b7760795952ce8a Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sat, 10 Sep 2022 00:07:42 +0200 Subject: [PATCH] CPackedStore: do not pack empty files Empty files have no place in a VPK. --- r5dev/vpklib/packedstore.cpp | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/r5dev/vpklib/packedstore.cpp b/r5dev/vpklib/packedstore.cpp index 66e4233e..37e69866 100644 --- a/r5dev/vpklib/packedstore.cpp +++ b/r5dev/vpklib/packedstore.cpp @@ -130,15 +130,19 @@ vector CPackedStore::GetEntryPaths(const string& svPathIn) const fs::recursive_directory_iterator dir(svPathIn), end; while (dir != end) { - vector::iterator it = std::find(vIgnore.begin(), vIgnore.end(), + const vector::iterator it = std::find(vIgnore.begin(), vIgnore.end(), GetExtension(dir->path().filename().u8string(), true, true)); if (it != vIgnore.end()) { dir.disable_recursion_pending(); // Skip all ignored folders and extensions. } - if (!GetExtension(dir->path().u8string()).empty()) + else if (dir->file_size() > 0) // Empty files are not supported. { - vPaths.push_back(ConvertToUnixPath(dir->path().u8string())); + const string svPath = dir->path().u8string(); + if (!GetExtension(svPath).empty()) + { + vPaths.push_back(ConvertToUnixPath(svPath)); + } } dir++; } @@ -159,27 +163,31 @@ vector CPackedStore::GetEntryPaths(const string& svPathIn, const nlohman fs::recursive_directory_iterator dir(svPathIn), end; while (dir != end) { - vector::iterator it = std::find(vIgnore.begin(), vIgnore.end(), + const vector::iterator it = std::find(vIgnore.begin(), vIgnore.end(), GetExtension(dir->path().filename().u8string(), true, true)); if (it != vIgnore.end()) { dir.disable_recursion_pending(); // Skip all ignored folders and extensions. } - else if (!GetExtension(dir->path().u8string()).empty()) + else if (dir->file_size() > 0) // Empty files are not supported. { - if (!jManifest.is_null()) + const string svPath = dir->path().u8string(); + if (!GetExtension(svPath).empty()) { - try + if (!jManifest.is_null()) { - string svEntryPath = ConvertToUnixPath(dir->path().u8string()); - if (jManifest.contains(StringReplaceC(svEntryPath, svPathIn, ""))) + try { - vPaths.push_back(svEntryPath); + const string svEntryPath = ConvertToUnixPath(svPath); + if (jManifest.contains(StringReplaceC(svEntryPath, svPathIn, ""))) + { + vPaths.push_back(svEntryPath); + } + } + catch (const std::exception& ex) + { + Warning(eDLL_T::FS, "Exception while reading VPK control file: '%s'\n", ex.what()); } - } - catch (const std::exception& ex) - { - Warning(eDLL_T::FS, "Exception while reading VPK control file: '%s'\n", ex.what()); } } }