mirror of
https://github.com/love2d/love.git
synced 2026-08-12 08:30:56 +02:00
macOS/iOS: Use more modern APIs for determining the save directory.
--HG-- branch : minor
This commit is contained in:
+8
-4
@@ -287,22 +287,26 @@ std::string getLoveInResources(bool &fused)
|
||||
return path;
|
||||
}
|
||||
|
||||
std::string getAppdataDirectory()
|
||||
static std::string getUserDirectory(NSSearchPathDirectory dir)
|
||||
{
|
||||
NSSearchPathDirectory searchdir = NSApplicationSupportDirectory;
|
||||
std::string path;
|
||||
|
||||
@autoreleasepool
|
||||
{
|
||||
NSArray *dirs = NSSearchPathForDirectoriesInDomains(searchdir, NSUserDomainMask, YES);
|
||||
NSArray<NSURL *> *dirs = [[NSFileManager defaultManager] URLsForDirectory:dir inDomains:NSUserDomainMask];
|
||||
|
||||
if (dirs.count > 0)
|
||||
path = [dirs[0] UTF8String];
|
||||
path = [dirs[0].path UTF8String];
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
std::string getAppdataDirectory()
|
||||
{
|
||||
return getUserDirectory(NSApplicationSupportDirectory);
|
||||
}
|
||||
|
||||
std::string getHomeDirectory()
|
||||
{
|
||||
std::string path;
|
||||
|
||||
@@ -32,6 +32,8 @@ namespace love
|
||||
namespace macosx
|
||||
{
|
||||
|
||||
std::string getAppdataDirectory();
|
||||
|
||||
/**
|
||||
* Returns the filepath of the first detected love file in the Resources folder
|
||||
* in the main bundle (love.app.)
|
||||
|
||||
@@ -36,6 +36,26 @@ namespace love
|
||||
namespace macosx
|
||||
{
|
||||
|
||||
static std::string getUserDirectory(NSSearchPathDirectory dir)
|
||||
{
|
||||
std::string path;
|
||||
|
||||
@autoreleasepool
|
||||
{
|
||||
NSArray<NSURL *> *dirs = [[NSFileManager defaultManager] URLsForDirectory:dir inDomains:NSUserDomainMask];
|
||||
|
||||
if (dirs.count > 0)
|
||||
path = [dirs[0].path UTF8String];
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
std::string getAppdataDirectory()
|
||||
{
|
||||
return getUserDirectory(NSApplicationSupportDirectory);
|
||||
}
|
||||
|
||||
std::string getLoveInResources()
|
||||
{
|
||||
std::string path;
|
||||
|
||||
@@ -231,7 +231,7 @@ public:
|
||||
* This "native" method returns a table of all
|
||||
* files in a given directory.
|
||||
**/
|
||||
virtual void getDirectoryItems(const char *dir, std::vector<std::string> &items) = 0;
|
||||
virtual bool getDirectoryItems(const char *dir, std::vector<std::string> &items) = 0;
|
||||
|
||||
/**
|
||||
* Enable or disable symbolic link support in love.filesystem.
|
||||
|
||||
@@ -46,6 +46,10 @@
|
||||
# include "common/ios.h"
|
||||
#endif
|
||||
|
||||
#ifdef LOVE_MACOSX
|
||||
# include "common/macosx.h"
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
|
||||
#ifdef LOVE_ANDROID
|
||||
@@ -497,9 +501,7 @@ std::string Filesystem::getAppdataDirectory()
|
||||
appdata = to_utf8(w_appdata);
|
||||
replace_char(appdata, '\\', '/');
|
||||
#elif defined(LOVE_MACOSX)
|
||||
std::string udir = getUserDirectory();
|
||||
udir.append("/Library/Application Support");
|
||||
appdata = normalize(udir);
|
||||
appdata = normalize(love::macosx::getAppdataDirectory());
|
||||
#elif defined(LOVE_IOS)
|
||||
appdata = normalize(love::ios::getAppdataDirectory());
|
||||
#elif defined(LOVE_LINUX)
|
||||
@@ -644,20 +646,21 @@ void Filesystem::append(const char *filename, const void *data, int64 size) cons
|
||||
throw love::Exception("Data could not be written.");
|
||||
}
|
||||
|
||||
void Filesystem::getDirectoryItems(const char *dir, std::vector<std::string> &items)
|
||||
bool Filesystem::getDirectoryItems(const char *dir, std::vector<std::string> &items)
|
||||
{
|
||||
if (!PHYSFS_isInit())
|
||||
return;
|
||||
return false;
|
||||
|
||||
char **rc = PHYSFS_enumerateFiles(dir);
|
||||
|
||||
if (rc == nullptr)
|
||||
return;
|
||||
return false;
|
||||
|
||||
for (char **i = rc; *i != 0; i++)
|
||||
items.push_back(*i);
|
||||
|
||||
PHYSFS_freeList(rc);
|
||||
return true;
|
||||
}
|
||||
|
||||
void Filesystem::setSymlinksEnabled(bool enable)
|
||||
|
||||
@@ -86,7 +86,7 @@ public:
|
||||
void write(const char *filename, const void *data, int64 size) const override;
|
||||
void append(const char *filename, const void *data, int64 size) const override;
|
||||
|
||||
void getDirectoryItems(const char *dir, std::vector<std::string> &items) override;
|
||||
bool getDirectoryItems(const char *dir, std::vector<std::string> &items) override;
|
||||
|
||||
void setSymlinksEnabled(bool enable) override;
|
||||
bool areSymlinksEnabled() const override;
|
||||
|
||||
Reference in New Issue
Block a user