From aebda108c2ce10fcbe581fa9aad5ab52ff34b67b Mon Sep 17 00:00:00 2001 From: Ghabry Date: Fri, 3 Jan 2025 18:13:54 +0100 Subject: [PATCH] Android Standalone mode: Fix save directory and attaching of files when bug reporting --- .../android/app/src/main/AndroidManifest.xml | 11 +++++++++ .../game_browser/GameBrowserHelper.java | 16 +++++++++---- .../player/player/EasyRpgPlayerActivity.java | 23 ++++++++++++++++--- .../app/src/main/res/xml/file_paths.xml | 3 +++ 4 files changed, 45 insertions(+), 8 deletions(-) create mode 100644 builds/android/app/src/main/res/xml/file_paths.xml diff --git a/builds/android/app/src/main/AndroidManifest.xml b/builds/android/app/src/main/AndroidManifest.xml index 6b69aa1ae9..3be2ba9ac3 100644 --- a/builds/android/app/src/main/AndroidManifest.xml +++ b/builds/android/app/src/main/AndroidManifest.xml @@ -106,6 +106,17 @@ + + + + + diff --git a/builds/android/app/src/main/java/org/easyrpg/player/game_browser/GameBrowserHelper.java b/builds/android/app/src/main/java/org/easyrpg/player/game_browser/GameBrowserHelper.java index dcb6d32460..131dfd1212 100644 --- a/builds/android/app/src/main/java/org/easyrpg/player/game_browser/GameBrowserHelper.java +++ b/builds/android/app/src/main/java/org/easyrpg/player/game_browser/GameBrowserHelper.java @@ -58,13 +58,19 @@ public static void launchGame(Context context, Game game, boolean debugMode) { String savePath = path; if (!game.getSavePath().isEmpty()) { - DocumentFile saveFolder = Helper.createFolderInSave(context, game.getSavePath()); - - // In error case the native code will try to put a save folder next to the zip - if (saveFolder != null) { - savePath = saveFolder.getUri().toString(); + if (game.isStandalone()) { + savePath = game.getSavePath(); args.add("--save-path"); args.add(savePath); + } else { + DocumentFile saveFolder = Helper.createFolderInSave(context, game.getSavePath()); + + // In error case the native code will try to put a save folder next to the zip + if (saveFolder != null) { + savePath = saveFolder.getUri().toString(); + args.add("--save-path"); + args.add(savePath); + } } } diff --git a/builds/android/app/src/main/java/org/easyrpg/player/player/EasyRpgPlayerActivity.java b/builds/android/app/src/main/java/org/easyrpg/player/player/EasyRpgPlayerActivity.java index 828be979ea..8c32ed2e2c 100644 --- a/builds/android/app/src/main/java/org/easyrpg/player/player/EasyRpgPlayerActivity.java +++ b/builds/android/app/src/main/java/org/easyrpg/player/player/EasyRpgPlayerActivity.java @@ -47,6 +47,7 @@ import android.widget.RelativeLayout.LayoutParams; import android.widget.TextView; +import androidx.core.content.FileProvider; import androidx.core.view.GravityCompat; import androidx.drawerlayout.widget.DrawerLayout; @@ -65,6 +66,7 @@ import java.io.File; import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.Locale; /** * EasyRPG Player for Android (inheriting from SDLActivity) @@ -239,12 +241,27 @@ private void reportBug() { .setPositiveButton(R.string.ok, (dialog, id) -> { // Attach to the email : the easyrpg log file and savefiles ArrayList files = new ArrayList<>(); - // The easyrpg_log.txt + String savepath = getIntent().getStringExtra(TAG_SAVE_PATH); if (getIntent().getBooleanExtra(TAG_STANDALONE, false)) { - // FIXME: Attaching files does not work because the files are in /data and - // other apps have no permission + File logFile = new File(savepath, "easyrpg_log.txt"); + if (logFile.exists()) { + Uri logUri = FileProvider.getUriForFile(this, getPackageName() + ".fileprovider", logFile); + if (logUri != null) { + files.add(logUri); + } + } + + for (int i = 1; i <= 15; ++i) { + File saveFile = new File(savepath, String.format(Locale.ROOT, "Save%02d.lsd", i)); + if (saveFile.exists()) { + Uri saveUri = FileProvider.getUriForFile(this, getPackageName() + ".fileprovider", saveFile); + if (saveUri != null) { + files.add(saveUri); + } + } + } } else { Uri saveFolder = Uri.parse(savepath); Uri log = Helper.findFileUri(getContext(), saveFolder, "easyrpg_log.txt"); diff --git a/builds/android/app/src/main/res/xml/file_paths.xml b/builds/android/app/src/main/res/xml/file_paths.xml new file mode 100644 index 0000000000..d2c05e9d88 --- /dev/null +++ b/builds/android/app/src/main/res/xml/file_paths.xml @@ -0,0 +1,3 @@ + + +