From 571012cd2942e502ac9318e4caefa964a684b923 Mon Sep 17 00:00:00 2001 From: RamiLego4Game Date: Mon, 14 May 2018 10:02:07 +0300 Subject: [PATCH] Added support for passing data as string --- love-pe.lua | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/love-pe.lua b/love-pe.lua index 539812e..f89156f 100644 --- a/love-pe.lua +++ b/love-pe.lua @@ -585,12 +585,54 @@ local function writeTree(tree,path) end end +local function newStringFile(data) + local str = data or "" + + local file = {} + + local pos = 0 + + function file:getSize() return #str end + function file:seek(p) pos = p end + function file:tell() return pos end + function file:read(bytes) + if bytes then + if pos+bytes > #str then bytes = #str-pos end + + local substr = str:sub(pos+1,pos+bytes) + + pos = pos + bytes + + return substr, bytes + else + return str + end + end + + function file:write(d) + if pos+#d > #str then d = d:sub(1,#str-pos) end + + str = str:sub(1,pos)..d..str:sub(pos+#d+1,-1) + + pos = pos + #d + + return #d + end + + function file:flush() end + function file:close() end + + return file +end + --==User API==-- local icapi = {} function icapi.extractIcon(exeFile) + if type(exeFile) == "string" then exeFile = newStringFile(exeFile) end + --DOS Header skipDOSHeader(exeFile) @@ -637,6 +679,10 @@ end function icapi.replaceIcon(exeFile,icoFile,newFile) + if type(exeFile) == "string" then exeFile = newStringFile(exeFile) end + if type(icoFile) == "string" then icoFile = newStringFile(icoFile) end + if type(newFile) == "string" or not newFile then newFile = newStringFile(newFile) end + --DOS Header skipDOSHeader(exeFile) @@ -734,7 +780,7 @@ function icapi.replaceIcon(exeFile,icoFile,newFile) writeSections(newFile,Sections,SectionsData) newFile:write(TrailData) - return true + return true, newFile end return icapi \ No newline at end of file