-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEngine2.ahk
More file actions
1183 lines (1148 loc) · 31.9 KB
/
Engine2.ahk
File metadata and controls
1183 lines (1148 loc) · 31.9 KB
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
#Include Lib\MZ_API.ahk
#Include Lib\Yaml.ahk
/*
* 由于MenuZ\GestureZ\VimDesktop的需要,做一个统一的功能库
* 1、类似StrokeIt里的命令集成,发挥AHK的优势
* 2、此功能库有一个界面,可以允许加载,方便集成到三个程序中
* 3、此功能库是可扩展的,方便维护和使用的
* 4、此功能库使用yaml做为配置文件的保存、读取和执行
*/
GUI,Test:+hwndaa
GUI,Test:Font, s9, Microsoft YaHei
SR_Engine_Load("Test",10)
SR_Engine_Show()
return
f1::
SR_Engine_HideControl()
return
f2::
n:=1
SR_Engine_ShowTab%n%()
SR_Engine_Exec(v:=SR_Engine_ShowTab1_Save())
return
TestGUIClose:
GUI,Test:Destroy
;Msgbox % Yaml_Dump(SRE_Object,1)
return
/*
WinGet,v,id,ahk_class Notepad
save := {"hwnd":v}
SR_Engine_Interpret("{window:dir}",Save)
*/
/*
变量
SRE_GUIName: 功能库界面名,方便功能块嵌入
SRE_Handle: 功能库界面的Handle
SRE_Object: 功能库界面保存到数据(按数据结构)
*/
/*
数据结构:
Method: Run
File: ''
WorkingDir: ''
Param: ''
State: '0|1|2|3'
--- 0为正常运行; 1为最小化运行; 2为最大化运行; 3为隐藏运行
Method: RunWait
File: ''
WorkingDir: ''
Param: ''
State: '0|1|2|3'
--- 0为正常运行; 1为最小化运行; 2为最大化运行; 3为隐藏运行
Method: WinActivate
Class: ''
Title: ''
fuzzy: False
Wait: 0
Method: WinResize
Width: 0
Height: 0
Method: WinMove
X: 0
Y: 0
Method: WinMaximize
Class: ''
Title: ''
fuzzy: False
Method: WinMinimize
Class: ''
Title: ''
fuzzy: False
Method: WinRestore
Class: ''
Title: ''
fuzzy: False
Method: AlwayOnTop
Class: ''
Title: ''
fuzzy: False
Method: SendMessage
Class: ''
Title: ''
fuzzy: False
Message: 0
WParam:
LParam:
Method: Send
HK1: '{down 10}'
HK2: '{s 30}'
HK3: '+{TAB 4}'
Method: Input
String: ''
Method: Click
X: 0
Y: 0
Count: 1
Key: 'Right'
Method: Sleep
Time: 0
Method: Label
Sub: ''
Method: Function
Name: ''
暂不支持:
Method: AHK
Script: ''
*/
; SR_Engine_Load(GUIName="SRE",y=10) {{{1
; 此函数用于加载界面库
; 需要提供界面名称,默认为SR_Engine
SR_Engine_Load(GUIName="SRE",yy=10)
{
Global SRE_GUIName
,SRE_ListView_Step,SER_DDL_Method
,SRE_Tab1_Edit1,SRE_Tab1_Edit2,SRE_Tab1_Edit3,SRE_Tab1_DDL
SRE_GUIName := GUIName
CH := "运行`n"
. "运行并等待"
y := yy
GUI,%SRE_GUIName%:+Delimiter`n
GUI,%SRE_GUIName%:Add,ListView,w200 h400 x10 y%y% hwndSRE_ListView_Step, 步骤
y+=5
GUI,%SRE_GUIName%:Add,Text,w200 h28 x225 y%y% ,命令(&D):
y-=2
GUI,%SRE_GUIName%:Add,DDL,w200 h28 x285 y%y% hwndSRE_DDL_Methd r10 ,% CH
y+=40
GUI,%SRE_GUIName%:Add,Text,w260 h50 x225 y%y% border
y+=5
GUI,%SRE_GUIName%:Add,Text,w256 h40 x227 y%y% center
y+=54
GUI,%SRE_GUIName%:Add,Tab2,w300 h420 x210 y%y% Bottom buttons,Run
GUI,%SRE_GUIName%:Add,GroupBox,w260 h280 x225 y%y%
y+=16
GUI,%SRE_GUIName%:Add,Text,h26 x235 y%y%,文件/文件夹:(&E)
y+=20
GUI,%SRE_GUIName%:Add,Edit,w240 h24 x235 y%y% hwndSRE_Tab1_Edit1
y+=30
GUI,%SRE_GUIName%:Add,Button,w90 h26 x285 y%y%,浏览文件(&F)
GUI,%SRE_GUIName%:Add,Button,w90 h26 x385 y%y%,浏览文件夹(&D)
y+=40
GUI,%SRE_GUIName%:Add,Text,h26 x235 y%y%,参数:(&P)
y+=20
GUI,%SRE_GUIName%:Add,Edit,w240 h24 x235 y%y% hwndSRE_Tab1_Edit2
y+=35
GUI,%SRE_GUIName%:Add,Text,h26 x235 y%y%,工作目录:(&W)
y+=20
GUI,%SRE_GUIName%:Add,Edit,w240 h24 x235 y%y% hwndSRE_Tab1_Edit3
y+=35
GUI,%SRE_GUIName%:Add,Text,h26 x235 y%y%,运行方式:(&M)
y+=20
GUI,%SRE_GUIName%:Add,DDL,w240 h26 x235 r4 y%y% hwndSRE_Tab1_DDL,正常运行`n最小化运行`n最大化运行`n隐藏运行
}
; SR_Engine_Show(option,title="StarRed Engine") {{{1
; 此函数显示配置界面,保存并返回Yaml格式
SR_Engine_Show(option="",title="StarRed Engine")
{
Global SRE_Object,SRE_GUIName
SRE_Object := yaml("",False)
GUI,%SRE_GUIName%:+hwndSRE_Handle
GUI,%SRE_GUIName%:Show,w500 h420 %option%,%title%
}
; 界面切换 {{{1
; SR_Engine_HideControl() {{{2
SR_Engine_HideControl()
{
Global SRE_GUIName
GUI,%SRE_GUIName%:Default
GUIControl,Hide,SysTabControl321
GUIControl,Hide,SysTabControl322
}
; SR_Engine_ShowTab1() {{{2
SR_Engine_ShowTab1()
{
Global SRE_GUIName
GUI,%SRE_GUIName%:Default
GUIControl,Show,SysTabControl321
}
; SR_Engine_ShowTab1_Save() {{{2
SR_Engine_ShowTab1_Save()
{
Global SRE_Tab1_Edit1,SRE_Tab1_Edit2,SRE_Tab1_Edit3,SRE_Tab1_DDL
v := yaml("",0)
v.add("Method: Run")
v.add("File: ")
v.add("Param: ")
v.add("WorkingDir: ")
v.add("State: 2")
v.file := "Notepad"
return v
}
; SR_Engine_Interpret() {{{1
; 适用于Run/RunWait
; 解析内容,返回解析完成的新内容
SR_Engine_Interpret(String,Save)
{
/*
Save
Hwnd:
Text:
File:
Type:
*/
; 替换变量
RunString := ReplaceEnv(LTrim(string,">"))
; 判断类型并获取相应的内容
SelectType := Save.Type
Hwnd := Save.Hwnd
WinGet,pPath,ProcessPath,ahk_id %hwnd%
If SelectType = 0
Content := pPath
If SelectType = 1
Content := Save.File
If SelectType = 2
Content := Save.Text
; 开始进行判断所有的 {switch} 开关
P1 := 1
Loop
{
Pos := RegExMatch(RunString,"\{[^\{\}]*\}",switch,P1)
If Pos
{
RtString := switch
If RegExMatch(switch,"i)\{file[^\{\}]*\}")
{
If RegExMatch(iGetFileType(Save.File),"i)^(\..*)|(Multifiles)|(Folder)$")
RtString := fileswitch(content,switch)
Else
RtString := ""
}
If RegExMatch(switch,"i)\{select[^\{\}]*\}")
RtString := selectswitch(content,switch)
If RegExMatch(switch,"i)\{window[^\{\}]*\}")
RtString := WindowSwitch(pPath,switch)
If RegExMatch(switch,"i)\{box[^\{\}]*\}",box)
RtString := boxswitch(box)
If RegExMatch(switch,"i)\{date[^\{\}]*\}",date)
RtString := dateswitch(date)
If RegExMatch(switch,"i)\{do:([^\{\}]*)\}",Func)
{
RtString := ""
If Isfunc(Func1)
RtString := %Func1%()
If IsLabel(Func1)
{
MZ_Return := ""
GoSub,%Func1%
RtString := MZ_Return
}
}
P1 := Pos + Strlen(switch)
RunString := SubStr(RunString,1,Pos-1) RtString Substr(RunString,P1)
P1 := Pos + Strlen(RtString)
}
Else
Break
}
Return RunString
}
; dateswitch(switch) {{{2
; 根据参数返回对应的时间
dateswitch(switch)
{
If RegExMatch(switch,"\[(.*?)(?<!\\)\]",now)
{
If RegExMatch(now1,"^\w*$")
now := now1
Else
{
Now := A_now
If RegExMatch(now1,"i)d\s*\+\s*(\d+)",d)
now += d1 , d
If RegExMatch(now1,"i)m\s*\+\s*(\d+)",m)
now += d1 , m
If RegExMatch(now1,"i)s\s*\+\s*(\d+)",s)
now += d1 , s
}
}
Else
now := A_Now
If RegExMatch(switch,"i)^\{date\}$")
FormatTime, time , %now% ,yyyyMMdd
Else
{
format := RegExReplace(RegExReplace(switch,"i)(^\{date:)|(\}$)"),"\[(.*?)(?<!\\)\]")
If RegExMatch(format,"\w*")
FormatTime, time , %now% ,%format%
}
return time
}
; boxswitch(switch) {{{2
; {box} 输入内容
; 提供一个简洁的界面给用户输入
boxswitch(switch)
{
Global MZ_NotRun
GUI,boxswitch:Destroy
GUI,boxswitch:Font ,s9 ,Microsoft YaHei
GUI,boxswitch:Default
GUI,boxswitch:+hwndboxhandle
Exist := 0
; {box:input} {{{4
If RegExMatch(switch,"i)^\{box:input")
{
If RegExMatch(switch,"\[>(.*?)(?<!\\)\]",tips)
{
tips := RegExReplace(RegExReplace(tips1,"\\\]","]"),"i)\\n","`n")
GUI,boxswitch:Add,Edit,x10 y10 w400 h60 ReadOnly, %Tips%
}
Exist++
If RegExMatch(switch,"\[\*\]")
opt := "Password"
GUI,boxswitch:Add,Edit, x10 w400 h24 R1 %opt%
GUIControl, Focus , Edit2
GUI,boxswitch:Add,Button,x120 w120 h26 default gGUI_boxswitch_EditOK, 确定(&O)
GUI,boxswitch:Add,Button,x274 yp w120 h26 gGUI_boxswitch_Cancel, 取消(&C)
title := MenuZ 输入内容
}
; {box:list} {{{4
If RegExMatch(switch,"i)^\{box:list")
{
If RegExMatch(switch,"\[>(.*?)(?<!\\)\]",tips)
{
tips := RegExReplace(RegExReplace(tips1,"\\\]","]"),"i)\\n","`n")
GUI,boxswitch:Add,Edit,x10 y10 w300 r1 ReadOnly, %Tips%
}
Exist++
GUI,boxswitch:Add,Listview,x10 w300 h200 gGUI_boxswitch_ListViewOK , 序号|选项
P1 := 1
Loop
{
Pos := RegExMatch(switch,"\[[^>](.*?)(?<!\\)\]",opt,P1)
If Pos
{
P1 := Pos + strlen(opt)
LV_Add("",A_Index,RegExReplace(opt,"(^\[)|(\]$)"))
}
Else
Break
}
GUI,boxswitch:Add,Button,x20 w120 h26 default gGUI_boxswitch_ListViewOK, 确定(&O)
GUI,boxswitch:Add,Button,x174 yp w120 h26 gGUI_boxswitch_ListViewClose, 取消(&C)
title := MenuZ 选择列表
}
If Exist
{
Box_OK := ""
GUI,boxswitch:Show,xCenter yCenter,% title
OnMessage(0x4e,"")
WinWaitClose,ahk_id %boxhandle%
return Box_OK
}
; {box:file} {{{4
If RegExMatch(switch,"i)^\{box:file")
{
If RegExMatch(switch,"\[>(.*?)(?<!\\)\]",tips)
tips := RegExReplace(RegExReplace(tips1,"\\\]","]"),"i)\\n","`n")
Else
tips := "MenuZ 选择文件"
;opt := ""
If RegExMatch(switch,"i)\[m\]")
opt := "M35"
Else If RegExMatch(switch,"i)\[s\]")
opt := "S24"
If RegExMatch(switch,"\[&(.*?)\*(?<!\\)\]",rootdir)
rootdir := RegExReplace(rootdir1,"\\\]","]")
Else
SplitPath,SaveSelect,,rootdir
If RegExMatch(switch,"\[#(.*?)(?<!\\)\]",filter)
filter := RegExReplace(RegExReplace(filter1,"\\\]","]"),"i)\\n","`n")
Else
filter := ""
FileSelectFile,Box_OK,%opt%,%rootdir%,%tips%,%filter%
If opt = M35
{
Loop,Parse,Box_OK,`n
{
If not strlen(A_LoopField)
continue
If A_Index = 1
dir := A_LoopField
Else
newTemp .= dir "\" A_LoopField "`n"
}
If RegExMatch(switch,"i)\[(file:.*)\]",file)
{
file := "{" file1 "}"
Box_OK := fileswitch(newTemp,file)
}
Else
Box_OK := newTemp
}
return Box_OK
}
; {box:dir} {{{4
If RegExMatch(switch,"i)^\{box:dir")
{
If RegExMatch(switch,"\[>(.*?)(?<!\\)\]",tips)
tips := RegExReplace(RegExReplace(tips1,"\\\]","]"),"i)\\n","`n")
Else
tips := "MenuZ 选择文件夹"
If RegExMatch(switch,"\[&(.*?)\*(?<!\\)\]",rootdir)
rootdir := RegExReplace(rootdir1,"\\\]","]")
Else
SplitPath,SaveSelect,,rootdir
FileSelectFolder, Box_OK, %rootdir%, 3, %tips%
}
return
GUI_boxswitch_EditOK:
GuiControlGet, vis, Visible,Edit2
If vis
GUIControlGet,Box_OK,,Edit2
Else
GUIControlGet,Box_OK,,Edit1
GUI,boxswitch:Destroy
return
GUI_boxswitch_Cancel:
MZ_NotRun := true
GUI,boxswitch:Destroy
return
GUI_boxswitch_ListViewOK:
If A_GuiEvent = DoubleClick
{
If not A_EventInfo
return
If ( idx := A_EventInfo)
LV_GetText(Box_OK,idx,2)
GUI,boxswitch:Destroy
}
Else If Not A_EventInfo
{
If ( idx := LV_GetNext())
LV_GetText(Box_OK,idx,2)
GUI,boxswitch:Destroy
}
return
GUI_boxswitch_ListViewClose:
MZ_NotRun := true
GoSub,boxswitchGUIClose
return
boxswitchGUIClose:
GUI,boxswitch:Destroy
OnMessage(0x4e,"TV_WM_NOTIFY")
return
}
; selectswitch(select,switch) {{{2
; {select} 选择内容
selectswitch(select,switch)
{
RtString := select
If RegExMatch(switch,"\[@(.*?)(?<!\\)\]",RegExSelect)
{
RegExSelect:= RegExReplace(RegExSelect1,"\\\]","]")
RegExMatch(select,RegExSelect,RtString)
}
If RegExMatch(switch,"\[(?<!@)(.*?)(?<!\\)\]",RegExEncode)
{
Encode := RegExReplace(RegExEncode1,"\\\]","]")
RtString := SksSub_UrlEncode(select,Encode)
}
Return RtString
}
; SksSub_UrlEncode(string, enc="UTF-8") {{{4
; 来自万年书妖的Candy里的函数,用于转换编码。感谢!
SksSub_UrlEncode(string, enc="UTF-8")
{ ;url编码
enc:=trim(enc)
If enc=
Return string
If Strlen(String) > 200
string := Substr(string,1,200)
formatInteger := A_FormatInteger
SetFormat, IntegerFast, H
VarSetCapacity(buff, StrPut(string, enc))
Loop % StrPut(string, &buff, enc) - 1
{
byte := NumGet(buff, A_Index-1, "UChar")
encoded .= byte > 127 or byte <33 ? "%" Substr(byte, 3) : Chr(byte)
}
SetFormat, IntegerFast, %formatInteger%
return encoded
}
; fileSwitch(FileList,switch) {{{2
; 非常复杂的文件参数,需要时间学习
fileSwitch(FileList,switch){
If Strlen(switch) And RegExMatch(switch,"^\{.*\}$")
Temp := switch
Else
Return switch
If RegExMatch(switch,"i)^\{file\}$",m)
OR RegExMatch(switch,"i)^\{file:((path)|(name)|(dir)|(ext)|(namenoext)|(drive)|(ver))\}$",m)
OR RegExMatch(switch,"i)^\{file:size(\[[KMG]B\])?\}",m)
OR RegExMatch(switch,"i)^\{file:time(\[[MAC]\])?\}",m)
; OR RegExMatch(switch,"i)^\{file:content(\[((uft-(8|16)(-raw)?)|(cp\d{1,5}))\])?\}",m) {
OR RegExMatch(switch,"i)^\{file:content(\[((cp\d{1,5})|(utf-(8|16))(-raw)?)\])?\}",m) {
Loop,Parse,FileList,`n,`r
{
m := mFileGetAttrib(A_LoopField,"fn,fd,fe,fo,ff,v")
If RegExMatch(switch,"i)^\{file\}$") Or RegExMatch(switch,"i)^\{file:path\}$"){
nSwitch := A_LoopField
break
}
If RegExMatch(switch,"i)^\{file:name\}$") {
nSwitch := m["fn"]
break
}
If RegExMatch(switch,"i)^\{file:dir\}$") {
nSwitch := m["ff"]
break
}
If RegExMatch(switch,"i)^\{file:ext\}$") {
nSwitch := m["fe"]
break
}
If RegExMatch(switch,"i)^\{file:namenoext\}$") {
nSwitch := m["fo"]
break
}
If RegExMatch(switch,"i)^\{file:drive\}$") {
nSwitch := m["fd"]
break
}
If RegExMatch(switch,"i)^\{file:ver\}$") {
nSwitch := m["v"]
break
}
If RegExMatch(switch,"i)^\{file:size(\[[kmg]b\])?\}$",m) {
Units := SubStr(m,12,strlen(m)-14)
m := mFileGetAttrib(A_LoopField,"sb,sk,sm,sg")
If Strlen(Units) = 0
nSwitch := m["sb"]
Else If InStr(Units,"k")
nSwitch := m["sk"]
Else If InStr(Units,"m")
nSwitch := m["sm"]
Else If InStr(Units,"g")
nSwitch := m["sg"]
Else
nSwitch := m["sb"]
break
}
If RegExMatch(switch,"i)^\{file:time(\[[mac]\])?\}$",m) {
WhichTime := SubStr(m,12,strlen(m)-13)
If Instr("mac",WhichTime) {
FileGetTime,nSwitch,%A_LoopField%,%WhichTime%
Break
}
FileGetTime,nSwitch,%A_LoopField%
break
}
If RegExMatch(switch,"i)^\{file:content(\[[^\[\]]*\])?\}$",m) {
If InStr(FileExist(A_LoopField),"D")
nSwitch := ""
Else {
Encode := SubStr(m,15,strlen(m)-16)
SaveEncode := A_FileEncoding
FileEncoding, %Encode%
FileRead,nSwitch,%A_LoopField%
FileEncoding, %SaveEncode%
}
Break
}
Break
}
Return nSwitch
}
Else {
co_Regex := ""
co_Index := ""
co_Equal := ""
co_Unequ := ""
co_Folder := ""
co_File := ""
co_Char := 0
If RegExMatch(switch,"\[@.*?(?<!\\)\]",co_Regex) {
Temp := RegexReplace(Temp,ToMatch(co_Regex))
co_Regex := EscapeSwitch(SubStr(co_Regex,3,Strlen(co_Regex)-3))
}
If RegExMatch(switch,"\[<\d*\]",co_Char) {
Temp := RegexReplace(Temp,ToMatch(co_Char))
co_Char := Substr(co_Char,3,Strlen(co_Char)-3)
}
If RegExMatch(switch,"\[%[\d,-]*\]",idx) {
; [1,2-4,5,6,7]
Temp := RegexReplace(Temp,ToMatch(idx))
co_Index := ","
idx := EscapeSwitch(SubStr(idx ,3,Strlen(idx)-3))
If Instr(idx,",") OR InStr(idx,"-") {
Loop,Parse,Idx,`,
{
If RegExMatch(A_LoopField,"\d*-\d*",lidx)
{
N1 := Substr(lidx,1,Instr(A_LoopField,"-")-1)
N2 := SubStr(lidx, InStr(A_LoopField,"-")+1)
co_Index .= N1 ","
Loop % ( N2 - N1 )
co_Index .= (A_Index + N1 ) ","
}
Else
co_Index .= A_LoopField ","
}
}
Else
co_Index .= Idx ","
}
If RegExMatch(switch,"\[!.*?(?<!\\)\]",Ex) {
Temp := RegexReplace(Temp,ToMatch(Ex))
Ex := EscapeSwitch(SubStr(Ex,3,Strlen(Ex)-3))
If Instr(Ex,"|") {
Loop,Parse,Ex,|
co_Unequ .= "(" RegExReplace(RegExReplace(A_LoopField,"\s"),"\+|\?|\.|\*|\{|\}|\(|\)|\||\[|\]|\\","\$0") ")|"
co_Unequ := "i)" SubStr(co_Unequ,1,Strlen(co_Unequ)-1)
}
Else
co_Unequ := "i)" Ex
}
If RegExMatch(switch,"\[=.*?(?<!\\)\]",Ix) {
Temp := RegexReplace(Temp,ToMatch(Ix))
Ix := EscapeSwitch(SubStr(Ix,3,Strlen(Ix)-3))
If InStr(Ix,"|") {
Loop,Parse,Ix,|
co_Equal .= "(" RegExReplace(RegExReplace(A_LoopField,"\s"),"\+|\?|\.|\*|\{|\}|\(|\)|\||\[|\]|\\","\$0") ")|"
co_Equal := "i)" SubStr(co_Equal,1,Strlen(co_Equal)-1)
}
Else
co_Equal := "i)" Ix
}
If RegExMatch(switch,"i)\[OF\]") {
Temp := RegexReplace(Temp,"i)\[OF\]")
co_File := True
}
If RegExMatch(switch,"i)\[OD\]") {
Temp := RegexReplace(Temp,"i)\[OD\]")
co_Folder := True
}
LoopListCount := 0
Loop,Parse,FileList,`n,`r
{
AddLine := True
m := mFileGetAttrib(A_LoopField,"n")
If co_Regex And (Not RegExMatch(A_LoopField,co_Regex) )
AddLine := False
If co_Index And (Not InStr(co_Index,"," A_Index ",") )
AddLine := False
If co_Equal And (Not RegExMatch(m["n"],co_Equal) )
AddLine := False
If co_Unequ And RegExMatch(m["n"],co_Unequ)
AddLine := False
If co_File And InStr(FileExist(A_LoopField),"D")
AddLine := False
If co_Folder And (Not InStr(FileExist(A_LoopField),"D"))
AddLine := False
If AddLine {
LoopList .= A_LoopField "`n"
LoopListCount++
}
}
; Msgbox % LoopList
Temp := SubStr(Temp,7,Strlen(Temp)-7)
Loop,Parse,LoopList,`n
{
If Strlen(A_LoopField) = 0
Continue
LoopListIndex := A_Index
m := mFileGetAttrib(A_LoopField,"fn,ff,fe,fo,fd")
r := ""
P1 := 1
Loop
{
P2 := RegExMatch(Temp,"\[((P)|(F)|(N)|(n)|(E)|(e)|(CR)|(TAB)|(I)|(II)|(C)|(D)|(d)|(M)|(m)|(Y)|(h)|(s)|(t)|(#.*?(?<!\\)))\]",s,P1)
If P2
{
Loop
{
If RegExMatch(s,"\[P\]") {
RString := A_LoopField
Break
}
If RegExMatch(s,"\[F\]") {
RString := m["ff"]
Break
}
If RegExMatch(s,"\[N\]") {
RString := m["fn"]
Break
}
If RegExMatch(s,"\[E\]") {
RString := m["fe"]
Break
}
If RegExMatch(s,"\[n\]") {
RString := m["fo"]
Break
}
If RegExMatch(s,"\[e\]") {
RString := m["fd"]
Break
}
If RegExMatch(s,"\[CR\]") {
RString := "`r`n"
Break
}
If RegExMatch(s,"\[Tab\]") {
RString := A_Tab
Break
}
If RegExMatch(s,"\[I\]") {
RString := LoopListIndex
Break
}
If RegExMatch(s,"\[II\]") {
Index := ""
If Strlen(LoopListIndex) < Strlen(LoopListCount) {
Loop, % strlen(LoopListCount) - strlen(LoopListIndex)
Index .= "0"
Index .= LoopListIndex
}
Else
Index := LoopListIndex
RString := Index
Break
}
If RegExMatch(s,"\[C\]") {
RString := LoopListCount
Break
}
If RegExMatch(s,"\[d\]") {
RString := A_YYYY "-" A_MM "-" A_DD
Break
}
If RegExMatch(s,"\[t\]") {
RString := A_Hour A_Min A_Sec
Break
}
If RegExMatch(s,"\[Y\]") {
RString := A_YYYY
Break
}
If RegExMatch(s,"\[M\]") {
RString := A_MM
Break
}
If RegExMatch(s,"\[D\]") {
RString := A_DD
Break
}
If RegExMatch(s,"\[h\]") {
RString := A_Hour
Break
}
If RegExMatch(s,"\[m\]") {
RString := A_Min
Break
}
If RegExMatch(s,"\[s\]") {
RString := A_Sec
Break
}
If RegExMatch(s,"\[#.*?(?<!\\)\]",Exten) {
Exten := SubStr(Exten,3,Strlen(Exten)-3)
If Isfunc(Exten)
RString := %Exten%()
Else
RString := ""
Break
}
}
}
Else {
If P1 > 1
r .= Over
Else
r := Temp
Break
}
Inter := Substr(Temp,P1,P2-P1)
P1 := P2 + Strlen(s)
Over := Substr(Temp,P1)
r .= Inter RString
}
k .= r
}
co_Char := co_Char ? co_Char : 0
return SubStr(k,1,Strlen(k) - co_Char)
}
}
; iGetFileType(file) {{{3
iGetFileType(file,dot="."){
If InStr(file,"`n") ;多文件
Return "MultiFiles"
Else
{
If RegExMatch(file,"[a-zA-Z]:\\$")
Return "Drive"
Else
{
Attrib := FileExist(file)
If InStr(Attrib,"D")
Return "Folder"
Else
{
SplitPath,file,,,ext
If strlen(ext)
Return dot ext
Else
Return "NoExt"
}
}
}
}
; 获取文件的属性
; type 的设置
; f 相当于Splitpath, 返回名称、目录、扩展名、驱动器
; fn 文件名
; ff 文件目录
; fe 文件拓展名
; fo 文件不事拓展名的名称
; fd 驱动器
; a 相当于FileGetAttrib,返回字符串 "RASHNDOCT" 中部分字母组成的子集
; s 相当于FileGetSize ,返回文件大小 , s/sb sk sm 分别代表返回字节大小、返回千字节大小,返回兆字节大小,默认字节
; t 相当于FileGetTime , 返回文件的时间,t/tm tc ta 分别代表修改时间,创建时间,上次访问时间
; v 相当于FileGetVersion ,返回文件的版本
; l 相当于FileGetShortcut ,返回快捷方式的属性 ,
; lt 用来存储快捷方式目标的变量名 (不包含它可能含有的任何参数). 例如: C:\WINDOWS\system32\notepad.exe
; lf 用来保存快捷方式工作目录的变量名. 例如: C:\My Documents. 如果在字符串中存在像 %WinDir% 这样的环境变量, 那么解决它们的一种方法是使用
; la 用来保存快捷方式参数的变量名 (如果没有则为空).
; ld 用来保存快捷方式注释的变量名 (如果没有则为空).
; li 用来保存快捷方式图标文件名的变量名 (如果没有则为空).
; ln 用来保存快捷方式图标在图标文件中编号的变量名 (如果没有则为空). 这个值通常为 1, 表示首个图标.
; lr 用来存储快捷方式初始运行方式的变量名, 其值为下列数字的其中一个: 1: 普通 3: 最大化 7: 最小化
; n 获取文件名/文件夹名
; mFileGetAttrib(file,type) {{{3
mFileGetAttrib(file,type){
If Not FileExist(file) {
ErrorLevel := True
Return
}
If RegExMatch(type,"(`,f)|^f") {
SplitPath, file, fn, ff, fe, fo, fd
fd .= "\"
}
If RegExMatch(type,"(`,l)|^l") And RegExmatch(file,"i)\.lnk$")
FileGetShortcut,%file%,lt,lf,la,ld,li,ln,lr
If RegExMatch(type,"(`,a)|^a")
FileGetAttrib, a, %file%
If RegExMatch(type,"(`,s)|^s") {
FileGetSize, s, %file%
sb := s
sk := Round((sb/1024))
sm := Round((sk/1024))
sg := Round((sm/1024))
;FileGetSize, sk, %file% ,k
;FileGetSize, sm, %file% ,m
}
If RegExMatch(type,"(`,t)|^t") {
FileGetTime, t, %file% , m
FormatTime , t , %t% , yyyy年MM月dd日 HH:mm:ss
tm := t
FileGetTime, tc, %file% , c
FileGetTime, ta, %file% , a
}
If RegExMatch(type,"(`,v)|^v") {
FileGetVersion, v, %file%
}
If RegExMatch(type,"(`,n)|^n") {
If InStr(FileExist(file),"D") {
Loop,Parse,file
{
If RegExMatch(Substr(file,1-A_Index,1),"\\")
{
n:= Substr(file,Strlen(file)-A_index+2)
Break
}
}
}
Else
Splitpath,file,n
}
r := []
Loop,Parse,Type,`,
r[A_LoopField] := %A_LoopField%
return r
}
; WindowSwitch(f,switch) {{{2
WindowSwitch(f,switch)
{
Splitpath,f,filename,dir,,namenoext,drive
If RegExMatch(switch,"i)\{window:file\}")
return filename
If RegExMatch(switch,"i)\{window:dir\}")
return dir
If RegExMatch(switch,"i)\{window:name\}")
return namenoext
If RegExMatch(switch,"i)\{window:drive\}")
return drive
}
; EscapeSwitch(switch) {{{2
; 转义
EscapeSwitch(switch){
;switch := RegExReplace(switch,"(^\{)|(\}$)")
switch := RegExReplace(switch,"\\(?=[\[\]\{\}])")
return switch
}
; SR_Engine_Exec() {{{1
; 此函数负责执行配置
; Object: 保存配置内容,根据设置执行对应的功能
SR_Engine_Exec(Object)
{
Global SR_Save
If not Isobject(SR_Save)
SR_Save := []
If RegExMatch(Object.Method,"i)^Run$")
{
Target := Object.file Object.Param
wDir := Object.WorkingDir
If Object.State = 1
Run,%Target%,%wDir%,Min UseErrorLevel
Else If Object.State = 2
Run,%Target%,%wDir%,Max UseErrorLevel
Else If Object.State = 3
Run,%Target%,%wDir%,Hide UseErrorLevel
Else
Run,%Target%,%wDir%,UseErrorLevel
}
If RegExMatch(Object.Method,"i)^RunWait$")
{
Target := Object.file Object.Param
wDir := Object.WorkingDir
If Object.State = 1
RunWait,%Target%,%wDir%,Min UseErrorLevel
Else If Object.State = 2
RunWait,%Target%,%wDir%,Max UseErrorLevel
Else If Object.State = 3
RunWait,%Target%,%wDir%,Hide UseErrorLevel
Else
RunWait,%Target%,%wDir%,UseErrorLevel
}
If RegExMatch(Object.Method,"i)^WinActivate$")
{
If Strlen(c:=Object.Class)
{
If (s:=Object.Wait)
WinWait,ahk_class %c%,,%s%
WinActivate,ahk_class %c%
}
Else
{
If Object.Fuzzy
{
TMM := A_TitleMatchMode
SetTitleMatchMode, 2
}
t := Object.Title
If (s:=Object.Wait)
WinWait,%t%,,%s%
WinActivate,%t%
If Object.Fuzzy
SetTitleMatchMode, %TMM%
}
}
If RegExMatch(Object.Method,"i)^WinMaximize$")
{
If Strlen(c:=Object.Class)
WinMaximize,ahk_class %c%
Else
{
If Object.Fuzzy
{