-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathconfig.lua
More file actions
100 lines (69 loc) · 2.48 KB
/
config.lua
File metadata and controls
100 lines (69 loc) · 2.48 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
g_ConfigDefaults =
{
Storage = "sqlite",
LoginMessageTime = 50,
}
function InitConfig()
local Path = cPluginManager:Get():GetCurrentPlugin():GetLocalFolder() .. "/config.cfg"
if (not cFile:IsFile(Path)) then
LOGWARNING("[Login] The config file doesn't exist. Login will write and load the default settings for now")
WriteDefaultSettings(Path)
LoadDefaultSettings()
return
end
local ConfigContent = cFile:ReadWholeFile(Path)
if (ConfigContent == "") then
LOGWARNING("[Login] The config file is empty. Login will use the default settings for now")
LoadDefaultSettings()
return
end
local ConfigLoader, Error = loadstring("return {" .. ConfigContent .. "}")
if (not ConfigLoader) then
LOGWARNING("[Login] There is a problem in the config file. Login will use the default settings for now.")
LoadDefaultSettings()
return
end
local Result, ConfigTable, Error = pcall(ConfigLoader)
if (not Result) then
LOGWARNING("[Login] There is a problem in the config file. Login will use the default settings for now.")
LoadDefaultSettings()
return
end
if (type(ConfigTable.Storage) ~= 'string') then
LOGWARNING("[Login] Invalid storage type configurated. Login will use SQLite")
ConfigTable.Storage = 'sqlite'
end
if (ConfigTable.Storage == "file") then
if ((type(ConfigTable.CompressionLevel) ~= 'number') and (not tonumber(ConfigTable.CompressionLevel))) then
LOGWARNING("[Login] Invalid compression level.")
ConfigTable.CompressionLevel = 5
end
ConfigTable.CompressionLevel = tonumber(ConfigTable.CompressionLevel)
end
if (type(ConfigTable.LoginMessageTime) ~= 'number') then
if (type(ConfigTable.LoginMessageTime) == 'string') then
local Time = tonumber(ConfigTable.LoginMessageTime)
if (not Time) then
LOGWARNING("[Login] Invalid login message time. Default will be used.")
ConfigTable.LoginMessageTime = g_ConfigDefaults.LoginMessageTime
else
ConfigTable.LoginMessageTime = Time
end
else
LOGWARNING("[Login] Invalid login message time. Default will be used.")
ConfigTable.LoginMessageTime = g_ConfigDefaults.LoginMessageTime
end
end
g_Config = ConfigTable
end
function LoadDefaultSettings()
g_Config = g_ConfigDefaults
end
function WriteDefaultSettings(a_Path)
local File = io.open(a_Path, "w")
for Key, Value in pairs(g_ConfigDefaults) do
local StringToFormat = type(Value) == 'string' and "%s = '%s',\n" or "%s = %s,\n"
File:write(StringToFormat:format(Key, Value))
end
File:close()
end