-
Notifications
You must be signed in to change notification settings - Fork 10
/
SmartZip.ahk
1982 lines (1674 loc) · 68.1 KB
/
SmartZip.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
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
;@Ahk2Exe-SetName SmartZip
;@Ahk2Exe-SetDescription 7-zip的功能扩展
;@Ahk2Exe-SetCopyright Copyright (c) since 2022
;@Ahk2Exe-SetCompanyName viv
;@Ahk2Exe-SetOrigFilename SmartZip.exe
;@Ahk2Exe-SetMainIcon ico.ico
;@Ahk2Exe-SetFileVersion 3.4
;@Ahk2Exe-SetProductVersion 17
;@Ahk2Exe-ExeName SmartZip.exe
buildVersion := 18
MainVersion := "3.4"
;Msgbox FormatTime(A_Now, "yyyy/M/d H:m:s")
buileTime := "2022/8/3 14:27:28"
app := "SmartZip"
#SingleInstance off
#NoTrayIcon
ini.Init(A_ScriptDir "\" app ".ini")
IniCreate
zip := SmartZip(RelativePath(ini.zipDir))
;https://www.iconfont.cn/collections/detail?spm=a313x.7781069.0.da5a778a4&cid=24599
icon := FileExist(icon := RelativePath(ini.icon)) ? icon : ""
TraySetIcon(icon)
if A_Args.Length
zip.Init(A_Args).Exec()
else
Setting
class SmartZip
{
__New(sevenZipDir)
{
this.now := A_TickCount
this.exitCode := -1
this.setShow := false
sevenZipDir := sevenZipDir ~= "i)^[a-z]:\\$" ? sevenZipDir : RTrim(sevenZipDir, "\")
if !DirExist(sevenZipDir)
return MsgBox("7-zip 文件夹不存在,请设置其路径")
this.7z := sevenZipDir "\7z.exe"
this.7zG := sevenZipDir "\7zG.exe"
this.7zFM := sevenZipDir "\7zFM.exe"
if !FileExist(this.7z) || !FileExist(this.7zG) || !FileExist(this.7zFM)
return MsgBox("7-zip 文件夹中必需包含 7z.exe,7zG.exe,7zFM.exe`n请检测文件夹是否设置正确")
}
Init(argsArr)
{
this.codePage := ""
if argsArr[1] = "xc"
SetCodePage(), argsArr.RemoveAt(1)
if RegExMatch(argsArr[1], "^[xoa]$")
this.to := argsArr[1], argsArr.RemoveAt(1) ;根据第一个传入参数决定动作
else
this.to := "x"
this.arr := []
for i in argsArr
{
if FileExist(i)
loop files RTrim(i, "\"), "DF"
this.arr.Push(A_LoopFileFullPath)
}
if !this.arr.Length
ExitApp(2)
this.isRunning := true
this.muilt := this.arr.Length > 1 ;多文件
SplitPath(this.arr[1], , &dir)
SetWorkingDir(this.defaultDir := dir)
this.continue := this.guiShow := this.cmdHide := false
this.pid := this.log := this.testLog := ''
this.ext := Map()
this.extExp := []
ini.ReadLoop("ext", this.ext, true)
ini.ReadLoop("extExp", this.extExp)
this.logLevel := ini.logLevel
this.cmdLog := ini.cmdLog
this.hideRunSize := ini.hideRunSize
if this.logLevel || this.cmdLog
OnExit(ExitLog)
return this
ExitLog(*)
{
if this.log
FileAppend(this.log "`n", A_ScriptDir "\log.txt", "UTF-8")
if this.testLog
FileAppend(this.testLog "`n", A_ScriptDir "\cmdLog.txt", "UTF-8")
}
SetCodePage()
{
ini.ReadLoop("codepage", cpCustomArr := [])
arr := ["简体中文(GBK)", "繁体中文(大五码)", "日文(Shift_JIS)", "韩文(EUC-KR)", "UTF-8 Unicode"]
for i in cpCustomArr
arr.Push(i)
cpArr2 := [936, 950, 932, 949, 65001]
cpG := gui("+AlwaysOnTop +ToolWindow", "请选择或输入你需要的代码页")
cpG.AddText()
cpG.SetFont(, "Segoe UI")
cpG.AddLink("", '<a href="https://docs.microsoft.com/zh-cn/windows/win32/intl/code-page-identifiers">其他代码页</a>')
v := cpG.AddComboBox("", arr)
v.ToolTip := "如需添加其他常用代码页,请参考上方链接`n输入 数字(标识符) 点击右边的 添加`n删除只能移除添加的项目"
cpG.AddButton("yp", "添加").OnEvent("Click", Add)
cpG.AddButton("yp", "删除").OnEvent("Click", Delete)
cpG.AddText()
cpG.AddButton("", "确定").OnEvent("Click", DetectCp)
cpG.OnEvent("Escape", Close)
cpG.OnEvent("Close", Close)
cpG.Show()
OnMessage(0x200, WM_MOUSEMOVE)
WinWaitClose(cpg.Hwnd)
Close(*) => (OnMessage(0x200, WM_MOUSEMOVE, 0), cpg.Destroy())
Add(*)
{
if !(text := v.Text) || !IsNumber(text)
return
for i in arr
if i = text
return
cpCustomArr.Push(text), arr.push(Text), v.Delete(), v.Add(arr)
}
Delete(*)
{
if v.Value < 6 || !(text := v.Text) || !IsNumber(text)
return
cpCustomArr.RemoveAt(v.Value - 5), arr.RemoveAt(v.Value), arr.Text := "", v.Delete(), v.Add(arr)
}
DetectCp(*)
{
if IsNumber(text := v.Text)
this.codePage := " -mcp=" text
else
{
for i in arr
{
if text = i
{
this.codePage := " -mcp=" cpArr2[A_Index]
break
}
}
}
for i in cpCustomArr
{
if ini.Read(A_Index, , "codepage") != i
ini.Write(i, A_Index, "codepage")
}
loop
{
if !(vaf := ini.Read(cpCustomArr.Length + A_Index, , "codepage"))
break
ini.Delete("codepage", cpCustomArr.Length + A_Index)
}
Close
}
}
}
Exec()
{
switch this.to
{
case "x": this.Unzip()
case "o": this.OpenZip()
case "a": this.CreateZip()
default:this.Unzip()
}
this.isRunning := false
if this.cmdHide && !this.guiShow
{
ToolTip("处理完成")
Sleep(2000)
ToolTip()
}
if !this.setShow
ExitApp
}
Unzip(loopPath := "")
{
if !loopPath
{
arr := this.arr
this.autoAddPass := ini.autoAddPass
this.dynamicPassSort := ini.dynamicPassSort
this.test := ini.test
this.partSkip := ini.partSkip
this.delSource := ini.delSource
this.delWhenHasPass := ini.delWhenHasPass
this.nesting := ini.nesting
this.nestingMuilt := ini.nestingMuilt
this.succesSpercent := ini.successPercent
this.autoRemovePass := ini.autoRemovePass
if (targetDir := ini.targetDir)
targetDir := targetDir ~= "i)^[a-z]:\\$" ? targetDir : RTrim(targetDir, "\")
this.addDir2Pass := ini.Read("addDir2Pass", , "set")
if targetDir && DirExist(targetDir)
SetWorkingDir(this.defaultDir := targetDir)
this.password := ["", ini.lastPass, FormatPassword(A_Clipboard)]
ini.ReadLoop("password", this.password)
excludeExt := []
ini.ReadLoop("excludeExt", excludeExt)
excludeName := []
ini.ReadLoop("excludeName", excludeName)
this.excludeArgs := ""
if excludeExt.Length || excludeName.Length
{
for i in excludeExt
this.excludeArgs .= ' -x!*.' i
for i in excludeName
this.excludeArgs .= ' -x!*' i '*'
}
if this.excludeArgs
this.excludeArgs .= " -r"
if this.dynamicPassSort || this.autoAddPass
{
ini.ReadLoop("password", this.dynamicPassArr := [])
this.passwordMap := Map()
for i in this.dynamicPassArr
{
this.passwordMap[i] := A_Index
this.dynamicPassArr[A_Index] := [i, ini.Read(A_Index, 0, "passwordSort")]
; if !IsNumber(this.dynamicPassArr[A_Index][2])
; ini.Write(this.dynamicPassArr[A_Index][2] := 0, A_Index, "passwordSort")
}
}
this.fileSystemObject := ComObject("Scripting.FileSystemObject")
} else
{
arr := [loopPath]
SplitPath(loopPath, , &dir)
SetWorkingDir(dir)
}
for i in arr
{
if !loopPath && A_WorkingDir != this.defaultDir
SetWorkingDir(this.defaultDir)
if !loopPath
this.index := A_Index
this.temp := tmpDir := '__7z' A_Now
this.currentSize := FileGetSize(i)
hideBool := this.currentSize / 1024 / 1024 < this.hideRunSize
part := IsPart(i)
if this.partSkip && !part
continue
if this.muilt && !this.guiShow && !hideBool
this.Gui()
if this.addDir2Pass
SplitPath(i, , &dir), this.password.Push(RegExReplace(dir, ".+\\"))
zipx(i)
if this.addDir2Pass
this.password.RemoveAt(this.password.Length)
if !DirExist(tmpDir) ;密码错误以及未输入正确密码
continue
loop files tmpDir "\*.*", "RDF"
AfterUnzip(A_LoopFileFullPath)
loop files tmpDir "\*.*", "DF"
{
count := A_Index, souceFile := A_LoopFileFullPath
if A_Index > 2
break
}
;解压后没有文件
if !IsSet(count)
{
this.RecycleItem(tmpDir, A_LineNumber, true)
continue
}
notDir := 0
loop files tmpDir "\*.*", "FR"
{
if !DirExist(A_LoopFileFullPath)
notDir++ , souceFile2 := A_LoopFileFullPath
if notDir = 2
break
}
if count = 1 || notDir = 1 ;只有一个文件或文件夹
{
if notDir = count ;单个文件夹包含单个文件
souceFile := souceFile2
isDir := DirExist(souceFile)
SplitPath(souceFile, &name, , &ext)
outFile := this.MoveItem(souceFile, A_WorkingDir "\" name, isDir, A_LineNumber)
this.RecycleItem(tmpDir, A_LineNumber, true)
if !this.nesting || !this.nestingMuilt
continue
if !isDir
{
if this.nesting
UnZipNesting(outFile, ext)
} else if this.nestingMuilt
loop files outFile "\*.*", "F"
UnZipNesting(A_LoopFileFullPath, A_LoopFileExt)
} else ;多个文件
{
SplitPath(i, , , , &nameNoEXT)
outFile := this.MoveItem(tmpDir, A_WorkingDir "\" nameNoEXT, 1, A_LineNumber)
if this.nestingMuilt
loop files outFile "\*.*", "F"
UnZipNesting(A_LoopFileFullPath, A_LoopFileExt)
}
}
if loopPath
return
if this.autoRemovePass && (this.dynamicPassSort || this.autoAddPass)
{
if this.dynamicPassSort
PasswordSort
for i in this.dynamicPassArr
if A_Index > this.autoRemovePass
PasswordClear(A_Index, true)
if this.dynamicPassArr.Length > this.autoRemovePass
this.dynamicPassArr.RemoveAt(this.autoRemovePass + 1, this.dynamicPassArr.Length - this.autoRemovePass)
} else if this.dynamicPassSort
PasswordSort
;执行解压
zipx(path)
{
if this.logLevel
this.log .= '`n#####`n' path '`n'
pass := ""
this.continue := false
for i in this.password
{
if A_Index = 1
{
this.isFile := this.isCmdReturn := false
this.needPass := 4
cmdArgs := this.7z ' l -slt -bsp1 "' path '"'
if this.cmdLog
this.testLog .= '`n#####`n' cmdArgs '`n'
this.RunCmd(cmdArgs, , CheckEncrypted)
switch this.needPass
{
case 0: break
case 1: continue
case 2:
{
for n in this.password
{
if n
{
this.isFile := this.isCmdReturn := false
this.needPass := 5
cmdArgs := this.7z ' l -slt -bsp1 -p"' n '" "' path '"'
this.RunCmd(cmdArgs, , CheckEncrypted)
if this.cmdLog
this.testLog .= '`n#####`n' cmdArgs '`n'
if this.needPass = 1
{
this.error := 0
pass := ' -p"' AddPass(n) '"'
break 2
}
}
}
}
case 3: return
}
}
this.CheckCMD(, this.7z ' t -bsp1 "' path '" -p"' i '"')
if this.continue
return
if !this.error
{
if i
pass := ' -p"' AddPass(i) '"'
break
}
}
if !this.needPass || !this.error ;密码正确或无需密码
{
this.Run7z(hideBool, 'x', path, '" -aou -o' tmpDir pass this.excludeArgs this.codePage, hideBool || this.guiShow, () => IsSuccess(), A_LineNumber)
if IsSuccess()
{
if part != -1
return
if loopPath
this.RecycleItem(path, A_LineNumber, true)
else if this.delSource || (pass && this.delWhenHasPass)
this.RecycleItem(path, A_LineNumber)
}
} else
{
this.tryPasssword := ""
if this.autoAddPass
SetTimer(TrackPass, 10)
this.Run7z(false, 'x', path, '" -aou -o' tmpDir this.excludeArgs this.codePage, , () => IsSuccess(), A_LineNumber)
SetTimer(TrackPass, 0), ToolTip()
if this.tryPasssword && this.exitCode != 255
{
this.error := true
this.CheckCMD(, this.7z ' t -bsp1 "' path '" -p"' this.tryPasssword '"')
if !this.error
AddPass(this.tryPasssword)
}
if IsSuccess() && part = -1 && this.delWhenHasPass
this.RecycleItem(path, A_LineNumber) ;密码错误需手动输入密码
}
TrackPass()
{
title := "ahk_pid " this.pid
if WinExist(title) && WinActive(title)
{
try
if InStr(ControlGetText("Button1", title), "&S")
{
if !ControlGetChecked("Button1", title)
return (this.tryPasssword := "", ToolTip())
} else if !ControlGetText("Static14", title)
return (SetTimer(TrackPass, 0), ToolTip())
try
if (str := ControlGetText("Edit1", title))
this.tryPasssword := str
try
if ControlGetText("Static14", title)
this.tryPasssword := ""
if this.tryPasssword
ToolTip "当前密码 : " this.tryPasssword
} else
ToolTip()
}
AddPass(pass)
{
static notLoopPass := "" ;用以确保嵌套和源文件同密码时不会重复记录
if !pass
return
if !loopPath
notLoopPass := pass
else if pass = notLoopPass
return pass
if ini.lastPass != pass
ini.Write(pass, "lastPass", "temp")
if this.dynamicPassSort || this.autoAddPass
{
if !this.passwordMap.Has(pass) && this.password.Length > 2 && this.password[3] = pass
return pass
if !this.passwordMap.Has(pass)
{
this.dynamicPassArr.Push([pass, 0]), this.passwordMap[pass] := this.dynamicPassArr.Length
if this.autoAddPass
ini.Write(pass, this.passwordMap.Count, "password")
} else
this.dynamicPassArr[this.passwordMap[pass]][2]++
}
return pass
}
CheckEncrypted(LineNum, Line)
{
if this.isCmdReturn
return
if this.cmdLog
this.testLog .= "[" LineNum "] " line '`n'
if !this.isFile && InStr(Line, "Attributes = A") || Line ~= "CRC = [A-Z0-9]+"
this.isFile := true
else if this.isFile && InStr(Line, "Attributes = D") || Line ~= "CRC = *?$"
this.isFile := false
else if this.isFile && InStr(Line, "Encrypted = -")
LogAndReturn(0, A_LineNumber)
else if InStr(Line, "Encrypted = +") || InStr(Line, "Wrong password?")
LogAndReturn(1, A_LineNumber)
else if InStr(Line, "Enter password (will not be echoed):")
LogAndReturn(2, A_LineNumber)
else if this.needPass = 5 && InStr(Line, "Errors: 1")
LogAndReturn(2, A_LineNumber)
else if InStr(Line, "Errors: 1") || InStr(Line, "Cannot open the file as archive") || InStr(Line, "Unexpected end of archive")
this.continue := true, LogAndReturn(3, A_LineNumber)
LogAndReturn(num := "", logLineNum := "")
{
this.isCmdReturn := true
this.needPass := num
ProcessClose(this.CMDPID), ProcessWaitClose(this.CMDPID)
this.CMDPID := 0
this.Loging(cmdArgs '`n[' LineNum '] ' line, logLineNum, this.needPass > 2 ? 3 : 4)
}
}
IsSuccess()
{
if !this.exitCode
return true
if !DirExist(tmpDir)
return false
if this.exitCode != 255
{
folderSize := this.fileSystemObject.GetFolder(tmpDir).Size
this.Loging("文件大小: " this.currentSize " 临时文件夹大小: " folderSize, A_LineNumber)
if folderSize >= this.currentSize
return true
else if folderSize / this.currentSize * 100 > this.succesSpercent
return true
}
this.RecycleItem(tmpDir, A_LineNumber, true)
return false
}
}
;解压嵌套
UnZipNesting(path, ext)
{
if !this.IsArchive(ext) || !(part := IsPart(path))
return
timeSave := FileGetTime(path), sizeSave := FileGetSize(path)
this.exitCode := -1
this.Unzip(path)
this.Loging("解压嵌套 <--> " path, A_LineNumber)
if !this.exitCode && part = -1 && FileExist(path) && FileGetTime(path) = timeSave && FileGetSize(path) = sizeSave ;!exitCode &&
this.RecycleItem(path, A_LineNumber)
}
; 解压后处理
AfterUnzip(path)
{
static isRead := false, obj := { rename: { ext: Map(), name: Map(), exp: Map() },
deleteExp: [] }
if !isRead
{
ini.ReadLoop("renameExt", obj.rename.ext, , true)
ini.ReadLoop("renameName", obj.rename.name, , true)
ini.ReadLoop("renameExp", obj.rename.exp, , true)
ini.ReadLoop("deleteExp", obj.deleteExp)
isRead := true
}
if (isDir := DirExist(path)) && this.fileSystemObject.GetFolder(path).Size = 0 ;空文件夹
return this.RecycleItem(path, A_LineNumber)
SplitPath(path, &name, &dir, &ext, &nameNoExt)
for i in obj.deleteExp
if name ~= i
return this.RecycleItem(path, A_LineNumber)
for ori, out in obj.rename.ext
{
if !isDir && ext = ori
{
name := nameNoExt '.' out
break
}
}
for needle, replaceText in obj.rename.name
if InStr(name, needle)
name := StrReplace(name, needle, replaceText)
for needle, replaceText in obj.rename.exp
if name ~= needle
name := RegExReplace(name, needle, replaceText)
if path != dir "\" name
this.MoveItem(path, dir "\" name, isDir, A_LineNumber)
}
IsPart(path)
{
SplitPath(path, &name)
if name ~= "i)\.part\d\.rar$"
{
if InStr(name, ".part1.rar") ;第一卷
return 1
this.Loging("可能是分卷包 <--> " path, A_LineNumber, 5)
return 0
} else if name ~= "\..+\.\d+$"
{
if name ~= "\..+.0+1" ;第一卷
return 1
this.Loging("可能是分卷包 <--> " path, A_LineNumber, 5)
return 0
}
return -1
}
PasswordSort()
{
;排序
i := 0
while (++ i <= this.dynamicPassArr.Length)
{
j := 0
while (++ j <= this.dynamicPassArr.Length - i)
{
if this.dynamicPassArr[j][2] < this.dynamicPassArr[j + 1][2]
{
temp := this.dynamicPassArr[j]
this.dynamicPassArr[j] := this.dynamicPassArr[j + 1]
this.dynamicPassArr[j + 1] := temp
}
}
}
for i in this.dynamicPassArr
{
if ini.Read("A_Index", , "passwordSort") != i[2]
ini.Write(i[2], A_Index, "passwordSort")
if ini.Read("A_Index", , "password") != i[1]
ini.Write(i[1], A_Index, "password")
}
arr := []
loop ;清除重复密码
{
if (pwd := ini.Read(this.dynamicPassArr.Length + A_Index))
{
if !this.passwordMap.Has(pwd)
arr.Push(pwd)
PasswordClear(this.dynamicPassArr.Length + A_Index, true)
} else
break
}
; if arr.Length
; for i in arr
; ini.Write(i, this.dynamicPassArr.Length + A_Index, "password")
}
PasswordClear(index, delete := false)
{
if delete
IniDelete(ini, "password", index), IniDelete(ini, "passwordSort", index)
else
ini.Write(, index, "password"), ini.Write(, index, "passwordSort")
}
FormatPassword(str) => StrLen(str) < 100 ? Trim(RegExReplace(str, "(\R*)")) : "" ;移除所有换行符及首尾所有空格或制表符
}
OpenZip()
{
SplitPath(this.arr[1], , &dir, &ext, &nameNoExt)
if !this.muilt
{
extForOpen := Map()
ini.ReadLoop("extForOpen", extForOpen, true)
path := ' "' this.arr[1] '" '
If DirExist(this.arr[1])
this.error := true
else if (this.IsArchive(ext) || extForOpen.Has(ext))
this.error := false
else
{
if this.logLevel
this.log .= '`n#####`n' this.arr[1] '`n'
this.CheckCMD("openZip", this.7z ' l ' path)
}
if !this.error
{
Run(this.7zFM path, , , &pid)
this.Loging("打开 <--> " path, A_LineNumber)
}
}
if this.muilt || this.error
{
args := ini.openAdd
path := ""
for i in this.arr
path .= ' "' i '" '
zipName := this.muilt ? StrReplace(RegExReplace(A_WorkingDir, ".+\\"), ":") : DirExist(this.arr[1]) ? RegExReplace(this.arr[1], ".+\\") : nameNoExt
ext := RegExReplace(args, '(.+?)".*', "$1")
this.Run7z(, 'a', this.AUO(zipName, ext), args path, , , A_LineNumber)
}
}
CreateZip()
{
SplitPath(this.arr[1], , , , &nameNoExt)
count := 0
for i in this.arr
if DirExist(i)
count++
hideBool := IsHide()
args := ini.add
ext := RegExReplace(args, '(.+?)".*', "$1")
if count = this.arr.Length ;全是文件夹,单独添加
{
for i in this.arr
{
hideBool := IsHide(i)
if count > 1 && !hideBool && !this.guiShow
this.Gui
zipName := this.AUO(RegExReplace(i, ".*\\"), ext)
this.temp := zipName ext
this.index := A_Index
this.Run7z(hideBool, 'a', zipName, args ' "' i '\*"', hideBool || count > 1, , A_LineNumber)
}
return
} else if this.arr.Length = 1 ;单个文件
this.Run7z(hideBool, 'a', this.AUO(nameNoExt, ext), args ' "' this.arr[1] '"', hideBool, , A_LineNumber)
else ;文件文件夹混合
{
for i in this.arr
path .= ' "' i '" '
this.Run7z(hideBool, 'a', this.AUO(RegExReplace(A_WorkingDir, ".+\\"), ext), args path, hideBool, , A_LineNumber)
}
IsHide(dir := "")
{
countSzie := 0
if dir
{
loop files dir "\*.*", "RDF"
if (countSzie += A_LoopFileSizeMB) > this.hideRunSize
return false
return true
}
for i in this.arr
{
if DirExist(i)
{
loop files i "\*.*", "RDF"
if (countSzie += A_LoopFileSizeMB) > this.hideRunSize
return false
} else
countSzie += FileGetSize(i, "M")
if countSzie > this.hideRunSize
return false
}
return true
}
}
Gui()
{
this.guiShow := true
DetectHiddenWindows(1)
g := Gui("+LastFound")
DllCall("RegisterShellHookWindow", "UInt", WinExist())
msgNum := DllCall("RegisterWindowMessage", "Str", "SHELLHOOK")
OnMessage(msgNum, ShellMessage)
g.SetFont(, "Segoe UI")
g.BackColor := "FFFFFF"
已用时间1 := g.Add("text", "w100"), 已用时间2 := leftVaule()
总大小1 := rightTitle(), 总大小2 := rightVaule()
剩余时间1 := leftTitle(), 剩余时间2 := leftVaule()
速度1 := rightTitle(), 速度2 := rightVaule()
文件1 := leftTitle(), 文件2 := leftVaule()
已处理1 := rightTitle(), 已处理2 := rightVaule()
leftTitle(), 文件3 := leftVaule()
压缩后大小1 := rightTitle(), 压缩后大小2 := rightVaule()
总进度1 := leftTitle(), 总进度2 := leftVaule()
压缩率1 := rightTitle(), 压缩率2 := rightVaule()
g.Add("text", "h1 w1")
处理1 := g.Add("text", "xs w500")
if this.to = "x"
处理2 := g.Add("text", "w500")
处理3 := g.Add("text", "w500")
进度 := g.Add("Progress", "w500 h20")
leftTitle() => g.Add("text", "xs w100")
leftVaule() => g.Add("text", "yp w100 x120 Right")
rightTitle() => g.Add("text", "yp w100 x300")
rightVaule() => g.Add("text", "yp w100 x420 Right")
g.Add("text")
g.AddButton("w100 x10", "显示原始界面").OnEvent("Click", ButtonShowHide)
暂停 := g.AddButton("x300 w100 yp")
暂停.OnEvent("Click", ButtonPause)
取消 := g.AddButton("w100 yp")
取消.OnEvent("Click", ButtonCance)
g.OnEvent("Close", Close)
g.OnEvent("Escape", Close)
sub() => "ahk_pid " this.pid
g.Show("AutoSize")
Close(*)
{
if ProcessExist(this.pid)
ProcessClose(this.pid), ProcessWaitClose(this.pid)
if this.HasOwnProp("temp")
this.RecycleItem(this.temp, A_LineNumber, true)
if !this.setShow
ExitApp(255)
OnMessage(msgNum, ShellMessage, 0), g.Destroy()
}
ButtonShowHide(GuiCtrlObj, *)
{
DetectHiddenWindows(0)
if !ProcessExist(this.pid)
return
if WinExist(sub())
WinHide(sub()), GuiCtrlObj.Text := "显示原始界面"
else
WinShow(sub()), WinActivate(sub()), GuiCtrlObj.Text := "隐藏原始界面"
}
ButtonPause(GuiCtrlObj, Info)
{
DetectHiddenWindows(1)
if !WinExist(sub())
return
textSave := GuiCtrlObj.Text
ControlClick("Button2", sub())
ShellMessage
while WinExist(sub()) && GuiCtrlObj.Text = textSave
ControlClick("Button2", sub()), Sleep(500), ShellMessage()
}
ButtonCance(GuiCtrlObj, Info)
{
DetectHiddenWindows(1)
if !WinExist(sub())
return
ControlClick("Button3", sub())
ShellMessage
while WinExist(sub()) && !InStr(WinGetText(sub()), "否(&N)")
ControlClick("Button3", sub()), Sleep(500)
WinWaitActive(sub())
WinWaitClose
num := 0
loop 5
if !WinExist(sub())
num++
if num = 5
Close
}
DetectError()
{
DetectHiddenWindows(0)
if WinExist(sub())
return
else
WinShow(sub())
}
ShellMessage(wParam := 6, *)
{
ListLines(0)
DetectHiddenWindows(1)
static timeSave := A_TickCount
if !this.isRunning
Close()
if A_TickCount - timeSave < 50 || wParam != 6 || !WinExist(sub())
return
IsChanged(总进度1, "总进度:")
, IsChanged(总进度2, this.index "\" this.arr.Length)
try
{
if g.Title != WinGetTitle(sub())
g.Title := WinGetTitle(sub())
arr := StrSplit(WinGetText(sub()), "`n")
for i in arr
{
if InStr(i, "您真的要取消吗")
return
arr[A_Index] := SubStr(i, 1, -1)
}
IsChanged(进度, RegExReplace(g.Title, "(.+ )?(\d+)%.+", "$2"))
, IsChanged(暂停, arr[2], 1)
, IsChanged(取消, arr[3], 1)
, IsChanged(已用时间1, arr[4])
, IsChanged(剩余时间1, arr[5])
, IsChanged(文件1, arr[6])
; IsChanged(发生错误, arr[7])
IsChanged(总大小1, arr[8])
, IsChanged(速度1, arr[9])
, IsChanged(已处理1, arr[10])
, IsChanged(压缩后大小1, arr[11])
, IsChanged(压缩率1, arr[12])
, IsChanged(已用时间2, arr[13])
, IsChanged(剩余时间2, arr[14])
, IsChanged(文件2, arr[15])
index := 16
if this.to = "a"
IsChanged(文件3, arr[index++ ])
if IsNumber(arr[index++ ]) ;发生错误