I have a few questions about loading files from the zip folder, I understand that I need to have a copy of the zip file in the save folder of the love project directory.
So the structure i have is
loveproject/assets/save/data.zip
I found the following code on the forum and this appears to unzip the contents of the zip folder to the save directory.
I keep getting assertion fails when I tried to mount the zip file in the source directory (upon reading the forums it appears this is not possible and needs to be done from the projects save directory.
I have some question,
1. I would like to unzip the zip file in the save directory, read the files I want into memory then delete the files. Is this possible or advisable? or should I just leave the files be in the save directory and delete them upon program exit?
2. I am not to clear about what this code is doing - ok I understand that its unpacking the zip file into some directory, but how should i edit it so it works in my project folder?
Code: Select all
local lfs = love.filesystem
local function enu(folder, saveDir)
local filesTable = lfs.getDirectoryItems(folder)
if saveDir ~= "" and not lfs.isDirectory(saveDir) then lfs.createDirectory(saveDir) end
for i,v in ipairs(filesTable) do
local file = folder.."/"..v
local saveFile = saveDir.."/"..v
if saveDir == "" then saveFile = v end
if lfs.isDirectory(file) then
lfs.createDirectory(saveFile)
enu(file, saveFile)
else
lfs.write(saveFile, tostring(lfs.read(file)))
end
end
end
function extractZIP(file, dir, delete)
local dir = dir or ""
local temp = tostring(math.random(1000, 2000))
success = lfs.mount(file, temp)
if success then enu(temp, dir) end
lfs.unmount(file)
if delete then lfs.remove(file) end
end
Code: Select all
function love.load()
love.filesystem.mount("data.zip", "assets/save")
assert(love.filesystem.exists("assets/save/225_img224.png"))
background = love.graphics.newImage("assets/save/225_img224.png")
end
function love.quit()
print("***************************\n* Have a nice day. *\n***************************")
love.event.quit()
end
function love.keypressed(key)
if key == 'b' then
print("The B key was pressed.")
end
if key == 'a' then
file = love.filesystem.newFile("data.txt")
file:open("r")
data = file:read()
print(data)
file:close()
end
if key == 'escape' then
love.event.push("quit")
end
end
function love.update(dt)
end
function love.draw()
love.graphics.draw(background,0,0)
end
My system is linux.
4. so I was wondering is there a way in love I can read in the image data without having to extract the png's from the archive. Like with text files in linux I can do somthing like this...
unzip -c archive.zip file1.txt file2.txt | less
I was thinking there might be a way to do this with the image data in the archive in love2d?