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
Before you make a thread asking for help, read this.
User avatar
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

Post 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.
Last edited by BlackBulletIV on Sun May 22, 2011 7:57 am, edited 1 time in total.
User avatar
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

Post by Robin »

Note: this doesn't work any more for SELÖVE, since it is a security hole which has been fixed.
Help us help you: attach a .love.
User avatar
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

Post 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).
User avatar
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

Post 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).
User avatar
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

Post 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
User avatar
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

Post by tentus »

Cool, very clever all around. BBIV, I can't wait to see what you make, sounds like fun.
Kurosuke needs beta testers
User avatar
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

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

Re: Filesystem Hack: Set Identity to Whatever You Want

Post 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 :)
Attachments
File Explorer.love
Tested with Windows 7, should work on any system
(1.12 KiB) Downloaded 196 times
User avatar
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

Post by Robin »

The way you open files is Windows-centric, otherwise very nice.
Help us help you: attach a .love.
User avatar
kalle2990
Party member
Posts: 245
Joined: Sat Sep 12, 2009 1:17 pm
Location: Sweden

Re: Filesystem Hack: Set Identity to Whatever You Want

Post by kalle2990 »

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

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 55 guests