Skip to content

Commit

Permalink
use release hash instead of modified time
Browse files Browse the repository at this point in the history
  • Loading branch information
qimiko committed Jan 21, 2024
1 parent 36152d8 commit cf568bc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class PreferenceUtils(private val sharedPreferences: SharedPreferences) {
Key.CURRENT_VERSION_TIMESTAMP -> "PreferenceCurrentVersionDescriptor"
Key.THEME -> "PreferenceTheme"
Key.BLACK_BACKGROUND -> "PreferenceBlackBackground"
Key.CURRENT_RELEASE_MODIFIED -> "PreferenceReleaseModified"
Key.CURRENT_RELEASE_MODIFIED -> "PreferenceReleaseModifiedHash"
}
}

Expand Down
22 changes: 13 additions & 9 deletions app/src/main/java/com/geode/launcher/utils/ReleaseManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch
import okhttp3.Cache
import okhttp3.OkHttpClient
import okio.buffer
import okio.source
import java.io.File
import java.io.InterruptedIOException

Expand Down Expand Up @@ -145,13 +147,12 @@ class ReleaseManager private constructor(
}

val sharedPreferences = PreferenceUtils.get(applicationContext)
val originalFileHash = sharedPreferences.getString(PreferenceUtils.Key.CURRENT_RELEASE_MODIFIED)
?: return false

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

return fileLastModified != geodeFile.lastModified()
return originalFileHash != currentFileHash
}

private suspend fun checkForNewRelease(allowOverwriting: Boolean = false) {
Expand Down Expand Up @@ -203,13 +204,16 @@ class ReleaseManager private constructor(
release.getDescriptor()
)

// store hash as modified time is unreliable (don't know why)
val outputFile = getGeodeOutputPath()
sharedPreferences.setLong(
PreferenceUtils.Key.CURRENT_RELEASE_MODIFIED,
outputFile.lastModified()
)
val fileHash = computeFileHash(outputFile)

sharedPreferences.setString(PreferenceUtils.Key.CURRENT_RELEASE_MODIFIED, fileHash)
}

private fun computeFileHash(file: File): String =
file.source().buffer().readByteString().md5().hex()

private fun getGeodeOutputPath(): File {
val geodeName = LaunchUtils.geodeFilename
val geodeDirectory = LaunchUtils.getBaseDirectory(applicationContext)
Expand Down

0 comments on commit cf568bc

Please sign in to comment.