-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.lua
81 lines (46 loc) · 1.67 KB
/
config.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
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
g_ConfigDefaults = [[
Storage = 'sqlite',
-- This can cause huge amounts of lagg and cause the database to grow really big.
LogNature = false,
]]
g_Config = {}
function InitConfig()
local Path = cPluginManager:Get():GetCurrentPlugin():GetLocalFolder() .. "/config.cfg"
if (not cFile:IsFile(Path)) then
LOGWARNING("[PreciousBlocks] The config file doesn't exist. PreciousBlocks will write and load the default settings for now")
WriteDefaultSettings(Path)
LoadDefaultSettings()
return
end
local ConfigContent = cFile:ReadWholeFile(Path)
if (ConfigContent == "") then
LOGWARNING("[PreciousBlocks] The config file is empty. PreciousBlocks will use the default settings for now")
LoadDefaultSettings()
return
end
local ConfigLoader, Error = loadstring("return {" .. ConfigContent .. "}")
if (not ConfigLoader) then
LOGWARNING("[PreciousBlocks] There is a problem in the config file. PreciousBlocks will use the default settings for now.")
LoadDefaultSettings()
return
end
local Result, ConfigTable, Error = pcall(ConfigLoader)
if (not Result) then
LOGWARNING("[PreciousBlocks] There is a problem in the config file. PreciousBlocks will use the default settings for now.")
LoadDefaultSettings()
return
end
if (type(ConfigTable.Storage) ~= 'string') then
LOGWARNING("[PreciousBlocks] Invalid storage type configurated. PreciousBlocks will use SQLite")
ConfigTable.Storage = 'sqlite'
end
g_Config = ConfigTable
end
function LoadDefaultSettings()
g_Config = loadstring("return {" .. g_ConfigDefaults .. "}")()
end
function WriteDefaultSettings(a_Path)
local File = io.open(a_Path, "w")
File:write(g_ConfigDefaults)
File:close()
end