Skip to content

Commit

Permalink
Fix rare Android crash where we don't have permissions to copy extern…
Browse files Browse the repository at this point in the history
…al mods on app start
  • Loading branch information
yairm210 committed Dec 17, 2024
1 parent 096f62a commit 9921004
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions android/src/com/unciv/app/AndroidLauncher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 9921004

Please sign in to comment.