mirror of
https://github.com/love2d/love.git
synced 2026-08-16 00:02:12 +02:00
Merged default into minor
--HG-- branch : minor
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#include "common/config.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include "common/utf8.h"
|
||||
#include "common/b64.h"
|
||||
@@ -47,6 +48,21 @@ namespace
|
||||
{
|
||||
return input.substr(getDriveDelim(input)+1);
|
||||
}
|
||||
|
||||
std::string normalize(const std::string &input)
|
||||
{
|
||||
std::stringstream out;
|
||||
bool seenSep = false, isSep = false;
|
||||
for (size_t i = 0; i < input.size(); ++i)
|
||||
{
|
||||
isSep = (input[i] == LOVE_PATH_SEPARATOR[0]);
|
||||
if (!isSep || !seenSep)
|
||||
out << input[i];
|
||||
seenSep = isSep;
|
||||
}
|
||||
|
||||
return out.str();
|
||||
}
|
||||
}
|
||||
|
||||
namespace love
|
||||
@@ -116,6 +132,8 @@ bool Filesystem::setIdentity(const char *ident, bool appendToPath)
|
||||
else
|
||||
save_path_full += save_path_relative;
|
||||
|
||||
save_path_full = normalize(save_path_full);
|
||||
|
||||
// We now have something like:
|
||||
// save_identity: game
|
||||
// save_path_relative: ./LOVE/game
|
||||
@@ -354,40 +372,33 @@ const char *Filesystem::getWorkingDirectory()
|
||||
|
||||
std::string Filesystem::getUserDirectory()
|
||||
{
|
||||
return std::string(PHYSFS_getUserDir());
|
||||
static std::string userDir = normalize(PHYSFS_getUserDir());
|
||||
return userDir;
|
||||
}
|
||||
|
||||
std::string Filesystem::getAppdataDirectory()
|
||||
{
|
||||
#ifdef LOVE_WINDOWS
|
||||
if (appdata.empty())
|
||||
{
|
||||
#ifdef LOVE_WINDOWS
|
||||
wchar_t *w_appdata = _wgetenv(L"APPDATA");
|
||||
appdata = to_utf8(w_appdata);
|
||||
replace_char(appdata, '\\', '/');
|
||||
}
|
||||
return appdata;
|
||||
#elif defined(LOVE_MACOSX)
|
||||
if (appdata.empty())
|
||||
{
|
||||
std::string udir = getUserDirectory();
|
||||
udir.append("/Library/Application Support");
|
||||
appdata = udir;
|
||||
}
|
||||
return appdata;
|
||||
appdata = normalize(udir);
|
||||
#elif defined(LOVE_LINUX)
|
||||
if (appdata.empty())
|
||||
{
|
||||
char *xdgdatahome = getenv("XDG_DATA_HOME");
|
||||
if (!xdgdatahome)
|
||||
appdata = std::string(getUserDirectory()) + "/.local/share/";
|
||||
appdata = normalize(std::string(getUserDirectory()) + "/.local/share/");
|
||||
else
|
||||
appdata = xdgdatahome;
|
||||
#else
|
||||
appdata = getUserDirectory();
|
||||
#endif
|
||||
}
|
||||
return appdata;
|
||||
#else
|
||||
return getUserDirectory();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -645,6 +656,21 @@ int64 Filesystem::getSize(const char *filename) const
|
||||
return size;
|
||||
}
|
||||
|
||||
void Filesystem::setSymlinksEnabled(bool enable)
|
||||
{
|
||||
PHYSFS_permitSymbolicLinks(enable ? 1 : 0);
|
||||
}
|
||||
|
||||
bool Filesystem::areSymlinksEnabled() const
|
||||
{
|
||||
return PHYSFS_symbolicLinksPermitted() != 0;
|
||||
}
|
||||
|
||||
bool Filesystem::isSymlink(const char *filename) const
|
||||
{
|
||||
return PHYSFS_isSymbolicLink(filename) != 0;
|
||||
}
|
||||
|
||||
} // physfs
|
||||
} // filesystem
|
||||
} // love
|
||||
|
||||
@@ -80,6 +80,8 @@ public:
|
||||
Filesystem();
|
||||
virtual ~Filesystem();
|
||||
|
||||
// Implements Module.
|
||||
virtual ModuleType getModuleType() const { return M_FILESYSTEM; }
|
||||
const char *getName() const;
|
||||
|
||||
void init(const char *arg0);
|
||||
@@ -237,6 +239,22 @@ public:
|
||||
**/
|
||||
int64 getSize(const char *filename) const;
|
||||
|
||||
/**
|
||||
* Enable or disable symbolic link support in love.filesystem.
|
||||
**/
|
||||
void setSymlinksEnabled(bool enable);
|
||||
|
||||
/**
|
||||
* Gets whether symbolic link support is enabled.
|
||||
**/
|
||||
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;
|
||||
|
||||
/**
|
||||
* Text file line-reading iterator function used and
|
||||
* pushed on the Lua stack by love.filesystem.lines
|
||||
|
||||
Reference in New Issue
Block a user