Transformed "Encoded shaders" into "Encoded Resources"

Former-commit-id: ead4cc9bb162d2f9e5c08756575e84f3a9056679
This commit is contained in:
Lynix
2013-09-20 16:20:51 +02:00
parent 693aec36c3
commit 197bddb6ba
51 changed files with 117 additions and 90 deletions

View File

@@ -0,0 +1,50 @@
function encodeResources()
print("Encoding resources ...")
local modules = os.matchdirs("../src/Nazara/*")
for k, modulePath in pairs(modules) do
local files = os.matchfiles(modulePath .. "/Resources/**")
local resourceContent
local headerContent
local file
for k, filePath in pairs(files) do
if (filePath:sub(-2) ~= ".h") then
file = filePath:sub(modulePath:len() + 12, -1)
local resource, err = io.open(filePath, "rb")
if (not resource) then
error("Failed to read resource file " .. file .. ": " .. err)
end
resourceContent = resource:read("*a")
resource:close()
local contentLength = resourceContent:len()
headerContent = ""
for i = 1, contentLength do
local b = resourceContent:sub(i, i):byte()
if (b >= 128) then
b = b - 256
end
headerContent = headerContent .. string.format("%d,", b)
end
local header, err = io.open(filePath .. ".h", "w+")
if (not header) then
error("Failed to create header file for " .. file .. ": " .. err)
end
header:write(headerContent)
header:close()
print(string.format("%s (raw: %.3g kB, header: %.3g kB)", file, contentLength/1024, string.format("%.3g", headerContent:len()/1024)))
end
end
end
end
newaction
{
trigger = "encoderesources",
description = "Generate a includable header version of resources",
execute = encodeResources
}