From 5301f931b27689d2c7b1829b1ba8593a32e29acf Mon Sep 17 00:00:00 2001 From: craftablescience Date: Thu, 1 Aug 2024 22:44:58 -0400 Subject: [PATCH] feat: change archive excludes/includes to apply to contents of archives, not VPK files --- src/create.cpp | 32 +++++++------------------------- src/main.cpp | 26 ++++++++++++++++++-------- 2 files changed, 25 insertions(+), 33 deletions(-) diff --git a/src/create.cpp b/src/create.cpp index 1f83190..9ef384b 100644 --- a/src/create.cpp +++ b/src/create.cpp @@ -67,36 +67,18 @@ auto createFromRoot( std::string_view root_, std::string_view indexLocation, boo auto pathRel{ std::filesystem::relative( path, root ).string() }; sourcepp::string::normalizeSlashes( pathRel ); - if ( path.ends_with( ".vpk" ) ) { - static const std::regex numberedVpkRegex { R"(.*_[0-9][0-9][0-9]\.vpk)", std::regex::ECMAScript | std::regex::icase | std::regex::optimize }; - - if ( skipArchives || std::regex_match( pathRel, numberedVpkRegex ) ) { - continue; - } - - if ( !archiveExclusionREs.empty() && matchPath( pathRel, archiveExclusionREs ) ) { - continue; - } - - if ( !archiveInclusionREs.empty() && !matchPath( pathRel, archiveInclusionREs ) ) { - continue; - } - + if ( ( !fileExclusionREs.empty() && matchPath( pathRel, fileExclusionREs ) ) || ( !fileInclusionREs.empty() && !matchPath( pathRel, fileInclusionREs ) ) ) { + // File is either excluded or not included + continue; + } - if ( enterVPK( writer, path, pathRel, fileExclusionREs, fileInclusionREs, count ) ) { + if ( !skipArchives && path.ends_with( ".vpk" ) ) { + if ( enterVPK( writer, path, pathRel, archiveExclusionREs, archiveInclusionREs, count ) ) { Log_Info( "Processed VPK at `{}`", path ); continue; } Log_Warn( "Unable to open VPK at `{}`. Treating as a regular file...", path ); - } else { - if ( !fileExclusionREs.empty() && matchPath( pathRel, fileExclusionREs ) ) { - continue; - } - - if ( !fileInclusionREs.empty() && !matchPath( pathRel, fileInclusionREs ) ) { - continue; - } } // open file @@ -196,7 +178,7 @@ auto createFromSteamDepotConfigs( const std::string& configPath, const std::vect continue; } - const auto createFromSteamDepotConfig{ [ &configPath, &indexLocation, skipArchives, &fileExcludes, &contentRoot, &fileIncludes, &archiveExcludes, &archiveIncludes ]( const KV1Element& depotBuildConfig ) { + const auto createFromSteamDepotConfig{ [ &configPath, &indexLocation, skipArchives, &fileExcludes, &fileIncludes, &archiveExcludes, &archiveIncludes, &contentRoot ]( const KV1Element& depotBuildConfig ) { std::vector exclusionRegexes; exclusionRegexes.insert( exclusionRegexes.end(), fileExcludes.begin(), fileExcludes.end() ); for ( int i = 0; i < depotBuildConfig.getChildCount( "FileExclusion" ); i++ ) { diff --git a/src/main.cpp b/src/main.cpp index da2e4e3..08e7bb5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -75,13 +75,13 @@ auto main( int argc, char* argv[] ) -> int { params.add_parameter( fileIncludes, "--include" ) .help( "RegExp pattern(s) to include files when creating the index. If not present, all files not matching an exclusion will be included.") .metavar( "included" ); - params.add_parameter( archiveExcludes, "--exclude-archives", "-E" ) - .help( "RegExp pattern(s) to exclude VPKs when creating the index. Ignored if `--steam-depot-config` is present." ) - .metavar( "excluded-archives" ) + params.add_parameter( archiveExcludes, "--archive-exclude", "-E" ) + .help( "RegExp pattern(s) to exclude files inside VPKs when creating the index." ) + .metavar( "archive-excluded" ) .minargs( 1 ); - params.add_parameter( archiveIncludes, "--include-archives" ) - .help( "RegExp pattern(s) to include VPKs when creating the index. If not present, all VPKs not matching an exclusion will be included." ) - .metavar( "included-archives" ); + params.add_parameter( archiveIncludes, "--archive-include" ) + .help( "RegExp pattern(s) to include files inside VPKs when creating the index. If not present, all files inside VPKs not matching an exclusion will be included." ) + .metavar( "archive-included" ); params.add_parameter( steamDepotConfig, "--steam-depot-config" ) .help( "Use a Steam depot configuration file to include/exclude content. Pair this option with `--steam-depot-ids`." ) .metavar( "steam-depot-config" ) @@ -142,6 +142,16 @@ auto main( int argc, char* argv[] ) -> int { fileExcludes.emplace_back( ".*\\.log" ); fileExcludes.emplace_back( ".*verifier_index\\.rsv" ); + // if we're reading the contents of archives, numbered VPKs should not be considered + if (! skipArchives ) { + fileExcludes.emplace_back( R"(.*_[0-9][0-9][0-9]\.vpk)" ); + } else { + if (! archiveExcludes.empty() ) + Log_Warn( "The current action doesn't support `--archive-exclude`, it will be ignored." ); + if (! archiveIncludes.empty() ) + Log_Warn( "The current action doesn't support `--archive-include`, it will be ignored." ); + } + // create from a steam depot config if ( !steamDepotConfig.empty() || !steamDepotIDs.empty() ) { if ( steamDepotConfig.empty() && !steamDepotIDs.empty() ) { @@ -166,9 +176,9 @@ auto main( int argc, char* argv[] ) -> int { if (! fileIncludes.empty() ) Log_Warn( "The current action doesn't support `--include`, it will be ignored." ); if (! archiveExcludes.empty() ) - Log_Warn( "The current action doesn't support `--exclude-archives`, it will be ignored." ); + Log_Warn( "The current action doesn't support `--archive-exclude`, it will be ignored." ); if (! archiveIncludes.empty() ) - Log_Warn( "The current action doesn't support `--include-archives`, it will be ignored." ); + Log_Warn( "The current action doesn't support `--archive-include`, it will be ignored." ); if (! steamDepotConfig.empty() ) Log_Warn( "The current action doesn't support `--steam-depot-config`, it will be ignored." ); if (! steamDepotIDs.empty() )