mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 20:45:43 +00:00
upscale: refresh staged bridge DLLs when the pack or local copy changes
Staging ran only when no DLLs were staged, so a newer add-on pack or local copy never reached the games. ensure() now re-stages when DLLs are present (stageBridges returns at once when the stamp matches) and downloads only when none are staged. The local-copy stamp is a hash of the files' contents: CI builds every DLL with the same date and libxess.dll kept its size, so the old size+date stamp matched (Red Magic 12 Pro, r5 test).
This commit is contained in:
1 parent
537b52585a
commit
aabacc106d
2 files changed
+50
-3
No files matched your search
@@ -232,7 +232,8 @@ object UpscaleComponent {
|
|||||||
Thread({
|
Thread({
|
||||||
val ok = try {
|
val ok = try {
|
||||||
val files = filesReady(app, groups) || download(app, groups)
|
val files = filesReady(app, groups) || download(app, groups)
|
||||||
val bridges = files && (bridgesReady(app) || fetchBridges(app))
|
// Staged DLLs are refreshed when the pack or local copy changed; a download only when none are staged.
|
||||||
|
val bridges = files && (if (bridgesReady(app)) stageBridges(app) else fetchBridges(app))
|
||||||
when {
|
when {
|
||||||
bridges -> mutableState.value = State.Ready
|
bridges -> mutableState.value = State.Ready
|
||||||
files -> mutableState.value = State.Failed("upscaler DLLs not installed")
|
files -> mutableState.value = State.Failed("upscaler DLLs not installed")
|
||||||
@@ -319,6 +320,16 @@ object UpscaleComponent {
|
|||||||
return stageBridges(context)
|
return stageBridges(context)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Content hash of a local bridges/ tree: CI builds every DLL with the same date, and sizes often stay the same. */
|
||||||
|
internal fun localVersion(source: File): String {
|
||||||
|
val digest = MessageDigest.getInstance("SHA-256")
|
||||||
|
for (name in BRIDGE_FILES) {
|
||||||
|
digest.update(name.toByteArray())
|
||||||
|
digest.update(sha256(File(source, name)).toByteArray())
|
||||||
|
}
|
||||||
|
return digest.digest().take(8).joinToString("") { "%02x".format(it) }
|
||||||
|
}
|
||||||
|
|
||||||
/** A complete, readable bridges/ tree in one of [localRoots]: builds without a published pack. */
|
/** A complete, readable bridges/ tree in one of [localRoots]: builds without a published pack. */
|
||||||
private fun localBridges(context: Context): File? = localRoots(context).map { File(it, "bridges") }.firstOrNull { dir ->
|
private fun localBridges(context: Context): File? = localRoots(context).map { File(it, "bridges") }.firstOrNull { dir ->
|
||||||
runCatching { BRIDGE_FILES.all { File(dir, it).let { f -> f.isFile && f.canRead() && f.length() > 0 } } }.getOrDefault(false)
|
runCatching { BRIDGE_FILES.all { File(dir, it).let { f -> f.isFile && f.canRead() && f.length() > 0 } } }.getOrDefault(false)
|
||||||
@@ -338,8 +349,7 @@ object UpscaleComponent {
|
|||||||
if (!ready) Log.w(TAG, "upscaler bridges: no add-on pack and no readable local copy")
|
if (!ready) Log.w(TAG, "upscaler bridges: no add-on pack and no readable local copy")
|
||||||
return ready
|
return ready
|
||||||
}
|
}
|
||||||
val version = if (packDir != null && source == pack) packDir.name
|
val version = if (packDir != null && source == pack) packDir.name else "local-" + localVersion(source)
|
||||||
else "local-" + File(source, "x86_64-windows/libxess.dll").let { it.length().toString() + "-" + it.lastModified() }
|
|
||||||
val target = bridgesDir(context)
|
val target = bridgesDir(context)
|
||||||
val stamp = File(target, BRIDGES_STAMP)
|
val stamp = File(target, BRIDGES_STAMP)
|
||||||
if (bridgesReady(context) && runCatching { stamp.readText() }.getOrNull() == version) return true
|
if (bridgesReady(context) && runCatching { stamp.readText() }.getOrNull() == version) return true
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package com.droiddeck.launcher.session
|
||||||
|
|
||||||
|
import java.io.File
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Assert.assertNotEquals
|
||||||
|
import org.junit.Rule
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.rules.TemporaryFolder
|
||||||
|
|
||||||
|
class UpscaleBridgeVersionTest {
|
||||||
|
@get:Rule val tmp = TemporaryFolder()
|
||||||
|
|
||||||
|
private fun tree(name: String, nvngx: String): File {
|
||||||
|
val dir = tmp.newFolder(name)
|
||||||
|
for (file in UpscaleComponent.BRIDGE_FILES) {
|
||||||
|
File(dir, file).apply { parentFile?.mkdirs() }.writeText(if (file.endsWith("/nvngx.dll")) nvngx else file)
|
||||||
|
}
|
||||||
|
return dir
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun aChangedDllWithTheSameSizeAndDateIsANewVersion() {
|
||||||
|
val old = tree("old", "aaaa")
|
||||||
|
val new = tree("new", "bbbb")
|
||||||
|
for (file in UpscaleComponent.BRIDGE_FILES) {
|
||||||
|
File(old, file).setLastModified(0)
|
||||||
|
File(new, file).setLastModified(0)
|
||||||
|
}
|
||||||
|
assertNotEquals(UpscaleComponent.localVersion(old), UpscaleComponent.localVersion(new))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun theSameFilesWithOtherDatesAreTheSameVersion() {
|
||||||
|
val a = tree("a", "same")
|
||||||
|
val b = tree("b", "same")
|
||||||
|
File(b, UpscaleComponent.BRIDGE_FILES.first()).setLastModified(1_000_000)
|
||||||
|
assertEquals(UpscaleComponent.localVersion(a), UpscaleComponent.localVersion(b))
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user