-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththkmc.ahk
956 lines (804 loc) · 22.2 KB
/
thkmc.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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Touhou Keyboard Mapping Changer
;;; Written by wz520
;;; Tested AutoHotkey Version: 1.1.30.01
;;; Download on Github: https://github.com/wz520/thkmc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#NoEnv
#SingleInstance, force
#Persistent
#include gamedata.ahk
#include KeyNamesDX.ahk
#include <utils>
#include <PatchProcessor>
#include <LVRow>
#include <wzclipboard>
#include <LVUtils>
#include <PEHelper>
#include <WZSplashWindow>
title = THKMC
helpfilecmd = https://wz520.github.io/thkmc/help.html
g_bakfilesuffix = .thkmcbackup ; 备份文件后缀
g_inifilepath = thkmc.ini ; 键位配置文件
g_configfilepath = config.ini ; 程序配置文件
SetWorkingDir, %A_ScriptDir%
ShowLog := True
; #NoTrayIcon ;; 由于要用 TrayTip 显示一些提示,所以不能禁掉 TrayIcon
; 不过要把TrayTip菜单给删掉(仅编译版)
if ( A_IsCompiled ) {
Menu, Tray, NoStandard
}
doBackup(inifilepath, exefilepath) {
global ddlBackup
global g_bakfilesuffix
Gui, Submit, NoHide
if ( ddlBackup = 1 || ddlBackup = 2 ) {
backupfilepath=%exefilepath%%g_bakfilesuffix%
if ( ddlBackup = 1 ) {
; 1 = 如果备份文件已存在,则不进行备份
IfExist, %backupfilepath%
{
AddLog("【备份】备份文件已存在,跳过")
backupfilepath=
}
}
if ( backupfilepath != "" ) {
FileCopy, %exefilepath%, %backupfilepath%, 1
AddLog("【备份】成功!")
}
}
}
doProcess(patch_processor, filename, bTestMode) {
if ( patch_processor.isEXEThisGame() ) {
if ( bTestMode ) {
AddLog("【提示】“测试模式”已开启。EXE文件不会被修改,备份文件也不会被创建。")
}
AddLog("【目标文件】" . filename)
AddLog("【所属游戏】" . patch_processor._d.gamenameCN)
patch_processor.doPatch()
patch_processor.updateEXECache()
if ( bTestMode ) {
return True ; 如果勾选“测试模式”,则在此直接返回
}
else {
doBackup(patch_processor._d.inifilepath, filename)
fileobj := FileOpen(filename, "w")
if ( isObject(fileobj) ) {
; 打开成功
filesize := patch_processor._exesize
if ( fileobj.RawWrite(patch_processor._pEXEData, filesize) = filesize ) {
fileobj.Close()
return True
}
else
throw Exception("写入文件失败", filename)
}
else
throw Exception("以写入方式打开文件失败", filename)
}
}
return False
}
; throw exception on error
; outvar: exedata and filesize.
; if file not found, filesize will be set to -1, and exedata will be
; set to an empty string
readEXEData(filename, ByRef exedata, ByRef filesize) {
filesize := -1
exedata =
; NOTE:
; When inside a try-block, FileOpen() will throw an exception on error.
; To throw our customized error when the file cannot be opened, we need
; to add one more try-block here to prevent the exeuction flow from
; jumping to the outer catch-block.
fileobj =
try {
fileobj := FileOpen(filename, "r")
}
catch {
; nothing
}
if ( !isObject(fileobj) ) {
; NOTE:
; If we don't put a try-block above, and this function is being
; executed inside a try-block, this line would be NEVER executed.
throw Exception("以读取方式打开文件失败或者文件不存在", filename)
}
filesize := fileobj.Length
;; 目前支持的游戏中还没有这么大的EXE
if ( filesize > 1048576 ) {
throw Exception("这文件太大我不敢看…… > _ <", filename)
}
;; FileOpen() 碰到带 BOM 的 UTF-8 或 UTF-16 的文本文件会自动跳过 BOM,
;; 这会导致下面抛出“读取文件失败”异常
;; 所以要先手动定位到文件起始处
fileobj.Seek(0)
; 分配内存用于存储 EXE 的二进制数据
VarSetCapacity(exedata, filesize, 0)
; 读取
if ( fileobj.RawRead( exedata, filesize ) != filesize ) {
throw Exception("读取文件失败", filename)
}
fileobj.Close()
}
askInputFilename() {
Gui, +OwnDialogs
FileSelectFile, files, M3, %A_ScriptDir%, 请选择一个东方 STG 的主程序文件, 应用程序文件 (*.exe)
if ( errorlevel != 0 || files = "" ) {
; throw Exception("由于你没有选择文件,于是我不知道该修改啥……", "*")
Exit
}
dir=
filepaths := []
Loop, parse, files, `n
{
if (A_Index = 1)
dir := A_LoopField
else
filepaths.Push(dir . "\" . A_LoopField)
}
return filepaths
}
; filename 不得为空,否则扔异常
; 本函数无返回值。若有任何错误,则扔异常
; NOTE: It's not recommended to call this function directly. Use tryDoWork() instead.
_doWork(filename) {
if ( filename="" ) {
throw Exception("内部错误ERR233:没有文件名")
}
readEXEData( filename, exedata, filesize )
succeeded := False
global THKMC_GameIDList, chkTestMode
Gui, 1:Default
Gui, Submit, NoHide
for k, id in THKMC_GameIDList {
gamedata := new THKMC_GameData%id%()
patch_processor := new THKMC_PatchProcessor(&exedata, filesize, gamedata)
if ( doProcess(patch_processor, filename, chkTestMode) ) {
AddLog("`r`n修改成功!`r`n")
succeeded := True
break
}
}
if ( !succeeded ) {
wocao := []
wocao.Push("此乃何物?吾不识也。")
wocao.Push("无法识别的文件。")
wocao.Push("啊哈哈,琪露诺看不懂。")
wocao.Push("对不起,我的智商刚刚下线,这是啥我看不懂……")
throw Exception(array_choose(wocao), filename)
}
}
; e is an Exception object
addErrorObjectToLog(e, bShow:=False) {
msg := "【错误】" e.message
if ( e.what ) {
msg .= "`r`n【相关文件】" e.what
}
AddLog(msg, True)
if ( bShow ) {
DoShowLog()
ClearLog()
}
}
; filenames 可以接受多个文件(使用数组)
tryDoWork(filenames="") {
global HasError
global chkAlwaysAddToList
filepaths := !IsObject(filenames)
? [filenames]
: filenames.Count() = 0
? [""]
: filenames
if ( filepaths[1] = "" ) {
filepaths := askInputFilename()
}
Gui, 1:Default
Gui, Submit, NoHide
for k, f in filepaths {
succeeded := False
if ( k > 1 ) {
AddLog("`r`n`r`n####################### 分割线 #######################`r`n`r`n")
}
try {
_doWork(f)
succeeded := True
}
catch e {
addErrorObjectToLog(e)
}
if ( chkAlwaysAddToList || succeeded ) {
addFileToList(f, True)
}
}
DoShowLog()
refreshFileList()
; DEBUG
if ( 0 ) {
ExitApp, HasError ? 1 : 0
}
else {
; 清除log
return ClearLog()
}
}
;; ------------
;; GUI 相关
;; ------------
assertLVHasSelection() {
Gui, +OwnDialogs
for c, r in LVRow {
}
if ( c <= 0 ) {
global title
MsgBox, 0x40, %title%, 没有高亮的项目 poi
Exit
}
}
; atTop: 添加到最上面
; return a value returned by LV_Add() or LV_InsertIfNotExist()
addFileToList(filename, atTop:=False) {
global g_ImageListID, g_bakfilesuffix
backupfilepath=%filename%%g_bakfilesuffix%
backupfileexists := FileExist(backupfilepath) ? "√" : "×"
; 获取文件属于哪个游戏
gamenameCN := "未知"
e = ; clear error object
try {
readEXEData(filename, exedata, filesize)
global THKMC_GameIDList
for k, id in THKMC_GameIDList {
gamedata := new THKMC_GameData%id%()
patch_processor := new THKMC_PatchProcessor(&exedata, filesize, gamedata)
if ( patch_processor.isEXEThisGame() ) {
gamenameCN := gamedata.gamenameCN
break
}
}
}
catch e {
gamenameCN := Format("【{:s}】", e.Message)
}
; 图标
if ( isObject(e) ) { ; there was an error
iconID := 9999
}
else {
iconID := IL_Add(g_ImageListID, filename, 1)
}
; 其他文件属性
try {
FileGetTime, filetime, %filename%
FormatTime, filetimestring, %filetime% R T0
}
catch e {
filetimestring = 无可奉告
}
try {
FileGetAttrib, fileattrib, %filename%
}
catch e {
fileattrib = 布吉岛
}
filesize := DecimalMark(filesize, 0)
result := atTop
? LV_InsertIfNotExist(filename, 1, 1, "Icon" . iconID, filename, gamenameCN, filesize, filetimestring, fileattrib, backupfileexists)
: LV_Add("Icon" . iconID, filename, gamenameCN, filesize, filetimestring, fileattrib, backupfileexists)
return result
}
loadFileList() {
; 当文件列表很长时可能需要一点时间。所以显示一个提示框
splash := new WZSplashWindow("Praying" , "正在载入文件列表", "少女祈祷中...")
splash.Show()
try {
loop, Read, recentfiles.txt
{
l := A_LoopReadLine
; 忽略空行和包含 *、? 的行
if ( l = "" || RegExMatch(l, "[*?]") ) {
continue
}
addFileToList(l)
}
}
finally {
LAutoSizeColumn()
splash.Destroy()
}
}
saveFileList() {
fp := FileOpen("recentfiles.txt", "w`n", "UTF-16")
if ( IsObject(fp) ) {
loop, % LV_GetCount()
{
result := LV_GetText(l, A_Index)
if (result)
fp.WriteLine(l)
}
fp.Close()
}
}
refreshFileList() {
saveFileList()
LV_Delete()
loadFileList()
}
createINIFile(inifilepath) {
filecontent=
(LTrim
; 关于本设置文件的完整说明,请参看 thkmc_sample.ini
[Default]
UP=W
DOWN=S
LEFT=A
RIGHT=D
Z=j
X=k
C=l
LSHIFT=i
)
fileobj := FileOpen(inifilepath, "w`n", "UTF-16")
if ( isObject(fileobj) ) {
if (fileobj.Write(filecontent)) {
fileobj.Close()
}
else
throw Exception("写入文件失败", inifilepath)
}
else
throw Exception("以写入方式打开文件失败", inifilepath)
}
ensureINIExists() {
global title, g_inifilepath
IfNotExist, %g_inifilepath%
{
createINIFile(g_inifilepath)
Gui, +OwnDialogs
msg=【%g_inifilepath%】文件不存在。`r`n`r`n已自动生成。
MsgBox, 64, %title%, %msg%
}
}
confirmApply(filepaths) {
global vCA_OK
IsOK := False
txtFiles := array_join(filepaths, "`r`n")
Gui, WndConfirm:New, +LabelCA_ +Owner1 -SysMenu -Resize +LastFound, 确认 - THKMC
Gui, Color, Fuchsia
Gui, Add, Edit, w500 r25, 你选择的文件是:`r`n%txtFiles%`r`n`r`n真的要将 INI 文件中的键位映射设置应用到这些程序上吗?
Gui, Add, Button, gCA_OK Default w150 vvCA_OK, 是(&Y)
Gui, Add, Button, gCA_Close x+20 w150 , 否(&H)
GuiControl, Focus, vCA_OK
Gui, Show, Center AutoSize
Gui, 1:+Disabled
WinWaitClose
return IsOK
CA_OK:
IsOK := True
; no return
CA_Close:
CA_Cancel:
Gui, 1:-Disabled
Gui, WndConfirm:Destroy
return
}
LOpenINI() {
global g_inifilepath
ensureINIExists()
Run, %g_inifilepath%
}
LOpenAndApply() {
assertLVHasSelection()
filepaths := []
for c, row in LVRow {
LV_GetText(filename, row)
filepaths.Push(filename)
}
if (confirmApply(filepaths)) {
tryDoWork(filepaths)
}
}
; ListView 按键处理
LFileLV() {
if ( A_GuiEvent = "DoubleClick" ) {
LRunEXE()
}
else if ( A_GuiEvent = "K" ) {
key := GetKeyName(Format("vk{:x}", A_EventInfo))
ShortcutkeyToFuncMap := {}
if ( GetKeyState("Ctrl") && !GetKeyState("Alt") ) {
ShortcutkeyToFuncMap["G"] := Func("LOpenAndApply")
ShortcutkeyToFuncMap["D"] := Func("LOpenFolder")
ShortcutkeyToFuncMap["B"] := Func("LRestoreFromBackup")
ShortcutkeyToFuncMap["V"] := Func("LRunVPatch")
ShortcutkeyToFuncMap["C"] := Func("LRunCustom")
ShortcutkeyToFuncMap["Z"] := Func("LRunNyasama")
ShortcutkeyToFuncMap["A"] := Func("LSelectAll")
ShortcutkeyToFuncMap["S"] := Func("LOpenShanghaiAlice")
}
else if ( GetKeyState("Alt") && !GetKeyState("Ctrl") ) {
ShortcutkeyToFuncMap["Enter"] := Func("LOpenFileProperties")
}
else {
ShortcutkeyToFuncMap["NumpadDel"] := Func("LRemove")
ShortcutkeyToFuncMap["F5"] := Func("refreshFileList")
}
if ( ShortcutkeyToFuncMap.HasKey(key) ) {
ShortcutkeyToFuncMap[key].Call()
}
}
}
LOpenEXE() {
tryDoWork()
}
LRunEXE() {
assertLVHasSelection()
for c, row in LVRow {
LV_GetText(filename, row)
CriticalRun(filename, "CMDDIR")
}
}
RunOtherFileInEXEDir(newfilename) {
assertLVHasSelection()
for c, row in LVRow {
LV_GetText(filename, row)
SplitPath, filename, , dir
filename=%dir%\%newfilename%
CriticalRun(filename, "CMDDIR")
}
}
LRunVPatch() {
RunOtherFileInEXEDir("vpatch.exe")
}
LRunCustom() {
RunOtherFileInEXEDir("custom.exe")
}
LRunNyasama() {
assertLVHasSelection()
for c, row in LVRow {
LV_GetText(filename, row)
SplitPath, filename, , dir, ext, namenoext
filename=%dir%\%namenoext%c.%ext%
CriticalRun(filename, "CMDDIR")
}
}
LSelectAll() {
LV_Modify(0, "Select")
}
; 返回错误信息,若有错误则扔异常
doRestoreFromBackup( filename, bKeep )
{
global g_bakfilesuffix
bakfilename = %filename%%g_bakfilesuffix%
if ( !FileExist(bakfilename) ) {
throw Exception("备份文件不存在", filename)
}
if ( bKeep ) {
FileCopy, %bakfilename%, %filename%, 1
}
else {
FileMove, %bakfilename%, %filename%, 1
}
}
LRestoreFromBackup() {
assertLVHasSelection()
global title, g_bakfilesuffix
MsgBox, 0x33, %title%,
(LTrim
恢复后是否要保留备份文件(*%g_bakfilesuffix%)?
【是】 :恢复并保留备份文件
【否】 :恢复并删除备份文件
【取消】:不做任何事情
)
bKeep := True
IfMsgBox, Cancel
{
return
}
else IfMsgBox, No
{
bKeep := False
}
success_count := 0
for c, row in LVRow {
LV_GetText(filename, row)
try {
doRestoreFromBackup(filename, bKeep)
success_count++
}
catch e {
e.what := filename
addErrorObjectToLog(e, True)
}
}
refreshFileList()
TrayTip, %title%, 成功恢复了 %success_count% 个文件。
}
LDeleteBackup() {
assertLVHasSelection()
global title, g_bakfilesuffix
MsgBox, 0x134, %title%, 真的要【从磁盘上】删除所有选中项目的备份文件(*%g_bakfilesuffix%)吗?
IfMsgBox, No
{
return
}
success_count := 0
for c, row in LVRow {
LV_GetText(filename, row)
try {
bakfile =%filename%%g_bakfilesuffix%
IfExist, %bakfile%
{
FileDelete, %bakfile%
success_count++
}
}
catch e {
; ignore errors
}
}
refreshFileList()
TrayTip, %title%, 成功删除了 %success_count% 个备份文件。
}
; return a list
LVGetAllSelection() {
files := []
for c, row in LVRow {
LV_GetText(filename, row)
files.Push(filename)
}
return files
}
LCopyFullPath() {
assertLVHasSelection()
files := LVGetAllSelection()
c := files.MaxIndex()
if ( c ) {
global title
Clipboard := array_join(files)
TrayTip, %title%, 复制%c%个文件的路径到剪贴板成功!
}
}
LCopyOrCutFile(itemname) {
assertLVHasSelection()
bCopy := InStr(itemname, "复制") ? True : False
files := LVGetAllSelection()
c := files.MaxIndex()
if ( c ) {
global title
verb := bCopy ? "复制" : "剪切"
CopyFilesToClipboard(files, bCopy)
TrayTip, %title%, %verb%%c%个文件到剪贴板成功!
}
}
LOpenFolder() {
assertLVHasSelection()
for c, row in LVRow {
LV_GetText(filename, row)
; NOTE: Run 貌似没用,换成 DllCall()
; Run, *open explorer.exe /select,%filename%
; DllCall("shell32.dll\ShellExecute", "ptr", 0, "str", "open", "str", "Explorer.exe", "str", " /select," . filename, "ptr", 0, "int", 10, "int")
; NOTE: 不不不,其实 Run 还是有用的,只是我参数没写对。>_<
Run, *open explorer.exe /select`,%filename%, , UseErrorLevel
}
}
LOpenShanghaiAlice() {
cmd = *open %A_AppData%\ShanghaiAlice
CriticalRun(cmd)
}
LOpenFileProperties() {
assertLVHasSelection()
for c, row in LVRow {
LV_GetText(filename, row)
Run, properties %filename%, , UseErrorLevel
if ( ErrorLevel = "ERROR" ) {
global title
TrayTip, %title% - 打开文件属性失败, 文件:%filename%, ,3
}
}
}
;; Load/Save Config
loadConfig(key, default) {
global g_configfilepath, g_inifilepath
IniRead, chkstate, %g_configfilepath%, thkmc, %key%
if ( chkstate = "ERROR" ) {
IniRead, chkstate, %g_inifilepath%, thkmc, %key%, %default%
}
return chkstate
}
saveConfig() {
global ddlBackup, chkTestMode, chkAlwaysAddToList, g_configfilepath
Gui, Submit, NoHide
IniWrite, %ddlBackup%, %g_configfilepath%, thkmc, DoBackup
IniWrite, %chkTestMode%, %g_configfilepath%, thkmc, TestMode
IniWrite, %chkAlwaysAddToList%, %g_configfilepath%, thkmc, AlwaysAddToList
}
; return the count of the deleted items
LRemove() {
assertLVHasSelection()
global title
delcount := 0
MsgBox, 0x34, %title%, 真的要清除列表中所有已选中的项目吗?
IfMsgBox, Yes
{
rownum := 0
Loop {
rownum := LV_GetNext(rownum)
if ( rownum ) {
LV_Delete(rownum--)
delcount++
} else
break
}
}
return delcount
}
LRemoveAll() {
global title
Gui, +OwnDialogs
MsgBox, 0x34, %title%, 真的要清除列表中的所有项目吗?
IfMsgBox, Yes
{
LV_Delete()
}
}
GuiSize(GuiHwnd, EventInfo, Width, Height) {
if ( EventInfo != 1 ) {
neww := Width - 20
newh := Height - 120
GuiControl, Move, vFileLV, w%neww% h%newh%
}
}
; 拖拽处理
GuiDropFiles(GuiHwnd, FileArray, CtrlHwnd, X, Y) {
_files := []
splash=
for k, f in FileArray {
attr := FileExist(f)
if ( InStr(attr, "D") ) {
if ( !IsObject(splash) ) {
splash := new WZSplashWindow("SearchingEXE" , "正在搜索 .exe 文件", "少女祈祷中...")
splash.Show()
}
loop, Files, %f%\*.exe, R
{
_files.Push(A_LoopFileFullPath)
}
}
else {
_files.Push(f)
}
}
if ( IsObject(splash) ) {
splash.Destroy()
}
if (confirmApply(_files)) {
tryDoWork(_files)
}
}
GuiContextMenu(GuiHwnd, CtrlHwnd, EventInfo, IsRightClick, X, Y) {
if (A_GuiControl = "vFileLV") {
Menu, mnuLV, Show, %A_GuiX%, %A_GuiY%
}
}
; ------------------------
; -- ENTRY
; ------------------------
; 创建 GUI
Gui, +Hwndg_hWnd
Gui, Add, Button, gLOpenINI, 编辑 thkmc.ini(&E)
Gui, Add, Button, gLOpenEXE x+10, 打开程序并应用补丁(&O)
Gui, Add, Button, gLOpenAndApply x+10 hwndhBtnApply, 应用补丁(&A)
Gui, Add, Button, gLRunEXE x+10 hwndhBtnRun +Default, 运行(&R)
Gui, Add, Button, grefreshFileList x+10 y5 hwndhBtnRefresh, 刷新(&E)
Gui, Add, Button, gRunHelpAndExit hwndhBtnHelp x+10 y5, 帮助(&H)
Gui, Add, Custom, ClassSysLink hwndhSysLinkAbout gLSysLinkEvent x+5 w50 r1 y10, <a>关于...</a>
Gui, Add, Text, xm+0, 备份到 *%g_bakfilesuffix% ?
cfgvalue := loadConfig("DoBackup", 1)
Gui, Add, DropDownList, AltSubmit vddlBackup x+10 yp-3 w210 Choose%cfgvalue%, 只在备份文件不存在时备份(推荐)|总是备份(若备份已存在则覆盖)|不备份(不推荐)
cfgvalue := loadConfig("TestMode", 0)
Gui, Add, Checkbox, x+10 yp-3 h30 vchkTestMode Checked%cfgvalue%, 测试模式(&T)
cfgvalue := loadConfig("AlwaysAddToList", 0)
Gui, Add, Checkbox, x+10 h30 vchkAlwaysAddToList Checked%cfgvalue%, 总是添加至列表(&P)
Gui, Add, Text, x10, 查看更新:
Gui, Add, Custom, ClassSysLink hwndhSysLink gLSysLinkEvent x+5 w40 r1, <a>喵玉殿</a>
Gui, Add, Custom, ClassSysLink hwndhSysLinkGitHub gLSysLinkEvent x+5 w40 r1, <a>GitHub</a>
g_updatelink = http://bbs.nyasama.com/forum.php?mod=viewthread&tid=78904
g_githublink = https://github.com/wz520/thkmc
Gui, Add, Text, xm CBlue, ※最近打开的文件(双击可运行程序,右击有菜单):
Gui, Add, ListView, vvFileLV xm w740 h400 gLFileLV AltSubmit LV0x4000, 文件|游戏版本|大小|最后修改时间|属性|存在备份 ; LVS_EX_LABELTIP:=0x4000
LV_ModifyCol(3, "Integer") ; For sorting purposes, indicate that column 2 is an integer.
g_ImageListID := IL_Create(10)
LV_SetImageList(g_ImageListID)
Gui, +Resize +OwnDialogs
; GUI ToolTip
GuiControlGet, hCtrl, Hwnd, chkTestMode
AttachTipToControl(hCtrl, "模拟打补丁的过程:会显示修改结果,但不会创建/修改EXE文件和备份文件。`r`n【提示】若打补丁成功,仍会将文件路径添加至文件列表。")
GuiControlGet, hCtrl, Hwnd, chkAlwaysAddToList
AttachTipToControl(hCtrl, "即使打补丁失败也会将文件路径添加至文件列表。`r`n若不勾选此项, THKMC 只会在打补丁成功后才将文件路径添加至文件列表。")
AttachTipToControl(hBtnApply, "将 .INI 中的映射配置重新应用到选中的程序上")
AttachTipToControl(hBtnRun, "运行选中的游戏程序")
AttachTipToControl(hBtnRefresh, "刷新“最近打开的文件”列表")
AttachTipToControl(hBtnHelp, helpfilecmd)
AttachTipToControl(hSysLink, g_updatelink)
AttachTipToControl(hSysLinkGitHub, g_githublink)
Gui, Show, Center, %title%
GuiControl, Focus, vFileLV
; 快捷菜单
Menu, mnuLV, Add, 应用改键补丁`tCtrl+G, LOpenAndApply
Menu, mnuLV, Add
Menu, mnuLV, Add, 运行该程序`tEnter, LRunEXE
Menu, mnuLV, Default, 运行该程序`tEnter
Menu, mnuLV, Add, 运行所在目录下的 vpatch.exe`tCtrl+V, LRunVPatch
Menu, mnuLV, Add, 运行所在目录下的 custom.exe`tCtrl+C, LRunCustom
Menu, mnuLV, Add, 运行所在目录下的汉化版游戏程序(th???c.exe)`tCtrl+Z, LRunNyasama
Menu, mnuLV, Add, 打开所在目录`tCtrl+D, LOpenFolder
Menu, mnuLV, Add, 打开 ShanghaiAlice 目录`tCtrl+S, LOpenShanghaiAlice
Menu, mnuLV, Add
Menu, mnuLV, Add, 属性...`tAlt+Enter, LOpenFileProperties
Menu, mnuLV, Add
Menu, mnuLV, Add, 从备份文件恢复`tCtrl+B, LRestoreFromBackup
Menu, mnuLV, Add, 删除备份文件, LDeleteBackup
Menu, mnuLV, Add
Menu, mnuLV, Add, 复制完整路径, LCopyFullPath
Menu, mnuLV, Add, 剪切, LCopyOrCutFile
Menu, mnuLV, Add, 复制, LCopyOrCutFile
Menu, mnuLV, Add, 全选`tCtrl+A, LSelectAll
Menu, mnuLV, Add
Menu, mnuLV, Add, 移除高亮的项目`tDelete, LRemove
Menu, mnuLV, Add, 移除所有项目, LRemoveAll
Menu, mnuLV, Add
Menu, mnuLV, Add, 自动调整表格宽度, LAutoSizeColumn
Menu, mnuLV, Add, 刷新`tF5, refreshFileList
Menu, mnuLV, Add
Menu, mnuLV, Add, 关于..., LAbout
OnExit("LOnExit")
loadFileList()
return
LOnExit(ExitReason, ExitCode) {
saveFileList()
saveConfig()
}
GuiClose:
GuiEscape:
ExitApp
lSysLinkEvent:
if ( A_GuiEvent = "N" ) {
code := NumGet(A_EventInfo, A_PtrSize+4, "Int") ; NMHDR->hwndFrom
if ( code = -2 || code = -4 ) { ; NM_CLICK = -2, NM_RETURN = -4
hwndFrom := NumGet(A_EventInfo, 0, "UPtr") ; NMHDR->hwndFrom
if ( hwndFrom = hSysLink ) {
Run, %g_updatelink%
}
else if (hwndFrom = hSysLinkGitHub) {
Run, %g_githublink%
}
else if (hwndFrom = hSysLinkAbout) {
LAbout()
}
}
}
return
GetAHKVersionString() {
strIsUnicode := A_IsUnicode ? "Unicode" : "ANSI"
strIs64bit := A_PtrSize = 8 ? "64位" : "32位"
result=%A_AhkVersion% %strIsUnicode% %strIs64bit%
return result
}
LAbout() {
global title
Gui, +OwnDialogs
gamelist := THKMC_GetGameNameList()
ahkver := GetAHKVersionString()
MsgBox, 64, %title%,
(LTrim
THKMC - 东方STG专用键盘键位映射修改工具 1.40
AutoHotkey 版本:%ahkver%
Written by wz520 <[email protected]>
百度贴吧ID:天使的枷锁
支持的游戏:
%gamelist%
)
}
LAutoSizeColumn() {
LVAutoSizeHeader("vFileLV")
}