mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 04:46:08 +00:00
feat: store games get their logo from the store
GOG (api.gog.com v2 `_links.logo`), Epic (catalog keyImage `DieselGameBoxLogo`) and Amazon (`productDetail.details.logoUrl`) logos are kept in the install record as an optional `logo` field and written next to the game as logo.png when the install finishes. The PNG is kept as it came, transparency included, and anything that does not decode as an image is dropped. Older install records without the field still read as before.
This commit is contained in:
1 parent
5970de928e
commit
8ceff5641a
15 files changed
+193
-12
No files matched your search
@@ -34,6 +34,17 @@ class StoreGameSidecarTest {
|
||||
assertEquals("ns", back.extra["namespace"])
|
||||
}
|
||||
|
||||
@Test fun theStoreLogoRoundTripsAndOlderFilesHaveNone() {
|
||||
val withLogo = sample.copy(logo = "https://x/logo.png")
|
||||
val back = StoreGameSidecar.parse(withLogo.toJson().toString())!!
|
||||
assertEquals("https://x/logo.png", back.logo)
|
||||
assertEquals("https://x/logo.png", back.copy(state = StoreGameSidecar.STATE_UPDATING).logo)
|
||||
assertFalse(sample.toJson().has("logo"))
|
||||
assertNull(StoreGameSidecar.parse(sample.toJson().toString())!!.logo)
|
||||
assertNull(StoreGameSidecar.parse("""{"store":"gog","id":"1","title":"T","exe":"game.exe","cover":"c","hero":"h"}""")!!.logo)
|
||||
assertNull(StoreGameSidecar.parse("""{"store":"gog","id":"1","title":"T","exe":"game.exe","logo":""}""")!!.logo)
|
||||
}
|
||||
|
||||
@Test fun defaultsWhenFieldsAreAbsent() {
|
||||
val back = StoreGameSidecar.parse("""{"store":"gog","id":"1","title":"T","exe":"bin\\game.exe","addToSteam":false}""")!!
|
||||
assertEquals("bin/game.exe", back.exe)
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
package com.droiddeck.launcher.stores
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.graphics.Color
|
||||
import com.droiddeck.launcher.stores.amazon.AmazonLibrary
|
||||
import com.droiddeck.launcher.stores.gog.GogBackend
|
||||
import org.json.JSONObject
|
||||
import org.junit.Assert.assertArrayEquals
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.annotation.GraphicsMode
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.File
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [33])
|
||||
@GraphicsMode(GraphicsMode.Mode.NATIVE)
|
||||
class StoreLogoTest {
|
||||
@get:Rule val tmp = TemporaryFolder()
|
||||
|
||||
private fun encoded(format: Bitmap.CompressFormat): ByteArray {
|
||||
val bmp = Bitmap.createBitmap(8, 4, Bitmap.Config.ARGB_8888)
|
||||
bmp.eraseColor(Color.TRANSPARENT)
|
||||
bmp.setPixel(1, 1, Color.RED)
|
||||
return ByteArrayOutputStream().also { bmp.compress(format, 100, it) }.toByteArray()
|
||||
}
|
||||
|
||||
@Test fun aPngLogoIsKeptAsItCameWithItsTransparency() {
|
||||
val png = encoded(Bitmap.CompressFormat.PNG)
|
||||
val dst = File(tmp.root, StoreArt.LOGO)
|
||||
assertTrue(StoreArt.writeLogo(png, dst))
|
||||
assertArrayEquals(png, dst.readBytes())
|
||||
val back = BitmapFactory.decodeFile(dst.path)
|
||||
assertEquals(0, Color.alpha(back.getPixel(0, 0)))
|
||||
assertEquals(Color.RED, back.getPixel(1, 1))
|
||||
assertFalse(File(dst.path + ".tmp").exists())
|
||||
}
|
||||
|
||||
@Test fun anotherImageFormatIsStoredAsPng() {
|
||||
val dst = File(tmp.root, StoreArt.LOGO)
|
||||
assertTrue(StoreArt.writeLogo(encoded(Bitmap.CompressFormat.JPEG), dst))
|
||||
val head = dst.readBytes().take(4)
|
||||
assertEquals(listOf(0x89.toByte(), 'P'.code.toByte(), 'N'.code.toByte(), 'G'.code.toByte()), head)
|
||||
assertEquals(8, BitmapFactory.decodeFile(dst.path).width)
|
||||
}
|
||||
|
||||
@Test fun whatIsNotAnImageIsRefusedAndAnExistingLogoStays() {
|
||||
val dst = File(tmp.root, StoreArt.LOGO)
|
||||
assertFalse(StoreArt.writeLogo("<html>not found</html>".toByteArray(), dst))
|
||||
assertFalse(dst.exists())
|
||||
dst.writeBytes(byteArrayOf(1, 2, 3))
|
||||
assertTrue(StoreArt.writeLogo(encoded(Bitmap.CompressFormat.PNG), dst))
|
||||
assertArrayEquals(byteArrayOf(1, 2, 3), dst.readBytes())
|
||||
assertTrue(StoreArt.fetchLogo(tmp.root, "https://invalid.example/logo.png"))
|
||||
}
|
||||
|
||||
@Test fun gogTakesTheV2LogoLinkOnly() {
|
||||
val v2 = JSONObject("""{"_links":{"logo":{"href":"https://images.gog-statics.com/abc_logo.png"},"galaxyBackgroundImage":{"href":"https://x/bg.jpg"}}}""")
|
||||
assertEquals("https://images.gog-statics.com/abc_logo.png", GogBackend.logoOf(v2))
|
||||
assertEquals("https://images.gog-statics.com/rel.png", GogBackend.logoOf(JSONObject("""{"_links":{"logo":{"href":"//images.gog-statics.com/rel.png"}}}""")))
|
||||
assertNull(GogBackend.logoOf(JSONObject("""{"_links":{}}""")))
|
||||
assertNull(GogBackend.logoOf(JSONObject("""{"images":{"logo2x":"https://x/glx_logo_2x.jpg"}}""")))
|
||||
assertNull(GogBackend.logoOf(JSONObject("""{"_links":{"logo":{"href":"http://x/logo.png"}}}""")))
|
||||
}
|
||||
|
||||
@Test fun amazonKeepsTheLogoFromTheLibraryAndItsCache() {
|
||||
val app = RuntimeEnvironment.getApplication()
|
||||
val fresh = AmazonLibrary.gameFrom(JSONObject().put("productId", "p").put("title", "Game").put("logo", "https://m/logo.png"), null)
|
||||
assertEquals("https://m/logo.png", fresh.logoUrl)
|
||||
assertEquals("https://m/logo.png", AmazonLibrary.toCatalogItem(app, fresh).logoUrl)
|
||||
assertEquals(listOf(fresh), AmazonLibrary.fromCacheJson(AmazonLibrary.toCacheJson(listOf(fresh))))
|
||||
val kept = AmazonLibrary.gameFrom(JSONObject().put("productId", "p").put("title", "Game"), fresh)
|
||||
assertEquals("https://m/logo.png", kept.logoUrl)
|
||||
val none = AmazonLibrary.gameFrom(JSONObject().put("productId", "q").put("title", "Other"), null)
|
||||
assertNull(AmazonLibrary.toCatalogItem(app, none).logoUrl)
|
||||
assertEquals("", AmazonLibrary.fromCacheJson("""[{"productId":"old","title":"Old"}]""").single().logoUrl)
|
||||
}
|
||||
}
|
||||
@@ -83,6 +83,18 @@ class EpicLibraryTest {
|
||||
assertEquals("Fig", EpicLibrary.gameFrom(record, null, null).title)
|
||||
}
|
||||
|
||||
@Test fun theCatalogLogoIsKeptInTheCacheAndHandedToTheInstall() {
|
||||
val record = JSONObject().put("appName", "Fig").put("namespace", "ns").put("catalogItemId", "cat")
|
||||
val fresh = EpicLibrary.gameFrom(record, JSONObject().put("logo", "https://e/logo.png"), null)
|
||||
assertEquals("https://e/logo.png", fresh.artLogo)
|
||||
assertEquals("https://e/logo.png", EpicLibrary.gameFrom(record, JSONObject().put("title", "Fig"), fresh).artLogo)
|
||||
assertEquals(listOf(fresh), EpicLibrary.fromCacheJson(EpicLibrary.toCacheJson(listOf(fresh))))
|
||||
assertEquals("https://e/logo.png", EpicLibrary.toCatalogItem(app, fresh).logoUrl)
|
||||
val plain = EpicGame("Old", "ns", "c", "Old")
|
||||
assertFalse(JSONArray(EpicLibrary.toCacheJson(listOf(plain))).getJSONObject(0).has("artLogo"))
|
||||
assertEquals(null, EpicLibrary.toCatalogItem(app, plain).logoUrl)
|
||||
}
|
||||
|
||||
@Test fun signOutForgetsOnlyTheLibrary() {
|
||||
EpicPrefs.get(app).edit().putString(EpicLibrary.KEY_CACHE, "[]").putLong(EpicLibrary.KEY_SYNCED_AT, 1L)
|
||||
.putString("cloud_template_Fig", "{AppData}/x").commit()
|
||||
|
||||
Reference in new issue
Block a user