#!/perl -w use warnings; use File::Slurp qw(:std); use File::stat; use File::Path; use Archive::Zip; # imports # use IO::Socket::SSL; use LWP::UserAgent; use Data::Printer; use Crypt::SSLeay; use Net::SSL; use Mojo::UserAgent; use JSON; $ENV{PERL_NET_HTTPS_SSL_SOCKET_CLASS} = "Net::SSL"; $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0; my $delzip = 0; my @folders = ( 'D:\\vsc\\vs-codium\\', 'D:\\vsc\\vs-codium-local\\' ); for my $f ( @folders ) { mkdir $f unless -d $f; } my $ua = Mojo::UserAgent->new(); $ua->max_redirects(5); my $res = $ua->insecure(1)->get('https://github.com/VSCodium/vscodium/releases')->result->body; # write_file('test.html', $res); # my $res = read_file('test.html'); my $downloadfolder = 'D:\\Downloads\\'; my $filename = 'vscodium.zip'; my @url = $res =~ /"(https:\/\/.*win32-x64.*zip?)"/g; print "downloade VS-Codium Version: $url[0]\n"; if ( -e $downloadfolder.$filename ) { print "entferne $downloadfolder$filename\n"; unlink("$downloadfolder.$filename"); } my $tx = $ua->insecure(1)->get( $url[0] ); $tx->res->content->asset->move_to( $downloadfolder.$filename); # löschen aller Cached Dateien und Unterordner my @cacheddir = qw(Cache GPUCache CachedData CachedData-x64); if ( -e $downloadfolder.$filename ) { for my $fold ( @folders ) { opendir (my $dh, $fold); print "$fold --> "; my @fol = readdir $dh; my $test = 1; if ( -e $fold.'VSCodium.exe' ) { $test = unlink($fold.'VSCodium.exe'); } if ( $test == 1 ) { for my $d ( @fol ) { if ( $d =~ /^\.|^\.\./ ) { next; } if ( -d "$fold$d" ) { if ( $d ne 'data' ) { rmtree("$fold$d"); } else { # Cache löschen print "leere"; for my $cdir ( @cacheddir ) { print " $cdir"; rmtree( "$fold$d\\user-data\\$cdir", {keep_root => 1} ); } } } else{ unlink("$fold$d"); } } print "--> geloescht, Userdaten behalten\n"; $delzip++; } } my $obj = Archive::Zip->new(); # new instance my $status = $obj->read("$downloadfolder$filename"); # read file contents if ($status != 0) { die('Error in file!'); } else { if ( scalar @folders == $delzip ) { for my $f ( @folders ) { print "entpacke neue Version in $f\n"; $obj->extractTree(undef, $f); # extract files } unlink("$downloadfolder$filename"); print "zip datei von VSCode gelöscht\n"; } else { print "zip nicht gelöscht da nicht alle Ordner verarbeitet wurden\n"; } } } else { print "keine neue Version gefunden\n"; } for my $fold ( @folders ) { my $prodjson = $fold.'\\resources\\app\\product.json'; # "serviceUrl": "https://marketplace.visualstudio.com/_apis/public/gallery", # "itemUrl": "https://marketplace.visualstudio.com/items", if ( -e $prodjson ) { my $pro = decode_json(read_file($prodjson)); $pro->{extensionsGallery}->{serviceUrl} = "https://marketplace.visualstudio.com/_apis/public/gallery"; $pro->{extensionsGallery}->{itemUrl} = "https://marketplace.visualstudio.com/items"; write_file($prodjson, to_json($pro, { pretty => 1}) ); } } system("pause"); 1;