Page 1 of 4

Filesystem Hack: Set Identity to Whatever You Want

Posted: Sun May 22, 2011 7:27 am
by BlackBulletIV
Here's an 8 line function that allows you to set the identity (save directory) to whatever you want. Two things to note:
  • 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.
So anyway, here it is:

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
Simply pass in the absolute path you want to set the identity to like this:

Code: Select all

setIdentity("/Users/username/games/foo/blah") -- or (the first slash is irrelevant)
setIdentity("Users/username/games/foo/blah")
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.

Re: Filesystem Hack: Set Identity to Whatever You Want

Posted: Sun May 22, 2011 7:55 am
by Robin
Note: this doesn't work any more for SELÖVE, since it is a security hole which has been fixed.

Re: Filesystem Hack: Set Identity to Whatever You Want

Posted: Sun May 22, 2011 7:57 am
by BlackBulletIV
Yeah I know that, but thankfully LOVE hasn't had it fixed (yes, that sounds weird, but for me, it's a big deal for the editor).

Re: Filesystem Hack: Set Identity to Whatever You Want

Posted: Sun May 22, 2011 9:12 am
by bartbes
Though this isn't something I'd encourage (but it has its use cases!), it's not something I plan on 'fixing' either, since LÖVE obviously doesn't have a secure sandbox (as illustrated by the existence of SELOVE).

Re: Filesystem Hack: Set Identity to Whatever You Want

Posted: Sun May 22, 2011 10:15 am
by BlackBulletIV
bartbes wrote:Though this isn't something I'd encourage (but it has its use cases!)
Exactly.
bartbes wrote:it's not something I plan on 'fixing' either
Well that's good. :D

Re: Filesystem Hack: Set Identity to Whatever You Want

Posted: Sun May 22, 2011 7:09 pm
by tentus
Cool, very clever all around. BBIV, I can't wait to see what you make, sounds like fun.

Re: Filesystem Hack: Set Identity to Whatever You Want

Posted: Sun May 22, 2011 9:47 pm
by BlackBulletIV
tentus wrote:BBIV, I can't wait to see what you make, sounds like fun.
Thanks. I'm making it for Launcher, as most of the gameplay mechanics are fairly done, but at the same time I'm making it a reusable editor for my personal framework (which Launcher is using).

Re: Filesystem Hack: Set Identity to Whatever You Want

Posted: Mon May 23, 2011 4:13 pm
by kalle2990
I made a proof-of-concept file explorer using this function, it features browsing your entire drive and opening files. The default scrolling is done with with the mouse-wheel, but I also added arrow key movement (instead of scroll-wheel up/down, for those who doesn't have one).

Browsing is easy, click a folder to enlarge, click again to close. If you click on a file it will open :)

Re: Filesystem Hack: Set Identity to Whatever You Want

Posted: Mon May 23, 2011 4:40 pm
by Robin
The way you open files is Windows-centric, otherwise very nice.

Re: Filesystem Hack: Set Identity to Whatever You Want

Posted: Mon May 23, 2011 5:38 pm
by kalle2990
Robin wrote:The way you open files is Windows-centric
I thought it would be, guess you can't have it all ;)