forked from MisterZakary/AHKCommand
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLauncher.ahk
More file actions
77 lines (64 loc) · 2.56 KB
/
Launcher.ahk
File metadata and controls
77 lines (64 loc) · 2.56 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
; Launcher.ahk
; Bootstrapper: Scans Commands and Texts, compiles runtime script.
#Requires AutoHotkey v2.0
#SingleInstance Force
#NoTrayIcon ; 启动器自身不显示图标
class Bootstrapper {
static Run() {
rootDir := A_ScriptDir
libPath := rootDir "\Lib\Core.ahk"
cmdDir := rootDir "\Commands"
txtDir := rootDir "\Texts"
; 临时文件路径
tempScript := A_Temp "\AHKCommand_Runtime.ahk"
if !FileExist(libPath) {
MsgBox("Error: Lib\Core.ahk not found!")
ExitApp
}
scriptContent := ""
scriptContent .= "#Requires AutoHotkey v2.0`n"
scriptContent .= "#SingleInstance Force`n"
scriptContent .= "SetWorkingDir `"" rootDir "`"`n"
scriptContent .= "#Include `"" libPath "`"`n"
;引入表单库
formPath := rootDir "\Lib\Form.ahk"
if FileExist(formPath)
scriptContent .= "#Include `"" formPath "`"`n"
; 引入用户命令脚本
if DirExist(cmdDir) {
Loop Files, cmdDir "\*.ahk" {
scriptContent .= "#Include `"" A_LoopFileFullPath "`"`n"
}
}
; 生成文本加载指令
if DirExist(txtDir) {
Loop Files, txtDir "\*.txt", "R"
{
fileName := A_LoopFileName
; 修复:查找最后一个点,处理文件名中有多个点的情况(如"新闻(新媒体).txt")
lastDotPos := InStr(fileName, ".", , -1)
if (lastDotPos > 0)
nameNoExt := SubStr(fileName, 1, lastDotPos - 1)
else
nameNoExt := fileName ; 没有扩展名的情况
parts := StrSplit(nameNoExt, "__", , 2)
trigger := parts[1]
desc := (parts.Length > 1) ? parts[2] : ""
safePath := StrReplace(A_LoopFileFullPath, "`"", "`"`"")
scriptContent .= "App.LoadText(`"" safePath "`", `"" trigger "`", `"" desc "`")`n"
}
}
; [关键修改] 将项目根目录路径传递给 Init 函数
scriptContent .= "`nApp.Init(`"" rootDir "`")"
try {
if FileExist(tempScript)
FileDelete(tempScript)
FileAppend(scriptContent, tempScript, "UTF-8")
; 隐藏启动,无窗口闪烁
Run(A_AhkPath " `"" tempScript "`"", , "Hide")
} catch as err {
MsgBox("Failed to launch: " err.Message)
}
}
}
Bootstrapper.Run()