|
@@ -24,47 +24,9 @@
|
|
|
// STD
|
|
// STD
|
|
|
#include <cstdlib>
|
|
#include <cstdlib>
|
|
|
#include <cstring>
|
|
#include <cstring>
|
|
|
-#include <string>
|
|
|
|
|
-#include <vector>
|
|
|
|
|
|
|
|
|
|
// LOVE
|
|
// LOVE
|
|
|
-#include "common/Module.h"
|
|
|
|
|
-#include "common/config.h"
|
|
|
|
|
-#include "common/int.h"
|
|
|
|
|
-#include "common/runtime.h"
|
|
|
|
|
-#include "filesystem/FileData.h"
|
|
|
|
|
-#include "File.h"
|
|
|
|
|
-
|
|
|
|
|
-// For great CWD. (Current Working Directory)
|
|
|
|
|
-// Using this instead of boost::filesystem which totally
|
|
|
|
|
-// cramped our style.
|
|
|
|
|
-#ifdef LOVE_WINDOWS
|
|
|
|
|
-# include <windows.h>
|
|
|
|
|
-# include <direct.h>
|
|
|
|
|
-#else
|
|
|
|
|
-# include <sys/param.h>
|
|
|
|
|
-# include <unistd.h>
|
|
|
|
|
-#endif
|
|
|
|
|
-
|
|
|
|
|
-// In Windows, we would like to use "LOVE" as the
|
|
|
|
|
-// application folder, but in Linux, we like .love.
|
|
|
|
|
-#define LOVE_APPDATA_PREFIX ""
|
|
|
|
|
-#ifdef LOVE_WINDOWS
|
|
|
|
|
-# define LOVE_APPDATA_FOLDER "LOVE"
|
|
|
|
|
-# define LOVE_PATH_SEPARATOR "/"
|
|
|
|
|
-# define LOVE_MAX_PATH _MAX_PATH
|
|
|
|
|
-#else
|
|
|
|
|
-# ifdef LOVE_MACOSX
|
|
|
|
|
-# define LOVE_APPDATA_FOLDER "LOVE"
|
|
|
|
|
-# elif defined(LOVE_LINUX)
|
|
|
|
|
-# define LOVE_APPDATA_FOLDER "love"
|
|
|
|
|
-# else
|
|
|
|
|
-# define LOVE_APPDATA_PREFIX "."
|
|
|
|
|
-# define LOVE_APPDATA_FOLDER "love"
|
|
|
|
|
-# endif
|
|
|
|
|
-# define LOVE_PATH_SEPARATOR "/"
|
|
|
|
|
-# define LOVE_MAX_PATH MAXPATHLEN
|
|
|
|
|
-#endif
|
|
|
|
|
|
|
+#include "filesystem/Filesystem.h"
|
|
|
|
|
|
|
|
namespace love
|
|
namespace love
|
|
|
{
|
|
{
|
|
@@ -73,7 +35,7 @@ namespace filesystem
|
|
|
namespace physfs
|
|
namespace physfs
|
|
|
{
|
|
{
|
|
|
|
|
|
|
|
-class Filesystem : public Module
|
|
|
|
|
|
|
+class Filesystem : public love::filesystem::Filesystem
|
|
|
{
|
|
{
|
|
|
public:
|
|
public:
|
|
|
|
|
|
|
@@ -81,7 +43,6 @@ public:
|
|
|
virtual ~Filesystem();
|
|
virtual ~Filesystem();
|
|
|
|
|
|
|
|
// Implements Module.
|
|
// Implements Module.
|
|
|
- virtual ModuleType getModuleType() const { return M_FILESYSTEM; }
|
|
|
|
|
const char *getName() const;
|
|
const char *getName() const;
|
|
|
|
|
|
|
|
void init(const char *arg0);
|
|
void init(const char *arg0);
|
|
@@ -89,183 +50,55 @@ public:
|
|
|
void setFused(bool fused);
|
|
void setFused(bool fused);
|
|
|
bool isFused() const;
|
|
bool isFused() const;
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * This sets up the save directory. If the
|
|
|
|
|
- * it is already set up, nothing happens.
|
|
|
|
|
- * @return True on success, false otherwise.
|
|
|
|
|
- **/
|
|
|
|
|
bool setupWriteDirectory();
|
|
bool setupWriteDirectory();
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * Sets the name of the save folder.
|
|
|
|
|
- * @param ident The name of the game. Will be used to
|
|
|
|
|
- * to create the folder in the LOVE data folder.
|
|
|
|
|
- **/
|
|
|
|
|
bool setIdentity(const char *ident, bool appendToPath = false);
|
|
bool setIdentity(const char *ident, bool appendToPath = false);
|
|
|
const char *getIdentity() const;
|
|
const char *getIdentity() const;
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * Sets the path to the game source.
|
|
|
|
|
- * This can only be set once.
|
|
|
|
|
- * @param source Path to a directory or a .love-file.
|
|
|
|
|
- **/
|
|
|
|
|
bool setSource(const char *source);
|
|
bool setSource(const char *source);
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * Gets the path to the game source.
|
|
|
|
|
- * Returns a 0-length string if the source has not been set.
|
|
|
|
|
- **/
|
|
|
|
|
const char *getSource() const;
|
|
const char *getSource() const;
|
|
|
|
|
|
|
|
bool mount(const char *archive, const char *mountpoint, bool appendToPath = false);
|
|
bool mount(const char *archive, const char *mountpoint, bool appendToPath = false);
|
|
|
bool unmount(const char *archive);
|
|
bool unmount(const char *archive);
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * Creates a new file.
|
|
|
|
|
- **/
|
|
|
|
|
File *newFile(const char *filename) const;
|
|
File *newFile(const char *filename) const;
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * Creates a new FileData object. Data will be copied.
|
|
|
|
|
- * @param data Pointer to the data.
|
|
|
|
|
- * @param size The size of the data.
|
|
|
|
|
- * @param filename The full filename used to file type identification.
|
|
|
|
|
- **/
|
|
|
|
|
FileData *newFileData(void *data, unsigned int size, const char *filename) const;
|
|
FileData *newFileData(void *data, unsigned int size, const char *filename) const;
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Creates a new FileData object from base64 data.
|
|
|
|
|
- * @param b64 The base64 data.
|
|
|
|
|
- **/
|
|
|
|
|
FileData *newFileData(const char *b64, const char *filename) const;
|
|
FileData *newFileData(const char *b64, const char *filename) const;
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * Gets the current working directory.
|
|
|
|
|
- **/
|
|
|
|
|
const char *getWorkingDirectory();
|
|
const char *getWorkingDirectory();
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Gets the user home directory.
|
|
|
|
|
- **/
|
|
|
|
|
std::string getUserDirectory();
|
|
std::string getUserDirectory();
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Gets the APPDATA directory. On Windows, this is the folder
|
|
|
|
|
- * in the %APPDATA% enviroment variable. On Linux, this is the
|
|
|
|
|
- * user home folder.
|
|
|
|
|
- **/
|
|
|
|
|
std::string getAppdataDirectory();
|
|
std::string getAppdataDirectory();
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Gets the full path of the save folder.
|
|
|
|
|
- **/
|
|
|
|
|
const char *getSaveDirectory();
|
|
const char *getSaveDirectory();
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Gets the full path to the directory containing the game source.
|
|
|
|
|
- * For example if the game source is C:\Games\mygame.love, this will return
|
|
|
|
|
- * C:\Games.
|
|
|
|
|
- **/
|
|
|
|
|
std::string getSourceBaseDirectory() const;
|
|
std::string getSourceBaseDirectory() const;
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * Gets the real directory path containing the file.
|
|
|
|
|
- **/
|
|
|
|
|
std::string getRealDirectory(const char *filename) const;
|
|
std::string getRealDirectory(const char *filename) const;
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * Checks if a path is a directory.
|
|
|
|
|
- * @param dir The directory name to check.
|
|
|
|
|
- **/
|
|
|
|
|
bool isDirectory(const char *dir) const;
|
|
bool isDirectory(const char *dir) const;
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Checks if a filename exists.
|
|
|
|
|
- * @param file The filename to check.
|
|
|
|
|
- **/
|
|
|
|
|
bool isFile(const char *file) const;
|
|
bool isFile(const char *file) const;
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * Creates a directory. Write dir must be set.
|
|
|
|
|
- * @param dir The directory to create.
|
|
|
|
|
- **/
|
|
|
|
|
bool createDirectory(const char *dir);
|
|
bool createDirectory(const char *dir);
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * Removes a file (or directory).
|
|
|
|
|
- * @param file The file or directory to remove.
|
|
|
|
|
- **/
|
|
|
|
|
bool remove(const char *file);
|
|
bool remove(const char *file);
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * Reads data from a file.
|
|
|
|
|
- * @param filename The name of the file to read from.
|
|
|
|
|
- * @param size The size in bytes of the data to read.
|
|
|
|
|
- **/
|
|
|
|
|
FileData *read(const char *filename, int64 size = File::ALL) const;
|
|
FileData *read(const char *filename, int64 size = File::ALL) const;
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Write data to a file.
|
|
|
|
|
- * @param filename The name of the file to write to.
|
|
|
|
|
- * @param data The data to write.
|
|
|
|
|
- * @param size The size in bytes of the data to write.
|
|
|
|
|
- **/
|
|
|
|
|
void write(const char *filename, const void *data, int64 size) const;
|
|
void write(const char *filename, const void *data, int64 size) const;
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Append data to a file, creating it if it doesn't exist.
|
|
|
|
|
- * @param filename The name of the file to write to.
|
|
|
|
|
- * @param data The data to append.
|
|
|
|
|
- * @param size The size in bytes of the data to append.
|
|
|
|
|
- **/
|
|
|
|
|
void append(const char *filename, const void *data, int64 size) const;
|
|
void append(const char *filename, const void *data, int64 size) const;
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * This "native" method returns a table of all
|
|
|
|
|
- * files in a given directory.
|
|
|
|
|
- **/
|
|
|
|
|
int getDirectoryItems(lua_State *L);
|
|
int getDirectoryItems(lua_State *L);
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * Gets the last modification time of a file, in seconds
|
|
|
|
|
- * since the Unix epoch.
|
|
|
|
|
- * @param filename The name of the file.
|
|
|
|
|
- **/
|
|
|
|
|
int64 getLastModified(const char *filename) const;
|
|
int64 getLastModified(const char *filename) const;
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Gets the size of a file in bytes.
|
|
|
|
|
- * @param filename The name of the file.
|
|
|
|
|
- **/
|
|
|
|
|
int64 getSize(const char *filename) const;
|
|
int64 getSize(const char *filename) const;
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * Enable or disable symbolic link support in love.filesystem.
|
|
|
|
|
- **/
|
|
|
|
|
void setSymlinksEnabled(bool enable);
|
|
void setSymlinksEnabled(bool enable);
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Gets whether symbolic link support is enabled.
|
|
|
|
|
- **/
|
|
|
|
|
bool areSymlinksEnabled() const;
|
|
bool areSymlinksEnabled() const;
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Gets whether a filepath is actually a symlink.
|
|
|
|
|
- * Always returns false if symlinks are not enabled.
|
|
|
|
|
- **/
|
|
|
|
|
bool isSymlink(const char *filename) const;
|
|
bool isSymlink(const char *filename) const;
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * Text file line-reading iterator function used and
|
|
|
|
|
- * pushed on the Lua stack by love.filesystem.lines
|
|
|
|
|
- * and File:lines.
|
|
|
|
|
- **/
|
|
|
|
|
- static int lines_i(lua_State *L);
|
|
|
|
|
-
|
|
|
|
|
- // Require path accessors
|
|
|
|
|
- // Not const because it's R/W
|
|
|
|
|
std::vector<std::string> &getRequirePath();
|
|
std::vector<std::string> &getRequirePath();
|
|
|
|
|
|
|
|
|
|
+ void allowMountingForPath(const std::string &path);
|
|
|
|
|
+
|
|
|
private:
|
|
private:
|
|
|
|
|
|
|
|
// Contains the current working directory (UTF8).
|
|
// Contains the current working directory (UTF8).
|
|
@@ -286,9 +119,6 @@ private:
|
|
|
// The full path to the source of the game.
|
|
// The full path to the source of the game.
|
|
|
std::string game_source;
|
|
std::string game_source;
|
|
|
|
|
|
|
|
- // Workaround for machines without PhysFS 2.0
|
|
|
|
|
- bool initialized;
|
|
|
|
|
-
|
|
|
|
|
// Allow saving outside of the LOVE_APPDATA_FOLDER
|
|
// Allow saving outside of the LOVE_APPDATA_FOLDER
|
|
|
// for release 'builds'
|
|
// for release 'builds'
|
|
|
bool fused;
|
|
bool fused;
|
|
@@ -297,6 +127,8 @@ private:
|
|
|
// Search path for require
|
|
// Search path for require
|
|
|
std::vector<std::string> requirePath;
|
|
std::vector<std::string> requirePath;
|
|
|
|
|
|
|
|
|
|
+ std::vector<std::string> allowedMountPaths;
|
|
|
|
|
+
|
|
|
}; // Filesystem
|
|
}; // Filesystem
|
|
|
|
|
|
|
|
} // physfs
|
|
} // physfs
|