-
Notifications
You must be signed in to change notification settings - Fork 56
/
main.aardio
385 lines (329 loc) · 10.7 KB
/
main.aardio
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
//RUNAS//GitHub 优化
import fonts.fontAwesome;
import win.ui;
import win.ui.atom;
/*DSG{{*/
var winform = win.form(text="Ghips - GitHub 网速优化工具";right=655;bottom=277;bgcolor=16777215;border="none";max=false)
winform.add(
bk={cls="bk";left=2;top=0;right=658;bottom=32;bgcolor=16777215;forecolor=8882055;linearGradient=0;z=7};
bk2={cls="bk";text="Ghips - GitHub 网速优化工具";left=46;top=4;right=256;bottom=26;align="left";color=4934475;z=8};
bk3={cls="bk";text='\uF0E8';left=16;top=6;right=38;bottom=24;color=4934475;font=LOGFONT(h=-18;name='FontAwesome');z=9};
cmbIpCidrs={cls="combobox";left=49;top=100;right=328;bottom=126;edge=1;items={};mode="dropdown";z=1};
editIpCurrent={cls="plus";left=114;top=196;right=399;bottom=222;align="left";border={bottom=1;color=-6908266};editable=1;font=LOGFONT(h=-13);textPadding={top=6;bottom=2};z=11};
lbTimer={cls="static";text="0 秒( 已禁用 )";left=411;top=243;right=496;bottom=263;transparent=1;z=14};
lnkWeb={cls="plus";text="获取源码";left=523;top=239;right=607;bottom=263;align="left";iconStyle={align="left";font=LOGFONT(h=-15;name='FontAwesome')};iconText='\uF09B ';notify=1;textPadding={left=18;bottom=1};z=10};
plusExploreHosts={cls="plus";text='\uF07C 编辑hosts文件';left=450;top=193;right=607;bottom=222;bgcolor=-6371181;font=LOGFONT(h=-15;name='FontAwesome';charset=0);notify=1;z=6};
plusUpdateDns={cls="plus";text='\uF0AD 更改github.com解析到选定IP / 并更新图像等服务器IP';left=121;top=148;right=607;bottom=177;bgcolor=-6371181;font=LOGFONT(h=-15;name='FontAwesome';charset=0);notify=1;z=3};
plusUpdateIps={cls="plus";text='\uF021 获取最新IP列表 / 测速';left=345;top=97;right=607;bottom=126;bgcolor=-6371181;font=LOGFONT(h=-15;name='FontAwesome';charset=0);notify=1;z=2};
static={cls="static";text="本工具使用 GitHub 官网接口获取访问速度最快的 IP 地址( 适用于无代理连接 )";left=49;top=50;right=635;bottom=86;color=3947580;font=LOGFONT(h=-13);transparent=1;z=4};
static2={cls="static";text="当前指向IP:";left=22;top=205;right=106;bottom=225;align="right";transparent=1;z=5};
static3={cls="static";text="自动刷新间隔:";left=20;top=241;right=104;bottom=261;align="right";transparent=1;z=13};
tbTimer={cls="plus";left=114;top=244;right=399;bottom=259;bgcolor=-2512093;border={radius=-1};color=23807;foreRight=15;forecolor=-14911489;paddingBottom=5;paddingTop=5;z=12}
)
/*}}*/
var atom,hwnd = winform.atom("683FC72C-F549-4B6D-BAE0-3DA5855C11ED.Ghips");
if(!atom){
win.setForeground(hwnd);
win.quitMessage();
return;
}
winform.cmbIpCidrs.onListChange = function(){
winform.setTimeout(
function(){
var ip = string.match(winform.cmbIpCidrs.selText,"\d+\.\d+\.\d+\.\d+");
if( ip) winform.plusUpdateDns.text = "更改 github.com 域名解析到:" + ip
}
);
}
import wsock;
winform.plusUpdateIps.oncommand = function(id,event,triggeredByTimer){
winform.editIpCurrent.text = wsock.getIp("www.github.com")
winform.plusUpdateIps.disabledText = {'\uF254';'\uF251';'\uF252';'\uF253';'\uF250'}
var metaInfo = thread.invokeAndWait(
function(){
import web.rest.jsonClient;
var http = web.rest.jsonClient();
var github = http.api("https://api.github.com/");
return github.meta.get();
}
)
var gitHubIps;
if(metaInfo[["web"]]){
gitHubIps = table.map(metaInfo.web,lambda(v)..string.match(v,"^\d+\.\d+\.\d+\.\d+"))
}
elseif(!gitHubIps){
gitHubIps = {
"192.30.252.0",
"185.199.108.0",
"140.82.112.0",
"143.55.64.0",
"20.201.28.151",
"20.205.243.166",
"102.133.202.242",
"20.248.137.48",
"20.207.73.82",
"20.27.177.113",
"20.200.245.247",
"20.233.54.53"
}
}
var pingThread = function( ip ) {
import wsock.tcp.client;
var result = 0;
for(i=1;4;1){
var beginTick = ..time.tick()
var tcp = wsock.tcp.client()
tcp.setTimeouts(1000,1000);
if( ! tcp.connectTimeout(ip,80,2) ){
return;
};
var sendData =/***********
GET / HTTP/1.1
Host: www.github.com
Connection: close
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64)
Accept: */*;
Accept-Language: zh-CN,zh;
Accept-Charset:utf-8;
***********/
tcp.write( sendData + '\r\n\r\n' )
var rep = tcp.readAll();
tcp.close();
if( rep && ..string.startWith(rep,"HTTP/1.1 301 Moved Permanently") ){
result = result + ((..time.tick() - beginTick)/1000);
}
else {
return;
}
}
return ip,math.round(result/4,2);
}
import thread.manage;
var manage = thread.manage(#gitHubIps)
var ipData = {}
for(k,ip in gitHubIps){
manage.createSuspended(pingThread,ip).onEnd = function(ip,sec){
if(ip && sec!==null ) {
table.push(ipData,ip + " 响应速度:" + sec + "秒");
winform.cmbIpCidrs.items = ipData;
winform.cmbIpCidrs.selIndex = 1;
if(triggeredByTimer && (#ipData == 1) ){
winform.plusUpdateDns.oncommand(,,true);
}
}
}
}
manage.resume();
manage.waitClose();
winform.cmbIpCidrs.items = ipData;
winform.cmbIpCidrs.selIndex = 1;
winform.cmbIpCidrs.onListChange();
winform.text = "github.com 网速优化工具"
winform.plusUpdateIps.disabledText = null;
}
winform.plusUpdateDns.oncommand = function(id,event,triggeredByTimer){
var ip = winform.cmbIpCidrs.text;
if(!#ip){
if(triggeredByTimer) return;
winform.msgboxErr("请选选择IP地址")
return;
}
ip = string.match(ip,"\d+\.\d+\.\d+\.\d+");
if( ip == winform.editIpCurrent.text ) {
if(triggeredByTimer) return;
return winform.msgboxErr("域名之前已经解析到该IP地址");
}
winform.plusUpdateDns.disabledText = {'\uF254';'\uF251';'\uF252';'\uF253';'\uF250';text=" 正在更新IP ……"};
var tick = time.tick();
thread.invokeAndWait(
function(ip){
var githubIps = {
["www.github.com"] = ip;
["github.com"] = ip;
}
import web.rest.jsonLiteClient;
var http = web.rest.jsonLiteClient();
var ipApi = http.api("http://ip-api.com/json");
var data = ipApi["raw.githubusercontent.com"].get();
var cIp = data[["query"]];
if( !cIp || string.match(cIp,"\x+\:[\x\:]") ){
cIp = ip;
}
githubIps["raw.github.com"] = cIp;
githubIps["assets-cdn.github.com"] = cIp;
githubIps["raw.githubusercontent.com"] = cIp;
githubIps["gist.githubusercontent.com"] = cIp;
githubIps["cloud.githubusercontent.com"] = cIp;
githubIps["camo.githubusercontent.com"] = cIp;
githubIps["avatars0.githubusercontent.com"] = cIp;
githubIps["avatars1.githubusercontent.com"] = cIp;
githubIps["avatars2.githubusercontent.com"] = cIp;
githubIps["avatars3.githubusercontent.com"] = cIp;
githubIps["avatars4.githubusercontent.com"] = cIp;
githubIps["avatars5.githubusercontent.com"] = cIp;
githubIps["avatars6.githubusercontent.com"] = cIp;
githubIps["avatars7.githubusercontent.com"] = cIp;
githubIps["avatars8.githubusercontent.com"] = cIp;
githubIps["marketplace-screenshots.githubusercontent.com"] = cIp;
githubIps["repository-images.githubusercontent.com"] = cIp;
githubIps["user-images.githubusercontent.com"] = cIp;
githubIps["desktop.githubusercontent.com"] = cIp;
import fsys.hosts;
fsys.hosts.ownCacls();
fsys.hosts.update(githubIps);
},ip
)
tick = time.tick() - tick;
if(tick<1000){
win.delay(1000 - tick);
}
winform.editIpCurrent.text = wsock.getIp("www.github.com");
winform.plusUpdateDns.disabledText = null;
if( ip != winform.editIpCurrent.text ){
if(triggeredByTimer) return;
winform.msgboxErr("修改 hosts 文件失败,如果hosts文件被其他软件锁定时请先解除锁定,也可以搜索网上教程试试设置文件权限")
}
}
winform.plusExploreHosts.skin(
background = {
hover = "/res/images/btn-hover.png";
focus = "/res/images/btn-focus.jpg";
active = "/res/images/btn-active.png";
disabled = "/res/images/btn-disabled.png";
}
)
import process;
import fsys.hosts;
winform.plusExploreHosts.oncommand = function(id,event){
process.execute("notepad.exe",fsys.hosts.path,"runas")
}
winform.plusUpdateDns.skin({
background={
default=0xFF93C89E;
hover=0xFF928BB3
}
})
winform.plusUpdateIps.skin({
background={
default=0xFF93C89E;
hover=0xFF928BB3
}
})
winform.plusExploreHosts.skin({
background={
default=0xFF93C89E;
hover=0xFF928BB3
}
})
winform.lnkWeb.skin({
color={
active=0xFF00FF00;
default=0xFF000080;
disabled=0xFF6D6D6D;
hover=0xFFFF0000
}
})
winform.lnkWeb.oncommand = function(id,event){
import process;
process.openUrl("https://www.github.com/aardio/Ghips")
}
import win.ui.simpleWindow2;
win.ui.simpleWindow2(winform);
import win.ui.menu;
import win.util.tray;
winform.tray = win.util.tray(winform);
winform.onTrayMessage = {
[0x205/*_WM_RBUTTONUP*/ ] = function(wParam){
import win.ui.menu;
var popmenu = win.ui.popmenu(winform);
win.setForeground(winform.hwnd);
if(!_STUDIO_INVOKED){
import sys.runAsTask;
var sysTask = sys.runAsTask("Ghips","GitHub 网速优化工具")
var id = popmenu.add('设为开机启动',function(id){
if(sysTask.get()){
sysTask.delete();
}
else {
sysTask.register("/tray");
}
});
popmenu.check(id,!!sysTask.get(),0/*_MF_BYCOMMAND*/);
}
popmenu.add('ImTip',function(id){
import process;
process.openUrl("https://imtip.aardio.com/");
});
popmenu.add('退出',function(id){
winform.onClose = null;
winform.close();
});
popmenu.popup();
};
[0x202/*_WM_LBUTTONUP*/] = function(wParam){
winform.show(true);
win.setForeground(winform.hwnd);
if(!winform.plusUpdateIps.disabled){
winform.plusUpdateIps.oncommand();
}
};
}
winform.tbTimer.setTrackbarRange(0,24);
winform.tbTimer.skin({
background={
default=0xFF23ABD9
};
foreground={
default=0xFFFF771C;
hover=0xFFFF6600
};
color={
default=0xFFFF5C00;
hover=0xFFFF6600
}
})
import config;
winform.tbTimer.onPosChanged = function( interval,triggeredByUser ){
winform.lbTimer.text = (interval * 5) + " 秒";
if(!interval) winform.lbTimer.text = winform.lbTimer.text + "( 已禁用 )";
if(triggeredByUser){
config.meta.interval = interval;
config.meta.save();
}
if(interval != winform.githubInterval){
if(winform.githubTimer){
winform.clearInterval(winform.githubTimer);
}
if(interval){
winform.githubTimer = winform.setInterval(
function(){
if(!winform.plusUpdateIps.disabled){
winform.plusUpdateIps.oncommand(,,true);
}
},interval * 5000
)
}
}
}
winform.tbTimer.progressPos = config.meta.interval || 0;
winform.onMinimize = function(lParam){
winform.show(false);
return true;
}
winform.onClose = function(hwnd,message,wParam,lParam){
winform.show(false);
return true;
}
if(!_ARGV.tray){
winform.show();
if(config.meta.interval){
winform.plusUpdateIps.oncommand(,,true);
}
else {
winform.plusUpdateIps.oncommand();
}
}
else {
winform.plusUpdateIps.oncommand(,,true);
}
win.loopMessage();