mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-29 06:51:30 -04:00
Add support for loading mods on Android (#1825)
* Add support for loading mods * Move mod folder copying into its own function * Only request permission to read storage, not write * Only allow mods on KK+ (removes storage permission)
This commit is contained in:
parent
3f27bdb19e
commit
ddf86ecf2f
@ -1,17 +1,46 @@
|
|||||||
package com.unciv.app
|
package com.unciv.app
|
||||||
|
|
||||||
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import com.badlogic.gdx.backends.android.AndroidApplication
|
import com.badlogic.gdx.backends.android.AndroidApplication
|
||||||
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration
|
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration
|
||||||
import com.unciv.UncivGame
|
import com.unciv.UncivGame
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
class AndroidLauncher : AndroidApplication() {
|
class AndroidLauncher : AndroidApplication() {
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
|
// Only allow mods on KK+, to avoid READ_EXTERNAL_STORAGE permission earlier versions need
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||||
|
copyMods()
|
||||||
|
}
|
||||||
|
|
||||||
val config = AndroidApplicationConfiguration().apply { useImmersiveMode = true }
|
val config = AndroidApplicationConfiguration().apply { useImmersiveMode = true }
|
||||||
val game = UncivGame(BuildConfig.VERSION_NAME,
|
val game = UncivGame(BuildConfig.VERSION_NAME,
|
||||||
CrashReportSenderAndroid(this))
|
CrashReportSenderAndroid(this))
|
||||||
{this.finish()}
|
{this.finish()}
|
||||||
initialize(game, config)
|
initialize(game, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies mods from external data directory (where users can access) to the private one (where
|
||||||
|
* libGDX reads from). Note: deletes all files currently in the private mod directory and
|
||||||
|
* replaces them with the ones in the external folder!)
|
||||||
|
*/
|
||||||
|
private fun copyMods() {
|
||||||
|
// Mod directory in the internal app data (where Gdx.files.local looks)
|
||||||
|
val internalModsDir = File("${filesDir.path}/mods")
|
||||||
|
|
||||||
|
// Mod directory in the shared app data (where the user can see and modify)
|
||||||
|
val externalModsDir = File("${getExternalFilesDir(null)?.path}/mods")
|
||||||
|
|
||||||
|
// Empty out the mods directory so it can be replaced by the external one
|
||||||
|
// Done to ensure it only contains mods in the external dir (so users can delete some)
|
||||||
|
if (internalModsDir.exists()) internalModsDir.deleteRecursively()
|
||||||
|
|
||||||
|
// Copy external mod directory (with data user put in it) to internal (where it can be read)
|
||||||
|
if (!externalModsDir.exists()) externalModsDir.mkdirs()
|
||||||
|
externalModsDir.copyRecursively(internalModsDir)
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user