From 992100412d0b6349a5c37395a65cf9e356b67971 Mon Sep 17 00:00:00 2001 From: yairm210 Date: Tue, 17 Dec 2024 12:14:22 +0200 Subject: [PATCH] Fix rare Android crash where we don't have permissions to copy external mods on app start --- android/src/com/unciv/app/AndroidLauncher.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/android/src/com/unciv/app/AndroidLauncher.kt b/android/src/com/unciv/app/AndroidLauncher.kt index 29367c58689a5..0bb417bdfba37 100644 --- a/android/src/com/unciv/app/AndroidLauncher.kt +++ b/android/src/com/unciv/app/AndroidLauncher.kt @@ -11,6 +11,7 @@ import com.unciv.ui.components.fonts.Fonts import com.unciv.utils.Display import com.unciv.utils.Log import java.io.File +import java.lang.Exception open class AndroidLauncher : AndroidApplication() { @@ -65,9 +66,11 @@ open class AndroidLauncher : AndroidApplication() { val externalPath = getExternalFilesDir(null)?.path ?: return val externalModsDir = File("$externalPath/mods") - // Copy external mod directory (with data user put in it) to internal (where it can be read) - if (!externalModsDir.exists()) externalModsDir.mkdirs() // this can fail sometimes, which is why we check if it exists again in the next line - if (externalModsDir.exists()) externalModsDir.copyRecursively(internalModsDir, true) + try { // Rarely we get a kotlin.io.AccessDeniedException, if so - no biggie + // Copy external mod directory (with data user put in it) to internal (where it can be read) + if (!externalModsDir.exists()) externalModsDir.mkdirs() // this can fail sometimes, which is why we check if it exists again in the next line + if (externalModsDir.exists()) externalModsDir.copyRecursively(internalModsDir, true) + } catch (ex: Exception) {} } override fun onPause() {