-
Notifications
You must be signed in to change notification settings - Fork 7
/
update.c
executable file
·95 lines (75 loc) · 2.58 KB
/
update.c
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
/*
Copyright 2013 Luigi Auriemma
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
http://www.gnu.org/licenses/gpl-2.0.txt
*/
#include "libs/mydownlib/mydownlib.h"
int quickbms_update(void) {
static u8 *website[] = {
"aluigi.org/quickbms.htm",
"aluigi.altervista.org/quickbms.htm",
NULL
};
mydown_options opt;
int n,
buffsz;
u8 *buff = NULL,
*p,
*v,
*s;
for(n = 0; website[n]; n++) {
memset(&opt, 0, sizeof(opt));
opt.verbose = 1;
opt.useragent = "Mozilla/4.0";
opt.filedata = &buff;
buffsz = mydown(
website[n],
NULL,
&opt);
if(buffsz != -1) break;
}
if(!website[n] || !buff || !buffsz) {
fprintf(stderr, "\nError: the QuickBMS website isn't available\n");
myexit(QUICKBMS_ERROR_UPDATE);
}
// the current version of mydownlib adds the final 0x00 automatically
//buff[buffsz - 1] = 0; // doesn't matter if the last byte is zeroed
p = strstr(buff, "quickbms.zip");
if(!p) {
fprintf(stderr, "\nError: the QuickBMS page content (zip) isn't available\n");
myexit(QUICKBMS_ERROR_UPDATE);
}
v = strstr(p, "0.");
if(!v) {
fprintf(stderr, "\nError: the QuickBMS page content (version) isn't available\n");
myexit(QUICKBMS_ERROR_UPDATE);
}
strstr(p, ".zip")[4] = 0;
for(; p >= buff; p--) {
if(strchr("\"'= ", *p)) break;
}
p++;
strchr(v, '<')[0] = 0;
s = strchr(website[n], '/');
if(!s) s = website[n] + strlen(website[n]);
if(!stricmp(v, VER)) {
printf("\n- No updates available, you already have the latest version\n");
} else {
printf("\n- Update %s available:\n\n http://%.*s/%s\n\n",
v,
s - website[n], website[n], p);
}
FREE(buff);
myexit(QUICKBMS_OK);
return 0;
}