Filesystem Hack: Set Identity to Whatever You Want

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Filesystem Hack: Set Identity to Whatever You Want

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.
Last edited by BlackBulletIV on Sun May 22, 2011 7:57 am, edited 1 time in total.
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Filesystem Hack: Set Identity to Whatever You Want

Note: this doesn't work any more for SELÖVE, since it is a security hole which has been fixed.
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: Filesystem Hack: Set Identity to Whatever You Want

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).
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Filesystem Hack: Set Identity to Whatever You Want

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).
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: Filesystem Hack: Set Identity to Whatever You Want

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.
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Filesystem Hack: Set Identity to Whatever You Want

Cool, very clever all around. BBIV, I can't wait to see what you make, sounds like fun.
Kurosuke needs beta testers
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: Filesystem Hack: Set Identity to Whatever You Want

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).
kalle2990
Party member
Posts: 245
Joined: Sat Sep 12, 2009 1:17 pm
Location: Sweden

Re: Filesystem Hack: Set Identity to Whatever You Want

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
Attachments
File Explorer.love
Tested with Windows 7, should work on any system
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Filesystem Hack: Set Identity to Whatever You Want

The way you open files is Windows-centric, otherwise very nice.
kalle2990
Party member
Posts: 245
Joined: Sat Sep 12, 2009 1:17 pm
Location: Sweden

Re: Filesystem Hack: Set Identity to Whatever You Want

Robin wrote:The way you open files is Windows-centric
I thought it would be, guess you can't have it all

Who is online

Users browsing this forum: No registered users and 21 guests