home *** CD-ROM | disk | FTP | other *** search
/ GameStar Special 2004 January / GSSH0104TT.iso / Extras / Tron20 / tron_tools.exe / TRON_Tools / Tools / AssetLists / processNewLogs.pl < prev   
Perl Script  |  2003-03-10  |  3KB  |  147 lines

  1. #! /usr/bin/perl
  2. use File::Find;
  3. use File::Path;
  4. use File::Copy;
  5. use Cwd;
  6.  
  7. $ROOT             = "c:/proj/TRON/tools/assetlists";
  8. $NEWLOGS         = "$ROOT/logs/new";
  9. $PROCESSEDLOGS     = "$ROOT/logs/processed";
  10. $ASSETLISTS        = "$ROOT/processing";
  11.  
  12. # set output to not line-buffered
  13. $| = 1;
  14.  
  15. sub removeDups {
  16.     # get the parameters
  17.     my $list = shift( @_ );
  18.  
  19.     $i = 0; $j = 0;
  20.     while ( $i <= ( $#$list - 1 ) ) {
  21.         $j = $i + 1;
  22.         while ( $j <= $#$list ) {
  23.             if ( $$list[ $i ] eq $$list[ $j ] ) {
  24.                 splice( @$list, $j, 1 );
  25.             } else {
  26.                 ++$j;
  27.             }
  28.         }
  29.         ++$i;
  30.     }
  31. }
  32.  
  33. # Edit the following RegExps to finetune things to filterout
  34. sub filterout {
  35.     my $pat = shift;
  36.  
  37.     return 1 if $pat =~ m/^\s*$/;
  38.  
  39.     return 0;
  40. }
  41.  
  42. sub outputWorldData {
  43.  
  44.     undef @oldAssets;
  45.     undef @assets;
  46.  
  47.     # read in the previous file (if there)
  48.     open INFILE, "<$ASSETLISTS/$worldName.out";
  49.  
  50.     while (<INFILE>) {
  51.         chop;
  52.         push @oldAssets, $_;
  53.     }
  54.  
  55.     close INFILE;
  56.  
  57.     # open the file for output now
  58.     open OUTFILE, ">$ASSETLISTS/$worldName.out" || 
  59.         die "Can't open outout world file: $worldname\n";
  60.  
  61.     
  62.     # accumulate assets
  63.     @assets = (@newAssets, @oldAssets);
  64.     removeDups (\@assets);
  65.     
  66.     foreach (@assets) {
  67.         print OUTFILE "$_\n";
  68.     }
  69.     close OUTFILE;
  70. }
  71.  
  72. #
  73. # method for processing each lta file
  74. #
  75. $logNumber = 0;
  76. ($sec, $min, $hour, $mday, $mon, $year, @foo) = localtime(time);
  77. $dateString = "$year$mon$mday$min$sec";
  78.  
  79. sub process_file {
  80.  
  81.     # save so that we can copy it later
  82.     $fileName = $_;
  83.  
  84.     # return if this is not an log file
  85.     return if ! /\.log$/;
  86.  
  87.     # pull out the worldname
  88.     /^(.*)\.log/;
  89.     $worldName = lc($1);
  90.  
  91.     # clear all old data
  92.     undef @newAssets;
  93.  
  94.     # open up this log
  95.     open LOG, "< $File::Find::name" || 
  96.         die "Can't open log file: $File::Find::name\n";
  97.  
  98.     # go through log and generate the per level data
  99.     while (<LOG>) {
  100.         chop;
  101.  
  102.         # skip "music files"
  103.         next if /.*\s+music\\.*/i;
  104.  
  105.         # skip "world textures"
  106.         next if /.*\s+tex\\.*/i;
  107.  
  108.         # skip "render styles"
  109.         next if /.*\s+rs\\.*/i;
  110.  
  111.         # change all \ to /
  112.         tr!\\!/!;
  113.         s/\/\//\//g;
  114.  
  115.         # skip other comments
  116.         next if /^- ---/;
  117.  
  118.         # skip "unfreed string lines"
  119.         next if /^- Unfreed string:/;
  120.  
  121.         # regexp out filter
  122.         next if filterout ($_);
  123.  
  124.         split;
  125.         push (@newAssets, lc($_[4]));
  126.     }
  127.  
  128.     # if there is a world, write it out
  129.     if (defined $worldName) {
  130.         outputWorldData();
  131.     }
  132.     close LOG;
  133.  
  134.     # move the log to the processed directory
  135.     copy ("$fileName", "$PROCESSEDLOGS/${dateString}_${logNumber}.log");
  136.     unlink $fileName;
  137.     $logNumber++;
  138. }
  139.  
  140.  
  141. ###
  142. ### MAIN
  143. ###
  144.  
  145. # find and process all .log files
  146. find (\&process_file, $NEWLOGS);
  147.