From bfa4bbe20a0de61a4ce52d139abff8feb9d3ce09 Mon Sep 17 00:00:00 2001 From: Sergii Pylypenko Date: Sun, 28 Nov 2021 01:33:53 +0200 Subject: [PATCH] SDL: auto-switch data path to internal storage if writing to SD card fails --- project/java/DataDownloader.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/project/java/DataDownloader.java b/project/java/DataDownloader.java index 42d60e82e..133ef9034 100644 --- a/project/java/DataDownloader.java +++ b/project/java/DataDownloader.java @@ -53,14 +53,13 @@ import java.util.Arrays; import android.text.SpannedString; import android.app.AlertDialog; import android.content.DialogInterface; +import android.content.Intent; import android.Manifest; import android.content.pm.PackageManager; import android.os.storage.StorageManager; import android.os.storage.OnObbStateChangeListener; -//import com.google.android.play.core.assetpacks.AssetPackManagerFactory; -//import com.google.android.play.core.assetpacks.AssetPackManager; import android.content.res.AssetManager; import android.content.pm.PackageManager; import android.content.pm.ApplicationInfo; @@ -219,6 +218,16 @@ class DataDownloader extends Thread ! DownloadDataFile(downloadFiles[i].replace("", android.os.Build.CPU_ABI2), DOWNLOAD_FLAG_FILENAME + String.valueOf(i) + ".flag", count+1, total, i) ) ) { DownloadFailed = true; + if (!Parent.getFilesDir().getAbsolutePath().equals(Globals.DataDir)) + { + Globals.DataDir = Parent.getFilesDir().getAbsolutePath(); + Globals.DownloadToSdcard = false; + Log.i("SDL", "Switching download destination directory to internal storage and restarting the app: " + Globals.DataDir); + Settings.Save(Parent); + Intent intent = new Intent(Parent, RestartMainActivity.class); + Parent.startActivity(intent); + System.exit(0); + } return; } }