-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMyChrome.au3
2847 lines (2612 loc) · 109 KB
/
MyChrome.au3
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
#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=Icon_1.ico
#AutoIt3Wrapper_Compile_Both=y
#AutoIt3Wrapper_UseX64=y
#AutoIt3Wrapper_Res_Comment=可自动更新的 Google Chrome 便携版
#AutoIt3Wrapper_Res_Description=Google Chrome 便携版
#AutoIt3Wrapper_Res_Fileversion=3.0.1.0
#AutoIt3Wrapper_Res_LegalCopyright=(C)甲壳虫<[email protected]>
#AutoIt3Wrapper_Res_Language=1033
#AutoIt3Wrapper_AU3Check_Parameters=-q
#AutoIt3Wrapper_Run_Au3Stripper=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------
AutoIt Version: 3.3.10.2
作者: 甲壳虫 < [email protected] >
网站: http://code.google.com/p/my-chrome/
脚本说明: MyChrome - 可自动更新的 Google Chrome 便携版
#ce ----------------------------------------------------------------------------
#include <Date.au3>
#include <Constants.au3>
#include <StaticConstants.au3>
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <ComboConstants.au3>
#include <GuiStatusBar.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <WinAPIFiles.au3>
#include <APIFilesConstants.au3>
#include <WinAPI.au3>
#include <WinAPIProc.au3>
#include <WinAPIReg.au3>
#include <APIRegConstants.au3>
#include <WinAPIDiag.au3>
#include <WinAPIMisc.au3>
#include <Security.au3>
#include "WinHttp.au3" ; http://www.autoitscript.com/forum/topic/84133-winhttp-functions/
#include "SimpleMultiThreading.au3"
Opt("TrayAutoPause", 0)
Opt("TrayMenuMode", 3) ; Default tray menu items (Script Paused/Exit) will not be shown.
Opt("TrayOnEventMode", 1)
Opt("GUIOnEventMode", 1)
Opt("WinTitleMatchMode", 4)
Global Const $AppVersion = "3.0.1" ; MyChrome version
Global $AppName, $inifile, $FirstRun = 0, $ChromePath, $ChromeDir, $ChromeExe, $UserDataDir, $Params
Global $CacheDir, $CacheSize, $PortableParam
Global $LastCheckUpdate, $UpdateInterval, $Channel, $IsUpdating = 0, $AskBeforeUpdateChrome, $x86 = 0
Global $EnableProxy, $ProxySever, $ProxyPort
Global $AutoUpdateApp, $LastCheckAppUpdate
Global $RunInBackground, $ExApp, $ExAppAutoExit, $ExApp2, $AppPID, $ExAppPID
Global $TaskBarDir = @AppDataDir & "\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar"
Global $TaskBarLastChange
Global $aExApp, $aExApp2, $aExAppPID[2]
Global $hSettings, $SettingsOK
Global $hSettingsOK, $hSettingsApply, $hStausbar
Global $hChromePath, $hGetChromePath, $hChromeSource, $hCheckUpdate
Global $hChannel, $hx86, $hUpdateInterval, $hLatestChromeVer, $hCurrentVer, $hUserDataDir, $hCopyData
Global $hAutoUpdateApp, $hCacheDir, $hSelectCacheDir, $hCacheSize
Global $hParams, $hDownloadThreads, $hEnableProxy, $hProxySever, $hProxyPort
Global $hAskBeforeUpdateChrome
Global $hRunInBackground, $hExApp, $hExAppAutoExit, $hExApp2
Global $ChromeFileVersion, $ChromeLastChange, $LatestChromeVer, $LatestChromeUrls
Global $DefaultChromeDir, $DefaultChromeVer, $DefaultUserDataDir
Global $TrayTipProgress = 0
Global $iThreadPid, $DownloadThreads
Global $aDlInfo[6]
;~ 0 - Latest Chrome Version / Bytes read so far
;~ 1 - Latest Chrome url / The size of the download (this may not always be present)
;~ 2 - Set to True if the download is complete, False if the download is still ongoing.
;~ 3 - True if the download was successful. If this is False then the next data member will be non-zero.
;~ 4 - The error value for the download. The value itself is arbitrary. Testing that the value is non-zero is sufficient for determining if an error occurred.
;~ 5 - The extended value for the download. The value is arbitrary and is primarily only useful to the AutoIt developers.
Global $hEvent, $ClientKey, $Progid
Global $aREG[6][3] = [[$HKEY_CURRENT_USER, 'Software\Clients\StartMenuInternet'], _
[$HKEY_LOCAL_MACHINE, 'Software\Clients\StartMenuInternet'], _
[$HKEY_CLASSES_ROOT, 'ftp'], _
[$HKEY_CLASSES_ROOT, 'http'], _
[$HKEY_CLASSES_ROOT, 'https'], _
[$HKEY_CLASSES_ROOT, '']] ; ChromeHTML.XXX
Global $aFileAsso[6] = [".htm", ".html", ".shtml", ".webp", ".xht", ".xhtml"]
Global $aUrlAsso[13] = ["ftp", "http", "https", "irc", "mailto", "mms", "news", "nntp", "sms", "smsto", "tel", "urn", "webcal"]
FileChangeDir(@ScriptDir)
$AppName = StringRegExpReplace(@ScriptName, "\.[^.]*$", "")
$inifile = @ScriptDir & "\" & $AppName & ".ini"
Global $EnvID = RegRead('HKLM64\SOFTWARE\Microsoft\Cryptography', 'MachineGuid')
$EnvID &= RegRead("HKLM64\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "InstallDate")
$EnvID &= DriveGetSerial(@HomeDrive & "\")
$EnvID = StringTrimLeft(_WinAPI_HashString($EnvID, 0, 16), 2)
If Not FileExists($inifile) Then
$FirstRun = 1
IniWrite($inifile, "Settings", "AppVersion", $AppVersion)
IniWrite($inifile, "Settings", "ChromePath", ".\Chrome\chrome.exe")
IniWrite($inifile, "Settings", "UserDataDir", ".\User Data")
IniWrite($inifile, "Settings", "CacheDir", "")
IniWrite($inifile, "Settings", "CacheSize", 0)
IniWrite($inifile, "Settings", "Channel", "Stable")
IniWrite($inifile, "Settings", "x86", 0)
IniWrite($inifile, "Settings", "LastCheckUpdate", "2014/05/01 00:00:00")
IniWrite($inifile, "Settings", "UpdateInterval", 24)
IniWrite($inifile, "Settings", "AskBeforeUpdateChrome", 1) ; 1 - 更新前询问
IniWrite($inifile, "Settings", "EnableUpdateProxy", 0)
IniWrite($inifile, "Settings", "UpdateProxy", "")
IniWrite($inifile, "Settings", "UpdatePort", "")
IniWrite($inifile, "Settings", "DownloadThreads", 3)
IniWrite($inifile, "Settings", "Params", "")
IniWrite($inifile, "Settings", "RunInBackground", 1)
IniWrite($inifile, "Settings", "AutoUpdateApp", 1) ; 0 - 什么也不做,1 - 通知我,2 - 自动更新(无提示)
IniWrite($inifile, "Settings", "LastCheckAppUpdate", "2014/01/01 00:00:00")
IniWrite($inifile, "Settings", "CheckDefaultBrowser", 1)
IniWrite($inifile, "Settings", "ExApp", "")
IniWrite($inifile, "Settings", "ExAppAutoExit", 1)
IniWrite($inifile, "Settings", "ExApp2", "")
EndIf
;~ 从配置文件读取参数
$ChromePath = IniRead($inifile, "Settings", "ChromePath", ".\Chrome\chrome.exe")
$UserDataDir = IniRead($inifile, "Settings", "UserDataDir", ".\User Data")
$CacheDir = IniRead($inifile, "Settings", "CacheDir", "")
$CacheSize = IniRead($inifile, "Settings", "CacheSize", 0) * 1
$Channel = IniRead($inifile, "Settings", "Channel", "Stable")
$x86 = IniRead($inifile, "Settings", "x86", 0) * 1
$LastCheckUpdate = IniRead($inifile, "Settings", "LastCheckUpdate", "2014/01/01 00:00:00")
$UpdateInterval = IniRead($inifile, "Settings", "UpdateInterval", 24)
$AskBeforeUpdateChrome = IniRead($inifile, "Settings", "AskBeforeUpdateChrome", 1) * 1
$EnableProxy = IniRead($inifile, "Settings", "EnableUpdateProxy", 0) * 1
$ProxySever = IniRead($inifile, "Settings", "UpdateProxy", "")
$ProxyPort = IniRead($inifile, "Settings", "UpdatePort", "")
$DownloadThreads = IniRead($inifile, "Settings", "DownloadThreads", 3) * 1
$Params = IniRead($inifile, "Settings", "Params", "")
$RunInBackground = IniRead($inifile, "Settings", "RunInBackground", 1) * 1
$AutoUpdateApp = IniRead($inifile, "Settings", "AutoUpdateApp", 1) * 1
$LastCheckAppUpdate = IniRead($inifile, "Settings", "LastCheckAppUpdate", "2014/01/01 00:00:00")
$CheckDefaultBrowser = IniRead($inifile, "Settings", "CheckDefaultBrowser", 1) * 1
$ExApp = IniRead($inifile, "Settings", "ExApp", "")
$ExAppAutoExit = IniRead($inifile, "Settings", "ExAppAutoExit", 1) * 1
$ExApp2 = IniRead($inifile, "Settings", "ExApp2", "")
#Region ========= 兼容旧版 MyChrome =========
If $AppVersion <> IniRead($inifile, "Settings", "AppVersion", "") Then
$FirstRun = 1
IniWrite($inifile, "Settings", "AppVersion", $AppVersion)
If FileExists($AppName & "设置.vbs") Then FileDelete($AppName & "设置.vbs")
If StringRight($Channel, 4) = "-x86" Then
$Channel = StringTrimRight($Channel, 4)
$x86 = 1
IniWrite($inifile, "Settings", "Channel", $Channel)
IniWrite($inifile, "Settings", "x86", $x86)
ElseIf StringRight($Channel, 4) = "-x64" Then
$Channel = StringTrimRight($Channel, 4)
IniWrite($inifile, "Settings", "Channel", $Channel)
EndIf
EndIf
#EndRegion ========= 兼容旧版 MyChrome =========
Opt("ExpandEnvStrings", 1)
EnvSet("APP", @ScriptDir)
;~ 第一个启动参数为“-set”,或第一次运行,Chrome.exe、用户数据文件夹不存在,则显示设置窗口
If ($cmdline[0] = 1 And $cmdline[1] = "-set") Or $FirstRun Or Not FileExists($ChromePath) Or Not FileExists($UserDataDir) Then
CreateSettingsShortcut(@ScriptDir & "\" & $AppName & ".vbs")
Settings()
EndIf
$ChromePath = FullPath($ChromePath)
SplitPath($ChromePath, $ChromeDir, $ChromeExe)
$UserDataDir = FullPath($UserDataDir)
If IsAdmin() And $cmdline[0] = 1 And $cmdline[1] = "-SetDefaultGlobal" Then
CheckDefaultBrowser($ChromePath)
Exit
EndIf
CheckEnv()
;~ write file First Run to prevent chrome from generate shortcut on desktop
If Not FileExists($ChromeDir & "\First Run") Then FileWrite($ChromeDir & "\First Run", "")
; quote external cmdline.
For $i = 1 To $cmdline[0]
If StringInStr($cmdline[$i], " ") Then
$Params &= ' "' & $cmdline[$i] & '"'
Else
$Params &= ' ' & $cmdline[$i]
EndIf
Next
;~ $PortableParam = '--no-default-browser-check'
$PortableParam = '--user-data-dir="' & $UserDataDir & '"'
If $CacheDir <> "" Then
$CacheDir = FullPath($CacheDir)
$PortableParam &= ' --disk-cache-dir="' & $CacheDir & '"'
EndIf
If $CacheSize <> 0 Then
$PortableParam &= ' --disk-cache-size=' & $CacheSize
EndIf
Local $ChromeIsRunning = AppIsRunning($ChromePath)
If Not $ChromeIsRunning And FileExists($ChromeDir & "\~updated") Then
ApplyUpdate()
EndIf
; start chrome
$AppPID = Run('"' & $ChromePath & '" ' & $PortableParam & ' ' & $Params, $ChromeDir)
FileChangeDir(@ScriptDir)
CreateSettingsShortcut(@ScriptDir & "\" & $AppName & ".vbs")
If $ChromeIsRunning Then
; check if another instance of mychrome is running
$list = ProcessList(StringRegExpReplace(@AutoItExe, ".*\\", ""))
For $i = 1 To $list[0][0]
If $list[$i][1] <> @AutoItPID And GetProcPath($list[$i][1]) = @AutoItExe Then
Exit ;exit if another instance of mychrome/chrome is running
EndIf
Next
EndIf
; Start external apps
If $ExApp <> "" Then
$aExApp = StringSplit($ExApp, "||", 1)
ReDim $aExAppPID[$aExApp[0] + 1]
$aExAppPID[0] = $aExApp[0]
For $i = 1 To $aExApp[0]
$match = StringRegExp($aExApp[$i], '^"(.*?)" *(.*)', 1)
If @error Then
$file = $aExApp[$i]
$args = ""
Else
$file = $match[0]
$args = $match[1]
EndIf
$file = FullPath($file)
$aExAppPID[$i] = ProcessExists(StringRegExpReplace($file, '.*\\', ''))
If Not $aExAppPID[$i] And FileExists($file) Then
$aExAppPID[$i] = ShellExecute($file, $args, StringRegExpReplace($file, '\\[^\\]+$', ''))
EndIf
Next
EndIf
If $CheckDefaultBrowser Then
CheckDefaultBrowser($ChromePath)
EndIf
If FileExists($TaskBarDir) Then
CheckPinnedPrograms($ChromePath)
EndIf
Global $FirstUpdateCheck = 1
If Not $RunInBackground Then
UpdateCheck()
Exit
EndIf
; ========================= app ended if not run in background ================================
If $CheckDefaultBrowser Then ; register REG for notification
$hEvent = _WinAPI_CreateEvent()
For $i = 0 To UBound($aREG) - 1
If $aREG[$i][1] Then
$aREG[$i][2] = _WinAPI_RegOpenKey($aREG[$i][0], $aREG[$i][1], $KEY_NOTIFY)
If $aREG[$i][2] Then
_WinAPI_RegNotifyChangeKeyValue($aREG[$i][2], $REG_NOTIFY_CHANGE_LAST_SET, 1, 1, $hEvent)
EndIf
EndIf
Next
EndIf
OnAutoItExitRegister("OnExit")
AdlibRegister("UpdateCheck", 10000)
Local $hWnd
WinWait("[REGEXPCLASS:(?i)Chrome]", "", 15)
$list = WinList("[REGEXPCLASS:(?i)Chrome]")
For $i = 1 To $list[0][0]
If $AppPID = WinGetProcess($list[$i][1]) Then
$hWnd = $list[$i][1]
ExitLoop
EndIf
Next
ReduceMemory()
; wait for chrome exit
While 1
Sleep(500)
If $hWnd Then
If Not WinExists($hWnd) Then ExitLoop
Else ; ProcessExists() is resource consuming than WinExists()
If Not ProcessExists($AppPID) Then ExitLoop
EndIf
If $TaskBarLastChange Then
CheckPinnedPrograms($ChromePath)
EndIf
If $hEvent And Not _WinAPI_WaitForSingleObject($hEvent, 0) Then
; MsgBox(0, "", "Reg changed!")
Sleep(50)
CheckDefaultBrowser($ChromePath)
For $i = 0 To UBound($aREG) - 1
If $aREG[$i][2] Then
_WinAPI_RegNotifyChangeKeyValue($aREG[$i][2], $REG_NOTIFY_CHANGE_LAST_SET, 1, 1, $hEvent)
EndIf
Next
EndIf
WEnd
If $ExAppAutoExit And $ExApp <> "" Then
For $i = 1 To $aExAppPID[0]
If Not $aExAppPID[$i] Then ContinueLoop
If @OSArch = "X86" Then
$aChildren = _ProcessGetChildren($aExAppPID[$i])
Else
$aChildren = _ChildProcess($aExAppPID[$i])
EndIf
ProcessClose($aExAppPID[$i])
If IsArray($aChildren) Then
For $j = 1 To $aChildren[0][0]
ProcessClose($aChildren[$j][0])
Next
EndIf
Next
EndIf
; Start external apps
If $ExApp2 <> "" Then
$aExApp2 = StringSplit($ExApp2, "||", 1)
For $i = 1 To $aExApp2[0]
$match = StringRegExp($aExApp2[$i], '^"(.*?)" *(.*)', 1)
If @error Then
$file = $aExApp2[$i]
$args = ""
Else
$file = $match[0]
$args = $match[1]
EndIf
$file = FullPath($file)
If Not ProcessExists(StringRegExpReplace($file, '.*\\', '')) Then
If FileExists($file) Then
ShellExecute($file, $args, StringRegExpReplace($file, '\\[^\\]+$', ''))
EndIf
EndIf
Next
EndIf
If 0 Then ; ========= Lines below will never be executed =========
; put functions here to prevent these functions from being stripped
GetLatestVersion("")
DownloadChrome("", "")
EndIf ; ============= Lines above will never be executed =========
Exit
; ==================== above is auto-exec codes ========================
Func GetChromeLastChange($path)
; chrome "LastChange" changed from digits as 312162 to commit hashes
; chrome release : 800fe26985bd6fd8626dd80f710fae8ac527bd6b-refs/branch-heads/2171@{#470}
; chromium : 32cbfaa6478f66b93b6d383a58f606960e02441e-refs/heads/master@{#312162}
Local $ret
Local $match = StringRegExp(FileGetVersion($path, "LastChange"), '(\d{6,})\D*$', 1)
If Not @error Then $ret = $match[0]
Return $ret
EndFunc ;==>GetChromeLastChange
Func CheckEnv()
Local $oldstr, $var, $EnvString, $variations_seed, $variations_seed_signature
$EnvString = FileRead($UserDataDir & "\EnvId")
If $EnvString = $EnvID Then Return
FileDelete($UserDataDir & "\EnvId")
If FileExists($UserDataDir & "\Local State") Then
$EnvString = FileWrite($UserDataDir & "\EnvId", $EnvID)
FileInstall(".\Local State.MyChrome", $UserDataDir & "\Local State.MyChrome", 1)
$var = FileRead($UserDataDir & "\Local State.MyChrome")
FileDelete($UserDataDir & "\Local State.MyChrome")
Local $match = StringRegExp($var, '(?im)^ *("variations_seed": *"\S+")', 1)
If Not @error Then $variations_seed = $match[0]
Local $match = StringRegExp($var, '(?im)^ *("variations_seed_signature": *"\S+")', 1)
If Not @error Then $variations_seed_signature = $match[0]
$oldstr = FileRead($UserDataDir & "\Local State")
$var = StringRegExpReplace($oldstr, '(?i)"variations_seed": *"\S+"', $variations_seed)
$var = StringRegExpReplace($var, '(?i)"variations_seed_signature": *"\S+"', $variations_seed_signature)
If $var <> $oldstr Then
Local $file = FileOpen($UserDataDir & "\Local State", 2 + 256)
FileWrite($file, $var)
FileClose($file)
EndIf
EndIf
EndFunc ;==>CheckEnv
Func OnExit()
If $hEvent Then
_WinAPI_CloseHandle($hEvent)
For $i = 0 To UBound($aREG) - 1
_WinAPI_RegCloseKey($aREG[$i][2])
Next
EndIf
EndFunc ;==>OnExit
Func UpdateCheck()
Local $updated, $var
; Check mychrome update
If $AutoUpdateApp <> 0 And _DateDiff("h", $LastCheckAppUpdate, _NowCalc()) >= 24 Then
CheckAppUpdate()
EndIf
; check chrome update
If $UpdateInterval >= 0 Then
If $UpdateInterval = 0 Then
If $FirstUpdateCheck Then
$updated = UpdateChrome($ChromePath, $Channel)
EndIf
Else
Local $var = _DateDiff("h", $LastCheckUpdate, _NowCalc())
If $var >= $UpdateInterval Then
$updated = UpdateChrome($ChromePath, $Channel)
EndIf
EndIf
If $updated And Not AppIsRunning($ChromePath) Then ; restart app/chrome
If @Compiled Then
Run('"' & @AutoItExe & '" --restore-last-session')
Else
Run('"' & @AutoItExe & '" "' & @ScriptFullPath & '" --restore-last-session')
EndIf
Exit
EndIf
EndIf
If $RunInBackground Then
If $FirstUpdateCheck Then
AdlibRegister("UpdateCheck", 300000)
EndIf
ReduceMemory()
EndIf
$FirstUpdateCheck = 0
EndFunc ;==>UpdateCheck
;~ for win7/vista or newer
Func CheckPinnedPrograms($path)
If Not FileExists($TaskBarDir) Then
Return
EndIf
Local $ftime = FileGetTime($TaskBarDir, 0, 1)
If $ftime = $TaskBarLastChange Then
Return
EndIf
$TaskBarLastChange = $ftime
Local $search = FileFindFirstFile($TaskBarDir & "\*.lnk")
If $search = -1 Then Return
Local $file, $ShellObj, $objShortcut
$ShellObj = ObjCreate("WScript.Shell")
If Not @error Then
While 1
$file = $TaskBarDir & "\" & FileFindNextFile($search)
If @error Then ExitLoop
$objShortcut = $ShellObj.CreateShortCut($file)
If $path = $objShortcut.TargetPath Then
$objShortcut.TargetPath = @ScriptFullPath
$objShortcut.IconLocation = $path & ",0"
$objShortcut.Save
$TaskBarLastChange = FileGetTime($TaskBarDir, 0, 1)
ExitLoop
EndIf
WEnd
$objShortcut = ""
EndIf
FileClose($search)
EndFunc ;==>CheckPinnedPrograms
;~ 设置批处理
Func CreateSettingsShortcut($fname)
Local $var = FileRead($fname)
If $var <> 'CreateObject("shell.application").ShellExecute "' & @ScriptName & '", "-set"' Then
FileDelete($fname)
FileWrite($fname, 'CreateObject("shell.application").ShellExecute "' & @ScriptName & '", "-set"')
EndIf
EndFunc ;==>CreateSettingsShortcut
Func CheckDefaultBrowser($BrowserPath)
Local $InternetClient, $key, $i, $j, $var, $RegWriteError = 0
; 在 StartMenuInternet 中注册后,Win XP 中点击开始菜单的“Internet”项才会启动chrome便携版
; Win vista / 7 “默认程序” 设置中才会出现Chrome浏览器
If Not $ClientKey Then
Local $aRoot[3] = ["HKCU", "HKLM64", "HKLM"]
For $i = 0 To 2 ; search chrome in internetclient
$j = 1
While 1
$InternetClient = RegEnumKey($aRoot[$i] & "\Software\Clients\StartMenuInternet", $j)
If @error <> 0 Then ExitLoop
$key = $aRoot[$i] & '\SOFTWARE\Clients\StartMenuInternet\' & $InternetClient
$var = RegRead($key & '\DefaultIcon', '')
If StringInStr($var, $BrowserPath) Then
$ClientKey = $key
$Progid = RegRead($ClientKey & '\Capabilities\URLAssociations', 'http')
ExitLoop 2
EndIf
$j += 1
WEnd
Next
EndIf
If $ClientKey Then
$var = RegRead($ClientKey & '\shell\open\command', '')
If Not StringInStr($var, @ScriptFullPath) Then
$RegWriteError += Not RegWrite($ClientKey & '\shell\open\command', _
'', 'REG_SZ', '"' & @ScriptFullPath & '"')
EndIf
EndIf
If Not $Progid Then
$Progid = FindChromeProgid($BrowserPath)
EndIf
If $Progid Then
$var = RegRead('HKCR\' & $Progid & '\shell\open\command', '')
If Not StringInStr($var, @ScriptFullPath) Then
RegWrite('HKCR\' & $Progid & '\shell\open\ddeexec', '', 'REG_SZ', '')
RegDelete('HKCR\' & $Progid & '\shell\open\command', 'DelegateExecute') ; 解决 Win8“未注册类”错误
$RegWriteError += Not RegWrite('HKCR\' & $Progid & '\shell\open\command', _
'', 'REG_SZ', '"' & @ScriptFullPath & '" -- "%1"')
EndIf
If Not $aREG[5][1] Then
$aREG[5][1] = $Progid ; for reg notification
$aREG[5][2] = _WinAPI_RegOpenKey($aREG[5][0], $aREG[5][1], $KEY_NOTIFY)
EndIf
EndIf
Local $aAsso[3] = ['ftp', 'http', 'https']
For $i = 0 To 2
$var = RegRead('HKCR\' & $aAsso[$i] & '\DefaultIcon', '')
If StringInStr($var, $BrowserPath) Then
$var = RegRead('HKCR\' & $aAsso[$i] & '\shell\open\command', '')
If Not StringInStr($var, @ScriptFullPath) Then
RegWrite('HKCR\' & $aAsso[$i] & '\shell\open\ddeexec', '', 'REG_SZ', '')
RegDelete('HKCR\' & $aAsso[$i] & '\shell\open\command', 'DelegateExecute')
$RegWriteError += Not RegWrite('HKCR\' & $aAsso[$i] & '\shell\open\command', _
'', 'REG_SZ', '"' & @ScriptFullPath & '" -- "%1"')
EndIf
EndIf
Next
If IsAdmin() Then
RegRead('HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe', '')
If Not @error Then
RegWrite('HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe', '', 'REG_SZ', @ScriptFullPath)
RegWrite('HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe', 'Path', 'REG_SZ', @ScriptDir)
EndIf
EndIf
If $RegWriteError And Not _IsUACAdmin() And @extended Then
If @Compiled Then
ShellExecute(@ScriptName, "-SetDefaultGlobal", @ScriptDir, "runas")
Else
ShellExecute(@AutoItExe, '"' & @ScriptFullPath & '" -SetDefaultGlobal', @ScriptDir, "runas")
EndIf
EndIf
EndFunc ;==>CheckDefaultBrowser
Func FindChromeProgid($BrowserPath)
Local $i, $id, $var
RegRead('HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts', '')
If @error <> 1 Then
For $i = 0 To UBound($aFileAsso) - 1
$id = RegRead('HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\' & $aFileAsso[$i] & '\UserChoice', 'Progid')
If $id Then
$var = RegRead('HKCR\' & $id & '\DefaultIcon', '')
If StringInStr($var, $BrowserPath) Then
Return $id
EndIf
EndIf
Next
EndIf
For $i = 0 To UBound($aFileAsso) - 1
$id = RegRead('HKCR\' & $aFileAsso[$i], '')
$var = RegRead('HKCR\' & $id & '\DefaultIcon', '')
If StringInStr($var, $BrowserPath) Then
Return $id
EndIf
Next
RegRead('HKCU\Software\Microsoft\Windows\Shell\Associations\UrlAssociations', '')
If @error <> 1 Then
For $i = 0 To UBound($aUrlAsso) - 1
$id = RegRead('HKCU\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\' & $aUrlAsso[$i] & '\UserChoice', 'Progid')
If $id Then
$var = RegRead('HKCR\' & $id & '\DefaultIcon', '')
If StringInStr($var, $BrowserPath) Then
Return $id
EndIf
EndIf
Next
EndIf
Return ""
EndFunc ;==>FindChromeProgid
;~ check MyChrome update
Func CheckAppUpdate()
Local $var, $match, $LatestAppVer, $msg, $update, $url
Local $slatest = "latest", $surl = "url", $supdate = "update"
If @AutoItX64 Then
$slatest &= "_x64"
$surl &= "_x64"
$supdate &= "_x64"
EndIf
$LastCheckAppUpdate = _NowCalc()
IniWrite($inifile, "Settings", "LastCheckAppUpdate", $LastCheckAppUpdate)
$var = BinaryToString(InetRead("http://code.taobao.org/p/mychrome/src/trunk/Update.txt?orig", 27), 4)
$var = StringStripWS($var, 3) ; 去掉开头、结尾的空字符
$match = StringRegExp($var, '(?im)^' & $slatest & '=(\S+)', 1)
If Not @error Then
$LatestAppVer = $match[0]
Else
If $EnableProxy Then
HttpSetProxy(2, $ProxySever & ":" & $ProxyPort)
Else
HttpSetProxy(0)
EndIf
$var = BinaryToString(InetRead("http://my-chrome.googlecode.com/svn/Update.txt", 27), 4) ; UTF-8
$var = StringStripWS($var, 3) ; 去掉开头、结尾的空字符
$match = StringRegExp($var, '(?im)^' & $slatest & '=(\S+)', 1)
If Not @error Then $LatestAppVer = $match[0]
EndIf
If Not $LatestAppVer Then Return
If Not VersionCompare($LatestAppVer, $AppVersion) Then Return
$match = StringRegExp($var, '(?im)^' & $surl & '=(\S+)', 1)
If @error Then Return
$url = $match[0]
$match = StringRegExp($var, '(?im)' & $supdate & '=(.+)', 1)
If @error Then Return
$update = StringReplace($match[0], "\n", @CRLF)
If $AutoUpdateApp = 1 Then
$msg = MsgBox(68, 'MyChrome', 'MyChrome 可以更新,是否立即下载?' & @CRLF & @CRLF & _
'您的版本:' & $AppVersion & ',' & '最新版本:' & $LatestAppVer & @CRLF & @CRLF & $update)
If $msg <> 6 Then Return
EndIf
Local $temp = @ScriptDir & "\MyChrome_temp"
$file = $temp & "\MyChrome.zip"
If Not FileExists($temp) Then DirCreate($temp)
TraySetState(1)
TraySetClick(0) ; Tray menu will never be shown through a mouseclick
TraySetToolTip("MyChrome")
TraySetOnEvent($TRAY_EVENT_PRIMARYDOWN, "")
TrayTip("MyChrome更新", "正在下载 MyChrome ...", 5, 1)
InetGet($url, $file, 19)
FileSetAttrib($file, "+A")
FileInstall("7z.exe", $temp & "\7z.exe", 1) ; http://www.7-zip.org/download.html
FileInstall("7z.dll", $temp & "\7z.dll", 1)
RunWait($temp & '\7z.exe x "' & $file & '" -y', $temp, @SW_HIDE)
If FileExists($temp & "\MyChrome.exe") Then
FileMove(@ScriptFullPath, @ScriptDir & "\" & @ScriptName & ".bak", 9)
FileMove($temp & "\MyChrome.exe", @ScriptFullPath, 9)
FileDelete($temp & "\7z.exe")
FileDelete($temp & "\7z.dll")
FileDelete($file)
FileMove($temp & "\*.*", @ScriptDir & "\", 9)
MsgBox(64, "MyChrome", "MyChrome 已更新至 " & $LatestAppVer & " !" & @CRLF & "原 App 已备份为 " & @ScriptName & ".bak。")
Else
$msg = MsgBox(20, "MyChrome", "MyChrome 自动更新失败!" & @CRLF & @CRLF & "是否去软件发布页手动下载更新?")
If $msg = 6 Then ; Yes
OpenWebsite()
EndIf
EndIf
DirRemove($temp, 1)
TraySetState(2)
EndFunc ;==>CheckAppUpdate
;~ 显示设置窗口
Func Settings()
SplitPath($ChromePath, $ChromeDir, $ChromeExe)
Switch $UpdateInterval
Case -1
$UpdateInterval = "从不"
Case 168
$UpdateInterval = "每周"
Case 24
$UpdateInterval = "每天"
Case 1
$UpdateInterval = "每小时"
Case Else
$UpdateInterval = "每次启动时"
EndSwitch
$ChromeFileVersion = FileGetVersion($ChromeDir & "\chrome.dll", "FileVersion")
$ChromeLastChange = GetChromeLastChange($ChromeDir & "\chrome.dll")
Opt("ExpandEnvStrings", 0)
$hSettings = GUICreate("MyChrome - 打造自己的 Google Chrome 便携版", 500, 520)
GUISetOnEvent($GUI_EVENT_CLOSE, "ExitApp")
GUICtrlCreateLabel("MyChrome " & $AppVersion & " by 甲壳虫 <[email protected]>", 5, 10, 490, -1, $SS_CENTER)
GUICtrlSetCursor(-1, 0)
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetTip(-1, "点击打开 MyChrome 主页")
GUICtrlSetOnEvent(-1, "OpenWebsite")
;常规
GUICtrlCreateTab(5, 35, 492, 410)
GUICtrlCreateTabItem("常规")
GUICtrlCreateGroup("Google Chrome 程序文件", 10, 80, 480, 180)
GUICtrlCreateLabel("chrome 路径:", 20, 110, 120, 20)
$hChromePath = GUICtrlCreateEdit($ChromePath, 130, 106, 290, 20, $ES_AUTOHSCROLL)
GUICtrlSetTip(-1, "浏览器主程序路径")
$hGetChromePath = GUICtrlCreateButton("浏览", 430, 106, 50, 20)
GUICtrlSetTip(-1, "选择便携版浏览器" & @CRLF & "主程序(chrome.exe)")
GUICtrlSetOnEvent(-1, "GetChromePath")
GUICtrlCreateLabel("获取 Google Chrome 浏览器程序文件:", 20, 144, 250, 20)
$hChromeSource = GUICtrlCreateCombo("", 280, 140, 130, 20, $CBS_DROPDOWNLIST)
GUICtrlSetData(-1, "---- 请选择 ----|从系统中提取|从网络下载|从离线安装文件提取", "---- 请选择 ----")
GUICtrlSetTip(-1, "获取便携版浏览器程序文件")
GUICtrlSetOnEvent(-1, "GetChrome")
GUICtrlCreateLabel("分支:", 20, 174, 80, 20)
$hChannel = GUICtrlCreateCombo("", 100, 170, 150, 20, $CBS_DROPDOWNLIST)
GUICtrlSetData(-1, "Stable|Beta|Dev|Canary|Chromium-Continuous|Chromium-Snapshots", $Channel)
GUICtrlSetTip(-1, "Stable - 稳定版(正式版)" & @CRLF & "Beta - 测试版" & @CRLF & "Dev - 开发版" & @CRLF & _
"Canary - 金丝雀版" & @CRLF & "Chromium - 更新快但不稳定")
GUICtrlSetOnEvent(-1, "CheckChrome")
GUICtrlCreateLabel("检查浏览器更新:", 20, 204, 110, 20)
$hUpdateInterval = GUICtrlCreateCombo("", 130, 200, 120, 20, $CBS_DROPDOWNLIST)
GUICtrlSetData(-1, "每次启动时|每小时|每天|每周|从不", $UpdateInterval)
$hx86 = GUICtrlCreateCheckbox(" 32-bit (x86)", 280, 174, -1, 20)
GUICtrlSetTip(-1, "勾选此项下载 32-bit 浏览器。")
GUICtrlSetOnEvent(-1, "Change_Browser_Bit")
If $x86 Then GUICtrlSetState(-1, $GUI_CHECKED)
$hCheckUpdate = GUICtrlCreateButton("立即更新", 400, 170, 80, 25)
GUICtrlSetTip(-1, "检查浏览器更新" & @CRLF & "下载最新版至 chrome 程序文件夹")
GUICtrlSetOnEvent(-1, "Start_End_ChromeUpdate")
GUICtrlCreateLabel("最新版本:", 280, 204, 70, 20)
$hLatestChromeVer = GUICtrlCreateLabel("", 350, 204, 140, 20)
GUICtrlSetTip(-1, "复制下载地址到剪贴板")
GUICtrlSetCursor(-1, 0)
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetOnEvent(-1, "ShowUrl")
GUICtrlCreateLabel("当前版本:", 280, 235, 70, 20)
$hCurrentVer = GUICtrlCreateLabel("", 350, 235, 140, 20)
GUICtrlSetData(-1, $ChromeFileVersion & " " & $ChromeLastChange)
GUICtrlCreateLabel("发现新版本时", 20, 235, 110, 20)
$hAskBeforeUpdateChrome = GUICtrlCreateCombo("", 130, 230, 120, 20, $CBS_DROPDOWNLIST)
Local $sAskBeforeUpdateChrome
If $AskBeforeUpdateChrome = 1 Then
$sAskBeforeUpdateChrome = "通知我"
Else
$sAskBeforeUpdateChrome = "自动更新"
EndIf
GUICtrlSetData(-1, "通知我|自动更新", $sAskBeforeUpdateChrome)
GUICtrlCreateGroup("Google Chrome 用户数据文件", 10, 280, 480, 80)
GUICtrlCreateLabel("用户数据文件夹:", 20, 310, 110, 20)
$hUserDataDir = GUICtrlCreateEdit($UserDataDir, 130, 305, 290, 20, $ES_AUTOHSCROLL)
GUICtrlSetTip(-1, "浏览器用户数据文件夹")
GUICtrlCreateButton("浏览", 430, 305, 50, 20)
GUICtrlSetTip(-1, "选择用户数据文件夹")
GUICtrlSetOnEvent(-1, "GetUserDataDir")
$hCopyData = GUICtrlCreateCheckbox("从系统中提取用户数据文件", 20, 330, -1, 20)
GUICtrlCreateLabel("MyChrome 发布新版时", 20, 380, 130, 20)
$hAutoUpdateApp = GUICtrlCreateCombo("", 150, 375, 120, 20, $CBS_DROPDOWNLIST)
Local $sAutoUpdateApp
If $AutoUpdateApp = 0 Then
$sAutoUpdateApp = "什么也不做"
ElseIf $AutoUpdateApp = 1 Then
$sAutoUpdateApp = "通知我"
Else
$sAutoUpdateApp = "自动更新"
EndIf
GUICtrlSetData(-1, "通知我|自动更新|什么也不做", $sAutoUpdateApp)
$hRunInBackground = GUICtrlCreateCheckbox("MyChrome 在后台运行直至浏览器退出", 20, 410, 400, 20)
GUICtrlSetOnEvent(-1, "RunInBackground")
If $RunInBackground Then
GUICtrlSetState($hRunInBackground, $GUI_CHECKED)
EndIf
; 高级
GUICtrlCreateTabItem("高级")
GUICtrlCreateGroup("Google Chrome 缓存", 10, 80, 480, 90)
GUICtrlCreateLabel("缓存位置:", 20, 110, 100, 20)
$hCacheDir = GUICtrlCreateEdit($CacheDir, 120, 106, 300, 20, $ES_AUTOHSCROLL)
GUICtrlSetTip(-1, "浏览器缓存位置" & @CRLF & "空白 = 默认路径" & @CRLF & "支持%TEMP%等环境变量")
$hSelectCacheDir = GUICtrlCreateButton("浏览", 430, 106, 50, 20)
GUICtrlSetTip(-1, "选择缓存位置")
GUICtrlSetOnEvent(-1, "SelectCacheDir")
GUICtrlCreateLabel("缓存大小:", 20, 140, 100, 20)
$hCacheSize = GUICtrlCreateEdit(Round($CacheSize / 1024 / 1024), 120, 136, 80, 20, $ES_AUTOHSCROLL)
GUICtrlSetTip(-1, "缓存大小" & @CRLF & "0 = 无限制")
GUICtrlCreateLabel(" MB", 200, 140, 40, 20)
; 启动参数
GUICtrlCreateLabel("Google Chrome 启动参数", 20, 190)
Local $lparams = StringReplace($Params, " --", Chr(13) & Chr(10) & "--") ; 空格换成换行符,便于显示
$hParams = GUICtrlCreateEdit($lparams, 20, 210, 460, 60, BitOR($ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL))
GUICtrlSetTip(-1, "Chrome 启动参数,每行写一个参数。" & @CRLF & "支持%TEMP%等环境变量," & @CRLF & "特别地,%APP%代表 MyChrome 所在目录。")
; 线程数
GUICtrlCreateGroup("Chrome 更新网络设置", 10, 290, 480, 90)
GUICtrlCreateLabel("下载线程数(1-10):", 20, 320, 130, 20)
$hDownloadThreads = GUICtrlCreateInput($DownloadThreads, 150, 316, 60, 20, $ES_NUMBER)
GUICtrlSetTip(-1, "增减线程数可调节下载速度" & @CRLF & "仅适用于下载 chrome 更新")
GUICtrlSetOnEvent(-1, "ThreadsLimit")
GUICtrlCreateUpdown($hDownloadThreads)
GUICtrlSetLimit(-1, 10, 1)
; 代理
$hEnableProxy = GUICtrlCreateCheckbox("代理服务器:", 20, 346, 130, 20)
GUICtrlSetTip(-1, "如果检查、下载更新出错," & @CRLF & "可尝试通过代理服务器下载。")
GUICtrlSetOnEvent(-1, "SetProxy")
$hProxySever = GUICtrlCreateCombo($ProxySever, 150, 346, 110, 20)
GUICtrlSetData(-1, "google.com|127.0.0.1")
GUICtrlSetOnEvent(-1, "SetProxyPort")
GUICtrlSetTip(-1, "代理服务器IP地址" & @CRLF & "仅适用于下载 chrome 更新")
GUICtrlCreateLabel("端口:", 290, 350, 80, 20)
$hProxyPort = GUICtrlCreateCombo($ProxyPort, 370, 346, 80, 20)
GUICtrlSetData(-1, "80|8087")
GUICtrlSetTip(-1, "代理服务器端口" & @CRLF & "仅适用于下载 chrome 更新")
If $EnableProxy Then
GUICtrlSetState($hEnableProxy, $GUI_CHECKED)
Else
GUICtrlSetState($hProxySever, $GUI_DISABLE)
GUICtrlSetState($hProxyPort, $GUI_DISABLE)
EndIf
;~ SetProxy()
; 外部程序
GUICtrlCreateTabItem("外部程序")
GUICtrlCreateLabel("浏览器启动时运行", 20, 80, -1, 20)
$hExAppAutoExit = GUICtrlCreateCheckbox(" #浏览器退出后自动关闭", 240, 75, -1, 20)
If $ExAppAutoExit = 1 Then
GUICtrlSetState($hExAppAutoExit, $GUI_CHECKED)
EndIf
$hExApp = GUICtrlCreateEdit("", 20, 100, 410, 50, BitOR($ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL))
If $ExApp <> "" Then
GUICtrlSetData(-1, StringReplace($ExApp, "||", @CRLF) & @CRLF)
EndIf
GUICtrlSetTip(-1, "浏览器启动时运行的外部程序,支持批处理、vbs文件等" & @CRLF & "如需启动参数,可添加在程序路径之后")
GUICtrlCreateButton("添加", 440, 100, 40, 20)
GUICtrlSetTip(-1, "选择外部程序")
GUICtrlSetOnEvent(-1, "AddExApp")
GUICtrlCreateLabel("#浏览器退出后运行", 20, 180, -1, 20)
$hExApp2 = GUICtrlCreateEdit("", 20, 200, 410, 50, BitOR($ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL))
If $ExApp2 <> "" Then
GUICtrlSetData(-1, StringReplace($ExApp2, "||", @CRLF) & @CRLF)
EndIf
GUICtrlSetTip(-1, "浏览器退出后运行的外部程序,支持批处理、vbs文件等" & @CRLF & "如需启动参数,可添加在程序路径之后")
GUICtrlCreateButton("添加", 440, 200, 40, 20)
GUICtrlSetTip(-1, "选择外部程序")
GUICtrlSetOnEvent(-1, "AddExApp2")
GUICtrlCreateTabItem("")
$hSettingsOK = GUICtrlCreateButton("确定", 260, 470, 70, 20)
GUICtrlSetTip(-1, "应用设置并启动浏览器")
GUICtrlSetOnEvent(-1, "SettingsOK")
GUICtrlSetState(-1, $GUI_FOCUS)
GUICtrlCreateButton("取消", 340, 470, 70, 20)
GUICtrlSetTip(-1, "取消")
GUICtrlSetOnEvent(-1, "ExitApp")
$hSettingsApply = GUICtrlCreateButton("应用", 420, 470, 70, 20)
GUICtrlSetTip(-1, "应用")
GUICtrlSetOnEvent(-1, "SettingsApply")
$hStausbar = _GUICtrlStatusBar_Create($hSettings, -1, '双击软件目录下的 "' & $AppName & '.vbs" 文件可调出此窗口')
Opt("ExpandEnvStrings", 1)
Local $ChromeExists = CheckChromeInSystem($Channel) ; 检查系统中是否有 Channel 对应的 Chrome 程序文件
FileChangeDir(@ScriptDir)
If $FirstRun And Not FileExists($ChromePath) Then
If $ChromeExists Then
_GUICtrlComboBox_SelectString($hChromeSource, "从系统中提取")
Else
_GUICtrlComboBox_SelectString($hChromeSource, "从网络下载")
EndIf
EndIf
; 复制用户数据文件选项
If Not FileExists(FullPath($UserDataDir) & "\Local State") And FileExists($DefaultUserDataDir & "\Local State") Then ; 文件夹中无数据文件且系统中有,则勾选复制
GUICtrlSetState($hCopyData, $GUI_CHECKED)
EndIf
GUISetState(@SW_SHOW)
AdlibRegister("ShowLatestChromeVer", 10) ; Channel 对应的 Chrome 程序文件及对应的最新版本号
While Not $SettingsOK
Sleep(100)
WEnd
GUIDelete($hSettings)
$hSettings = "" ; free the handle
EndFunc ;==>Settings
Func Change_Browser_Bit()
If GUICtrlRead($hx86) = $GUI_CHECKED Then
$x86 = 1
Else
$x86 = 0
EndIf
If $IsUpdating Then Return
If ProcessExists($iThreadPid) Then
_KillThread($iThreadPid)
EndIf
AdlibRegister("ShowLatestChromeVer", 10)
EndFunc ;==>Change_Browser_Bit
Func AddExApp()
Local $path
$path = FileOpenDialog("选择浏览器启动时需运行的外部程序", @ScriptDir, _
"所有文件 (*.*)", 1 + 2, "", $hSettings)
If $path = "" Then Return
$path = RelativePath($path)
$ExApp = GUICtrlRead($hExApp) & '"' & $path & '"' & @CRLF
GUICtrlSetData($hExApp, $ExApp)
EndFunc ;==>AddExApp
Func AddExApp2()
Local $path
$path = FileOpenDialog("选择浏览器启动时需运行的外部程序", @ScriptDir, _
"所有文件 (*.*)", 1 + 2, "", $hSettings)
If $path = "" Then Return
$path = RelativePath($path)
$ExApp2 = GUICtrlRead($hExApp2) & '"' & $path & '"' & @CRLF
GUICtrlSetData($hExApp2, $ExApp2)
EndFunc ;==>AddExApp2
Func RunInBackground()
If GUICtrlRead($hRunInBackground) = $GUI_CHECKED Then
Return
EndIf
$msg = MsgBox(36 + 256, "MyChrome", '允许 MyChrome 在后台运行可以带来更好的用户体验。若取消此选项,请注意以下几点:' & @CRLF & @CRLF & _
'1. 将浏览器锁定到任务栏或设为默认浏览器后,需再运行一次 MyChrome 才能生效;' & @CRLF & _
'2. MyChrome 设置界面中带“#”符号的功能/选项将不会执行,包括浏览器退出后关闭外部程序、运行外部程序等。' & @CRLF & @CRLF & _
'确定要取消此选项吗?', 0, $hSettings)
If $msg <> 6 Then
GUICtrlSetState($hRunInBackground, $GUI_CHECKED)
EndIf
EndFunc ;==>RunInBackground
;~ chrome.exe路径
Func GetChromePath()
Local $sChromePath
$sChromePath = FileOpenDialog("选择 Chrome 浏览器主程序(chrome.exe)", @ScriptDir, _
"可执行文件(*.exe)|所有文件(*.*)", 2, "chrome.exe", $hSettings)
If $sChromePath = "" Then Return
If FileExists($sChromePath) Then
_GUICtrlComboBox_SelectString($hChromeSource, "---- 请选择 ----")
EndIf
Local $chromedll = StringRegExpReplace($sChromePath, "[^\\]+$", "chrome.dll")
$ChromeFileVersion = FileGetVersion($chromedll, "FileVersion")
$ChromeLastChange = GetChromeLastChange($chromedll)
GUICtrlSetData($hCurrentVer, $ChromeFileVersion & " " & $ChromeLastChange)
$ChromePath = RelativePath($sChromePath) ; 绝对路径转成相对路径(如果可以)
GUICtrlSetData($hChromePath, $ChromePath)
EndFunc ;==>GetChromePath
; 指定用户数据文件夹
Func GetUserDataDir()
Local $sUserDataDir = FileSelectFolder("选择一个文件夹用来保存用户数据文件", "", 1 + 4, _
@ScriptDir & "\User Data", $hSettings)
If $sUserDataDir <> "" Then
$UserDataDir = RelativePath($sUserDataDir) ; 绝对路径转成相对路径(如果可以)
GUICtrlSetData($hUserDataDir, $UserDataDir)
EndIf
EndFunc ;==>GetUserDataDir
;~ 从系统中复制chrome程序文件
Func CopyChromeFromSystem()
$ChromePath = GUICtrlRead($hChromePath)
SplitPath($ChromePath, $ChromeDir, $ChromeExe)
$ChromeIsRunning = ChromeIsRunning($ChromePath, "请关闭 Google Chrome 浏览器,以便更新浏览器程序文件。")
If $ChromeIsRunning Then Return
_GUICtrlStatusBar_SetText($hStausbar, "从系统中提取 Google Chrome 程序文件...")
SplashTextOn("MyChrome", "正在提取 Chrome 程序文件...", 300, 100)
FileCopy($DefaultChromeDir & "\*.*", $ChromeDir & "\", 1 + 8)
DirCopy($DefaultChromeDir & "\" & $DefaultChromeVer, $ChromeDir, 1)
SplashOff()
; 如果设定的chrome程序文件路径不以chrome.exe结尾,则认为使用者将其改名,将chrome.exe重命名为设定的文件名
If StringRegExpReplace($ChromePath, ".*\\", "") <> "chrome.exe" Then
FileMove($ChromeDir & "\chrome.exe", $ChromePath, 1)
EndIf
Local $chromedll = StringRegExpReplace($ChromePath, "[^\\]+$", "chrome.dll")
$ChromeFileVersion = FileGetVersion($chromedll, "FileVersion")
$ChromeLastChange = GetChromeLastChange($chromedll)
GUICtrlSetData($hCurrentVer, $ChromeFileVersion & " " & $ChromeLastChange)
_GUICtrlStatusBar_SetText($hStausbar, '提取 Google Chrome 程序文件成功!')
EndFunc ;==>CopyChromeFromSystem