Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
2.5 KiB

  1. #! perl
  2. # make a simple fixed pak file for testing code. This utility is only for testing the code
  3. # before writing the "real" utility.
  4. use File::Find;
  5. use String::CRC32;
  6. use File::Basename;
  7. $ndatfileindex=0;
  8. $ndatoffset=0;
  9. $nullbyte = pack("C",0);
  10. # now, search for files
  11. find( {wanted => \&gotfile, no_chdir=>1 }, "." );
  12. undef $curext;
  13. $datlimit=50 * 1000 * 1000;
  14. foreach $_ ( sort ByExtensionAndDirectory @FilesToPack )
  15. {
  16. local($basename, $dir, $ext ) = fileparse( $_, qr/\.[^.]*/);
  17. $dir=~s@\\@/@g;
  18. $dir=~s@^\./@@;
  19. $dir=~s@/$@@;
  20. $dir=" " unless ( length($dir) );
  21. $ext=~s@^\.@@;
  22. $ext=" " unless ( length($ext) );
  23. print "Add $_ ($dir)\n";
  24. if ( $curext ne $ext )
  25. {
  26. $dirout.=$nullbyte.$nullbyte if length($curext); # mark no more files and end of extension
  27. $dirout.=$ext.$nullbyte;
  28. $dirout.=$dir.$nullbyte;
  29. $curext=$ext;
  30. $curdir=$dir;
  31. }
  32. elsif ( $curdir ne $dir )
  33. {
  34. $dirout.=$nullbyte if length($curdir); # mark no more files
  35. $dirout.=$dir.$nullbyte;
  36. $curdir = $dir;
  37. }
  38. $dirout.=$basename.$nullbyte;
  39. open(DATAIN, $_) || die "can't open $_";
  40. binmode DATAIN;
  41. { local($/); $fdata=<DATAIN>; }
  42. close DATAIN;
  43. $dirout.=pack("V", CRC32( $fdata) );
  44. $dirout.=pack("v",0); #meta data size
  45. $dirout.=pack("C",$ndatfileindex);
  46. $dirout.=pack("V",length($dataout));
  47. $dirout.=pack("V",length($fdata));
  48. $dataout.=$fdata;
  49. $dirout.=pack("C",-1);
  50. if (length($dataout) > $datlimit )
  51. {
  52. &writedata;
  53. undef $dataout;
  54. $ndatfileindex++;
  55. }
  56. }
  57. $dirout.=$nullbyte.$nullbyte;
  58. open(DIROUT,">test_dir.vpk") || die;
  59. binmode DIROUT;
  60. print DIROUT $dirout;
  61. close DIROUT;
  62. &writedata;
  63. sub writedata
  64. {
  65. my $fname=sprintf("test_%03d.vpk", $ndatfileindex );
  66. print STDERR "\nWriting $fname, length ", length($dataout),"\n";
  67. open(DATAOUT,">$fname") || die;
  68. binmode DATAOUT;
  69. print DATAOUT $dataout;
  70. close DATAOUT;
  71. }
  72. sub gotfile
  73. {
  74. return if ( -d $_ );
  75. s@\\@/@g;
  76. s@^\./@@; # kill leading "./"
  77. $_=lc($_);
  78. local($basename, $dir, $ext ) = fileparse( $_, qr/\.[^.]*/);
  79. return if ($basename=~/\.360$/);
  80. return if ( $ext eq ".dll" );
  81. return if ( $ext eq ".vpk" );
  82. return unless length($ext);
  83. # return unless ( $ext eq ".vtf" );
  84. push @FilesToPack, $_;
  85. }
  86. sub ByExtensionAndDirectory
  87. {
  88. local($basenamea, $dira, $exta ) = fileparse( $a, qr/\.[^.]*/);
  89. local($basenameb, $dirb, $extb ) = fileparse( $b, qr/\.[^.]*/);
  90. return $exta cmp $extb if ( $extb ne $exta );
  91. return $dira cmp $dirb if ( $dira ne $dirb );
  92. return $basenamea cmp $basenameb;
  93. }