forked from cnjackchen/my-firefox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyFirefox.au3
1379 lines (1242 loc) · 53 KB
/
MyFirefox.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=firefox.ico
#AutoIt3Wrapper_Compile_Both=y
#AutoIt3Wrapper_UseX64=y
#AutoIt3Wrapper_Res_Comment=Firefox Portable
#AutoIt3Wrapper_Res_Description=Firefox Portable
#AutoIt3Wrapper_Res_Fileversion=2.6.7.0
#AutoIt3Wrapper_Res_LegalCopyright=甲壳虫<[email protected]>
#AutoIt3Wrapper_AU3Check_Parameters=-q
#AutoIt3Wrapper_Run_Au3Stripper=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------
AutoIt Version: 3.3.14.0
Author: 甲壳虫
Link: http://code.taobao.org/p/MyFirefox/wiki/index/
Script Function:
自定义Firefox程序和配置文件夹的路径,用来制作Firefox便携版,便携版可设为默认浏览器。
#ce
#include <StaticConstants.au3>
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <GuiStatusBar.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ComboConstants.au3>
#include <Date.au3>
#include <TrayConstants.au3>
#include <WinAPIReg.au3>
#include <Security.au3>
#include <WinAPIMisc.au3>
#include "AppUserModelId.au3"
Opt("GUIOnEventMode", 1)
Opt("WinTitleMatchMode", 4)
Global Const $AppVersion = "2.6.7" ; 版本
Global $FirstRun, $FirefoxExe, $FirefoxDir
Global $TaskBarDir = @AppDataDir & "\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar"
Global $AppPID, $TaskBarLastChange
Global $CheckAppUpdate, $AppUpdateLastCheck, $RunInBackground, $FirefoxPath, $ProfileDir
Global $CustomPluginsDir, $CustomCacheDir, $CacheSize, $CacheSizeSmart, $CheckDefaultBrowser, $Params
Global $ExApp, $ExAppAutoExit, $ExApp2
Global $DefaultProfDir, $hSettings, $hFirefoxPath, $hProfileDir
Global $hCopyProfile, $hCustomPluginsDir, $hGetPluginsDir
Global $hCustomCacheDir, $hGetCacheDir, $hCacheSize, $hCacheSizeSmart
Global $hParams, $hStatus, $SettingsOK
Global $hCheckAppUpdate, $hRunInBackground, $hChannel, $hDownloadFirefox32, $hDownloadFirefox64, $FirefoxURL
Global $hExApp, $hExAppAutoExit, $hExApp2
Global $aExApp, $aExApp2, $aExAppPID[2]
Global $hEvent, $ClientKey, $FileAsso, $URLAsso
Global $aREG[7][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, ''], _ ; FirefoxHTML
[$HKEY_CLASSES_ROOT, '']] ; FirefoxURL
; Global Const $KEY_WOW64_32KEY = 0x0200 ; Access a 32-bit key from either a 32-bit or 64-bit application
; Global Const $KEY_WOW64_64KEY = 0x0100 ; Access a 64-bit key from either a 32-bit or 64-bit application
If Not @AutoItX64 Then ; 32-bit Autoit
$HKLM_Software_32 = "HKLM\SOFTWARE"
$HKLM_Software_64 = "HKLM64\SOFTWARE"
Else ; 64-bit Autoit
$HKLM_Software_32 = "HKLM\SOFTWARE\Wow6432Node"
$HKLM_Software_64 = "HKLM64\SOFTWARE"
EndIf
FileChangeDir(@ScriptDir)
$AppName = StringRegExpReplace(@ScriptName, "\.[^.]*$", "")
$inifile = @ScriptDir & "\" & $AppName & ".ini"
If Not FileExists($inifile) Then
$FirstRun = 1
IniWrite($inifile, "Settings", "AppVersion", $AppVersion)
IniWrite($inifile, "Settings", "CheckAppUpdate", 1)
IniWrite($inifile, "Settings", "AppUpdateLastCheck", "2015/01/01 00:00:00")
IniWrite($inifile, "Settings", "RunInBackground", 1)
IniWrite($inifile, "Settings", "FirefoxPath", ".\Firefox\firefox.exe")
IniWrite($inifile, "Settings", "ProfileDir", ".\profiles")
IniWrite($inifile, "Settings", "CustomPluginsDir", "")
IniWrite($inifile, "Settings", "CustomCacheDir", "")
IniWrite($inifile, "Settings", "CacheSize", "")
IniWrite($inifile, "Settings", "CacheSizeSmart", 1)
IniWrite($inifile, "Settings", "CheckDefaultBrowser", 1)
IniWrite($inifile, "Settings", "Params", "")
IniWrite($inifile, "Settings", "ExApp", "")
IniWrite($inifile, "Settings", "ExAppAutoExit", 1)
IniWrite($inifile, "Settings", "ExApp2", "")
EndIf
$CheckAppUpdate = IniRead($inifile, "Settings", "CheckAppUpdate", 1) * 1
$AppUpdateLastCheck = IniRead($inifile, "Settings", "AppUpdateLastCheck", "")
If Not $AppUpdateLastCheck Then
$AppUpdateLastCheck = "2015/01/01 00:00:00"
EndIf
$RunInBackground = IniRead($inifile, "Settings", "RunInBackground", 1) * 1
$FirefoxPath = IniRead($inifile, "Settings", "FirefoxPath", ".\Firefox\firefox.exe")
$ProfileDir = IniRead($inifile, "Settings", "ProfileDir", ".\profiles")
$CustomPluginsDir = IniRead($inifile, "Settings", "CustomPluginsDir", "")
$CustomCacheDir = IniRead($inifile, "Settings", "CustomCacheDir", "")
$CacheSize = IniRead($inifile, "Settings", "CacheSize", "")
$CacheSizeSmart = IniRead($inifile, "Settings", "CacheSizeSmart", 1) * 1
$CheckDefaultBrowser = IniRead($inifile, "Settings", "CheckDefaultBrowser", 1) * 1
$Params = IniRead($inifile, "Settings", "Params", "")
$ExApp = IniRead($inifile, "Settings", "ExApp", "")
$ExAppAutoExit = IniRead($inifile, "Settings", "ExAppAutoExit", 1) * 1
$ExApp2 = IniRead($inifile, "Settings", "ExApp2", "")
If $AppVersion <> IniRead($inifile, "Settings", "AppVersion", "") Then
$FirstRun = 1
IniWrite($inifile, "Settings", "AppVersion", $AppVersion)
EndIf
Opt("ExpandEnvStrings", 1)
EnvSet("APP", @ScriptDir)
;~ 第一个启动参数为“-set”,或第一次运行,Firefox、配置文件夹、插件目录不存在,则显示设置窗口
If ($cmdline[0] = 1 And $cmdline[1] = "-set") Or $FirstRun Or Not FileExists($FirefoxPath) Or Not FileExists($ProfileDir) Then
CreateSettingsShortcut(@ScriptDir & "\" & $AppName & ".vbs")
Settings()
EndIf
;~ 转换成绝对路径
$FirefoxPath = FullPath($FirefoxPath)
SplitPath($FirefoxPath, $FirefoxDir, $FirefoxExe)
$ProfileDir = FullPath($ProfileDir)
If IsAdmin() And $cmdline[0] = 1 And $cmdline[1] = "-SetDefaultGlobal" Then
CheckDefaultBrowser($FirefoxPath)
Exit
EndIf
;~ 插件目录
If $CustomPluginsDir <> "" Then
$CustomPluginsDir = FullPath($CustomPluginsDir)
EnvSet("MOZ_PLUGIN_PATH", $CustomPluginsDir) ; 设置环境变量
EndIf
; 给带空格的外部参数加上引号。
For $i = 1 To $cmdline[0]
If StringInStr($cmdline[$i], " ") Then
$Params &= ' "' & $cmdline[$i] & '"'
Else
$Params &= ' ' & $cmdline[$i]
EndIf
Next
FileDelete($FirefoxDir & "\defaults\pref\myfirefox.js")
FileDelete($FirefoxDir & "\myfirefox.cfg")
Local $FirefoxIsRunning = ProfileInUse($ProfileDir)
If Not $FirefoxIsRunning Then
Local $config = CheckPrefs()
If $config Then
FileWrite($FirefoxDir & "\defaults\pref\myfirefox.js", 'pref("general.config.obscure_value", 0);' & @CRLF & _
'pref("general.config.filename", "myfirefox.cfg");' & @CRLF)
FileWrite($FirefoxDir & "\myfirefox.cfg", $config)
EndIf
EndIf
;~ Start Firefox
$AppPID = Run($FirefoxPath & ' -profile "' & $ProfileDir & '" ' & $Params, $FirefoxDir)
FileChangeDir(@ScriptDir)
CreateSettingsShortcut(@ScriptDir & "\" & $AppName & ".vbs")
If $FirefoxIsRunning Then
$exe = StringRegExpReplace(@AutoItExe, ".*\\", "")
$list = ProcessList($exe)
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 myfirefox 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($FirefoxPath)
EndIf
WinWait("[REGEXPCLASS:(?i)MozillaWindowClass;REGEXPTITLE:(?i)Firefox]", "", 15)
$hWnd_browser = GethWndbyPID($AppPID, "MozillaWindowClass")
Global $AppUserModelId
If FileExists($TaskBarDir) Then ; win 7+
$AppUserModelId = _WindowAppId($hWnd_browser)
CheckPinnedPrograms($FirefoxPath)
EndIf
;~ Check myfirefox update
If $CheckAppUpdate And _DateDiff("h", $AppUpdateLastCheck, _NowCalc()) >= 48 Then
CheckAppUpdate()
EndIf
If Not $RunInBackground Then
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")
ReduceMemory()
AdlibRegister("ReduceMemory", 300000)
; wait for firefox exit
$AppIsRunning = 0
While 1
Sleep(500)
If $hWnd_browser Then
$AppIsRunning = WinExists($hWnd_browser)
Else ; ProcessExists() is resource consuming than WinExists()
$AppIsRunning = ProcessExists($AppPID)
EndIf
If Not $AppIsRunning Then
; check other chrome instance
$AppPID = AppIsRunning($FirefoxPath)
If Not $AppPID Then
ExitLoop
EndIf
$AppIsRunning = 1
$hWnd_browser = GethWndbyPID($AppPID, "MozillaWindowClass")
EndIf
If $TaskBarLastChange Then
CheckPinnedPrograms($FirefoxPath)
EndIf
If $hEvent And Not _WinAPI_WaitForSingleObject($hEvent, 0) Then
; MsgBox(0, "", "Reg changed!")
Sleep(500)
CheckDefaultBrowser($FirefoxPath)
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
$cmd = ''
For $i = 1 To $aExAppPID[0]
If Not $aExAppPID[$i] Then ContinueLoop
$cmd &= ' /PID ' & $aExAppPID[$i]
Next
If $cmd Then
$cmd = 'taskkill' & $cmd & ' /T /F'
Run(@ComSpec & ' /c ' & $cmd, '', @SW_HIDE)
EndIf
EndIf
; Start external apps
If $ExApp2 <> "" Then
$aExApp2 = StringSplit($ExApp2, "||")
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
Exit
;~ =================================== 以上为自动执行部分 ===============================
Func AppIsRunning($AppPath)
Local $exe = StringRegExpReplace($AppPath, '.*\\', '')
Local $list = ProcessList($exe)
For $i = 1 To $list[0][0]
If StringInStr(GetProcPath($list[$i][1]), $AppPath) Then
Return $list[$i][1]
EndIf
Next
Return 0
EndFunc ;==>AppIsRunning
Func GethWndbyPID($pid, $class = "")
$list = WinList("[REGEXPCLASS:(?i)" & $class & "]")
For $i = 1 To $list[0][0]
If Not BitAND(WinGetState($list[$i][1]), 2) Then ContinueLoop ; ignore hidden windows
If $pid = WinGetProcess($list[$i][1]) Then
;ConsoleWrite("--> " & $list[$i][1] & "-" & $list[$i][0] & @CRLF)
Return $list[$i][1]
EndIf
Next
EndFunc ;==>GethWndbyPID
Func OnExit()
If $hEvent Then
_WinAPI_CloseHandle($hEvent)
For $i = 0 To UBound($aREG) - 1
_WinAPI_RegCloseKey($aREG[$i][2])
Next
EndIf
EndFunc ;==>OnExit
;~ 查检 MyFirefox更新
Func CheckAppUpdate()
Local $var, $match, $LatestAppVer, $msg, $update, $url
Local $slatest = "latest", $surl = "url", $supdate = "update"
If @AutoItX64 Then
$surl &= "_x64"
EndIf
$AppUpdateLastCheck = _NowCalc()
IniWrite($inifile, "Settings", "AppUpdateLastCheck", $AppUpdateLastCheck)
HttpSetProxy(0) ; Use IE defaults for proxy
$var = BinaryToString(InetRead("http://code.taobao.org/svn/MyFirefox/Update.txt", 27), 4)
$var = StringStripWS($var, 3) ; 去掉开头、结尾的空字符
$match = StringRegExp($var, '(?im)^' & $slatest & '=(\S+)', 1)
If @error Then Return
$LatestAppVer = $match[0]
If VersionCompare($LatestAppVer, $AppVersion) <= 0 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)
$msg = MsgBox(68, 'MyFirefox', "MyFirefox " & $LatestAppVer & " 已发布,更新内容:" & _
@CRLF & @CRLF & $update & @CRLF & @CRLF & "是否自动更新?")
If $msg <> 6 Then Return
Local $temp = @ScriptDir & "\MyFirefox_temp"
$file = $temp & "\MyFirefox.zip"
If Not FileExists($temp) Then DirCreate($temp)
Opt("TrayAutoPause", 0)
Opt("TrayMenuMode", 3) ; Default tray menu items (Script Paused/Exit) will not be shown.
TraySetState(1)
TraySetClick(8)
TraySetToolTip("MyFirefox")
Local $hCancelAppUpdate = TrayCreateItem("取消更新...")
TrayTip("", "开始下载 MyFirefox", 10, 1)
Local $hDownload = InetGet($url, $file, 19, 1)
Local $DownloadSuccessful, $DownloadCancelled, $UpdateSuccessful, $error
Do
Switch TrayGetMsg()
Case $TRAY_EVENT_PRIMARYDOWN
TrayTip("", "正在下载 MyFirefox" & @CRLF & "已下载 " & Round(InetGetInfo($hDownload, 0) / 1024) & " KB", 5, 1)
Case $hCancelAppUpdate
$msg = MsgBox(4 + 32 + 256, "MyFirefox", "正在下载 MyFirefox,确定要取消吗?")
If $msg = 6 Then
$DownloadCancelled = 1
ExitLoop
EndIf
EndSwitch
Until InetGetInfo($hDownload, 2)
$DownloadSuccessful = InetGetInfo($hDownload, 3)
InetClose($hDownload)
If Not $DownloadCancelled Then
If $DownloadSuccessful Then
TrayTip("", "正在应用 MyFirefox 更新", 10, 1)
FileSetAttrib($file, "+A")
_Zip_UnzipAll($file, $temp)
If FileExists($temp & "\MyFirefox.exe") Then
FileMove(@ScriptFullPath, @ScriptDir & "\" & @ScriptName & ".bak", 9)
FileMove($temp & "\MyFirefox.exe", @ScriptFullPath, 9)
FileDelete($file)
DirCopy($temp, @ScriptDir, 1)
$UpdateSuccessful = 1
Else
$error = "解压更新文件失败。"
EndIf
Else
$error = "下载更新文件失败。"
EndIf
If $UpdateSuccessful Then
MsgBox(64, "MyFirefox", "MyFirefox 已更新至 " & $LatestAppVer & " !" & @CRLF & "原 MyFirefox 已备份为 " & @ScriptName & ".bak。")
Else
$msg = MsgBox(20, "MyFirefox", "MyFirefox 自动更新失败:" & @CRLF & $error & @CRLF & @CRLF & "是否去软件发布页手动下载 MyFirefox?")
If $msg = 6 Then ; Yes
ShellExecute("http://code.taobao.org/p/MyFirefox/src/release/")
EndIf
EndIf
EndIf
DirRemove($temp, 1)
TrayItemDelete($hCancelAppUpdate)
TraySetState(2)
EndFunc ;==>CheckAppUpdate
Func DeleteCfgFiles()
FileDelete($FirefoxDir & "\defaults\pref\myfirefox.js")
FileDelete($FirefoxDir & "\myfirefox.cfg")
EndFunc ;==>DeleteCfgFiles
Func CheckPrefs()
Local $var, $cfg
Local $prefs = FileRead($ProfileDir & "\prefs.js")
If Not StringRegExp($prefs, '(?i)(?m)^\Quser_pref("browser.shell.checkDefaultBrowser",\E *\Qfalse);\E') Then
$cfg &= 'pref("browser.shell.checkDefaultBrowser", false);' & @CRLF
EndIf
$CustomCacheDir = FullPath($CustomCacheDir)
If $CustomCacheDir = "" Or $CustomCacheDir = $ProfileDir Then ; profile\ is the default chache dir
If StringInStr($prefs, 'user_pref("browser.cache.disk.parent_directory",') Then
$cfg &= 'clearPref("browser.cache.disk.parent_directory");' & @CRLF
EndIf
Else
$var = StringReplace($CustomCacheDir, '\', '\\')
If Not StringRegExp($prefs, '(?i)(?m)^\Quser_pref("browser.cache.disk.parent_directory",\E *\Q"' & $var & '");\E') Then
$cfg &= 'pref("browser.cache.disk.parent_directory", "' & $var & '");' & @CRLF
EndIf
EndIf
If $CacheSize = "" Or $CacheSize = 250 Then ; 250 is the default
If StringInStr($prefs, 'user_pref("browser.cache.disk.capacity",') Then
$cfg &= 'clearPref("browser.cache.disk.capacity");' & @CRLF
EndIf
Else
$var = $CacheSize * 1024
If Not StringRegExp($prefs, '(?i)(?m)^\Quser_pref("browser.cache.disk.capacity",\E *\Q' & $var & ');\E') Then
$cfg &= 'pref("browser.cache.disk.capacity", ' & $var & ');' & @CRLF
EndIf
EndIf
If $CacheSizeSmart = 1 Then
If StringInStr($prefs, 'user_pref("browser.cache.disk.smart_size.enabled",') Then
$cfg &= 'clearPref("browser.cache.disk.smart_size.enabled");' & @CRLF
EndIf
Else
If Not StringRegExp($prefs, '(?i)(?m)^\Quser_pref("browser.cache.disk.smart_size.enabled",\E *\Qfalse);\E') Then
$cfg &= 'pref("browser.cache.disk.smart_size.enabled", false);' & @CRLF
EndIf
EndIf
If $cfg Then
$cfg = '//' & @CRLF & $cfg
EndIf
$prefs = ''
Return $cfg
EndFunc ;==>CheckPrefs
; for win7+
; Group different app icons on Taskbar need the same AppUserModelIDs
; http://msdn.microsoft.com/en-us/library/dd378459%28VS.85%29.aspx
Func CheckPinnedPrograms($browser_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, $shortcut_appid
$ShellObj = ObjCreate("WScript.Shell")
If Not @error Then
While 1
$file = $TaskBarDir & "\" & FileFindNextFile($search)
If @error Then ExitLoop
$objShortcut = $ShellObj.CreateShortCut($file)
$path = $objShortcut.TargetPath
If $path == $browser_path Or $path == @ScriptFullPath Then
If $path == $browser_path Then
$objShortcut.TargetPath = @ScriptFullPath
$objShortcut.Save
$TaskBarLastChange = FileGetTime($TaskBarDir, 0, 1)
EndIf
$shortcut_appid = _ShortcutAppId($file)
If Not $AppUserModelId Then
;Sleep(3000)
; usually fails to get firefox's window appid while succeeds on chrome,
; what's wrong?
$AppUserModelId = _WindowAppId($hWnd_browser)
If Not $AppUserModelId Then
$AppUserModelId = AppIdFromRegistry()
If Not $AppUserModelId Then
; helper.exe writes AppUserModelIDs to SOFTWARE\Mozilla\Firefox\TaskBarIDs
Local $pid = Run($FirefoxDir & "\uninstall\helper.exe /UpdateShortcutAppUserModelIds")
ProcessWaitClose($pid, 5)
$AppUserModelId = AppIdFromRegistry()
EndIf
If Not $AppUserModelId Then
If $shortcut_appid Then
$AppUserModelId = $shortcut_appid
Else ; if no window appid found,set an id for the window
$AppUserModelId = "MyFirefox." & StringTrimLeft(_WinAPI_HashString(@ScriptFullPath, 0, 16), 2)
EndIf
EndIf
_WindowAppId($hWnd_browser, $AppUserModelId)
EndIf
EndIf
If $shortcut_appid <> $AppUserModelId Then
_ShortcutAppId($file, $AppUserModelId)
$TaskBarLastChange = FileGetTime($TaskBarDir, 0, 1)
EndIf
ExitLoop
EndIf
WEnd
$objShortcut = ""
$ShellObj = ""
EndIf
FileClose($search)
EndFunc ;==>CheckPinnedPrograms
Func AppIdFromRegistry()
Local $appid
If @OSArch = "X86" Then
Local $aRoot[2] = ["HKCU\SOFTWARE", $HKLM_Software_32]
Else
Local $aRoot[3] = ["HKCU\SOFTWARE", $HKLM_Software_32, $HKLM_Software_64]
EndIf
For $i = 0 To UBound($aRoot)-1
$appid = RegRead($aRoot[$i] & "\Mozilla\Firefox\TaskBarIDs", $FirefoxDir)
If $appid Then ExitLoop
Next
Return $appid
EndFunc ;==>AppIdFromRegistry
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
If Not $ClientKey Then
If @OSArch = "X86" Then
Local $aRoot[2] = ["HKCU\SOFTWARE", $HKLM_Software_32]
Else
Local $aRoot[3] = ["HKCU\SOFTWARE", $HKLM_Software_32, $HKLM_Software_64]
EndIf
For $i = 0 To UBound($aRoot)-1 ; search FIREFOX.EXE in internetclient
$j = 1
While 1
$InternetClient = RegEnumKey($aRoot[$i] & "\Clients\StartMenuInternet", $j)
If @error <> 0 Then ExitLoop
$key = $aRoot[$i] & '\Clients\StartMenuInternet\' & $InternetClient
$var = RegRead($key & '\DefaultIcon', '')
If StringInStr($var, $BrowserPath) Then
$ClientKey = $key
$FileAsso = RegRead($ClientKey & '\Capabilities\FileAssociations', '.html')
$URLAsso = 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 & '"')
RegWrite($ClientKey & '\shell\properties\command', '', 'REG_SZ', '"' & @ScriptFullPath & '" -preferences')
RegWrite($ClientKey & '\shell\safemode\command', '', 'REG_SZ', '"' & @ScriptFullPath & '" -safe-mode')
EndIf
EndIf
If Not $FileAsso Then
If StringInStr(RegRead('HKCR\FirefoxHTML\DefaultIcon', ''), $BrowserPath) Then
$FileAsso = "FirefoxHTML"
EndIf
EndIf
If Not $URLAsso Then
If StringInStr(RegRead('HKCR\FirefoxURL\DefaultIcon', ''), $BrowserPath) Then
$URLAsso = "FirefoxURL"
EndIf
EndIf
Local $aAsso[2] = [$FileAsso, $URLAsso]
For $i = 0 To 1
If Not $aAsso[$i] Then ContinueLoop
$var = RegRead('HKCR\' & $aAsso[$i] & '\shell\open\command', '')
If Not StringInStr($var, @ScriptFullPath) Then
$RegWriteError += Not RegWrite('HKCR\' & $aAsso[$i] & '\shell\open\command', _
'', 'REG_SZ', '"' & @ScriptFullPath & '" -url "%1"')
RegDelete('HKCR\' & $aAsso[$i] & '\shell\open\command', 'DelegateExecute')
RegWrite('HKCR\' & $aAsso[$i] & '\shell\open\ddeexec', '', 'REG_SZ', '')
EndIf
If Not $aREG[5 + $i][1] Then
$aREG[5 + $i][1] = $aAsso[$i] ; for reg notification
$aREG[5 + $i][2] = _WinAPI_RegOpenKey($aREG[5 + $i][0], $aREG[5 + $i][1], $KEY_NOTIFY)
EndIf
Next
Local $aUrlAsso[3] = ['ftp', 'http', 'https']
For $i = 0 To 2
$var = RegRead('HKCR\' & $aUrlAsso[$i] & '\DefaultIcon', '')
If StringInStr($var, $BrowserPath) Then
$var = RegRead('HKCR\' & $aUrlAsso[$i] & '\shell\open\command', '')
If Not StringInStr($var, @ScriptFullPath) Then
$RegWriteError += Not RegWrite('HKCR\' & $aUrlAsso[$i] & '\shell\open\command', _
'', 'REG_SZ', '"' & @ScriptFullPath & '" -url "%1"')
RegDelete('HKCR\' & $aUrlAsso[$i] & '\shell\open\command', 'DelegateExecute')
RegWrite('HKCR\' & $aUrlAsso[$i] & '\shell\open\ddeexec', '', 'REG_SZ', '')
EndIf
EndIf
Next
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 Settings()
$DefaultProfDir = IniRead(@AppDataDir & '\Mozilla\Firefox\profiles.ini', 'Profile0', 'Path', '') ; 读取Firefox原版配置文件夹路径
If $DefaultProfDir <> "" Then
$DefaultProfDir = StringReplace($DefaultProfDir, "/", "\")
$DefaultProfDir = @AppDataDir & '\Mozilla\Firefox\' & $DefaultProfDir
EndIf
Opt("ExpandEnvStrings", 0)
$hSettings = GUICreate("MyFirefox - 打造自己的 Firefox 便携版", 500, 490)
GUISetOnEvent($GUI_EVENT_CLOSE, "ExitApp")
GUICtrlCreateLabel("MyFirefox " & $AppVersion & " by 甲壳虫 <[email protected]>", 5, 10, 490, -1, $SS_CENTER)
GUICtrlSetCursor(-1, 0)
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetTip(-1, "点击打开 MyFirefox 主页")
GUICtrlSetOnEvent(-1, "Website")
;常规
GUICtrlCreateTab(5, 40, 490, 390)
GUICtrlCreateTabItem("常规")
GUICtrlCreateLabel("Firefox 路径", 20, 90, 100, 20)
$hFirefoxPath = GUICtrlCreateEdit($FirefoxPath, 120, 85, 310, 20, $ES_AUTOHSCROLL)
GUICtrlSetTip(-1, "浏览器主程序路径")
GUICtrlSetOnEvent(-1, "OnFirefoxPathChange")
GUICtrlCreateButton("浏览", 440, 85, 40, 20)
GUICtrlSetTip(-1, "选择便携版浏览器" & @CRLF & "主程序(firefox.exe)")
GUICtrlSetOnEvent(-1, "GetFirefoxPath")
GUICtrlCreateLabel("更新通道", 20, 130, 100, 20)
$hChannel = GUICtrlCreateCombo("", 120, 125, 150, 20, $CBS_DROPDOWNLIST)
GUICtrlSetData($hChannel, "esr -企业版|release -正式版|beta -测试版|aurora -曙光版|nightly -每夜更新版|default -不更新", "release -正式版")
GUICtrlSetOnEvent(-1, "ChangeChannel")
;~ $hDownloadFirefox = GUICtrlCreateLabel("去下载 " & GUICtrlRead($hChannel), 300, 130, 180, 20)
;~ GUICtrlSetCursor(-1, 0)
;~ GUICtrlSetColor(-1, 0x0000FF)
;~ GUICtrlSetTip(-1, "去下载 Firefox")
;~ GUICtrlSetOnEvent(-1, "DownloadFirefox")
GUICtrlCreateLabel("下载 Firefox:", 20, 170, 100, 20)
$hDownloadFirefox32 = GUICtrlCreateLabel("release 32位", 120, 170, 140, 20)
GUICtrlSetCursor(-1, 0)
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetOnEvent(-1, "DownloadFirefox")
$hDownloadFirefox64 = GUICtrlCreateLabel("release 64位", 260, 170, 140, 20)
GUICtrlSetCursor(-1, 0)
GUICtrlSetColor(-1, 0x0000FF)
If @OSArch <> "X86" Then
GUICtrlSetOnEvent(-1, "DownloadFirefox")
EndIf
GUICtrlCreateLabel("配置文件夹", 20, 210, 100, 20)
$hProfileDir = GUICtrlCreateEdit($ProfileDir, 120, 205, 310, 20, $ES_AUTOHSCROLL)
GUICtrlSetTip(-1, "浏览器配置文件夹")
GUICtrlCreateButton("浏览", 440, 205, 40, 20)
GUICtrlSetTip(-1, "指定浏览器配置文件夹")
GUICtrlSetOnEvent(-1, "GetProfileDir")
$hCopyProfile = GUICtrlCreateCheckbox(" 从系统中提取 Firefox 配置文件", 30, 240, -1, 20)
$hCheckAppUpdate = GUICtrlCreateCheckbox(" MyFirefox 发布新版时通知我", 20, 360)
If $CheckAppUpdate Then
GUICtrlSetState(-1, $GUI_CHECKED)
EndIf
$hRunInBackground = GUICtrlCreateCheckbox(" MyFirefox 在后台运行直至浏览器退出", 20, 390)
GUICtrlSetOnEvent(-1, "RunInBackground")
If $RunInBackground Then
GUICtrlSetState($hRunInBackground, $GUI_CHECKED)
EndIf
; 高级
GUICtrlCreateTabItem("高级")
GUICtrlCreateLabel("插件目录", 20, 90, 100, 20)
$hCustomPluginsDir = GUICtrlCreateEdit($CustomPluginsDir, 120, 85, 310, 20, $ES_AUTOHSCROLL)
GUICtrlSetTip(-1, "浏览器插件目录" & @CRLF & "空白=默认位置")
$hGetPluginsDir = GUICtrlCreateButton("浏览", 440, 85, 40, 20)
GUICtrlSetTip(-1, "指定浏览器插件目录")
GUICtrlSetOnEvent(-1, "GetPluginsDir")
GUICtrlCreateLabel("缓存位置", 20, 130, 100, 20)
$hCustomCacheDir = GUICtrlCreateEdit($CustomCacheDir, 120, 125, 310, 20, $ES_AUTOHSCROLL)
GUICtrlSetTip(-1, "浏览器缓存位置" & @CRLF & "空白=默认位置")
$hGetCacheDir = GUICtrlCreateButton("浏览", 440, 125, 40, 20)
GUICtrlSetTip(-1, "指定浏览器缓存位置")
GUICtrlSetOnEvent(-1, "GetCacheDir")
GUICtrlCreateLabel("缓存大小", 20, 170, 100, 20)
$hCacheSize = GUICtrlCreateEdit($CacheSize, 120, 165, 60, 20, BitOR($ES_NUMBER, $ES_AUTOHSCROLL))
GUICtrlSetTip(-1, "缓存大小" & @CRLF & "空白=默认大小")
GUICtrlCreateLabel("MB", 195, 170, 35, 20)
$hCacheSizeSmart = GUICtrlCreateCheckbox(" 自动控制缓存大小", 250, 165, -1, 20)
If $CacheSizeSmart Then GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlCreateLabel("命令行参数", 20, 325, -1, 20)
$hParams = GUICtrlCreateEdit("", 20, 345, 460, 70, BitOR($ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL))
If $Params <> "" Then
GUICtrlSetData(-1, StringReplace($Params, " -", @CRLF & "-"))
EndIf
GUICtrlSetTip(-1, "Firefox 命令行参数,每行写一个参数。" & @CRLF & "支持%TEMP%等环境变量," & @CRLF & "特别地,%APP%代表 MyFirefox 所在目录")
; 外部程序
GUICtrlCreateTabItem("外部程序")
GUICtrlCreateLabel("浏览器启动时运行", 20, 90, -1, 20)
$hExAppAutoExit = GUICtrlCreateCheckbox(" #浏览器退出后自动关闭", 240, 85, -1, 20)
If $ExAppAutoExit = 1 Then
GUICtrlSetState($hExAppAutoExit, $GUI_CHECKED)
EndIf
$hExApp = GUICtrlCreateEdit("", 20, 110, 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, 110, 40, 20)
GUICtrlSetTip(-1, "选择外部程序")
GUICtrlSetOnEvent(-1, "AddExApp")
GUICtrlCreateLabel("#浏览器退出后运行", 20, 190, -1, 20)
$hExApp2 = GUICtrlCreateEdit("", 20, 210, 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, 210, 40, 20)
GUICtrlSetTip(-1, "选择外部程序")
GUICtrlSetOnEvent(-1, "AddExApp2")
GUICtrlCreateTabItem("")
GUICtrlCreateButton("确定", 235, 440, 70, 20)
GUICtrlSetTip(-1, "保存设置并启动浏览器")
GUICtrlSetOnEvent(-1, "SettingsOK")
GUICtrlSetState(-1, $GUI_FOCUS)
GUICtrlCreateButton("取消", 330, 440, 70, 20)
GUICtrlSetTip(-1, "取消")
GUICtrlSetOnEvent(-1, "ExitApp")
GUICtrlCreateButton("应用", 425, 440, 70, 20)
GUICtrlSetTip(-1, "保存设置")
GUICtrlSetOnEvent(-1, "SettingsApply")
$hStatus = _GUICtrlStatusBar_Create($hSettings, -1, '双击软件目录下的 "' & $AppName & '.vbs" 文件可调出此窗口')
Opt("ExpandEnvStrings", 1)
;~ 复制配置文件选项有效/无效
If FileExists($DefaultProfDir) Then
GUICtrlSetState($hCopyProfile, $GUI_ENABLE)
If $FirstRun And Not FileExists($ProfileDir & "\prefs.js") Then GUICtrlSetState($hCopyProfile, $GUI_CHECKED)
Else
GUICtrlSetState($hCopyProfile, $GUI_DISABLE)
EndIf
OnFirefoxPathChange()
GUISetState(@SW_SHOW)
While Not $SettingsOK
Sleep(100)
WEnd
GUIDelete($hSettings)
EndFunc ;==>Settings
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 OnFirefoxPathChange()
ShowCurrentChannel()
ChangeChannel()
EndFunc ;==>OnFirefoxPathChange
Func ChangeChannel()
Local $ChannelString = GUICtrlRead($hChannel)
Local $Channel = StringRegExpReplace($ChannelString, " *-.*", "")
If $Channel = "default" Then $Channel = "release"
GUICtrlSetData($hDownloadFirefox32, $Channel & " 32位")
GUICtrlSetData($hDownloadFirefox64, $Channel & " 64位")
EndFunc ;==>ChangeChannel
Func ShowCurrentChannel()
Local $path = GUICtrlRead($hFirefoxPath)
If Not FileExists($path) Then Return
Local $ChannelPath = StringRegExpReplace($path, "\\?[^\\]+$", "") & "\defaults\pref\channel-prefs.js"
Local $var = FileRead($ChannelPath)
Local $match = StringRegExp($var, '(?i)(?m)^\Qpref("app.update.channel",\E *"(.*)\Q");\E', 1)
If @error Then Return
$Channel = $match[0]
_GUICtrlComboBox_SelectString($hChannel, $Channel)
EndFunc ;==>ShowCurrentChannel
Func DownloadFirefox()
Local $os
If @GUI_CtrlId = $hDownloadFirefox32 Then
$os = "win"
Else
$os = "win64"
EndIf
Local $ChannelString = GUICtrlRead($hChannel)
Local $Channel = StringRegExpReplace($ChannelString, " *-.*", "")
; http://ftp.mozilla.org/pub/firefox/
If $Channel = "release" Or $Channel = "default" Then
$FirefoxURL = "https://download.mozilla.org/?product=firefox-latest&os=" & $os & "&lang=zh-CN"
ElseIf $Channel = "beta" Then
$FirefoxURL = "https://download.mozilla.org/?product=firefox-beta-latest&os=" & $os & "&lang=zh-CN"
ElseIf $Channel = "esr" Then
$FirefoxURL = "https://download.mozilla.org/?product=firefox-esr-latest&os=" & $os & "&lang=zh-CN"
ElseIf $Channel = "aurora" Then
$FirefoxURL = "https://download.mozilla.org/?product=firefox-aurora-latest-l10n&os=" & $os & "&lang=zh-CN"
Else ;If $Channel = "nightly" Then
$FirefoxURL = "https://download.mozilla.org/?product=firefox-nightly-latest&os=" & $os & "&lang=zh-CN"
EndIf
ClipPut($FirefoxURL)
Local $msg = MsgBox(65, "MyFirefox", "请下载 Firefox 安装包,用 WinRAR、7z 等解压软件打开安装包," & _
"将其中的 core 文件夹提取出来,即得到 Firefox 便携版所需的程序文件。" & @CRLF & @CRLF & _
'下载地址已复制到剪贴板,点击"确定"将在浏览器中打开下载页面。', 0, $hSettings)
If $msg = 1 Then
ShellExecute($FirefoxURL)
EndIf
EndFunc ;==>DownloadFirefox
Func RunInBackground()
If GUICtrlRead($hRunInBackground) = $GUI_CHECKED Then
Return
EndIf
Local $msg = MsgBox(36 + 256, "MyFirefox", '允许 MyFirefox 在后台运行可以带来更好的用户体验。若取消此选项,请注意以下几点:' & @CRLF & @CRLF & _
'1. 将浏览器锁定到任务栏或设为默认浏览器后,需再运行一次 MyFirefox 才能生效;' & @CRLF & _
'2. MyFirefox 设置界面中带“#”符号的功能/选项将不会执行,包括浏览器退出后关闭外部程序、运行外部程序等。' & @CRLF & @CRLF & _
'确定要取消此选项吗?', 0, $hSettings)
If $msg <> 6 Then
GUICtrlSetState($hRunInBackground, $GUI_CHECKED)
EndIf
EndFunc ;==>RunInBackground
;~ 设置界面取消
Func ExitApp()
Exit
EndFunc ;==>ExitApp
;~ 设置界面确定按钮
Func SettingsOK()
SettingsApply()
If @error Then Return
$SettingsOK = 1
EndFunc ;==>SettingsOK
;~ 设置界面应用按钮
Func SettingsApply()
Local $msg, $var
FileChangeDir(@ScriptDir)
Opt("ExpandEnvStrings", 0)
$FirefoxPath = RelativePath(GUICtrlRead($hFirefoxPath))
$ProfileDir = RelativePath(GUICtrlRead($hProfileDir))
$CustomPluginsDir = RelativePath(GUICtrlRead($hCustomPluginsDir))
$CustomCacheDir = RelativePath(GUICtrlRead($hCustomCacheDir))
$CacheSize = GUICtrlRead($hCacheSize)
If GUICtrlRead($hCacheSizeSmart) = $GUI_CHECKED Then
$CacheSizeSmart = 1
Else
$CacheSizeSmart = 0
EndIf
$var = GUICtrlRead($hParams)
$var = StringStripWS($var, 3)
$Params = StringReplace($var, @CRLF, " ") ; 换行符换成空格
If GUICtrlRead($hCheckAppUpdate) = $GUI_CHECKED Then
$CheckAppUpdate = 1
Else
$CheckAppUpdate = 0
EndIf
If GUICtrlRead($hRunInBackground) = $GUI_CHECKED Then
$RunInBackground = 1
Else
$RunInBackground = 0
EndIf
Local $var = GUICtrlRead($hExApp)
$var = StringStripWS($var, 3)
$var = StringReplace($var, @CRLF, "||")
$var = StringRegExpReplace($var, "\|+\s*\|+", "\|\|")
$ExApp = $var
If GUICtrlRead($hExAppAutoExit) = $GUI_CHECKED Then
$ExAppAutoExit = 1
Else
$ExAppAutoExit = 0
EndIf
$var = GUICtrlRead($hExApp2)
$var = StringStripWS($var, 3)
$var = StringReplace($var, @CRLF, "||")
$var = StringRegExpReplace($var, "\|+\s*\|+", "\|\|")
$ExApp2 = $var
IniWrite($inifile, "Settings", "CheckAppUpdate", $CheckAppUpdate)
IniWrite($inifile, "Settings", "RunInBackground", $RunInBackground)
IniWrite($inifile, "Settings", "FirefoxPath", $FirefoxPath)
IniWrite($inifile, "Settings", "ProfileDir", $ProfileDir)
IniWrite($inifile, "Settings", "CustomPluginsDir", $CustomPluginsDir)
IniWrite($inifile, "Settings", "CustomCacheDir", $CustomCacheDir)
IniWrite($inifile, "Settings", "CacheSize", $CacheSize)
IniWrite($inifile, "Settings", "CacheSizeSmart", $CacheSizeSmart)
IniWrite($inifile, "Settings", "Params", $Params)
$var = $ExApp
If StringRegExp($var, '^".*"$') Then $var = '"' & $var & '"'
IniWrite($inifile, "Settings", "ExApp", $var)
IniWrite($inifile, "Settings", "ExAppAutoExit", $ExAppAutoExit)
$var = $ExApp2
If StringRegExp($var, '^".*"$') Then $var = '"' & $var & '"'
IniWrite($inifile, "Settings", "ExApp2", $var)
Opt("ExpandEnvStrings", 1)
;Firefox path
If Not FileExists($FirefoxPath) Then
MsgBox(16, "MyFirefox", "Firefox 路径错误,请重新设置。" & @CRLF & @CRLF & $FirefoxPath, 0, $hSettings)
GUICtrlSetState($hFirefoxPath, $GUI_FOCUS)
Return SetError(1)
EndIf
Local $ChannelString = GUICtrlRead($hChannel)
Local $Channel = StringRegExpReplace($ChannelString, " -.*", "")
Local $ChannelPath = StringRegExpReplace($FirefoxPath, "\\?[^\\]+$", "") & "\defaults\pref\channel-prefs.js"
Local $var = FileRead($ChannelPath)
If Not StringInStr($var, 'pref("app.update.channel", "' & $Channel & '");') Then