Added add + added support for ElvUI

This commit is contained in:
2019-07-10 20:51:42 +02:00
parent fef6996b98
commit 31a3157dd3
2 changed files with 61 additions and 20 deletions

23
pcurse
View File

@ -25,11 +25,26 @@ unless($ret) {
$conf = pcurse::merge_opts($opts,$conf); $conf = pcurse::merge_opts($opts,$conf);
my $addons = pcurse::load_addons($conf->{'addons'}); my $addons = pcurse::load_addons($conf->{'addons'});
say 'Loaded '.scalar(@{$addons}).' addons'; say 'Loaded '.scalar(@{$addons}).' addons';
if(defined($opts->{'add'})) {
unless(defined($opts->{'name'})) {
say 'You need to specify a name for the addon with -name=string';
exit 1;
}
my $newaddon = {
'name' => $opts->{'name'},
'uri' => $opts->{'add'},
'version' => 'none',
};
pcurse::add_baseuri_to_addon($newaddon);
push(@{$addons},$newaddon);
}
my $pool = pcurse::init_pool($conf->{'workers'}); my $pool = pcurse::init_pool($conf->{'workers'});
my $worki = 0; my $worki = 0;
print 'Checking for updates '; print 'Checking for updates ';
foreach my $addon(@{$addons}) { foreach my $addon(@{$addons}) {
my $workid = $pool->job('check',$addon,$conf); my $workid = $pool->job('check',$addon);
$jobs{$workid}{'todo'} = 'check'; $jobs{$workid}{'todo'} = 'check';
$jobs{$workid}{'job'} = $addon; $jobs{$workid}{'job'} = $addon;
$jobs{$workid}{'i'} = $worki; $jobs{$workid}{'i'} = $worki;
@ -61,9 +76,9 @@ foreach my $a(@toupd) {
my $id = $a->[0]; my $id = $a->[0];
my $addon = $a->[1]; my $addon = $a->[1];
my $version = $a->[2]; my $version = $a->[2];
my $workid = $pool->job('download',$conf->{'baseuri'}.$addon->{'uri'},$addon->{'fileid'}); my $workid = $pool->job('download',$addon->{'downloaduri'},$addon->{'fileid'});
$jobs{$workid}{'todo'} = 'download'; $jobs{$workid}{'todo'} = 'download';
$jobs{$workid}{'job'} = [ $conf->{'baseuri'}.$addon->{'uri'},$addon->{'fileid'} ]; $jobs{$workid}{'job'} = [ $addon->{'downloaduri'},$addon->{'fileid'} ];
$jobs{$workid}{'id'} = $id; $jobs{$workid}{'id'} = $id;
$jobs{$workid}{'tv'} = $version; $jobs{$workid}{'tv'} = $version;
} }
@ -78,10 +93,8 @@ while(scalar(keys %jobs)) {
my $file = $jres[0]{'filecontent'}; my $file = $jres[0]{'filecontent'};
my $version = $jobs{$jobid}{'tv'}; my $version = $jobs{$jobid}{'tv'};
if(defined($filename)) { if(defined($filename)) {
#say 'Going to unpack file '.$filename.' containing version '.$version;
$tounpack{$filename} = [ $jobs{$jobid}{'id'},$file,$version ]; $tounpack{$filename} = [ $jobs{$jobid}{'id'},$file,$version ];
} else { } else {
#print Dumper @jres;
my $ai = $jobs{$jobid}{'id'}; my $ai = $jobs{$jobid}{'id'};
my $an = $addons->[$ai]->{'name'}; my $an = $addons->[$ai]->{'name'};
say 'Passed an empty filename? in update'; say 'Passed an empty filename? in update';

View File

@ -37,6 +37,8 @@ sub parse_arguments {
"test" => \$toret->{'test'}, "test" => \$toret->{'test'},
"workers" => \$toret->{'workers'}, "workers" => \$toret->{'workers'},
"debug" => \$toret->{'debug'}, "debug" => \$toret->{'debug'},
"add=s" => \$toret->{'add'},
"name=s" => \$toret->{'name'},
); );
return $toret; return $toret;
} }
@ -77,8 +79,6 @@ sub check_config {
sub sane_defaults { sub sane_defaults {
my $in = shift; my $in = shift;
$in->{'baseuri'} = 'https://www.curseforge.com' unless(exists($in->{'baseuri'}));
$in->{'baseuri'} =~ s/^http/https/ unless($in->{'baseuri'} =~ m/^https/);
$in->{'addons'} = $ENV{'HOME'}.'/.pcurse/addons.json' unless(exists($in->{'addons'})); $in->{'addons'} = $ENV{'HOME'}.'/.pcurse/addons.json' unless(exists($in->{'addons'}));
$in->{'workers'} = "4" unless(exists($in->{'workers'})); $in->{'workers'} = "4" unless(exists($in->{'workers'}));
return $in; return $in;
@ -97,24 +97,33 @@ sub load_addons {
if(-e $ENV{'HOME'}.'/.lcurse/addons.json') { if(-e $ENV{'HOME'}.'/.lcurse/addons.json') {
print 'There seems to be an addons.json from lcurse around, and we have no list ourself yet. Stealing it:)'."\n"; print 'There seems to be an addons.json from lcurse around, and we have no list ourself yet. Stealing it:)'."\n";
my $json = &import_json($ENV{'HOME'}.'/.lcurse/addons.json'); my $json = &import_json($ENV{'HOME'}.'/.lcurse/addons.json');
my $jsonref = ref $json;
$json = $json->{'addons'}; $json = $json->{'addons'};
my $jsonreff = ref $json; $json = pcurse::add_baseuri_to_addon($json);
foreach my $addon(@{$json}) {
$addon->{'uri'} =~ s/^http(s|)\:\/\/www.curseforge\.com//;
}
return $json; return $json;
} }
} else { } else {
my $json = &import_json($addons_file); my $json = &import_json($addons_file);
foreach my $addon(@{$json}) { $json = pcurse::add_baseuri_to_addon($json);
$addon->{'uri'} =~ s/^http(s|)\:\/\/www.curseforge\.com//;
}
return $json; return $json;
} }
return 0; return 0;
} }
sub add_baseuri_to_addon {
my $json = shift;
foreach my $addon(@{$json}) {
unless(exists($addon->{'host'})) {
my $str = $addon->{'uri'};
my (undef,$h,undef,$u) = split(/(http(|s)\:\/\/[a-zA-Z0-9.]+)(\/.+)/,$str,2);
$addon->{'uri'} = $u;
$addon->{'host'} = $h;
}
#$addon->{'uri'} = 'https://www.curseforge.com'.$addon->{'uri'} unless($addon->{'uri'} =~ m/^http/);
#$addon->{'baseuri'} =
}
return $json;
}
sub save_config { sub save_config {
my $json = JSON->new; my $json = JSON->new;
$json->convert_blessed; $json->convert_blessed;
@ -176,6 +185,7 @@ sub html_get {
sub get_latest_file_id { sub get_latest_file_id {
my $html = shift; my $html = shift;
my $uri = shift; my $uri = shift;
return 'elvui' if($uri =~ m/tukui/);
$uri .= '/download/'; $uri .= '/download/';
my $retstr = pcurse::find_in_html('dlstring',$html,$uri); my $retstr = pcurse::find_in_html('dlstring',$html,$uri);
return $retstr; return $retstr;
@ -185,7 +195,11 @@ sub get_product_version {
my $html = shift; my $html = shift;
my $uri = shift; my $uri = shift;
my $fileid = shift; my $fileid = shift;
$uri .= '/files/'.$fileid; if($fileid eq 'elvui') {
$uri = '/downloads/';
} else {
$uri .= '/files/'.$fileid;
}
my $retstr = pcurse::find_in_html('vstring',$html,$uri); my $retstr = pcurse::find_in_html('vstring',$html,$uri);
return $retstr; return $retstr;
} }
@ -194,6 +208,11 @@ sub find_in_html {
my $mode = shift; my $mode = shift;
my $html = shift; my $html = shift;
my $sstring = shift; my $sstring = shift;
unless($sstring =~ m/\/downloads\//) { #ElvUI hacks
my @sstringa = split /\//, $sstring,4;
$sstring = pop(@sstringa);
$sstring = '/'.$sstring;
}
my $ref = ref $html; my $ref = ref $html;
my $retstr; my $retstr;
if($ref) { if($ref) {
@ -207,7 +226,12 @@ sub find_in_html {
if($mode eq 'dlstring') { if($mode eq 'dlstring') {
$retstr = (split(/$sstring/, $href,2))[1]; $retstr = (split(/$sstring/, $href,2))[1];
} elsif($mode eq 'vstring') { } elsif($mode eq 'vstring') {
$retstr = $context->getAttribute('data-name'); if($sstring =~ m/downloads/) { #hack for elvui
$retstr = $context->getAttribute('href');
$retstr =~ s/$sstring//g;
} else {
$retstr = $context->getAttribute('data-name');
}
} }
return $retstr if($retstr); return $retstr if($retstr);
} }
@ -243,7 +267,6 @@ sub find_in_html {
sub download_update { sub download_update {
my $uri = shift; my $uri = shift;
my $fileid = shift; my $fileid = shift;
$uri .= '/download/'.$fileid.'/file';
my ($ret,$filename,$file) = pcurse::download($uri); my ($ret,$filename,$file) = pcurse::download($uri);
return (1,$filename,$file) if($ret); return (1,$filename,$file) if($ret);
return (0,undef,undef); return (0,undef,undef);
@ -286,13 +309,18 @@ sub init_pool {
if($todo eq 'check') { if($todo eq 'check') {
my $addon = shift; my $addon = shift;
my $conf = shift; my $conf = shift;
my $html = pcurse::html_get($conf->{'baseuri'}.$addon->{'uri'}); my $html = pcurse::html_get($addon->{'host'}.$addon->{'uri'});
my $fileid = pcurse::get_latest_file_id($html,$addon->{'uri'}); my $fileid = pcurse::get_latest_file_id($html,$addon->{'host'}.$addon->{'uri'});
if($fileid) { if($fileid) {
$addon->{'fileid'} = $fileid; $addon->{'fileid'} = $fileid;
my $version = pcurse::get_product_version($html,$addon->{'uri'},$fileid); my $version = pcurse::get_product_version($html,$addon->{'uri'},$fileid);
if($version && ($version ne $addon->{'version'})) { if($version && ($version ne $addon->{'version'})) {
unless($conf->{'test'}) { unless($conf->{'test'}) {
if($fileid eq 'elvui') {
$addon->{'downloaduri'} = $addon->{'host'}.'/downloads/'.$version;
} else {
$addon->{'downloaduri'} = $addon->{'host'}.$addon->{'uri'}.'/download/'.$fileid.'/file';
}
$addon->{'targetversion'} = $version; $addon->{'targetversion'} = $version;
return (1,$addon); return (1,$addon);
} }