Skip to content

Commit

Permalink
feat: change archive excludes/includes to apply to contents of archiv…
Browse files Browse the repository at this point in the history
…es, not VPK files
  • Loading branch information
craftablescience authored and ozxybox committed Aug 12, 2024
1 parent f0f6677 commit 5301f93
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 33 deletions.
32 changes: 7 additions & 25 deletions src/create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<std::string> exclusionRegexes;
exclusionRegexes.insert( exclusionRegexes.end(), fileExcludes.begin(), fileExcludes.end() );
for ( int i = 0; i < depotBuildConfig.getChildCount( "FileExclusion" ); i++ ) {
Expand Down
26 changes: 18 additions & 8 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" )
Expand Down Expand Up @@ -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() ) {
Expand All @@ -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() )
Expand Down

0 comments on commit 5301f93

Please sign in to comment.