Skip to content

Commit

Permalink
Write missing examples from the addon's data folder (#33)
Browse files Browse the repository at this point in the history
* Force data write & regenerate default data files

* Better solution, write only files that are missing

* Only check the following directories

* Rename data folder to data_static
  • Loading branch information
DerelictDrone authored Jan 4, 2024
1 parent 0fe670f commit 78172d5
Show file tree
Hide file tree
Showing 39 changed files with 16 additions and 14 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 0 additions & 2 deletions lua/autorun/cpu_load.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ include("wire/gpulib.lua")
AddCSLuaFile("wire/cpu_default_data_decompressor.lua")
include("wire/cpu_default_data_decompressor.lua")

AddCSLuaFile("wire/cpu_default_data_files.lua")

if CLIENT then
include("wire/client/hlzasm/hc_compiler.lua")
end
27 changes: 16 additions & 11 deletions lua/wire/cpu_default_data_decompressor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@ local ignored_dirs = {
["spuchip/tests"] = true
}

local checked_dirs = {
"cpuchip",
"gpuchip",
"spuchip"
}

-- Compress all files in addons/wire/data recursively into 1 json string
local function ReadDir(root)
if ignored_dirs[root] then return nil end
local tab = {}
local files,dirs = file.Find("addons/wire-cpu/data/"..root.."*","GAME")
local files,dirs = file.Find("addons/wire-cpu/data_static/"..root.."*","GAME")
for _, f in pairs(files) do
f = root..f
tab[f] = file.Read("addons/wire-cpu/data/"..f, "GAME")
tab[f] = file.Read("addons/wire-cpu/data_static/"..f, "GAME")
end
for _, f in pairs(dirs) do
f = root..f.."/"
Expand All @@ -24,26 +30,25 @@ local function ReadDir(root)
end

-- Uncomment and Rename this file to wire/lua/wire/default_data_files.lua to update it
-- file.Write("cpu_default_data_files.txt", "//"..util.TableToJSON(ReadDir("")))
-- file.Write("cpu_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)
if not file.Exists(f,"DATA") then
file.Write(f, contents)
end
else
file.CreateDir(f)
WriteDir(contents)
end
end
end

-- Only expand the files if they aren't present already
if CLIENT and not file.Exists("cpuchip/examples/helloworld.txt", "DATA") then
local compressed = file.Read("wire/cpu_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)))
-- Write any missing files to the folder
if CLIENT then
for _,dir in pairs(checked_dirs) do
WriteDir(ReadDir(dir..'/'), 3)
end
end
1 change: 0 additions & 1 deletion lua/wire/cpu_default_data_files.lua

This file was deleted.

0 comments on commit 78172d5

Please sign in to comment.