forked from wiremod/wire
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefault_data_decompressor.lua
More file actions
40 lines (38 loc) · 1.51 KB
/
Copy pathdefault_data_decompressor.lua
File metadata and controls
40 lines (38 loc) · 1.51 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
-- Garry has imposed a file extension whitelist for the Steam Workshop which does not permit the dangerous format .txt
-- Therefore, we must store our .txt's in default_data_files.lua, and then extract them when first run
-- Compress all files in addons/wire/data recursively into 1 json string
local function ReadDir(root)
local tab = {}
local files,dirs = file.Find("addons/wire/data/"..root.."*","GAME")
for _, f in pairs(files) do
f = root..f
tab[f] = file.Read("addons/wire/data/"..f, "GAME")
end
for _, f in pairs(dirs) do
f = root..f.."/"
tab[f] = ReadDir(f)
end
return tab
end
-- Uncomment and Rename this file to wire/lua/wire/default_data_files.lua to update it
//file.Write("default_data_files.txt", "//"..util.TableToJSON(ReadDir("")))
-- Decompress the json string wire/lua/wire/default_data_files.lua into the corresponding 36+ default data files
local function WriteDir(tab)
for f, contents in pairs(tab) do
if isstring(contents) then
file.Write(f, contents)
else
file.CreateDir(f)
WriteDir(contents)
end
end
end
-- Only expand the files if they aren't present already
if not file.Exists("expression2/_helloworld_.txt", "DATA") then
local compressed = file.Read("wire/default_data_files.lua","LUA")
-- The client cannot read lua files sent by the server (for security?), so clientside this'll only work
-- if the client actually has Wiremod installed, though with workshop autodownload that'll be common
if compressed != nil then
WriteDir(util.JSONToTable(string.sub(compressed, 3)))
end
end