-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUserRadEnv.lua
44 lines (38 loc) · 1.02 KB
/
UserRadEnv.lua
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
local win32 = require "lrwin32"
require "Utils"
function poutput(cmd)
local openPop = io.popen(cmd, 'r')
if openPop == nil then
print("Error popen: "..cmd)
return nil
end
local output = openPop:read('*all')
openPop:close()
return output
end
env = {}
function env.__PID__()
return win32.GetProcessId(win32.GetCurrentProcess())
end
env.__TICK__ = win32.GetTickCount
function env.__USERCD__()
return win32.GetCurrentDirectory():gsub("^"..OrigGetEnvironmentVariable("USERPROFILE"):escape(), "~")
end
function GetEnvironmentVariable(name)
if name:beginswith('[') and name:endswith(']') then
local o = poutput(name:sub(2, -2))
o = o:gsub('[\r\n]$', '')
o = o:gsub('[\r\n]', ';')
return o
else
local nameu = name:upper()
local e = env[nameu]
if e == nil then
return OrigGetEnvironmentVariable(name)
elseif type(e) == "function" then
return e()
else
return e
end
end
end