-
Notifications
You must be signed in to change notification settings - Fork 72
/
NetworkAPI.ahk
174 lines (155 loc) · 4.41 KB
/
NetworkAPI.ahk
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
API_u2vClean:=1 ;enable u2v_clean()
API_SetSource("aspdm.ahkscript.org") ; Über Default packs source
; Other/mirror servers - [not always updated]
; --------------------------------------------
; API_SetSource("aspdm.2fh.co")
;
; API_SetSource("ahk.cu.cc")
;
; API_SetSource("aspdm.cu.cc")
;
; API_SetSource("aspdm.1eko.com")
; --------------------------------------------
API_SetSource(domain) {
Global Package_Source
Global Packs_Source
Global API_Source
domain:=API_ParseSource(domain)
if (Package_Source == domain)
return 1
if API_ValidateSource(domain) {
Package_Source:=domain
;Packs_Source:="http://packs." domain
;API_Source:="http://api-php." domain
Packs_Source:="http://" domain "/packs"
API_Source:="http://" domain "/api-php"
return 1
}
return 0
}
API_ParseSource(domain,mainonly:=0) {
StringLower,domain,domain
if (mainonly) {
RegExMatch(domain "/","i)([a-z]+\.[a-z]+/)",m) ;Isolate main domain, ex: http://packs.fansite.com/asdsd/sdds --> fansite.com
StringTrimRight,domain,m1,1
return domain
} else {
RegExMatch("/" domain "/","i)(/[\w\.]+/)",m) ;Isolate full domain, ex: http://packs.fansite.com/asdsd/sdds --> packs.fansite.com
StringTrimRight,domain,m1,1
StringTrimLeft,domain,domain,1
return domain
}
}
API_ValidateSource(domain) {
check:=A_NowUTC "|" A_TickCount
;data:=JSON_ToObj(u2v_clean("http://api-php." domain "/status.php?_c=" check))
data:=JSON_ToObj(u2v_clean("http://" domain "/api-php/status.php?_c=" check))
if IsObject(data) {
if ( (data["api"]["check"] == check) && (data["api"]["name"] == "aspdm") )
return 1
}
return 0
}
CheckUpdate(version,silent:=0,Update_URL:="http://aspdm.ahkscript.org/client/update.ini") {
URLDownloadToFile,%Update_URL%, % tempupdatefile:=Util_TempFile()
IniRead,NewVersion,%tempupdatefile%,Update,Version,NULL (Error)
IniRead,__URL,%tempupdatefile%,Update,URL
FileDelete,%tempupdatefile%
if (InStr(NewVersion,"NULL") || InStr(NewVersion,"Error"))
{
if (silent)
return "ERROR"
else
MsgBox, 262192, %A_ScriptName% - Update, An error occured.`nPlease check your internet connection and try again.
}
else
{
if (Util_VersionCompare(NewVersion,Version))
{
if (silent==-1 || silent==0) {
MsgBox, 262212, %A_ScriptName% - Update, A new version is available.`nCurrent Version: `t%Version%`nLatest Version: `t%NewVersion%`nWould you like to update?
IfMsgBox, Yes
run, %__URL%
}
return 1
}
else
{
if (!silent)
MsgBox, 262208, %A_ScriptName% - Update, You have the latest version.
return 0
}
}
}
u2v(u){
URLDownloadToFile,%u%, % t:=Util_TempFile()
FileRead,x,%t%
FileDelete,%t%
return x
}
v_clean(s){ ;the new free host adds junk, this filters it out
/*
j:=substr(k:=RegExReplace(u2v(u),"s)<!--.*"),1,1)
return ((j=="?")?SubStr(k,2):k)
*/
i:=0, k:=RegExReplace(s,"s)<!--.*")
loop % strlen(3)
if (!Util_isASCII(SubStr(k,1,1)))
i+=1
k:=SubStr(k,i+1)
return ((SubStr(k,1,1)=="?")?SubStr(k,2):k)
}
u2v_clean(u){ ;the new free host adds junk, this filters it out
global API_u2vClean
if (API_u2vClean)
return v_clean(u2v(u))
return u2v(u)
}
API_List(sort:=0) {
global API_Source
l:=StrSplit(u2v_clean(API_Source "/list.php" ((sort)?"&sort":"") ),"`n")
l.Remove(l.MaxIndex())
return l
}
API_ListNum(lim,origin:=0,sort:=0) {
global API_Source
return JSON_ToObj(u2v_clean(API_Source "/list.php?" ((lim)?"lim=" lim:"") ((origin) ? "&origin=" origin : "") ((sort)?"&sort":"") ))
}
API_ListAll(sort:=0) {
global API_Source
k:=u2v_clean(API_Source "/list.php?full" ((sort)?"&sort":"") )
if (!InStr(SubStr(k,1,3),"{")) ;avoid javascript from error page to be considered as JSON
return ""
return JSON_ToObj(k)
}
API_Info(file,item="") {
global API_Source
return u2v_clean(API_Source "/info.php?f=" . file . "&c=" . item)
}
API_Get(file) {
global Packs_Source
StringLower,file,file
DownloadFile(Packs_Source "/" file,t:=Util_TempFile())
return t
}
API_GetDependencies(pack_ahkp) {
reqCSV:=API_Info(pack_ahkp,"required")
if InStr(reqCSV,"ERROR:")
return Object()
reqArr:=Object()
Loop,Parse,reqCSV,CSV
{
reqArr.Insert(A_LoopField ".ahkp")
k:=API_GetDependencies(A_LoopField ".ahkp")
if (k.MaxIndex > 0)
Util_ArrayInsert(reqArr,k)
}
return reqArr
}
API_UpdateExists(name,ver_local:="") {
if !StrLen(ver_local)
ver_local:=JSON_ToObj(Manifest_FromPackage(name)).version
if (Util_VersionCompare(ver_server:=API_Info(name,"version"),ver_local))
return ver_server
return 0
}