-
-
Save zorggn/1c5298c5a10cf20152f4 to your computer and use it in GitHub Desktop.
Provide a function to voluntarily set the writable directory to either the user's save directory, or the executable's source directory (when fused) in löve. (0.9.1+) P.S.: Probably unsafe/useless on linux.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local ffi = require "ffi" | |
local liblove = ffi.os == "Windows" and ffi.load "love" or ffi.C | |
ffi.cdef[[ | |
int PHYSFS_setWriteDir(const char* newDir); | |
]] -- This call will fail (and fail to change the write dir) if the current write dir still has files open in it. | |
local usrPath = love.filesystem.getSaveDirectory() | |
local srcPath = love.filesystem.getSourceBaseDirectory() | |
local dir = 'usr' | |
local t = {} | |
t.getCurrentWriteDirectory = function() | |
return dir | |
end | |
t.setCurrentWriteDirectory = function(d) | |
assert(string.lower(d) == 'usr' or string.lower(d) == 'src',"The given parameter is not accepted!") | |
if dir == d then return true end | |
dir = d | |
local success | |
if dir == 'usr' then | |
success = liblove.PHYSFS_setWriteDir(usrPath) | |
elseif dir == 'src' then | |
if not love.filesystem.isFused() then error "Can't set the write directory to the source; The game is not fused!" end | |
success = liblove.PHYSFS_setWriteDir(srcPath) | |
end | |
return success ~= 0 and true or false,success | |
end | |
return t |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment