Skip to content

Commit

Permalink
Android Standalone mode: Fix save directory and attaching of files wh…
Browse files Browse the repository at this point in the history
…en bug reporting
  • Loading branch information
Ghabry committed Jan 3, 2025
1 parent 9f5cc93 commit aebda10
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
11 changes: 11 additions & 0 deletions builds/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@
<activity
android:name=".button_mapping.ButtonMappingActivity"
android:configChanges="orientation|screenSize" />

<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">

<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
Expand Down Expand Up @@ -239,12 +241,27 @@ private void reportBug() {
.setPositiveButton(R.string.ok, (dialog, id) -> {
// Attach to the email : the easyrpg log file and savefiles
ArrayList<Uri> 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");
Expand Down
3 changes: 3 additions & 0 deletions builds/android/app/src/main/res/xml/file_paths.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<paths>
<external-path name="external_files" path="."/>
</paths>

0 comments on commit aebda10

Please sign in to comment.