Generate SSD bundled truth seeding from typed Jerboa
ober
39e463405f26196768bd62fab3dd71b57aa1428d
--- a/templates/ssd-review.ss +++ b/templates/ssd-review.ss @@ -15530,6 +15530,7 @@ (typed-kotlin-file "com/sfb/ssdreview/TruthStoreLocal.kt" (kotlin-imports (android content Context) (android content SharedPreferences) + (android content res AssetManager) (android util Base64) (java io File) (java io InputStream) @@ -15552,7 +15553,9 @@ truthStoreRemoteUrlLocal truthStoreReadResponseTextLocal truthStoreWriteRemoteTruthLocal - truthStoreApplyLearnedGuessesLocal) + truthStoreApplyLearnedGuessesLocal + truthStoreSeedBundledTruthLocal) + (type AssetManager) (type Context) (type Exception) (type File) @@ -15579,6 +15582,13 @@ (extern (truthStoreEventsDir (store : TruthStore)) : File (kotlin-member-get eventsDir)) + (extern (truthStoreContextAssets + (context : Context)) : AssetManager + (kotlin-member-get assets)) + (extern (truthStoreAssetOpen + (assets : AssetManager) + (name : String)) : InputStream + (kotlin-member-call open)) (extern (truthStoreLearnedDir (store : TruthStore)) : File (kotlin-member-get learnedDir)) @@ -15593,6 +15603,10 @@ (extern (truthStoreRebuildLearnedExamplesRaw (store : TruthStore)) : Unit (kotlin-member-call rebuildLearnedExamples)) + (extern (truthStoreImportZipRaw + (store : TruthStore) + (input : InputStream)) : Int32 + (kotlin-member-call importZip)) (extern (truthStoreSaveTruthSnapshotRaw (store : TruthStore) (truth : JSONObject)) : File @@ -16128,7 +16142,20 @@ session (learnedExamplesFromDocument (jsonObjectFromText - (truthStoreReadLocalText file)))))))))) + (truthStoreReadLocalText file)))))))) + (def (truthStoreSeedBundledTruthLocal + (store : TruthStore) + (context : Context)) : Int32 + (try + (let ((input + (truthStoreAssetOpen + (truthStoreContextAssets context) + "seed_ssd_review.zip"))) + (try-finally + (truthStoreImportZipRaw store input) + (truthStoreInputStreamClose input))) + (catch (error : Exception) + (int32 0)))))) (kotlin-file-lines "com/sfb/ssdreview/TruthStore.kt" ( @@ -16629,14 +16656,8 @@ " atomicWriteText(containedLeaf(learnedDir, learnedExamplesFileName()), learned.toString(2))" " }" "" - " internal fun seedBundledTruth(): Int {" - " return try {" - " context.assets.open(\"seed_ssd_review.zip\").use { importZip(it) }" - " } catch (_: Exception) {" - " // The app can still operate from local or remotely synced truth." - " 0" - " }" - " }" + " internal fun seedBundledTruth(): Int =" + " truthStoreSeedBundledTruthLocal(this, context)" "" " private fun exportToTree(tree: DocumentFile): Int {" " storageStats()"