|
| 1 | +use strictures; |
| 2 | + |
| 3 | +# this builds a portable zip with everything needed to run the game on windows |
| 4 | +# |
| 5 | +# first it builds a portable copy of a windows system perl by scanning a |
| 6 | +# procmon log file and copying all files read by perl.exe in the capture |
| 7 | +# |
| 8 | +# then it zips up all the files, skipping the ones not needed to run the game |
| 9 | + |
| 10 | +use 5.010; |
| 11 | +use Text::CSV_XS 'csv'; |
| 12 | +use IO::All -binary, -utf8; |
| 13 | +use Archive::Zip qw( :ERROR_CODES :CONSTANTS ); |
| 14 | + |
| 15 | +run(); |
| 16 | + |
| 17 | +sub status { say scalar( localtime ) . ": " . sprintf( shift, @_ ) } |
| 18 | + |
| 19 | +sub run { |
| 20 | + my $start = time; |
| 21 | + |
| 22 | + my $base_path = $ARGV[0] || "c:\\perl"; |
| 23 | + $base_path .= "\\"; |
| 24 | + my $base_path_q = quotemeta $base_path; |
| 25 | + my $target_base = $ARGV[1] || "perl"; |
| 26 | + |
| 27 | + if ( !-d "perl" ) { |
| 28 | + status "building portable perl"; |
| 29 | + my @log = do { |
| 30 | + my $data = io( "Logfile.CSV" )->all; |
| 31 | + $data =~ s/^.*?\n//; |
| 32 | + @{ csv in => \$data }; |
| 33 | + }; |
| 34 | + for my $filter ( |
| 35 | + sub { $_->[1] eq "perl.exe" }, # |
| 36 | + sub { $_->[4] eq "CreateFile" }, |
| 37 | + sub { $_->[7] eq "SUCCESS" }, |
| 38 | + sub { $_->[6] =~ /^$base_path_q/i }, |
| 39 | + sub { $_->[6] !~ /\.bs$/ }, |
| 40 | + sub { -f $_->[6] }, |
| 41 | + ) |
| 42 | + { |
| 43 | + @log = grep $filter->( $_ ), @log; |
| 44 | + } |
| 45 | + |
| 46 | + my %files = map { $_->[6] => 1 } @log; |
| 47 | + my @files = sort keys %files; |
| 48 | + |
| 49 | + status "copying %s files", scalar @files; |
| 50 | + for my $file ( @files ) { |
| 51 | + my $io = io( $file )->file; |
| 52 | + my $path = $io->filepath; |
| 53 | + $path =~ s/^$base_path_q//i; |
| 54 | + my $target_dir = io->catdir( $target_base, $path ); |
| 55 | + $target_dir->mkpath if !$target_dir->exists; |
| 56 | + my $target_file = io->catfile( $target_dir->pathname, $io->filename )->name; |
| 57 | + $io->copy( $target_file ); |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + my $target_file = "Microidium.zip"; |
| 62 | + if ( !-f $target_file ) { |
| 63 | + status "building zip"; |
| 64 | + |
| 65 | + my @local_files = map $_->name, io( "." )->All_Files; |
| 66 | + status "filtering local files"; |
| 67 | + |
| 68 | + my @to_ignore = grep { $_ and $_ !~ /^#/ and $_ ne "/perl" } split "\n", io( ".gitignore" )->all; |
| 69 | + push @to_ignore, "generate_colors", map "/$_", qw( .git Changes META |
| 70 | + README.PATCHING client.bat server.bat cpanfile dist.ini scratch |
| 71 | + t perlcritic.rc ), io( $0 )->filename; |
| 72 | + $_ =~ s/^\//^/g for @to_ignore; |
| 73 | + $_ =~ s/\./\\./g for @to_ignore; |
| 74 | + $_ =~ s/\*/.*/g for @to_ignore; |
| 75 | + |
| 76 | + for my $ignore ( @to_ignore ) { |
| 77 | + @local_files = grep { $_ !~ /$ignore/ } @local_files; |
| 78 | + } |
| 79 | + |
| 80 | + my $localdir = io( "." )->absolute->filename; |
| 81 | + |
| 82 | + status "zipping %s files", scalar @local_files; |
| 83 | + my $zip = Archive::Zip->new; |
| 84 | + $zip->addFile( $_, io->catfile( $localdir, $_ )->name, 9 ) for @local_files; |
| 85 | + $zip->writeToFileNamed( $target_file ); |
| 86 | + } |
| 87 | + |
| 88 | + status "done"; |
| 89 | + |
| 90 | + status "time taken: %s seconds", time - $start; |
| 91 | + |
| 92 | + return; |
| 93 | +} |
0 commit comments