diff --git a/.gitignore b/.gitignore index 265fbe0..9061bdb 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,4 @@ /cpanfile.snapshot /perl /Logfile.CSV +/Microidium.zip diff --git a/build_perl.pl b/build_perl.pl deleted file mode 100644 index e336f47..0000000 --- a/build_perl.pl +++ /dev/null @@ -1,50 +0,0 @@ -use strictures; - -# this builds a portable copy of a windows system perl by scanning a -# procmon log file and copying all files read by perl.exe in the capture - -use 5.010; -use Text::CSV_XS 'csv'; -use IO::All -binary, -utf8; - -run(); - -sub run { - my $base_path = $ARGV[0] || "c:\\perl"; - $base_path .= "\\"; - my $base_path_q = quotemeta $base_path; - my $target_base = $ARGV[1] || "perl"; - - my @log = do { - my $data = io( "Logfile.CSV" )->all; - $data =~ s/^.*?\n//; - @{ csv in => \$data }; - }; - for my $filter ( - sub { $_->[1] eq "perl.exe" }, # - sub { $_->[4] eq "CreateFile" }, - sub { $_->[7] eq "SUCCESS" }, - sub { $_->[6] =~ /^$base_path_q/i }, - sub { $_->[6] !~ /\.bs$/ }, - sub { -f $_->[6] }, - ) - { - @log = grep $filter->( $_ ), @log; - } - - my %files = map { $_->[6] => 1 } @log; - my @files = sort keys %files; - - for my $file ( @files ) { - say $file; - my $io = io( $file )->file; - my $path = $io->filepath; - $path =~ s/^$base_path_q//i; - my $target_dir = io->catdir( $target_base, $path ); - $target_dir->mkpath if !$target_dir->exists; - my $target_file = io->catfile( $target_dir->pathname, $io->filename )->name; - $io->copy( $target_file ); - } - - return; -} diff --git a/build_zip.pl b/build_zip.pl new file mode 100644 index 0000000..8c8b07f --- /dev/null +++ b/build_zip.pl @@ -0,0 +1,93 @@ +use strictures; + +# this builds a portable zip with everything needed to run the game on windows +# +# first it builds a portable copy of a windows system perl by scanning a +# procmon log file and copying all files read by perl.exe in the capture +# +# then it zips up all the files, skipping the ones not needed to run the game + +use 5.010; +use Text::CSV_XS 'csv'; +use IO::All -binary, -utf8; +use Archive::Zip qw( :ERROR_CODES :CONSTANTS ); + +run(); + +sub status { say scalar( localtime ) . ": " . sprintf( shift, @_ ) } + +sub run { + my $start = time; + + my $base_path = $ARGV[0] || "c:\\perl"; + $base_path .= "\\"; + my $base_path_q = quotemeta $base_path; + my $target_base = $ARGV[1] || "perl"; + + if ( !-d "perl" ) { + status "building portable perl"; + my @log = do { + my $data = io( "Logfile.CSV" )->all; + $data =~ s/^.*?\n//; + @{ csv in => \$data }; + }; + for my $filter ( + sub { $_->[1] eq "perl.exe" }, # + sub { $_->[4] eq "CreateFile" }, + sub { $_->[7] eq "SUCCESS" }, + sub { $_->[6] =~ /^$base_path_q/i }, + sub { $_->[6] !~ /\.bs$/ }, + sub { -f $_->[6] }, + ) + { + @log = grep $filter->( $_ ), @log; + } + + my %files = map { $_->[6] => 1 } @log; + my @files = sort keys %files; + + status "copying %s files", scalar @files; + for my $file ( @files ) { + my $io = io( $file )->file; + my $path = $io->filepath; + $path =~ s/^$base_path_q//i; + my $target_dir = io->catdir( $target_base, $path ); + $target_dir->mkpath if !$target_dir->exists; + my $target_file = io->catfile( $target_dir->pathname, $io->filename )->name; + $io->copy( $target_file ); + } + } + + my $target_file = "Microidium.zip"; + if ( !-f $target_file ) { + status "building zip"; + + my @local_files = map $_->name, io( "." )->All_Files; + status "filtering local files"; + + my @to_ignore = grep { $_ and $_ !~ /^#/ and $_ ne "/perl" } split "\n", io( ".gitignore" )->all; + push @to_ignore, "generate_colors", map "/$_", qw( .git Changes META + README.PATCHING client.bat server.bat cpanfile dist.ini scratch + t perlcritic.rc ), io( $0 )->filename; + $_ =~ s/^\//^/g for @to_ignore; + $_ =~ s/\./\\./g for @to_ignore; + $_ =~ s/\*/.*/g for @to_ignore; + + for my $ignore ( @to_ignore ) { + @local_files = grep { $_ !~ /$ignore/ } @local_files; + } + + my $localdir = io( "." )->absolute->filename; + + status "zipping %s files", scalar @local_files; + my $zip = Archive::Zip->new; + $zip->addFile( $_, io->catfile( $localdir, $_ )->name, 9 ) for @local_files; + $zip->writeToFileNamed( $target_file ); + } + + status "done"; + + status "time taken: %s seconds", time - $start; + + return; +} diff --git a/dist.ini b/dist.ini index 623ba23..3400701 100644 --- a/dist.ini +++ b/dist.ini @@ -5,7 +5,7 @@ copyright_holder = Christian Walde copyright_year = 2014 [@MITHALDU] -exclude_match = ^(scratch|nytprof|kryonet|IO-Async-|local|perl|Logfile.CSV) +exclude_match = ^(scratch|nytprof|kryonet|IO-Async-|local|perl|Logfile.CSV|Microidium.zip) gitignore = /local* gitignore = /nytprof* gitignore = /kryonet* @@ -13,6 +13,7 @@ gitignore = /IO-Async-* gitignore = /cpanfile.snapshot gitignore = /perl gitignore = /Logfile.CSV +gitignore = /Microidium.zip skip_prereq = ^Microidium::Client$ skip_prereq = ^IO::Async::Internals::Connector$