forked from orzTech/HostsXEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HostsX.ahkh
3691 lines (3367 loc) · 105 KB
/
HostsX.ahkh
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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#NoEnv
#KeyHistory 0
#Persistent
#SingleInstance off
#Include inc/Dlg.ahkh
#Include inc/HTTPRequest.ahkh
FileEncoding, CP936
If 1=/admin
{
PopularFile=%A_WinDir%\System32\drivers\etc\hosts
SystemHosts=%PopularFile%
ModuleName=%2%
Menu, Tray, NoStandard
Menu, Tray, NoIcon
if IsFunc("AdminModule" . ModuleName)
{
AdminModule%ModuleName%()
}
ExitApp
}
StatusLog := Object()
IfExist %A_ScriptFullPath%.dat\*
ConfigFoundHere = true
IfExist %A_AppData%\orzTech\HostsX\*
ConfigFoundAppData = true
ConfigHereWriteProtect=false
Random, rand1, 10000, 99999
Random, rand2, 10000, 99999
Random, rand3, 10000, 99999
Loop, %A_Temp%,2
{
FullTemp = %A_LoopFileLongPath%
}
Loop, %A_ScriptDir%,2
{
FullScriptDir = %A_LoopFileLongPath%
}
StringLower Lower_A_ScriptDir, FullScriptDir
StringLower Lower_A_Temp, FullTemp
StringLen Len_A_Temp, A_Temp
StringLeft Cutted_A_ScriptDir, Lower_A_ScriptDir, Len_A_Temp
If (Cutted_A_ScriptDir=Lower_A_Temp)
{
ConfigHereWriteProtect=true
}
Else IfInString, Lower_A_ScriptDir, locals~1\temp
{
ConfigHereWriteProtect=true
}
If ConfigHereWriteProtect=true
{ }
Else
{
If ConfigFoundHere = true
testFile = %A_ScriptFullPath%.dat\HostsX%rand1%%rand2%%rand3%.orz
Else
testFile = %A_ScriptDir%\HostsX%rand1%%rand2%%rand3%.orz
FileAppend, a, %testFile%
If ErrorLevel
ConfigHereWriteProtect = true
Else
FileDelete %testFile%
}
ConfigUseAppData = false
ConfigPath=
If ConfigFoundHere=true
{
if ConfigHereWriteProtect=true
{
if ConfigFoundAppData=true
{ }
else
{
FileCopyDir, %A_ScriptFullPath%.dat, %A_AppData%\orzTech\HostsX
}
ConfigPath = %A_AppData%\orzTech\HostsX
ConfigUseAppData = true
}
else
{
ConfigPath = %A_ScriptFullPath%.dat
ConfigUseAppData = false
}
}
else
{
if ConfigHereWriteProtect=true
{
if ConfigFoundAppData=true
{}
else
{
FileCreateDir, %A_AppData%\orzTech\HostsX
}
ConfigPath = %A_AppData%\orzTech\HostsX
ConfigUseAppData = true
}
else
{
if ConfigFoundAppData=true
{
FileMoveDir, %A_AppData%\orzTech\HostsX, %A_ScriptFullPath%.dat
}
else
{
FileCreateDir, %A_ScriptFullPath%.dat
}
ConfigPath = %A_ScriptFullPath%.dat
ConfigUseAppData = false
}
}
If ConfigUseAppData = true
{
TrayTip, HostsX 配置文件夹警告, HostsX 无法在当前所在文件夹写入数据,故已经切换到用户配置文件夹模式。请尝试将程序复制到本地硬盘可写入的文件夹运行,程序将自动将用户配置文件夹中创建的文件移动到当前文件夹。, 30, 3
LogStatus("HostsX 无法在当前所在文件夹写入数据,故已经切换到用户配置文件夹模式。请尝试将程序复制到本地硬盘可写入的文件夹运行,程序将自动将用户配置文件夹中创建的文件移动到当前文件夹。")
}
IfNotExist,%ConfigPath%\HostsX.orzconfig
GoSub FirstRun
FileInstall orzTech.com.png, %ConfigPath%\orzTech.com.png
applicationname=HostsX
applicationfunction=新一代记事本风格的 Hosts 文件编辑工具。
applicationtip=
applicationversion=0.7.1.18
LogStatus(applicationname " " applicationversion " 已经启动。")
Gosub ReloadSettings
BuildMenu:
If A_IsCompiled=1
Menu, Tray, Icon, %A_ScriptFullPath%
Else
Menu, Tray, Icon, HostsX.ico
Menu, Tray, NoStandard
Menu, Tray, Add, 关于 HostsX(&A), HelpAbout
Menu, Tray, Add
Menu, Tray, Add, 退出 HostsX(&X), FileExit
Menu, MyMenuBar,Add
Menu, MyMenuBar,DeleteAll
Menu, FileMenu, Add, 新建(&N)`tCtrl+N, FileNew
Menu, FileMenu, Add, 打开(&O)...`tCtrl+O, FileOpen
Menu, FileMenu, Add, 保存(&S)`tCtrl+S, FileSave
Menu, FileMenu, Add, 另存为(&A)..., FileSaveAs
Menu, FileMenu, Add ; Separator line.
Gosub FillPopularFiles
Menu, FileMenu, Add ; Separator line.
Menu, FileMenu, Add, 退出(&X), FileExit
Menu, EditMenu, Add, 撤销(&U)`tCtrl+Z, EditUndo
Menu, EditMenu, Add
Menu, EditMenu, Add, 剪切(&T)`tCtrl+X, EditCut
Menu, EditMenu, Add, 复制(&C)`tCtrl+C, EditCopy
Menu, EditMenu, Add, 粘贴(&P)`tCtrl+V, EditPaste
Menu, EditMenu, Add, 删除(&D)`tDelete` , EditDelete
Menu, EditMenu, Add, 删除全部(&E), EditDeleteAll
Menu, EditMenu, Add
Menu, EditMenu, Add, 查找(&F)...`tCtrl+F, EditFind
Menu, EditMenu, Add, 查找下一处(&N)`tF3, EditFindNext
Menu, EditMenu, Add, 查找上一处(&N)`tShift+F3, EditFindNext
Menu, EditMenu, Add, 替换(&R)...`tCtrl+H, EditReplace
Menu, EditMenu, Add, 转到(&G)...`tCtrl+G, EditGoto
Menu, EditMenu, Add
Menu, EditMenu, Add, 全选(&A)`tCtrl+A, EditSelectAll
Menu, FormatMenu, Add, 字体(&F)..., FormatFont
Menu, FormatMenu, Add
Menu, FormatMenu, Add, 纠正换行符号错误并删除空行(&R), HostsWrap
Menu, FormatMenu, Add
Menu, FormatMenu, Add, 注释(&M), HostsSortSelectedComment
Menu, FormatMenu, Add, 取消注释(&D), HostsSortSelectedUnComment
Menu, FormatMenu, Add, 删除注释(&D), HostsDelComments
Menu, FormatMenu, Add
Menu, FormatMenu, Add, 按照域名排序(&S), HostsSortSelected
Menu, FormatMenu, Add, 删除重复项并按照域名排序(&H), HostsSort
Menu, FormatMenu, Add, 按照域名分类(&C), HostsSortSelectedCategorized
Menu, FormatMenu, Add, 删除重复项并按照域名分类(&O), HostsSortCategorized
Menu, FormatMenu, Add
Menu, FormatMenu, Add, 屏蔽转向统一使用 0.0.0.0(&0), HostsReplace0000
Menu, FormatMenu, Add, 屏蔽转向统一使用 127.0.0.1(&1), HostsReplace127001
Menu, FormatMenu, Add, 屏蔽转向统一使用 127.1(&2), HostsReplace1271
GoSub BuildInsertMenu
GoSub BuildBackupMenu
Menu, ToolsMenu, Add, 根据 HostsX 白名单除错(&E)`tF10, CheckWhitelist
Menu, ToolsMenu, Add
Menu, ToolsMenu, Add, 刷新 DNS 缓存(&D)`tF7, ToolsCleanDNS
Menu, ToolsMenu, Add, 清除 Internet Explorer 缓存(&I)`tF8, ToolsCleanIE
Menu, ToolsMenu, Add, 清除 Windows Media Player 残余广告(&W), ToolsCleanWMP
Menu, ToolsMenu, Add
Menu, ToolsMenu, Add, 给 Hosts 文件加锁(&L)`tF5, ToolsLockHosts
Menu, ToolsMenu, Add, 给 Hosts 文件解锁(&U)`tF6, ToolsUnlockHosts
Menu, ToolsMenu, Add
Menu, ToolsMenu, Add, 执行 Ping 操作(&P)..., ToolsPing
Menu, ToolsMenu, Add, 执行 NSLookup 操作(&N)..., ToolsNSLookup
Gosub BuildUpdateMenu
Gosub BuildADPMenu
Menu, HelpMenu, Add, HostsX 帮助(&H), orzTechHelpPage
Menu, HelpMenu, Add, HostsX 产品主页(&P), orzTechPubPage
Menu, HelpMenu, Add, HostsX 数据发布点(&R), orzTechDataRepo
Menu, HelpMenu, Add
Menu, HelpMenu, Add, 发送反馈(&S)..., SendFeedback
Menu, HelpMenu, Add
Menu, HelpMenu, Add, 囧科技官方网站(&O), orzTech
Menu, HelpMenu, Add, 「必须的」网络隧道加速器(&V), VPNST
Menu, HelpMenu, Add
Menu, HelpMenu, Add, 关于 HostsX %applicationversion%(&A)..., HelpAbout
Menu, OptionsMenu, Add, 根据 HostsX 白名单除错时使用静默模式(&S), OptionsCheckWhitelistSilentMode
If (CheckWhitelistSilentMode = "orzYes")
Menu, OptionsMenu, Check, 根据 HostsX 白名单除错时使用静默模式(&S)
Menu, OptionsMenu, Add, 打开文件后自动根据 HostsX 白名单除错(&O), OptionsCheckWhitelistAfterOpen
If (CheckWhitelistAfterOpen = "orzYes")
Menu, OptionsMenu, Check, 打开文件后自动根据 HostsX 白名单除错(&O)
Menu, OptionsMenu, Add
Menu, OptionsMenu, Add, 启动程序时自动更新数据文件(&S), OptionsUpdateAtStartup
If (UpdateAtStartup = "orzYes")
Menu, OptionsMenu, Check, 启动程序时自动更新数据文件(&S)
Menu, OptionsMenu, Add, 数据文件不存在时自动更新数据文件(&M), OptionsUpdateWhenMissing
If (UpdateWhenMissing = "orzYes")
Menu, OptionsMenu, Check, 数据文件不存在时自动更新数据文件(&M)
; Create the menu bar by attaching the sub-menus to it:
Menu, MyMenuBar, Add, 文件(&F), :FileMenu
Menu, MyMenuBar, Add, 编辑(&E), :EditMenu
Menu, MyMenuBar, Add, 格式(&O), :FormatMenu
Menu, MyMenuBar, Add, 插入(&I), :InsertMenu
Menu, MyMenuBar, Add, HostX(&X), :InsertMenuItems
Menu, MyMenuBar, Add, 工具(&T), :ToolsMenu
Menu, MyMenuBar, Add, 备份(&B), :BackupMenu
Menu, MyMenuBar, Add, 更新(&U), :UpdateMenu
Menu, MyMenuBar, Add, 选项(&P), :OptionsMenu
Menu, MyMenuBar, Add, ADP(&A), :ADPMenu
Menu, MyMenuBar, Add, 帮助(&H), :HelpMenu
Gui, 1:Menu, MyMenuBar
; Attach the menu bar to the window:
Gui, 1:Menu, MyMenuBar
; Create the main Edit control and display the window:
Gui, +Resize ; Make the window resizable.
Gui, Margin, 0, 0
SetGUIFont(1)
Gui, Add, StatusBar, vMainStatus gMainStatus
SB_SetText("", 2, 1)
SB_SetParts(100)
gui, font,, Fixedsys
gui, font,, Courier
gui, font,, Courier New
gui, font,, Simsun
gui, font,, Consolas
gui, font,, Simsun_Yahei
gui, font,, Monaco
gui, font,, VL Gothic
Gui Font, %Style% c%Color%, %Font%
Gui, Add, Edit, vMainEdit WantTab WantReturn WantCtrlA HSCROLL -Wrap W800 R30
OnMessage(0x0200, "UpdateStatusBar")
OnMessage(0x0201, "UpdateStatusBar")
OnMessage(0x0202, "UpdateStatusBar")
OnMessage(0x0203, "UpdateStatusBar")
OnMessage(0x0204, "UpdateStatusBar")
OnMessage(0x0205, "UpdateStatusBar")
OnMessage(0x0206, "UpdateStatusBar")
OnMessage(0x0207, "UpdateStatusBar")
OnMessage(0x0208, "UpdateStatusBar")
OnMessage(0x0209, "UpdateStatusBar")
OnMessage(0x020a, "UpdateStatusBar")
OnMessage(0x020b, "UpdateStatusBar")
OnMessage(0x020c, "UpdateStatusBar")
OnMessage(0x020d, "UpdateStatusBar")
OnMessage(0x020e, "UpdateStatusBar")
OnMessage(0x020f, "UpdateStatusBar")
OnMessage(0x0100, "UpdateStatusBar")
OnMessage(0x0101, "UpdateStatusBar")
OnMessage(0x0102, "UpdateStatusBar")
OnMessage(0x0103, "UpdateStatusBar")
OnMessage(0x0104, "UpdateStatusBar")
OnMessage(0x0105, "UpdateStatusBar")
OnMessage(0x0106, "UpdateStatusBar")
OnMessage(0x0107, "UpdateStatusBar")
OnMessage(0x0108, "UpdateStatusBar")
OnMessage(0x0109, "UpdateStatusBar")
OnMessage(0x010a, "UpdateStatusBar")
OnMessage(0x010b, "UpdateStatusBar")
OnMessage(0x010c, "UpdateStatusBar")
OnMessage(0x010d, "UpdateStatusBar")
OnMessage(0x010e, "UpdateStatusBar")
OnMessage(0x010f, "UpdateStatusBar")
Gui, Show,, HostsX %applicationversion%
Gui +LastFound
hGui := WinExist()
WinGet ControlID, ID
GroupAdd, hostsx, ahk_id %ControlID%
ControlGet, EditHandle, HWND,, Edit1, ahk_id %ControlID%
DllCall("SendMessage", UInt, EditHandle, UInt, 0x00CB, UInt, 1, "UInt *", 100)
CurrentFileName = ; Indicate that there is no current file.
Unchanged=
_checkWhitelistAfterOpen = %CheckWhitelistAfterOpen%
CheckWhitelistAfterOpen = orzNo
IfExist,%SystemHosts%
{
SelectedFileName =%SystemHosts%
Gosub FileRead
}
Else
{
Gui +OwnDialogs
MsgBox, 35,,“%SystemHosts%”不存在,是否创建?
IfMsgBox, Yes
{
FileAppend, ,%SystemHosts%
SelectedFileName =%SystemHosts%
Gosub FileRead
}
}
CheckWhitelistAfterOpen = %_checkWhitelistAfterOpen%
NeedUpdate = false
if (UpdateWhenMissing = "orzYes")
{
IfNotExist,%ConfigPath%\servers.txt
{
NeedUpdate = true
FetchUpdateList(1)
}
IfNotExist,%ConfigPath%\hosts
{
NeedUpdate = true
gosub UpdateHostsFile
}
IfNotExist,%ConfigPath%\sources.txt
{
NeedUpdate = true
gosub UpdateOtherHosts
}
IfNotExist,%ConfigPath%\fixlist.txt
{
NeedUpdate = true
gosub UpdateWhitelist
}
}
If (UpdateAtStartup = "orzYes")
NeedUpdate = true
If NeedUpdate = true
{
LogStatus("本地数据库不完整,正在更新……")
}
Gosub ParseWhitelist
Loop, %0% ; For each parameter:
{
param := %A_Index% ; Fetch the contents of the variable whose name is contained in A_Index.
if param=auto
Gosub AutoParam
}
If CheckWhitelistAfterOpen = orzYes
{
CheckWhitelistInappMode=true
Gosub CheckWhitelist
}
LogStatus("就绪,单击此处可查看历史日志。")
return
#IfWinActive ahk_group hostsx
^N::
FileNew:
GoSub CheckSave
if ErrorLevel
Return
GuiControl,, MainEdit ; Clear the Edit control.
Unchanged=
CurrentFileName =
Gui +LastFound
WinSetTitle HostsX %applicationversion%
LogStatus("已创建新文件。")
return
^O::
FileOpen:
GoSub CheckSave
if ErrorLevel
Return
Gui +OwnDialogs ; Force the user to dismiss the FileSelectFile dialog before returning to the main window.
FileSelectFile, SelectedFileName, 3,, 打开 Hosts 文件
if SelectedFileName = ; No file selected.
return
Gosub FileRead
return
FileRead:
FileEncoding,
FileRead, MainEdit, %SelectedFileName% ; Read the file's contents into the variable.
FileEncoding, CP936
if ErrorLevel
{
Gui +OwnDialogs
MsgBox 无法打开“%SelectedFileName%”.
return
}
GuiControl,, MainEdit, %MainEdit% ; Put the text into the control.
GuiControlGet, MainEdit
Unchanged=%MainEdit%
CurrentFileName = %SelectedFileName%
Gui +LastFound
WinSetTitle HostsX %applicationversion% - %CurrentFileName%
LogStatus("已经打开文件 " CurrentFileName "。")
If CheckWhitelistAfterOpen = orzYes
{
CheckWhitelistInappMode=true
Gosub CheckWhitelist
}
return
^S::
FileSave:
if CurrentFileName = ; No filename selected yet, so do Save-As instead.
Goto FileSaveAs
Gosub SaveCurrentFile
return
FileSaveAs:
Gui +OwnDialogs ; Force the user to dismiss the FileSelectFile dialog before returning to the main window.
FileSelectFile, SelectedFileName, S16,, 保存 Hosts 文件
if SelectedFileName = ; No file selected.
{
ErrorLevel=1
return
}
CurrentFileName = %SelectedFileName%
Gosub SaveCurrentFile
ErrorLevel=0
return
SaveCurrentFile:
GuiControlGet, MainEdit ; Retrieve the contents of the Edit control.
EnvGet, Temp, Temp
Random, rand, 10000, 99999
FileEncoding,
FileAppend, %MainEdit%, %temp%\HostsX%rand%.orz
FileEncoding, CP936
FileGetAttrib, Attributes, %CurrentFileName%
IfInString, Attributes, R
FileSetAttrib, -R, %CurrentFileName%
IfInString, Attributes, H
FileSetAttrib, -H, %CurrentFileName%
IfInString, Attributes, S
FileSetAttrib, -S, %CurrentFileName%
FileCopy, %temp%\HostsX%rand%.orz, %CurrentFileName%, 1
If ErrorLevel
{
FileDelete, %temp%\HostsX%rand%.orz
Gui +OwnDialogs
MsgBox 16,,保存“%CurrentFileName%”失败,请检查是否有权限写入文件!`n`n请尝试使用管理员权限运行本程序重试,或暂时另存为至其他位置。`n如果您曾经给 Hosts 文件加锁过,请先解锁。
ErrorLevel=1
Return
}
IfInString, Attributes, R
FileSetAttrib, +R, %CurrentFileName%
IfInString, Attributes, H
FileSetAttrib, +H, %CurrentFileName%
IfInString, Attributes, S
FileSetAttrib, +S, %CurrentFileName%
FileDelete, %temp%\HostsX%rand%.orz
Gui +LastFound
WinSetTitle HostsX %applicationversion% - %CurrentFileName%
LogStatus(CurrentFileName " 保存成功。")
ErrorLevel=0
Unchanged=%MainEdit%
return
HelpAbout:
Gui,99:+owner1 ; Make the main window (Gui #1) the owner of the "about box" (Gui #2).
Gui +Disabled ; Disable main window.
Gui,99:Destroy
Gui,99:Margin,15,15
SetGUIFont(99)
Gui,99:Add,Picture,xm, orzTech.com.png
Gui,99:Font,Bold
Gui,99:Add,Text,xm y+20,%applicationname% %applicationversion%
Gui,99:Font
SetGUIFont(99)
Gui,99:Add,Text,x25 y+10,%applicationfunction%
Gui,99:Add,Text,x25 y+5,%applicationtip%
Gui,99:Font,Bold
Gui,99:Add,Text,xm y+20,by Yeechan Lu && Jock Kwok of 囧科技 | orzTech
Gui,99:Font
SetGUIFont(99)
Gui,99:Font,CBlue Underline
Gui,99:Add,Text,x25 y+5 gorzTech,http://orztech.com/
Gui,99:Font
SetGUIFont(99)
Gui,99:Font,Bold
Gui,99:Add,Text,xm y+20,囧科技技术支持
Gui,99:Font
SetGUIFont(99)
Gui,99:Font,CBlue Underline
Gui,99:Add,Text,x25 y+5 gorzTechSupport,http://orztech.com/support
Gui,99:Add,Text,x25 y+5 gorzTechSupportMail,[email protected]
Gui,99:Font
SetGUIFont(99)
Gui,99:Show,,关于 %applicationname% %applicationversion%
hCurs:=DllCall("LoadCursor","UInt",NULL,"Int",32649,"UInt") ;IDC_HAND
OnMessage(0x200,"WM_MOUSEMOVE")
Return
orzTechHelpPage:
Run, http://orztech.com/softwares/hostsx/help
Return
orzTechPubPage:
Run, http://orztech.com/softwares/hostsx
Return
orzTechDataRepo:
Run, https://github.com/orzTech/HostsX
return
orzTech:
Run,http://orztech.com/
Return
VPNST:
Run, http://vpnst.com/3.html
return
orzTechSupport:
Run,http://orztech.com/support
Return
orzTechAcknowledgementsPage:
Run,http://orztech.com/softwares/hostsx/acknowledgements
Return
orzTechSupportMail:
Run,% "mailto:[email protected]?subject=HostsX%20%E5%8F%8D%E9%A6%88%E8%A1%A8%E5%8D%95%20%5B%23NULL%5D%20from%20E-mail%20Supporting"
;HostsX 反馈表单 [#NULL] from E-mail Supporting
Return
WM_MOUSEMOVE(wParam,lParam)
{
Global hCurs
MouseGetPos,,,,ctrl
If ctrl in Static6,Static8,Static9
DllCall("SetCursor","UInt",hCurs)
Return
}
Return
99ButtonOK: ; This section is used by the "about box" above.
99GuiClose:
99GuiEscape:
Gui, 1:-Disabled ; Re-enable the main window (must be done prior to the next step).
Gui Destroy ; Destroy the about box.
return
GuiDropFiles:
GoSub CheckSave
if ErrorLevel
Return
Loop, parse, A_GuiEvent, `n
{
SelectedFileName = %A_LoopField% ; Get the first file only (in case there's more than one).
break
}
Gosub FileRead
return
GuiSize:
if ErrorLevel = 1 ; The window has been minimized. No action needed.
return
; Otherwise, the window has been resized or maximized. Resize the Edit control to match.
GuiControlGet, MainStatus, Pos
NewWidth := A_GuiWidth
NewHeight := A_GuiHeight - MainStatusH
GuiControl, Move, MainEdit, W%NewWidth% H%NewHeight%
return
FileExit:
GuiClose:
GoSub CheckSave
if ErrorLevel
Return
Gosub SaveSettings
ExitApp
CheckSave:
GuiControlGet, MainEdit
if Unchanged<>%MainEdit%
{
Gui +OwnDialogs
MsgBox,35, , “%SelectedFileName%”已修改,是否保存?
IfMsgBox Yes
{
Gosub FileSave
If ErrorLevel
{
ErrorLevel=1
Return
}
Else
{
ErrorLevel=0
return
}
}
IfMsgBox No
{
ErrorLevel=0
Return
}
ErrorLevel=1
Return
}
Else
ErrorLevel=0
Return
FillPopularFiles:
PopularFiles=
DriveGet, drives, List
Loop, parse, drives,,
{
PopularFile=%A_LoopField%:\Windows\HOSTS.SAM
Gosub FillPopularFile
PopularFile=%A_LoopField%:\Windows\System32\drivers\etc\hosts
Gosub FillPopularFile
PopularFile=%A_LoopField%:\Windows\Sysnative\drivers\etc\hosts
Gosub FillPopularFile
PopularFile=%A_LoopField%:\Windows\SysWOW64\drivers\etc\hosts
Gosub FillPopularFile
PopularFile=%A_LoopField%:\Windows\SysWOW64\drivers\128837
Gosub FillPopularFile
PopularFile=%A_LoopField%:\Windows\SysWOW64\drivers\138110
Gosub FillPopularFile
PopularFile=%A_LoopField%:\WinNT\System32\drivers\etc\hosts
Gosub FillPopularFile
PopularFile=%A_LoopField%:\WinNT\Sysnative\drivers\etc\hosts
Gosub FillPopularFile
PopularFile=%A_LoopField%:\WinNT\SysWOW64\drivers\etc\hosts
Gosub FillPopularFile
PopularFile=%A_LoopField%:\WinNT\hosts
Gosub FillPopularFile
PopularFile=%A_LoopField%:\Windows\hosts
Gosub FillPopularFile
PopularFile=%A_LoopField%:\system\data\hosts
Gosub FillPopularFile
PopularFile=%A_LoopField%:\private\10000882\hosts
Gosub FillPopularFile
PopularFile=%A_LoopField%:\hosts
Gosub FillPopularFile
PopularFile=%A_LoopField%:\dns\AcrylicHosts.txt
Gosub FillPopularFile
}
PopularFile=%A_WinDir%\System32\drivers\etc\hosts
SystemHosts = %PopularFile%
Gosub FillPopularFile
PopularFile=%A_WinDir%\Sysnative\drivers\etc\hosts
Gosub FillPopularFile
PopularFile=%A_WinDir%\SysWOW64\drivers\etc\hosts
Gosub FillPopularFile
PopularFile=%A_ScriptDir%\hosts
Gosub FillPopularFile
RegRead, TcpipDatabasePath, HKLM, SYSTEM\CurrentControlSet\Services\Tcpip\Parameters, DataBasePath
if ErrorLevel
{
TcpipDatabasePath = %A_WinDir%\System32\drivers\etc
}
else
{
StringReplace, TcpipDatabasePath, TcpipDatabasePath, `%Systemroot`%, %A_WinDir%
PopularFile=%TcpipDatabasePath%\hosts
SystemHosts = %PopularFile%
Gosub FillPopularFile
Loop %TcpipDatabasePath%\hosts* ; For each file dropped onto the script (or passed as a parameter).
{
PopularFile = %A_LoopFileLongPath%
Gosub FillPopularFile
}
}
RegRead, AcrylicPath, HKLM, SYSTEM\CurrentControlSet\services\AcrylicController, ImagePath
if ErrorLevel
{}
else
{
StringReplace PopularFile, AcrylicPath, AcrylicService.exe, AcrylicHosts.txt, All
Gosub FillPopularFile
}
PopularFiles=%PopularFiles%`n%A_ScriptDir%\hosts.txt
Sort, PopularFiles, U
Loop, parse, PopularFiles, `n,
{
if A_LoopField<>
Menu, FileMenu, Add, %A_LoopField%, FileOpenPopular
}
Return
FillPopularFile:
IfExist, %PopularFile%
{
Loop, %PopularFile%
{
PopularFile = %A_LoopFileLongPath%
}
PopularFiles=%PopularFiles%`n%PopularFile%
}
Return
FileOpenPopular:
GoSub CheckSave
if ErrorLevel
Return
IfExist,%A_ThisMenuItem%
{
SelectedFileName =%A_ThisMenuItem%
Gosub FileRead
}
Else
{
Gui +OwnDialogs
MsgBox, 35,,“%A_ThisMenuItem%”不存在,是否创建?
IfMsgBox, Yes
{
FileAppend, ,%A_ThisMenuItem%
SelectedFileName =%A_ThisMenuItem%
Goto FileRead
}
IfMsgBox, No
{
Return
}
Return
}
Return
HostsReplaceWith2000:
Hosts =
(
# Copyright (c) 1993-2006 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
127.0.0.1 localhost
)
GuiControl,, MainEdit, %Hosts%
Return
HostsReplaceWithVista:
Hosts =
(
# Copyright (c) 1993-2006 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
127.0.0.1 localhost
::1 localhost
)
GuiControl,, MainEdit, %Hosts%
Return
HostsReplaceWith7:
Hosts =
(
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
)
GuiControl,, MainEdit, %Hosts%
Return
HostsReplaceWithAcrylicHosts:
Hosts =
(
#############################################################################
# #
# This is the AcrylicHosts.txt file. #
# #
# It contains predefined mappings between names and addresses exactly the #
# same way the native HOSTS file does. #
# #
# Every line corresponds to a single record (mapping). #
# The format is: IPADDRESS HOSTNAME #
# #
# Where IPADDRESS is in quadded dot notation and HOSTNAME is a string. #
# The separator between IPADDRESS and HOSTNAME can be any number of spaces #
# or tabs or both. The HOSTNAME can also contain the special characters #
# '*' and '?' in which case a (slow) "dir" like pattern matching algorithm #
# is used instead of a (fast) binary search within the list of host names: #
# #
# 127.0.0.1 ad.* #
# 127.0.0.1 ads.* #
# #
# Note: Patterns are evaluated in the same order in which they are written. #
# #
# It is also possible to specify exceptions when pattern based matching is #
# used. If for example we would like to filter out all ads.* like domains #
# except for the ads.mydomain1 and the ads.mydomain2 we should write: #
# #
# 127.0.0.1 ads.* ads.mydomain1,ads.mydomain2 #
# #
# Multiple exceptions must be on a single line and separated by commas. #
# #
# Note: A line starting with the '#' character is considered a comment and #
# therefore ignored. #
# #
#############################################################################
127.0.0.1 localhost
)
GuiControl,, MainEdit, %Hosts%
Return
EditUndo:
GuiControl, Focus, MainEdit
Send ^Z
Return
EditCut:
GuiControl, Focus, MainEdit
Send ^X
Return
EditCopy:
GuiControl, Focus, MainEdit
Send ^C
Return
EditPaste:
GuiControl, Focus, MainEdit
Send ^V
Return
^G::
EditGoto:
ControlGet, MainEditCurrentLine, CurrentLine,, edit1
ControlGet, MainEditLineCount, LineCount,, edit1
Gui +OwnDialogs
InputBox, JumpToLine, 转到指定行, 行号(&L): 1 〜 %MainEditLineCount%, , , , , , , , %MainEditCurrentLine%
if (JumpToLine > 0 && JumpToLine <= MainEditLineCount)
{
JumpToLine:= JumpToLine - 1
SendMessage, 0x00BB, %JumpToLine%, 0, edit1
if (ErrorLevel != 0xFFFFFFFF)
{
SendMessage, 0x00B1, %ErrorLevel%, %ErrorLevel%, edit1
SendMessage, 0x00B7, 0, 0, edit1
}
/*
result = SendMessageW(hwndEdit, EM_LINEINDEX, a1 - 1, 0);
if ( result != -1 )
{
SendMessageW(hwndEdit, EM_SETSEL, result, result);
result = SendMessageW(hwndEdit, EM_SCROLLCARET, 0, 0);
}
return result;
*/
}
Return
EditDelete:
GuiControl, Focus, MainEdit
Send {Del}
Return
EditDeleteAll:
GuiControlGet, MainEdit
MainEdit=
GuiControl,, MainEdit, %MainEdit%
Return
EditSelectAll:
GuiControl, Focus, MainEdit
Send ^A
Return
BuildInsertMenu:
Gui 1:Menu
GoSub BuildInsertMenuItems
Menu, InsertMenu, Add
Menu, InsertMenu, DeleteAll
Menu, InsertMenu, Add, 域名解析数据(&L), InsertLookupIPLocal
Menu, InsertMenu, Add, localhost 本地解析数据(&O), InsertLocalhost
Menu, InsertMenu, Add
SourceIndex=0
Loop, Read, %ConfigPath%\sources.txt
{
Length := StrLen(A_LoopReadLine)
if Length > 0
{
fch:=SubStr(A_LoopReadLine, 1, 1)
if fch=-
{
Menu, InsertMenu, Add
}
else if fch=;
{
commentsource:=SubStr(A_LoopReadLine, InStr(SubStr(A_LoopReadLine, 2), "=")+2)
commentsourcename:=SubStr(SubStr(A_LoopReadLine, 1, InStr(A_LoopReadLine, "=")-1),2)
Commentsource%commentsourcename%:=commentsource
}