-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetGRSSDKP.pl
124 lines (109 loc) · 4.05 KB
/
GetGRSSDKP.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#perl2exe_include "Tk.pm";
#perl2exe_include "Tk/DialogBox.pm"
##perl2exe_include "File/BSDGlob.pm"
##perl2exe_include "Compress/Bzip2.pm"
use Tk;
require LWP::UserAgent;
my $message = "";
my $url = "http://demo.dkpsystem.com";
open(IN,"<url.txt");
$url = <IN>;
close(IN);
my $myversion;
open(IN,"<GuildRaidSnapShot.toc");
while(<IN>){
if(/Version (\S+)/i){
$myversion = $1;
}
}
close(IN);
my $mw = MainWindow->new;
$mw->title("GRSS DKP Downloader");
$mw->Label(-text => "DKPSystem.com's GuildRaidSnapShot DKP Downloader",-foreground=>"darkred",-relief=>"groove")->pack;
$mw->Label(-text => "Enter the URL of your website")->pack;
$mw->Entry(-textvariable => \$url,-background=>"white",-width=>"30")->pack;
$mw->Label(-textvariable => \$message)->pack;
$mw->Button(-text => "Cancel",-width=>10,-command => sub {exit})->pack(-side=>"left",-anchor=>"s");
$mw->Button(-text => "OK",-width=>10,-command => sub {&downloadfile($url)})->pack(-side=>"right",-anchor=>"s");
MainLoop;
sub downloadfile
{
my $newurl = $_[0];
$newurl = lc($newurl);
if($newurl =~ /^(?:http:\/\/)?([a-zA-Z0-9\.\-]+)/){
$newurl = "http://$1/luadkp.php";
$url = $1;
}
$message = "Downloading $newurl";
my $ua = LWP::UserAgent->new;
$ua->timeout(25);
$ua->env_proxy;
my $response = $ua->get($newurl);
if ($response->is_success) {
if($response->content !~ /^--GuildRaidSnapShot Data/i) {
$mw->Dialog(-title => "Something went wrong",-text => "The response from the webserver was not a valid GRSS Data file. Please make sure you've entered the address properly.",-buttons => ['OK'])->Show();
} else {
open(OUT,">url.txt");
print OUT $url;
close(OUT);
open(OUT,">GRSS_Data.lua");
print OUT $response->content;
close(OUT);
$mw->Dialog(-title => "Downloaded!",-text => "The download was a success. Simply type /console reloadui in WoW, or close WoW and reopen it.", -buttons => ['OK'])->Show();
#print "checking version my version $myversion\n";
my $version = $ua->get("http://www.dkpsystem.com/grssversion");
if($version->is_success){
#print "Current Version ".$version->content."\n";
if($version->content != $myversion){
$newversion = $version->content;
$newversion =~ s/\n//gs;
my $yesno=$mw->Dialog(-title => "New Version!!",-text => "Would you like GRSS to Automatically download the new version '$newversion' for you?", -default_button => "Yes", -buttons => ['Yes','No'])->Show();
if($yesno =~ /Yes/){
&downloadpatch($ua);
}
}
}
}
exit;
}else{
$mw->Dialog(-title => "Not Good...",-text => "Unfortunately, the URL entered didn't work. Make sure you have it entered properly, and that you don't have any firewall programs blocking this program (such as Norton Internet Security)", -buttons => ['OK'])->Show();
}
}
sub downloadpatch
{
my $prefix = "http://www.dkpsystem.com/files/GRSS";
my $ua = $_[0];
my $status;
$status=&downloadindependentfile("$prefix/GuildRaidSnapShot.lua","GuildRaidSnapShot.lua",$ua);
$status=&downloadindependentfile("$prefix/GuildRaidSnapShot.toc","GuildRaidSnapShot.toc",$ua) if($status);
$status=&downloadindependentfile("$prefix/readme.txt","readme.txt",$ua) if($status);
$status=&downloadindependentfile("$prefix/GuildRaidSnapShot.xml","GuildRaidSnapShot.xml",$ua) if($status);
$status=&downloadindependentfile("$prefix/GRSSWaitingInvite.xml","GRSSWaitingInvite.xml",$ua) if($status);
if($status){
$mw->Dialog(-title => "Successful",-text => "Patch downloaded successfully", -buttons => ['OK'])->Show();
}else{
my $yesno=$mw->Dialog(-title => "Upgrade Failed!",-text => "Patch download Failed! Try Again?", -default_button => "Yes",-buttons => ['Yes','No'])->Show();
if($yesno =~ /Yes/){
&downloadpatch($ua);
}
}
}
sub downloadindependentfile
{
my $newurl = $_[0];
my $localfilename = $_[1];
my $ua = $_[2];
$message = "Downloading $newurl";
my $ua = LWP::UserAgent->new;
$ua->timeout(15);
$ua->env_proxy;
my $response = $ua->get($newurl);
if ($response->is_success) {
open(OUT,">$localfilename");
print OUT $response->content;
close(OUT);
return 1;
}else{
return 0;
}
}