Browse Source

Merged bartbes/love-experiments/love.filesystem.mount2 into default

Alex Szpakowski 12 years ago
parent
commit
bf91d5cc6f

+ 44 - 0
src/modules/filesystem/physfs/Filesystem.cpp

@@ -182,6 +182,50 @@ bool Filesystem::setupWriteDirectory()
 	return true;
 	return true;
 }
 }
 
 
+bool Filesystem::mount(const char *archive, const char *mountpoint)
+{
+	if (!isInited || !archive)
+		return false;
+
+	// Not allowed for safety reasons.
+	if (strlen(archive) == 0 || strstr(archive, "..") || strcmp(archive, "/") == 0)
+		return false;
+
+	const char *realDir = PHYSFS_getRealDir(archive);
+	if (!realDir)
+		return false;
+
+	std::string realPath(realDir);
+	realPath += LOVE_PATH_SEPARATOR;
+	realPath += archive;
+
+	return PHYSFS_mount(realPath.c_str(), mountpoint, 0);
+}
+
+bool Filesystem::unmount(const char *archive)
+{
+	if (!isInited || !archive)
+		return false;
+
+	// Not allowed for safety reasons.
+	if (strlen(archive) == 0 || strstr(archive, "..") || strcmp(archive, "/") == 0)
+		return false;
+
+	const char *realDir = PHYSFS_getRealDir(archive);
+	if (!realDir)
+		return false;
+
+	std::string realPath(realDir);
+	realPath += LOVE_PATH_SEPARATOR;
+	realPath += archive;
+
+	const char *mountPoint = PHYSFS_getMountPoint(realPath.c_str());
+	if (!mountPoint)
+		return false;
+
+	return PHYSFS_removeFromSearchPath(realPath.c_str());
+}
+
 File *Filesystem::newFile(const char *filename) const
 File *Filesystem::newFile(const char *filename) const
 {
 {
 	return new File(filename);
 	return new File(filename);

+ 2 - 0
src/modules/filesystem/physfs/Filesystem.h

@@ -143,6 +143,8 @@ public:
 	 * @param source Path to a directory or a .love-file.
 	 * @param source Path to a directory or a .love-file.
 	 **/
 	 **/
 	bool setSource(const char *source);
 	bool setSource(const char *source);
+	bool mount(const char *archive, const char *mountpoint);
+	bool unmount(const char *archive);
 
 
 	/**
 	/**
 	 * Creates a new file.
 	 * Creates a new file.

+ 19 - 0
src/modules/filesystem/physfs/wrap_Filesystem.cpp

@@ -99,6 +99,23 @@ int w_setSource(lua_State *L)
 	return 0;
 	return 0;
 }
 }
 
 
+int w_mount(lua_State *L)
+{
+	const char *archive = luaL_checkstring(L, 1);
+	const char *mountpoint = luaL_checkstring(L, 2);
+
+	luax_pushboolean(L, instance->mount(archive, mountpoint));
+	return 1;
+}
+
+int w_unmount(lua_State *L)
+{
+	const char *archive = luaL_checkstring(L, 1);
+
+	luax_pushboolean(L, instance->unmount(archive));
+	return 1;
+}
+
 int w_newFile(lua_State *L)
 int w_newFile(lua_State *L)
 {
 {
 	const char *filename = luaL_checkstring(L, 1);
 	const char *filename = luaL_checkstring(L, 1);
@@ -544,6 +561,8 @@ static const luaL_Reg functions[] =
 	{ "setIdentity",  w_setIdentity },
 	{ "setIdentity",  w_setIdentity },
 	{ "getIdentity", w_getIdentity },
 	{ "getIdentity", w_getIdentity },
 	{ "setSource",  w_setSource },
 	{ "setSource",  w_setSource },
+	{ "mount", w_mount },
+	{ "unmount", w_unmount },
 	{ "newFile",  w_newFile },
 	{ "newFile",  w_newFile },
 	{ "getWorkingDirectory",  w_getWorkingDirectory },
 	{ "getWorkingDirectory",  w_getWorkingDirectory },
 	{ "getUserDirectory",  w_getUserDirectory },
 	{ "getUserDirectory",  w_getUserDirectory },

+ 2 - 0
src/modules/filesystem/physfs/wrap_Filesystem.h

@@ -42,6 +42,8 @@ int w_setRelease(lua_State *L);
 int w_setIdentity(lua_State *L);
 int w_setIdentity(lua_State *L);
 int w_getIdentity(lua_State *L);
 int w_getIdentity(lua_State *L);
 int w_setSource(lua_State *L);
 int w_setSource(lua_State *L);
+int w_mount(lua_State *L);
+int w_unmount(lua_State *L);
 int w_newFile(lua_State *L);
 int w_newFile(lua_State *L);
 int w_newFileData(lua_State *L);
 int w_newFileData(lua_State *L);
 int w_getWorkingDirectory(lua_State *L);
 int w_getWorkingDirectory(lua_State *L);