-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLibreDeck Server.ahk
More file actions
268 lines (246 loc) · 7.1 KB
/
LibreDeck Server.ahk
File metadata and controls
268 lines (246 loc) · 7.1 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
; OS Version ...: > Windows 10
; Requires AutoHotkeyU32
;@Ahk2Exe-SetName LibreDeck Server
;@Ahk2Exe-SetDescription Macro Panel Server
;@Ahk2Exe-SetVersion 0.4.6
;@Ahk2Exe-SetCopyright 2026`, elModo7
;@Ahk2Exe-SetOrigFilename LibreDeck Server.exe
; INITIALIZE
; *******************************
#SingleInstance,Force
SetBatchLines, -1
#NoEnv
#Persistent
global versionNumber := "0.4.6"
global clientVersion := versionNumber " - elModo7 / VictorDevLog " A_YYYY
#Include <Socket>
#Include <JSON>
#Include <MD5>
#Include <SplashScreen>
#Include <aboutScreen>
rutaSplash = ./resources/img/splash.png
SplashScreen(rutaSplash, 3000, 545, 160, 0, 0, true)
GuiControl, splashScreen:, splashTxt, % "Reading config..."
if(!FileExist("./conf/server_config.json"))
{
conf := {}
conf.builtin_ahk := 1
conf.port := 7778
conf.totalResourceSize := 0
conf.resourcePackMD5 := "MD5HashGoesHere"
conf.resourceSharePort := 7779
conf.startWithWindows := 1
gosub, guardarConfig
}
FileRead, conf, ./conf/server_config.json
global conf := ParseJson(conf)
gosub, guardarConfigShared
contextcolor() ; Dark Theme
; TRAY MENU
; *******************************
Menu, tray, NoStandard
Menu, tray, tip, % "LibreDeck Server v" versionNumber "`n`nPorts:`nsever: " conf.port "`nresources: " conf.resourceSharePort
Menu, tray, Add, Run LibreDeck client, runClient
Menu tray, Icon, Run LibreDeck client, .\resources\img\ico\libredeck.ico
Menu, tray, Add, Use built-in AHK, toggleBuiltInAhk
Menu, tray, Add, Update Resource Pack Now, 7zImageButtons
Menu tray, Icon, Update Resource Pack Now, .\resources\img\ico\windows\compressed_folder.ico
Menu, tray, Add, Set custom Port, setPort
Menu tray, Icon, Set custom Port, .\resources\img\ico\windows\network2.ico
Menu, tray, add, Open LibreDeck Folder, openLibreDeckFolder
Menu, tray, Icon, Open LibreDeck Folder, .\resources\img\ico\windows\folder.ico
Menu, tray, Add, Run on Startup, startWithWindows
Menu tray, Icon, Run on Startup, .\resources\img\ico\windows\window_possition.ico
Menu, tray, add
Menu, tray, add, % "v" clientVersion, showAboutScreen
Menu, tray, Icon, % "v" clientVersion, .\resources\img\ico\windows\info.ico
Menu, tray, Add, Restart Server, restart
Menu tray, Icon, Restart Server, .\resources\img\ico\windows\refresh.ico
Menu, tray, add, Exit, Exit
Menu tray, Icon, Exit, .\resources\img\ico\windows\close3.ico
if(conf.builtin_ahk)
{
Menu tray, Check, Use built-in AHK
}
else
{
Menu tray, UnCheck, Use built-in AHK
}
if(conf.startWithWindows)
{
Menu, tray, Check, Run on Startup
}
else
{
Menu, tray, Uncheck, Run on Startup
}
; Create zip for sharing to clients
gosub, 7zImageButtons
gosub, startWebServer
; Start Networking
global myTcp := new SocketTCP()
myTcp.bind("0.0.0.0", conf.port)
myTcp.listen() ; Escucha
myTcp.onAccept := Func("OnTCPAccept")
Gui, SplashScreen:Destroy
Return
toggleBuiltInAhk:
if(conf.builtin_ahk)
{
conf.builtin_ahk := 0
Menu tray, UnCheck, Use built-in AHK
}
else
{
conf.builtin_ahk := 1
Menu tray, Check, Use built-in AHK
}
gosub, guardarConfig
return
guardarConfig:
FileDelete, ./conf/server_config.json
FileAppend, % JSON_Beautify(BuildJson(conf)), ./conf/server_config.json
return
guardarConfigShared:
FileRead, shared_conf, ./resources/shared/resourcePack_info.txt
FileRead, client_conf, ./conf/config.json
client_conf := ParseJson(client_conf)
shared_conf := ParseJson(shared_conf)
shared_conf.folderButtons := client_conf.folderButtons
FileDelete, ./resources/shared/resourcePack_info.txt
FileAppend, % JSON_Beautify(BuildJson(shared_conf)), ./resources/shared/resourcePack_info.txt
return
OnExit, Exit
Exit:
gosub, killPreviousInstance
ExitApp
MoverVentana:
PostMessage, 0xA1, 2,,, A
Return
OnTCPRecvServer(this)
{
global Client
data := ParseJson(this.RecvText())
try
{
Client.sendText(data.BotonVisual)
if(FileExist(data.FicheroEjecutar))
{
if(conf.builtin_ahk)
{
Run, % A_ScriptDir "\lib\autohotkey.exe " data.FicheroEjecutar
}
else
{
Run, % data.FicheroEjecutar
}
}
}
}
OnTCPAccept(this)
{
global Client
Client := this.accept()
Client.onRecv := func("OnTCPRecvServer")
Client.sendText("LibreDeck Server")
}
7zImageButtons:
Run, % """" A_ScriptDir "/lib/autohotkey.exe"" " """" A_ScriptDir """/lib/compress_and_md5.ahk""", A_ScriptDir
return
restart:
Reload
return
FileMD5(filename)
{
return CalcFileHash(filename, 0x8003, 64 * 1024)
}
setPort:
InputBox, port, Port to Use, Insert Port to use for the server:
if(Trim(port) != "" && Trim(port) >= 1 && Trim(port) <= 65535)
{
InputBox, resourceSharePort, File Port to Use, Insert Port to use for button images:
if(Trim(resourceSharePort) != "" && Trim(resourceSharePort) >= 1 && Trim(resourceSharePort) <= 65535 && Trim(port) != Trim(resourceSharePort))
{
conf.port := Trim(port)
conf.resourceSharePort := Trim(resourceSharePort)
gosub, guardarConfig
}
else
{
MsgBox, You didn't set a port or it was invalid (valid range 1-65535)!`nAlso make sure that file port and server port are different!
}
}
else
{
MsgBox, You didn't set a port or it was invalid (valid range 1-65535)!
}
return
startWebServer:
gosub, killPreviousInstance
Run, % "./lib/httpsrv.exe -d 0 -v 0 -p " conf.resourceSharePort " -r """ A_ScriptDir "\resources\shared""",, Hide
return
killPreviousInstance:
process = httpsrv.exe
Process, Exist, %process%
if pid := ErrorLevel
{
Loop
{
WinClose, ahk_pid %pid%, , 5
if ErrorLevel
Process, Close, %pid%
Process, Exist, %process%
} Until !pid := ErrorLevel
}
return
startWithWindows:
conf.startWithWindows := !conf.startWithWindows
gosub, guardarConfig
if(conf.startWithWindows)
{
FileCreateShortcut, %A_ScriptFullPath%, %A_AppData%\Microsoft\Windows\Start Menu\Programs\Startup\LibreDeck Server.lnk, %A_ScriptDir%, LibreDeck Server Software
Menu, tray, Check, Run on Startup
}
else
{
FileDelete, %A_AppData%\Microsoft\Windows\Start Menu\Programs\Startup\LibreDeck Server.lnk
Menu, tray, Uncheck, Run on Startup
}
return
showAboutScreen:
showAboutScreen("LibreDeck Server v" versionNumber, "A multi-purpose RPC server for triggering scripts remotely on the running host via RAW TCP sockets.")
return
openLibreDeckFolder:
Run, % A_ScriptDir
return
runClient:
clienteExecutable := "LibreDeck Client.exe"
previousDetectHiddenWindows := A_DetectHiddenWindows
IfWinNotExist, ahk_exe %clienteExecutable%
{
DetectHiddenWindows, On
IfWinExist, ahk_exe %clienteExecutable%
{
WinShow, ahk_exe %clienteExecutable%
WinActivate, ahk_exe %clienteExecutable%
}
else
{
Run, "%A_ScriptDir%\LibreDeck Client.exe"
}
}
else
{
WinShow, ahk_exe %clienteExecutable%
WinActivate, ahk_exe %clienteExecutable%
}
DetectHiddenWindows, % previousDetectHiddenWindows
return
contextcolor(color:=2)
{
static uxtheme := DllCall("GetModuleHandle", "str", "uxtheme", "ptr")
static SetPreferredAppMode := DllCall("GetProcAddress", "ptr", uxtheme, "ptr", 135, "ptr")
static FlushMenuThemes := DllCall("GetProcAddress", "ptr", uxtheme, "ptr", 136, "ptr")
DllCall(SetPreferredAppMode, "int", color)
DllCall(FlushMenuThemes)
}