Android: Fix missing directories and files with externalstorage when trying to browse it through MTP.

This commit is contained in:
Miku AuahDark
2024-04-25 11:54:13 +08:00
parent 562de22289
commit 4270985df1
4 changed files with 94 additions and 5 deletions
+19
View File
@@ -27,6 +27,10 @@
#include "Filesystem.h"
#include "filesystem/FileData.h"
#ifdef LOVE_ANDROID
#include "common/android.h"
#endif
namespace love
{
namespace filesystem
@@ -50,6 +54,21 @@ File::File(const std::string &filename, Mode mode)
{
if (!open(mode))
throw love::Exception("Could not open file at path %s", filename.c_str());
#ifdef LOVE_ANDROID
// In Android with t.externalstorage = true, make sure the file opened or
// created in the save directory has permissions of ug+rw (0660) so that
// it's accessible through MTP.
auto fs = Module::getInstance<love::filesystem::Filesystem>(Module::M_FILESYSTEM);
if (fs != nullptr && fs->isAndroidSaveExternal())
{
const char *realdir = PHYSFS_getRealDir(filename.c_str());
const std::string &savedir = fs->getFullCommonPath(Filesystem::COMMONPATH_APP_SAVEDIR);
if (realdir != nullptr && strcmp(realdir, savedir.c_str()) == 0)
love::android::fixupPermissionSingleFile(savedir, filename);
#endif
}
}
File::File(const File &other)