Skip to content

Commit

Permalink
fix external check flagging deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
qimiko committed Jan 15, 2024
1 parent f938b64 commit e7ebea1
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions app/src/main/java/com/geode/launcher/utils/ReleaseManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,22 @@ class ReleaseManager private constructor(
_uiState.value = ReleaseManagerState.Finished(true)
}

private fun fileWasExternallyModified(): Boolean {
val geodeFile = getGeodeOutputPath()
if (!geodeFile.exists()) {
return false
}

val sharedPreferences = PreferenceUtils.get(applicationContext)

val fileLastModified = sharedPreferences.getLong(PreferenceUtils.Key.CURRENT_RELEASE_MODIFIED)
if (fileLastModified == 0L) {
return false
}

return fileLastModified != geodeFile.lastModified()
}

private suspend fun checkForNewRelease(allowOverwriting: Boolean = false) {
val release = try {
getLatestRelease()
Expand Down Expand Up @@ -166,8 +182,7 @@ class ReleaseManager private constructor(
}

// check if the file was externally modified
val fileLastModified = sharedPreferences.getLong(PreferenceUtils.Key.CURRENT_RELEASE_MODIFIED)
if (!allowOverwriting && fileLastModified != 0L && fileLastModified != geodeFile.lastModified()) {
if (!allowOverwriting && fileWasExternallyModified()) {
sendError(UpdateException(UpdateException.Reason.EXTERNAL_FILE_IN_USE))
return
}
Expand Down

0 comments on commit e7ebea1

Please sign in to comment.