summaryrefslogtreecommitdiff
path: root/Source/Android/app/src/main/java
diff options
context:
space:
mode:
authorJosJuice <josjuice@gmail.com>2020-11-05 19:47:23 +0100
committerJosJuice <josjuice@gmail.com>2020-12-20 13:24:54 +0100
commita7c05d7e84df5949e8edf42fa6332d6aa58282f6 (patch)
tree8d0d1bc7ba04a6c7131ddcbb6c15424ea64a8d8e /Source/Android/app/src/main/java
parent99ffee9a0acc3200f8c8af7b3fc58af2d38fb614 (diff)
Android: Add content provider support to File::FileInfo
Diffstat (limited to 'Source/Android/app/src/main/java')
-rw-r--r--Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/ContentHandler.java25
1 files changed, 25 insertions, 0 deletions
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/ContentHandler.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/ContentHandler.java
index dbeb410079..d3fbcce9c0 100644
--- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/ContentHandler.java
+++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/ContentHandler.java
@@ -74,6 +74,31 @@ public class ContentHandler
return false;
}
+ /**
+ * @return -1 if not found, -2 if directory, file size otherwise
+ */
+ @Keep
+ public static long getSizeAndIsDirectory(String uri)
+ {
+ final String[] projection = new String[]{Document.COLUMN_MIME_TYPE, Document.COLUMN_SIZE};
+ try (Cursor cursor = getContentResolver().query(Uri.parse(uri), projection, null, null, null))
+ {
+ if (cursor != null && cursor.moveToFirst())
+ {
+ if (Document.MIME_TYPE_DIR.equals(cursor.getString(0)))
+ return -2;
+ else
+ return cursor.isNull(1) ? 0 : cursor.getLong(1);
+ }
+ }
+ catch (SecurityException e)
+ {
+ Log.error("Tried to get metadata for " + uri + " without permission");
+ }
+
+ return -1;
+ }
+
@Nullable
public static String getDisplayName(@NonNull Uri uri)
{