mirror of
https://git.suyu.dev/suyu/suyu
synced 2024-11-01 21:07:52 +00:00
Merge pull request #10796 from bunnei/fix-saf
android: fs: Fix Exists / IsFile for SAF.
This commit is contained in:
commit
9a04793ae8
4 changed files with 54 additions and 1 deletions
|
@ -19,6 +19,8 @@ import org.yuzu.yuzu_emu.activities.EmulationActivity
|
||||||
import org.yuzu.yuzu_emu.utils.DocumentsTree.Companion.isNativePath
|
import org.yuzu.yuzu_emu.utils.DocumentsTree.Companion.isNativePath
|
||||||
import org.yuzu.yuzu_emu.utils.FileUtil.getFileSize
|
import org.yuzu.yuzu_emu.utils.FileUtil.getFileSize
|
||||||
import org.yuzu.yuzu_emu.utils.FileUtil.openContentUri
|
import org.yuzu.yuzu_emu.utils.FileUtil.openContentUri
|
||||||
|
import org.yuzu.yuzu_emu.utils.FileUtil.exists
|
||||||
|
import org.yuzu.yuzu_emu.utils.FileUtil.isDirectory
|
||||||
import org.yuzu.yuzu_emu.utils.Log.error
|
import org.yuzu.yuzu_emu.utils.Log.error
|
||||||
import org.yuzu.yuzu_emu.utils.Log.verbose
|
import org.yuzu.yuzu_emu.utils.Log.verbose
|
||||||
import org.yuzu.yuzu_emu.utils.Log.warning
|
import org.yuzu.yuzu_emu.utils.Log.warning
|
||||||
|
@ -85,6 +87,22 @@ object NativeLibrary {
|
||||||
} else getFileSize(appContext, path)
|
} else getFileSize(appContext, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Keep
|
||||||
|
@JvmStatic
|
||||||
|
fun exists(path: String?): Boolean {
|
||||||
|
return if (isNativePath(path!!)) {
|
||||||
|
YuzuApplication.documentsTree!!.exists(path)
|
||||||
|
} else exists(appContext, path)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Keep
|
||||||
|
@JvmStatic
|
||||||
|
fun isDirectory(path: String?): Boolean {
|
||||||
|
return if (isNativePath(path!!)) {
|
||||||
|
YuzuApplication.documentsTree!!.isDirectory(path)
|
||||||
|
} else isDirectory(appContext, path)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if pro controller isn't available and handheld is
|
* Returns true if pro controller isn't available and handheld is
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -36,6 +36,11 @@ class DocumentsTree {
|
||||||
return resolvePath(filepath) != null
|
return resolvePath(filepath) != null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun isDirectory(filepath: String): Boolean {
|
||||||
|
val node = resolvePath(filepath)
|
||||||
|
return node != null && node.isDirectory
|
||||||
|
}
|
||||||
|
|
||||||
private fun resolvePath(filepath: String): DocumentsNode? {
|
private fun resolvePath(filepath: String): DocumentsNode? {
|
||||||
val tokens = StringTokenizer(filepath, File.separator, false)
|
val tokens = StringTokenizer(filepath, File.separator, false)
|
||||||
var iterator = root
|
var iterator = root
|
||||||
|
|
|
@ -3,6 +3,9 @@
|
||||||
|
|
||||||
#include "common/fs/file.h"
|
#include "common/fs/file.h"
|
||||||
#include "common/fs/fs.h"
|
#include "common/fs/fs.h"
|
||||||
|
#ifdef ANDROID
|
||||||
|
#include "common/fs/fs_android.h"
|
||||||
|
#endif
|
||||||
#include "common/fs/path_util.h"
|
#include "common/fs/path_util.h"
|
||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
|
|
||||||
|
@ -525,15 +528,39 @@ void IterateDirEntriesRecursively(const std::filesystem::path& path,
|
||||||
// Generic Filesystem Operations
|
// Generic Filesystem Operations
|
||||||
|
|
||||||
bool Exists(const fs::path& path) {
|
bool Exists(const fs::path& path) {
|
||||||
|
#ifdef ANDROID
|
||||||
|
if (Android::IsContentUri(path)) {
|
||||||
|
return Android::Exists(path);
|
||||||
|
} else {
|
||||||
|
return fs::exists(path);
|
||||||
|
}
|
||||||
|
#else
|
||||||
return fs::exists(path);
|
return fs::exists(path);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsFile(const fs::path& path) {
|
bool IsFile(const fs::path& path) {
|
||||||
|
#ifdef ANDROID
|
||||||
|
if (Android::IsContentUri(path)) {
|
||||||
|
return !Android::IsDirectory(path);
|
||||||
|
} else {
|
||||||
|
return fs::is_regular_file(path);
|
||||||
|
}
|
||||||
|
#else
|
||||||
return fs::is_regular_file(path);
|
return fs::is_regular_file(path);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsDir(const fs::path& path) {
|
bool IsDir(const fs::path& path) {
|
||||||
|
#ifdef ANDROID
|
||||||
|
if (Android::IsContentUri(path)) {
|
||||||
|
return Android::IsDirectory(path);
|
||||||
|
} else {
|
||||||
|
return fs::is_directory(path);
|
||||||
|
}
|
||||||
|
#else
|
||||||
return fs::is_directory(path);
|
return fs::is_directory(path);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
fs::path GetCurrentDir() {
|
fs::path GetCurrentDir() {
|
||||||
|
|
|
@ -12,7 +12,10 @@
|
||||||
"openContentUri", "(Ljava/lang/String;Ljava/lang/String;)I")
|
"openContentUri", "(Ljava/lang/String;Ljava/lang/String;)I")
|
||||||
|
|
||||||
#define ANDROID_SINGLE_PATH_DETERMINE_FUNCTIONS(V) \
|
#define ANDROID_SINGLE_PATH_DETERMINE_FUNCTIONS(V) \
|
||||||
V(GetSize, std::uint64_t, get_size, CallStaticLongMethod, "getSize", "(Ljava/lang/String;)J")
|
V(GetSize, std::uint64_t, get_size, CallStaticLongMethod, "getSize", "(Ljava/lang/String;)J") \
|
||||||
|
V(IsDirectory, bool, is_directory, CallStaticBooleanMethod, "isDirectory", \
|
||||||
|
"(Ljava/lang/String;)Z") \
|
||||||
|
V(Exists, bool, file_exists, CallStaticBooleanMethod, "exists", "(Ljava/lang/String;)Z")
|
||||||
|
|
||||||
namespace Common::FS::Android {
|
namespace Common::FS::Android {
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue