From 95eb3d5cc08d6b621413fd586839bcbffd7afe23 Mon Sep 17 00:00:00 2001 From: craftablescience Date: Tue, 20 Aug 2024 05:41:31 -0400 Subject: [PATCH 1/2] fix: don't print absolute paths of vpk files when verifying them --- src/verify.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/verify.cpp b/src/verify.cpp index 56f4030..02ce004 100644 --- a/src/verify.cpp +++ b/src/verify.cpp @@ -11,12 +11,11 @@ #include #include #include -#include #include #include "log.hpp" -static auto verifyArchivedFile( const std::string& archivePath, const std::string& entryPath, std::uint64_t expectedSize, std::string_view expectedSha1, std::string_view expectedCrc32, unsigned int& entries, unsigned int& errors ) -> void; +static auto verifyArchivedFile( const std::string& archivePath, const std::string& archiveRel, const std::string& entryPath, std::uint64_t expectedSize, std::string_view expectedSha1, std::string_view expectedCrc32, unsigned int& entries, unsigned int& errors ) -> void; static auto splitString( const std::string& string, const std::string& delim ) -> std::vector; @@ -73,7 +72,7 @@ auto verify( std::string_view root_, std::string_view indexLocation ) -> int { } if ( insideArchive ) { - verifyArchivedFile( path.string(), pathRel, expectedSize, expectedSha1, expectedCrc32, entries, errors ); + verifyArchivedFile( path.string(), archive, pathRel, expectedSize, expectedSha1, expectedCrc32, entries, errors ); continue; } @@ -146,7 +145,7 @@ auto verify( std::string_view root_, std::string_view indexLocation ) -> int { return 0; } -static auto verifyArchivedFile( const std::string& archivePath, const std::string& entryPath, std::uint64_t expectedSize, std::string_view expectedSha1, std::string_view expectedCrc32, unsigned int& entries, unsigned int& errors ) -> void { +static auto verifyArchivedFile( const std::string& archivePath, const std::string& archiveRel, const std::string& entryPath, std::uint64_t expectedSize, std::string_view expectedSha1, std::string_view expectedCrc32, unsigned int& entries, unsigned int& errors ) -> void { using namespace vpkpp; static std::unordered_map> loadedVPKs{}; @@ -154,11 +153,11 @@ static auto verifyArchivedFile( const std::string& archivePath, const std::strin loadedVPKs[ archivePath ] = VPK::open( archivePath ); } if (! loadedVPKs[ archivePath ]) { - Log_Error( "Failed to open VPK at `{}` (containing file at `{}`)", archivePath, entryPath ); + Log_Error( "Failed to open VPK at `{}` (containing file at `{}`)", archiveRel, entryPath ); return; } - const auto fullPath{ archivePath + '/' + entryPath }; + const auto fullPath{ archiveRel + '/' + entryPath }; auto entry{ loadedVPKs[ archivePath ]->findEntry( entryPath ) }; if (! entry ) { From 03e8b73c41e32d969478baf50898faa66a1dbdc2 Mon Sep 17 00:00:00 2001 From: craftablescience Date: Tue, 20 Aug 2024 05:43:23 -0400 Subject: [PATCH 2/2] chore: bump sourcepp --- CMakeLists.txt | 4 +-- src/create.cpp | 63 +++++++++++++++++------------------ src/thirdparty/CMakeLists.txt | 1 + src/thirdparty/sourcepp | 2 +- src/verify.cpp | 2 +- 5 files changed, 35 insertions(+), 37 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2760d5f..166bf3a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.24) project( verifier DESCRIPTION "A tool used to verify a game's install." - VERSION 0.3.2 + VERSION 0.3.3 ) set( CMAKE_CXX_STANDARD 20 ) set( CMAKE_CXX_STANDARD_REQUIRED ON ) @@ -44,7 +44,7 @@ target_compile_definitions( ${PROJECT_NAME} PRIVATE $<$:DEBUG> "VE # Link to CLI dependencies include( "${CMAKE_CURRENT_SOURCE_DIR}/src/thirdparty/CMakeLists.txt" ) -target_link_libraries( ${PROJECT_NAME} PRIVATE Argumentum::argumentum cryptopp::cryptopp fmt::fmt kvpp vpkpp) +target_link_libraries( ${PROJECT_NAME} PRIVATE Argumentum::argumentum cryptopp::cryptopp fmt::fmt sourcepp::kvpp sourcepp::vpkpp) # Create GUI executable if( VERIFIER_BUILD_GUI ) diff --git a/src/create.cpp b/src/create.cpp index 9ef384b..2562fa7 100644 --- a/src/create.cpp +++ b/src/create.cpp @@ -15,8 +15,7 @@ #include #include #include -#include -#include +#include #include #include "log.hpp" @@ -242,46 +241,44 @@ auto createFromSteamDepotConfigs( const std::string& configPath, const std::vect static auto enterVPK( std::ofstream& writer, std::string_view vpkPath, std::string_view vpkPathRel, const std::vector& excludes, const std::vector& includes, unsigned int& count ) -> bool { using namespace vpkpp; - auto vpk = VPK::open( std::string{ vpkPath } ); + const auto vpk = VPK::open( std::string{ vpkPath } ); if (! vpk ) { return false; } - for ( const auto& [ entryDirectory, entries ] : vpk->getBakedEntries() ) { - for ( const auto& entry : entries ) { - if ( !excludes.empty() && matchPath( entry.path, excludes) ) { - continue; - } + vpk->runForAllEntries( [ &writer, &vpkPath, &vpkPathRel, &excludes, &includes, &count, &vpk ]( const std::string& path, const Entry& entry ) { + if ( !excludes.empty() && matchPath( path, excludes) ) { + return; + } - if ( !includes.empty() && !matchPath( entry.path, includes ) ) { - continue; - } + if ( !includes.empty() && !matchPath( path, includes ) ) { + return; + } - auto entryData{ vpk->readEntry( entry ) }; - if (! entryData ) { - Log_Error( "Failed to open file: `{}/{}`", vpkPath, entry.path ); - continue; - } + auto entryData{ vpk->readEntry( path ) }; + if (! entryData ) { + Log_Error( "Failed to open file: `{}/{}`", vpkPath, path ); + return; + } - // sha1 (crc32 is already computed) - CryptoPP::SHA1 sha1er{}; - sha1er.Update( reinterpret_cast( entryData->data() ), entryData->size() ); - std::array sha1Hash{}; - sha1er.Final( sha1Hash.data() ); - - std::string sha1HashStr; - std::string crc32HashStr; - { - CryptoPP::StringSource sha1HashStrSink{ sha1Hash.data(), sha1Hash.size(), true, new CryptoPP::HexEncoder{ new CryptoPP::StringSink{ sha1HashStr } } }; - CryptoPP::StringSource crc32HashStrSink{ reinterpret_cast( &entry.crc32 ), sizeof( entry.crc32 ), true, new CryptoPP::HexEncoder{ new CryptoPP::StringSink{ crc32HashStr } } }; - } + // sha1 (crc32 is already computed) + CryptoPP::SHA1 sha1er{}; + sha1er.Update( reinterpret_cast( entryData->data() ), entryData->size() ); + std::array sha1Hash{}; + sha1er.Final( sha1Hash.data() ); - // write out entry - writer << fmt::format( "{}\xFF{}\xFF{}\xFF{}\xFF{}\xFF\xFD", vpkPathRel, entry.path, entryData->size(), sha1HashStr, crc32HashStr ); - Log_Info( "Processed file `{}/{}`", vpkPath, entry.path ); - count += 1; + std::string sha1HashStr; + std::string crc32HashStr; + { + CryptoPP::StringSource sha1HashStrSink{ sha1Hash.data(), sha1Hash.size(), true, new CryptoPP::HexEncoder{ new CryptoPP::StringSink{ sha1HashStr } } }; + CryptoPP::StringSource crc32HashStrSink{ reinterpret_cast( &entry.crc32 ), sizeof( entry.crc32 ), true, new CryptoPP::HexEncoder{ new CryptoPP::StringSink{ crc32HashStr } } }; } - } + + // write out entry + writer << fmt::format( "{}\xFF{}\xFF{}\xFF{}\xFF{}\xFF\xFD", vpkPathRel, path, entryData->size(), sha1HashStr, crc32HashStr ); + Log_Info( "Processed file `{}/{}`", vpkPath, path ); + count += 1; + } ); return true; } diff --git a/src/thirdparty/CMakeLists.txt b/src/thirdparty/CMakeLists.txt index 63840f1..6be1c5d 100644 --- a/src/thirdparty/CMakeLists.txt +++ b/src/thirdparty/CMakeLists.txt @@ -12,6 +12,7 @@ add_subdirectory( "${CMAKE_CURRENT_LIST_DIR}/fmt" SYSTEM ) set( SOURCEPP_USE_BSPPP OFF CACHE INTERNAL "" ) set( SOURCEPP_USE_DMXPP OFF CACHE INTERNAL "" ) set( SOURCEPP_USE_FGDPP OFF CACHE INTERNAL "" ) +set( SOURCEPP_USE_GAMEPP OFF CACHE INTERNAL "" ) set( SOURCEPP_USE_MDLPP OFF CACHE INTERNAL "" ) set( SOURCEPP_USE_STEAMPP OFF CACHE INTERNAL "" ) set( SOURCEPP_USE_VICEPP OFF CACHE INTERNAL "" ) diff --git a/src/thirdparty/sourcepp b/src/thirdparty/sourcepp index f526905..e535a6d 160000 --- a/src/thirdparty/sourcepp +++ b/src/thirdparty/sourcepp @@ -1 +1 @@ -Subproject commit f52690591c3a82d0b3d86a609a432059cb437267 +Subproject commit e535a6dcc17e04bd9e38b8c8cb5a41521c4111c3 diff --git a/src/verify.cpp b/src/verify.cpp index 02ce004..3321494 100644 --- a/src/verify.cpp +++ b/src/verify.cpp @@ -166,7 +166,7 @@ static auto verifyArchivedFile( const std::string& archivePath, const std::strin return; } - auto entryData{ loadedVPKs[ archivePath ]->readEntry( *entry ) }; + auto entryData{ loadedVPKs[ archivePath ]->readEntry( entryPath ) }; if (! entryData ) { Log_Error( "Failed to open file: `{}`", fullPath ); return;