Filesystem Hack: Set Identity to Whatever You Want
Posted: Sun May 22, 2011 7:27 am
Here's an 8 line function that allows you to set the identity (save directory) to whatever you want. Two things to note:
Simply pass in the absolute path you want to set the identity to like this:
This function could of course be expanded to cater for relative directories, by using love.filesystem.getWorkingDirectory.
And no, the "tmp" save directory never gets created, so you won't have to worry about that.
- Most of the code you see in this function is the genius work of bartbes, from one of his responses to the SELOVE cracking challenge.
- I need this for a reusable level editor I'm about to make, which obviously needs to load and save files from various places.
Code: Select all
function setIdentity(to)
love.filesystem.setIdentity('tmp')
local new = ""
local path = love.filesystem.getSaveDirectory()
path = path:match("/(.+)") or path:match("%s:/(.+)")
for s in path:gmatch("/") do new = new .. "../" end
love.filesystem.setIdentity(new .. (to and to:gsub('^/', '') or ""))
end
Code: Select all
setIdentity("/Users/username/games/foo/blah") -- or (the first slash is irrelevant)
setIdentity("Users/username/games/foo/blah")
And no, the "tmp" save directory never gets created, so you won't have to worry about that.