I was thinking it would be smart to set up an automated version control system, but I'm having trouble accessing the directory of my lua files. I've tried appdir, workingdir, savedir, and userdir.
love.quit = function()
if _G.debugBuild then
local baseDir = love.filesystem.getBaseDirectory() --???
local dirname = os.date("%d.%m.%Y")
makeDir(dirname)
util.deepFileCopy(baseDir, dirname)
end
return false
end
Is something like this just impossible? Is there some easy way? Is there some hard way?
Thank you, that's very handy! It's not quite what I need-- but I discovered that "" or "/" is the read path containing main.lua. Not what I would have guessed since "" or "/" is the write path for appdata.
Still running into weird cases-- are folders created in the base directory and then immediately copied to appdata upon filesystem.makeDirectory? In any case, it can be worked around.
If it's useful to anybody, or if anybody wants to tell me a better way to do it, here is the function(s) I've settled on:
M.copyFile = function(src, dest)
local data = love.filesystem.read(src)
if type(data)~="string" then M.log("data in "..src.." is of type "..type(data)) return false end
love.filesystem.write(dest, data)
end
M.versionControl = function()
local dirname = os.date("%d.%m.%Y")
love.filesystem.createDirectory(dirname)
local source = "/"
local recursiveFileCopy
recursiveFileCopy = function(src, dest)
--src is string like "/" or "class/", dest is string like "112200" or "112200/class"
local files = love.filesystem.getDirectoryItems(src)
for key, file in ipairs(files) do
if love.filesystem.isDirectory(src..file) and file~=dirname then
--don't ask me why I need this, maybe it's writing the folders to basedir first, otherwise makes dirname/dirname/dirname to infinity
love.filesystem.createDirectory(dest.."/"..file)
recursiveFileCopy(src..file.."/", dest.."/"..file)
elseif file and file~=dirname then
M.copyFile(src..file, dest.."/"..file)
end
end
end
recursiveFileCopy(source, dirname)
end