-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReTAR.ahk
More file actions
232 lines (194 loc) · 6.3 KB
/
ReTAR.ahk
File metadata and controls
232 lines (194 loc) · 6.3 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
#SingleInstance force
#Include .\Lib\AutoComplete.ahk
#Include .\Lib\_eval.ahk
#Include .\Lib\FolderMenuList v1.1.2.ahk
SetTitleMatchMode 3 ;窗口标题必须和 WinTitle 完全一致才能匹配,否则热键在有“ReTAR”字样的窗口不起效
if !FileExist("Config.ini")
IniWrite("cmd", "Config.ini", "cmd", "path") ;如果不存在 config.ini,则自动创建,并创建一个[cmd] section,其 path 为 cmd
SectionNames := IniRead("Config.ini") ; 返回一个以换行符(`n) 分隔的 section 列表
CBXListTemp := StrReplace(SectionNames, "`nCount") ;去掉 section 列表中的 count
CBXList := StrSplit(CBXListTemp, "`n") ;分割成字符串数组,传递给 combobox 当列表参数
CreateGUI
CreateMenu
MainGui.Hide
Return
CreateGUI()
{
global
MainGui := Gui("+ToolWindow -Caption", "ReTAR")
MainGui.BackColor := "37377D"
MainGui.SetFont("s20", "Tahoma")
CBX := MainGui.Add("ComboBox", "x12 y9 w470 h180 vCBX", CBXList)
CBX.OnEvent("Change", Calc)
MainGui.SetFont("S12 c80FFFF", "Tahoma")
FixedText := MainGui.Add("Edit", "x12 y+8 w540 h25 ReadOnly Background37377D")
GoBtn := MainGui.Add("Button", "Default x492 y9 w60 h40", "Go")
GoBtn.OnEvent("Click", RunApp)
MainGui.Show("Center h90 w565")
}
CreateMenu()
{
global
Tray := A_TrayMenu
Tray.delete ; 删除标准菜单项目,不显示 ahk 自己的菜单
TraySetIcon("ReTAR.ico")
A_IconTip := "ReTAR" ; 托盘提示信息
Tray.Add "运行统计 (&E)", RunCount
Tray.Add
Tray.Add "开机启动 (&S)", AutoRun
Tray.Add "重新加载 (&R)", RL
Tray.Add "打开配置文件 (&C)", EditConfig
Tray.Add "打开脚本目录 (&F)", OpenDir
Tray.Add
Tray.Add "关于 (&A)", About
Tray.Add "退出 (&X)", ExitReTAR
If FileExist(A_Startup "\ReTAR.lnk")
Tray.Check "开机启动 (&S)"
}
OpenDir(*)
{
Run A_ScriptDir
}
RunCount(*)
{
TraySetIcon("ReTAR.ico") ;设置窗口图标
MyGui := Gui()
LV := MyGui.Add("ListView", "Grid r30 w405", ["快捷方式","运行次数","上次使用","添加日期"])
SectionNames := IniRead("Config.ini") ;获取所有 sections
SectionArray := StrSplit(SectionNames, "`n") ;将所有 sections 分割为数组
loop SectionArray.Length
{
sec := SectionArray[A_Index]
cnt := IniRead("Config.ini", sec, "count")
lst := IniRead("Config.ini", sec, "LastUse")
date := IniRead("Config.ini", sec, "date")
LV.Add(, sec, cnt, lst, date)
}
LV.ModifyCol ; 根据内容自动调整每列的大小.
LV.ModifyCol(2, "AutoHdr Integer") ; 为了进行排序, 指出列 2 是整数.
MyGui.Title := "运行统计"
MyGui.Show
}
ShowUI(*)
{
MainGui.Show
CBX.Text := ""
}
`::
{
if WinActive("ReTAR ahk_class AutoHotkeyGUI")
{
MainGui.Hide
}
else
{
ShowUI()
}
}
#Hotif WinActive("ReTAR")
Esc::
{
MainGui.Hide
}
AutoRun(*)
{
If FileExist(A_Startup "\ReTAR.lnk")
{
FileDelete A_Startup "\ReTAR.lnk"
Tray.Uncheck("开机启动 (&A)")
}
else
{
FileCreateShortcut A_ScriptFullPath, A_Startup "\ReTAR.lnk", A_ScriptDir
Tray.Check("开机启动 (&A)")
}
}
EditConfig(*)
{
Run "Config.ini"
}
RL(*)
{
Reload
}
About(*)
{
global AboutGUI := gui(, "关于 ReTAR")
AboutGUI.SetFont("s9", "Segoe UI")
OKBtn := AboutGUI.Add("Button", "x152 y270 w75 h25", "确定")
OKBtn.OnEvent("Click", CloseAbout)
AboutGUI.SetFont("s20", "Microsoft Sans Serif")
AboutGUI.Add("Text", "x54 y13 w272 h35", "ReTAR Version 0.9.6")
AboutGUI.SetFont("s9", "Segoe UI")
AboutGUI.Add("Text", "x130 y50 w200 h30", "Powered by AHK v2")
AboutGUI.SetFont("s9", "Segoe UI")
AboutGUI.Add("Text", "x120 y70 w148 h30", "Copyright © 2022-2025 FF `nUpdate: 2025-09-12 22:45")
AboutGUI.Add("Picture", "x36 y55 w48 h48", "ReTAR.ico")
AboutGUI.Add("text", "x121 y107 w150 h2 +0x10")
AboutGUI.Add("Link", "x45 y117 w318 h137", 'Icon:`n<a href="https://www.iconfinder.com/iconsets/military-and-guns">Military and Guns icon pack</a> - by Abderraouf omara`n`nComponents:`n<a href="https://www.reddit.com/r/AutoHotkey/comments/10wufmn/help_with_ahk_v2_gui_with_combobox_adding/?rdt=58525">AutoComplete</a> - by Ark565 && skyracer85`n<a href="https://github.com/TheArkive/eval_ahk2">eval_ahk2</a> - by TheArkive`nSpecial thanks to <a href="https://www.macrocreator.com/">Pulover</a> for <a href="https://github.com/pulover/cbautocomplete">CbAutoComplete</a> && <a href="https://github.com/pulover/eval">eval</a>')
AboutGUI.Show("w380 h306")
}
CloseAbout(*)
{
AboutGui.Destroy()
}
ExitReTAR(*)
{
ExitApp
}
IsVarInArr(item, arr)
{
for i in arr
if i = item
return true
return false
}
RunApp(*)
{
if IsVarInArr(OutputVar, CBXList) = true ;检查 edit 输入是否在 section 列表中
{
try Run PathVar
catch
{
MsgBox "路径未找到,请检查配置", "路径错误", "Iconx"
}
else
{
CountNumber := IniRead("Config.ini", OutputVar, "count", 0) ;读取 ini 中对应 section 下的运行计数("count" key),如果无此 key,则默认创建为 0
CountNumber += 1
IniWrite(CountNumber, "Config.ini", OutputVar, "count") ;运行计数 +1 后写回
TimeString := FormatTime(A_Now, "yyyy-MM-dd HH:mm")
IniWrite(TimeString, "Config.ini", OutputVar, "LastUse") ;写入最后运行日期时间
}
MainGui.Hide
}
else
{
if IsNumber(FixedText.Text)
{
A_Clipboard := ""
A_Clipboard := FixedText.Text
MsgBox "结果是 " FixedText.Text ",已复制到剪贴板。", "计算结果"
MainGui.Hide
}
else
{
MsgBox "请在 ini 文件中添加相应配置", "错误", "48"
MainGui.Hide
}
}
}
Calc(*)
{
global OutputVar := CBX.Text
AutoComplete(CBX, CBXList)
if IsVarInArr(OutputVar, CBXList) = true ;检查 edit 输入是否在 section 列表中
{
global PathVar := IniRead("Config.ini", OutputVar, "path")
FixedText.Text := PathVar
}
else
{
try FixedText.Text := eval(CBX.Text, test := false)
}
}