Last active
December 29, 2015 08:09
-
-
Save freman/7641109 to your computer and use it in GitHub Desktop.
also.pl (https://github.com/asiekierka/asielauncher) - generate a local install (Bit of a mess, soz)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use 5.10.0; | |
use warnings; | |
use strict; | |
use Data::Dumper; | |
use Digest::MD5 qw/md5_hex/; | |
use JSON::XS; | |
use File::Slurp qw/read_file write_file/; | |
use File::Path qw/mkpath/; | |
use File::Find; | |
use File::Copy qw/cp/; | |
use File::Basename; | |
use List::Util qw/sum/; | |
use File::Temp qw/tempfile/; | |
use LWP::Simple; | |
use Cwd qw/abs_path/; | |
use Archive::Zip; | |
my $json = JSON::XS->new->relaxed; | |
my $config = $json->decode(scalar read_file('also-config.json')); | |
sub md5_file{md5_hex scalar read_file shift, binmode => ':raw'} | |
sub build_search_dirs{grep {defined && -d} map {my $n=$_; (map {abs_path "$_$n"} @{$config->{modpack}->{lookupDirectories}})} @_} | |
sub file_entry{my ($filename, $real_file) = @_; (filename => $filename, size => -s $real_file, md5 => md5_file $real_file)} | |
my $output = abs_path $config->{output}->{local}->{location}; | |
mkpath [map {$output . "/$_"} @{$config->{modpack}->{directories}->{file}}, qw/zips platform/]; | |
my %also = ( | |
client_revision => 6, #todo | |
mcVersion => $config->{launcher}->{minecraftVersion}, | |
onlineMode => $config->{launcher}->{onlineMode}, | |
jvmArguments => $config->{launcher}->{javaArguments}, | |
windowName => $config->{launcher}->{windowName}, | |
jarPatches => [], #todo | |
options => {}, #todo | |
directoryName => $config->{launcher}->{directoryName}, | |
); | |
$also{servers} = {map {($_->{name} => $_->{ip})} @{$config->{serverList}}}; | |
find sub { | |
return if /^\./; | |
return unless -f; | |
$File::Find::dir =~ /^.+\/(.+?)(?:-client)?(?:\/(.+))?$/; | |
say "[@{[uc($1)]}] $_"; | |
my $subdir = $2 ? "/$2" : ''; | |
my $target = "$1/$subdir$_"; | |
push @{$also{files}}, { | |
file_entry($target, $_), | |
overwrite => \1, #TODO | |
}; | |
mkpath "$output/" . dirname($target); | |
cp $_, "$output/$target"; | |
}, grep {-d} map {($_, "$_-client")} build_search_dirs @{$config->{modpack}->{directories}->{file}}; | |
foreach my $zip (@{$config->{modpack}->{directories}->{zip}}) { | |
say "Building zip [$zip]"; | |
my $filename = "$zip.zip"; | |
my $target = "$output/zips/$filename"; | |
my $zip_file = Archive::Zip->new(); | |
foreach my $dir (build_search_dirs $zip) { | |
$zip_file->addTree($dir, ''); | |
} | |
$zip_file->writeToFileNamed($target); | |
push @{$also{zips}}, { | |
file_entry($filename, $target), | |
overwrite => \1, #todo | |
directory => "$zip", | |
}; | |
} | |
my $platform_dir = (build_search_dirs 'AsieLauncher/platform')[0]; | |
foreach my $platform (map {basename $_} glob "$platform_dir/*") { | |
say "Adding support for platform [$platform]"; | |
find sub { | |
return if /^\./; | |
return unless -f; | |
$File::Find::dir =~ /^.+\/platform\/$platform\/(.+)$/; | |
my $local_path = $1; | |
my $local_filename = "$local_path/$_"; | |
mkpath "$output/platform/$platform/$local_path"; | |
push @{$also{platforms}->{$platform}->{files}}, { | |
file_entry($local_filename, $_), | |
overwrite => \1, #todo | |
}; | |
cp $_, "$output/platform/$platform/$local_filename"; | |
}, "$platform_dir/$platform"; | |
$also{platforms}->{$platform}->{size} = sum map {$_->{size}} @{$also{platforms}->{$platform}->{files}}; | |
}; | |
say "Building launcher"; | |
my $launcher_config = (build_search_dirs 'AsieLauncher/launcherConfig')[0]; | |
my $fh = File::Temp->new(); | |
getstore($config->{updatesURL} . "AsieLauncher-latest.jar", $fh->filename); | |
my $zip_file = Archive::Zip->new(); | |
$zip_file->read($fh->filename); | |
$zip_file->addDirectory("resources"); | |
foreach my $file (qw/background background@2x icon/) { | |
$zip_file->addFile( "$launcher_config/$file.png", "resources/$file.png"); | |
} | |
$zip_file->addString($json->encode({ | |
serverUrl => $config->{launcher}->{serverUrl}, | |
directoryName => $config->{launcher}->{directoryName} | |
}), 'resources/config.json'); | |
$zip_file->writeToFileNamed("$output/launcher.jar"); | |
write_file("$output/also.json", $json->encode(\%also)); | |
say "In theory, we're all done here, copy $output to your web path"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment