mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-14 01:39:40 +07:00
Fix problems with dual save folder support (#8734)
This commit is contained in:
@ -59,7 +59,10 @@ class UncivFiles(
|
|||||||
val localFile = files.local(location)
|
val localFile = files.local(location)
|
||||||
val externalFile = files.external(location)
|
val externalFile = files.external(location)
|
||||||
|
|
||||||
val toReturn = if (preferExternalStorage && files.isExternalStorageAvailable && (externalFile.exists() || !localFile.exists())) {
|
val toReturn = if (files.isExternalStorageAvailable && (
|
||||||
|
preferExternalStorage && (externalFile.exists() || !localFile.exists())
|
||||||
|
|| !preferExternalStorage && (externalFile.exists() && !localFile.exists())
|
||||||
|
) ) {
|
||||||
externalFile
|
externalFile
|
||||||
} else {
|
} else {
|
||||||
localFile
|
localFile
|
||||||
@ -97,7 +100,7 @@ class UncivFiles(
|
|||||||
debug("Getting saves from folder %s, externalStoragePath: %s", saveFolder, files.externalStoragePath)
|
debug("Getting saves from folder %s, externalStoragePath: %s", saveFolder, files.externalStoragePath)
|
||||||
val localFiles = files.local(saveFolder).list().asSequence()
|
val localFiles = files.local(saveFolder).list().asSequence()
|
||||||
|
|
||||||
val externalFiles = if (files.isExternalStorageAvailable) {
|
val externalFiles = if (files.isExternalStorageAvailable && files.local("").file().absolutePath != files.external("").file().absolutePath) {
|
||||||
files.external(saveFolder).list().asSequence()
|
files.external(saveFolder).list().asSequence()
|
||||||
} else {
|
} else {
|
||||||
emptySequence()
|
emptySequence()
|
||||||
|
@ -96,7 +96,7 @@ class LoadGameScreen : LoadOrSaveScreen() {
|
|||||||
override fun onExistingSaveSelected(saveGameFile: FileHandle) {
|
override fun onExistingSaveSelected(saveGameFile: FileHandle) {
|
||||||
copySavedGameToClipboardButton.enable()
|
copySavedGameToClipboardButton.enable()
|
||||||
rightSideButton.isVisible = true
|
rightSideButton.isVisible = true
|
||||||
rightSideButton.setText("Load [$selectedSave]".tr())
|
rightSideButton.setText("Load [${saveGameFile.name()}]".tr())
|
||||||
rightSideButton.enable()
|
rightSideButton.enable()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,14 +115,14 @@ class LoadGameScreen : LoadOrSaveScreen() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun onLoadGame() {
|
private fun onLoadGame() {
|
||||||
if (selectedSave.isEmpty()) return
|
if (selectedSave == null) return
|
||||||
val loadingPopup = Popup( this)
|
val loadingPopup = Popup( this)
|
||||||
loadingPopup.addGoodSizedLabel(Constants.loading)
|
loadingPopup.addGoodSizedLabel(Constants.loading)
|
||||||
loadingPopup.open()
|
loadingPopup.open()
|
||||||
Concurrency.run(loadGame) {
|
Concurrency.run(loadGame) {
|
||||||
try {
|
try {
|
||||||
// This is what can lead to ANRs - reading the file and setting the transients, that's why this is in another thread
|
// This is what can lead to ANRs - reading the file and setting the transients, that's why this is in another thread
|
||||||
val loadedGame = game.files.loadGameByName(selectedSave)
|
val loadedGame = game.files.loadGameFromFile(selectedSave!!)
|
||||||
game.loadGame(loadedGame, true)
|
game.loadGame(loadedGame, true)
|
||||||
} catch (notAPlayer: UncivShowableException) {
|
} catch (notAPlayer: UncivShowableException) {
|
||||||
launchOnGLThread {
|
launchOnGLThread {
|
||||||
@ -183,9 +183,10 @@ class LoadGameScreen : LoadOrSaveScreen() {
|
|||||||
private fun getCopyExistingSaveToClipboardButton(): TextButton {
|
private fun getCopyExistingSaveToClipboardButton(): TextButton {
|
||||||
val copyButton = copyExistingSaveToClipboard.toTextButton()
|
val copyButton = copyExistingSaveToClipboard.toTextButton()
|
||||||
copyButton.onActivation {
|
copyButton.onActivation {
|
||||||
|
if (selectedSave == null) return@onActivation
|
||||||
Concurrency.run(copyExistingSaveToClipboard) {
|
Concurrency.run(copyExistingSaveToClipboard) {
|
||||||
try {
|
try {
|
||||||
val gameText = game.files.getSave(selectedSave).readString()
|
val gameText = selectedSave!!.readString()
|
||||||
Gdx.app.clipboard.contents = if (gameText[0] == '{') Gzip.zip(gameText) else gameText
|
Gdx.app.clipboard.contents = if (gameText[0] == '{') Gzip.zip(gameText) else gameText
|
||||||
} catch (ex: Throwable) {
|
} catch (ex: Throwable) {
|
||||||
ex.printStackTrace()
|
ex.printStackTrace()
|
||||||
|
@ -34,7 +34,7 @@ abstract class LoadOrSaveScreen(
|
|||||||
abstract fun onExistingSaveSelected(saveGameFile: FileHandle)
|
abstract fun onExistingSaveSelected(saveGameFile: FileHandle)
|
||||||
abstract fun doubleClickAction()
|
abstract fun doubleClickAction()
|
||||||
|
|
||||||
protected var selectedSave = ""
|
protected var selectedSave: FileHandle? = null
|
||||||
private set
|
private set
|
||||||
|
|
||||||
private val savesScrollPane = VerticalFileListScrollPane()
|
private val savesScrollPane = VerticalFileListScrollPane()
|
||||||
@ -79,19 +79,20 @@ abstract class LoadOrSaveScreen(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun onDeleteClicked() {
|
private fun onDeleteClicked() {
|
||||||
if (selectedSave.isEmpty()) return
|
if (selectedSave == null) return
|
||||||
|
val name = selectedSave!!.name()
|
||||||
ConfirmPopup(this, "Are you sure you want to delete this save?", "Delete save") {
|
ConfirmPopup(this, "Are you sure you want to delete this save?", "Delete save") {
|
||||||
val result = try {
|
val result = try {
|
||||||
if (game.files.deleteSave(selectedSave)) {
|
if (game.files.deleteSave(selectedSave!!)) {
|
||||||
resetWindowState()
|
resetWindowState()
|
||||||
"[$selectedSave] deleted successfully."
|
"[$name] deleted successfully."
|
||||||
} else {
|
} else {
|
||||||
"Failed to delete [$selectedSave]."
|
"Failed to delete [$name]."
|
||||||
}
|
}
|
||||||
} catch (ex: SecurityException) {
|
} catch (ex: SecurityException) {
|
||||||
"Insufficient permissions to delete [$selectedSave]."
|
"Insufficient permissions to delete [$name]."
|
||||||
} catch (ex: Throwable) {
|
} catch (ex: Throwable) {
|
||||||
"Failed to delete [$selectedSave]."
|
"Failed to delete [$name]."
|
||||||
}
|
}
|
||||||
descriptionLabel.setText(result.tr())
|
descriptionLabel.setText(result.tr())
|
||||||
}.open()
|
}.open()
|
||||||
@ -104,7 +105,7 @@ abstract class LoadOrSaveScreen(
|
|||||||
private fun selectExistingSave(saveGameFile: FileHandle) {
|
private fun selectExistingSave(saveGameFile: FileHandle) {
|
||||||
deleteSaveButton.enable()
|
deleteSaveButton.enable()
|
||||||
|
|
||||||
selectedSave = saveGameFile.name()
|
selectedSave = saveGameFile
|
||||||
showSaveInfo(saveGameFile)
|
showSaveInfo(saveGameFile)
|
||||||
rightSideButton.isVisible = true
|
rightSideButton.isVisible = true
|
||||||
onExistingSaveSelected(saveGameFile)
|
onExistingSaveSelected(saveGameFile)
|
||||||
|
Reference in New Issue
Block a user