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.

94 lines
2.0 KiB

  1. #!perl
  2. use File::Find;
  3. use File::Basename;
  4. $dir_to_run_on = shift;
  5. $max_size = shift;
  6. if ( (! length( $dir_to_run_on ) || (! $max_size ) ) )
  7. {
  8. die "format is 'limit_vtf_sizes game_dir_to_run_on size'. maxisze -1 to unlimit";
  9. }
  10. open(CMDOUT,">\runit.cmd");
  11. find(\&ProcessFile, $dir_to_run_on);
  12. close CMDOUT;
  13. sub ProcessFile
  14. {
  15. local($_) = $File::Find::name;
  16. my $origname=$_;
  17. my $srcname;
  18. s@\\@/@g;
  19. if (/\.vtf$/i) # is a vtf?
  20. {
  21. next if (m@/hud/@i); # don't shrink hud textures
  22. next if (m@/vgui/@i); # don't shrink hud textures
  23. my $vtex_it=0;
  24. if ( s@game/(.*)/materials/@content/\1/materialsrc/@i )
  25. {
  26. $srcname=$_;
  27. s/\.vtf$/\.txt/i;
  28. if (-e $_ )
  29. {
  30. my $txtname=$_;
  31. # decide whether or not to add the limits
  32. open(TXTIN,$txtname) || die "can't open $_ for read something weird has happened";
  33. my $txtout;
  34. my $should_add_it=1;
  35. while( <TXTIN>)
  36. {
  37. next if ( ( $max_size == -1) && (/maxwidth/i || /maxheight/i) ); # lose this line
  38. $txtout.=$_;
  39. $should_add_it = 0 if (/maxwidth/i || /maxheight/i || /nomip/i || /reduce/i );
  40. }
  41. close TXTIN;
  42. if ($should_add_it )
  43. {
  44. print `p4 edit $txtname`;
  45. open(TXTOUT,">$txtname");
  46. print TXTOUT $txtout;
  47. print TXTOUT "maxwidth $max_size\nmaxheight $max_size\n" if ($max_size != -1);
  48. close TXTOUT;
  49. $vtex_it = 1;
  50. }
  51. }
  52. else
  53. {
  54. if (-d dirname($_) )
  55. {
  56. print "$_ not found. Creating it\n";
  57. open(TXTOUT,">$_" ) || die "can't create $_?";
  58. print TXTOUT "maxwidth $max_size\nmaxheight $max_size\n" if( $max_size != -1);
  59. close TXTOUT;
  60. print `p4 add $_`;
  61. $vtex_it=1;
  62. }
  63. else
  64. {
  65. print "directory does not exist in content for $_\n";
  66. }
  67. }
  68. }
  69. else
  70. {
  71. die "I dont understand the file $_ : bad path?";
  72. }
  73. if ($vtex_it)
  74. {
  75. my $name=$srcname;
  76. $name=~s@\..*$@@; # kill extension
  77. $cmd="vtex -nopause $name";
  78. $cmd=~s@/@\\@g;
  79. print "execute:$cmd\n";
  80. print CMDOUT "$cmd\n";
  81. # print `$cmd`."\n";
  82. }
  83. }
  84. }