From a7c832b8c98d36ec127be76a5fcae0463de8cfb0 Mon Sep 17 00:00:00 2001 From: vrubelroman Date: Mon, 26 Oct 2026 01:07:21 +0300 Subject: [PATCH] Android: CheckedDownload shared by the engine's network and Maia's weights The system download with SHA-256 check moves out of EngineFiles into a class for any such file; EngineFiles keeps its behaviour (same preferences key); MaiaFiles fetches the small model of the pinned revision on request. Co-Authored-By: Claude Opus 5.5 --- .../chesspenguin/ChessPenguinApp.kt | 3 + .../chesspenguin/data/CheckedDownload.kt | 282 ++++++++++++++++++ .../chesspenguin/data/EngineFiles.kt | 271 ++--------------- .../chesspenguin/data/MaiaFiles.kt | 24 ++ .../app/src/main/res/values-de/strings.xml | 1 + .../app/src/main/res/values-es/strings.xml | 1 + .../app/src/main/res/values-fr/strings.xml | 1 + .../app/src/main/res/values-it/strings.xml | 1 + .../app/src/main/res/values-kk/strings.xml | 1 + .../app/src/main/res/values-pt/strings.xml | 1 + .../app/src/main/res/values-ru/strings.xml | 1 + .../app/src/main/res/values-uz/strings.xml | 1 + .../app/src/main/res/values/strings.xml | 1 + 13 files changed, 341 insertions(+), 248 deletions(-) create mode 100644 androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/data/CheckedDownload.kt create mode 100644 androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/data/MaiaFiles.kt diff --git a/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/ChessPenguinApp.kt b/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/ChessPenguinApp.kt index 20a4820..b20f813 100644 --- a/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/ChessPenguinApp.kt +++ b/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/ChessPenguinApp.kt @@ -9,6 +9,7 @@ import android.provider.OpenableColumns import io.github.vrubelroman.chesspenguin.data.AppUpdates import io.github.vrubelroman.chesspenguin.data.DbEntry import io.github.vrubelroman.chesspenguin.data.EngineFiles +import io.github.vrubelroman.chesspenguin.data.MaiaFiles import io.github.vrubelroman.chesspenguin.data.Library import io.github.vrubelroman.chesspenguin.data.OnlineDownloads import io.github.vrubelroman.chesspenguin.data.Settings @@ -30,6 +31,8 @@ class ChessPenguinApp : Application() { val library by lazy { Library(this) } val settings by lazy { Settings(this) } val engineFiles by lazy { EngineFiles(this, scope) } + /// Maia's weights, downloaded on request (android-play.md §31). + val maiaFiles by lazy { MaiaFiles(this, scope) } /// Games from Lichess and Chess.com being downloaded (android-ui.md §23). val downloads by lazy { OnlineDownloads(library, scope) } /// The app's own updates (android-ui.md §25). diff --git a/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/data/CheckedDownload.kt b/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/data/CheckedDownload.kt new file mode 100644 index 0000000..b112163 --- /dev/null +++ b/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/data/CheckedDownload.kt @@ -0,0 +1,282 @@ +package io.github.vrubelroman.chesspenguin.data + +import android.app.DownloadManager +import android.content.Context +import android.net.ConnectivityManager +import android.net.NetworkCapabilities +import android.net.Uri +import android.os.storage.StorageManager +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.Job +import kotlinx.coroutines.delay +import kotlinx.coroutines.ensureActive +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.isActive +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext +import java.io.File +import java.io.IOException +import java.io.InputStream +import java.security.MessageDigest + +/// Why a downloaded file is not there. +enum class NetProblem { NoInternet, Interrupted, NoSpace, Corrupt } + +sealed interface NetState { + data object Missing : NetState + data class Loading(val done: Long, val total: Long) : NetState + data class Failed(val problem: NetProblem) : NetState + data object Ready : NetState +} + +/// A file of known size and SHA-256 fetched on request into the app's storage: the +/// engine's network, Maia's weights. +data class FileSpec( + /// Folder in the app's files, and the file's name. + val dir: String, + val name: String, + val url: String, + val size: Long, + val sha256: String, + /// The download's title in the system's notification. + val title: String, + /// The preferences that keep the system's download id (one file each). + val prefs: String, +) + +/// The download is the system's (DownloadManager): it goes on with the app closed, +/// waits for the network and resumes, and shows its progress in a notification. Its id +/// is kept, so the app picks the download up again when it starts. The file is checked +/// by its SHA-256 as it is moved into place. +class CheckedDownload(private val context: Context, private val scope: CoroutineScope, private val spec: FileSpec) { + private val dir = File(context.filesDir, spec.dir) + val file = File(dir, spec.name) + private val part = File(dir, spec.name + ".part") + private val prefs = context.getSharedPreferences(spec.prefs, Context.MODE_PRIVATE) + private val downloads get() = context.getSystemService(DownloadManager::class.java) + + private val _state = MutableStateFlow(NetState.Missing) + val state: StateFlow = _state.asStateFlow() + private var job: Job? = null + + init { + // Files of other versions (kept before an update) are of no use to this one. + dir.listFiles()?.filter { it.name != file.name && it.name != part.name }?.forEach { it.delete() } + when { + installed() -> _state.value = NetState.Ready + downloadId() != NO_DOWNLOAD -> { + _state.value = NetState.Loading(0, spec.size) + watch(downloadId()) + } + } + } + + /// A file checked when it was written: the right size is enough later. + fun installed() = file.length() == spec.size + + /// True when the phone is on a metered (mobile) connection right now. + fun metered(): Boolean { + val cm = context.getSystemService(ConnectivityManager::class.java) ?: return false + val caps = cm.getNetworkCapabilities(cm.activeNetwork) ?: return false + return !caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED) + } + + /// Fetches the file from the internet. + fun download() { + if (_state.value == NetState.Ready || _state.value is NetState.Loading) return + if (!online()) { + _state.value = NetState.Failed(NetProblem.NoInternet) + return + } + // The file is downloaded next to the app's files, then checked and moved in. + if (freeSpace() < 2 * spec.size) { + _state.value = NetState.Failed(NetProblem.NoSpace) + return + } + target()?.delete() + val request = DownloadManager.Request(Uri.parse(spec.url)) + .setTitle(spec.title) + .setDestinationInExternalFilesDir(context, null, spec.name) + .setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE) + .setAllowedOverMetered(true) + val id = try { + downloads.enqueue(request) + } catch (e: IllegalArgumentException) { + // No shared storage for the download (or the download service is off). + _state.value = NetState.Failed(NetProblem.Interrupted) + return + } + prefs.edit().putLong(KEY, id).apply() + _state.value = NetState.Loading(0, spec.size) + watch(id) + } + + /// Writes the file from `open()` (inside the APK) into place, checked, in the + /// background, the progress shown as a download's. + fun installFrom(open: () -> InputStream) { + if (_state.value == NetState.Ready || _state.value is NetState.Loading) return + _state.value = NetState.Loading(0, spec.size) + job = scope.launch(Dispatchers.IO) { + val result = try { + open().use { install(it, progress = true) } + NetState.Ready + } catch (e: Failure) { + NetState.Failed(e.problem) + } catch (e: IOException) { + NetState.Failed(if (freeSpace() < spec.size) NetProblem.NoSpace else NetProblem.Interrupted) + } + if (isActive) _state.value = result + } + } + + /// The same, at once (the caller waits): false when it could not (no space). + suspend fun installNow(open: () -> InputStream): Boolean = withContext(Dispatchers.IO) { + if (installed()) return@withContext true + if (freeSpace() < 2 * spec.size) return@withContext false + try { + open().use { install(it, progress = false) } + _state.value = NetState.Ready + true + } catch (e: Exception) { + part.delete() + if (!installed()) _state.value = NetState.Missing + false + } + } + + /// Stops a download and throws away what came. + fun cancel() { + job?.cancel() + val id = downloadId() + if (id != NO_DOWNLOAD) downloads.remove(id) + forget() + part.delete() + if (!installed()) _state.value = NetState.Missing + } + + /// Removes the file. + fun delete() { + cancel() + file.delete() + _state.value = NetState.Missing + } + + private class Failure(val problem: NetProblem) : Exception() + + private fun downloadId(): Long = prefs.getLong(KEY, NO_DOWNLOAD) + + private fun forget() = prefs.edit().remove(KEY).apply() + + /// Where the system puts the downloaded file (the app's own external folder). + private fun target(): File? = context.getExternalFilesDir(null)?.let { File(it, spec.name) } + + /// Follows a download of the system until it ends. The state is set on the main + /// thread, as "Cancel" sets it: after a cancel the watcher sets nothing more. + private fun watch(id: Long) { + job = scope.launch(Dispatchers.Main.immediate) { + while (isActive) { + val row = withContext(Dispatchers.IO) { progress(id) } + if (row == null) { + // Removed in the system's list of downloads. + forget() + _state.value = NetState.Missing + return@launch + } + when (row.status) { + DownloadManager.STATUS_SUCCESSFUL -> { + val result = withContext(Dispatchers.IO) { + try { + val f = target() ?: throw IOException("no external folder") + f.inputStream().use { install(it, progress = false) } + NetState.Ready + } catch (e: Failure) { + NetState.Failed(e.problem) + } catch (e: IOException) { + NetState.Failed(if (freeSpace() < spec.size) NetProblem.NoSpace else NetProblem.Interrupted) + } + } + downloads.remove(id) + forget() + _state.value = result + return@launch + } + DownloadManager.STATUS_FAILED -> { + downloads.remove(id) + forget() + _state.value = NetState.Failed( + if (row.reason == DownloadManager.ERROR_INSUFFICIENT_SPACE) NetProblem.NoSpace else NetProblem.Interrupted, + ) + return@launch + } + else -> _state.value = NetState.Loading(row.done.coerceAtLeast(0), spec.size) + } + delay(500) + } + } + } + + private class Row(val status: Int, val reason: Int, val done: Long) + + private fun progress(id: Long): Row? = + downloads.query(DownloadManager.Query().setFilterById(id))?.use { c -> + if (!c.moveToFirst()) return null + Row( + c.getInt(c.getColumnIndexOrThrow(DownloadManager.COLUMN_STATUS)), + c.getInt(c.getColumnIndexOrThrow(DownloadManager.COLUMN_REASON)), + c.getLong(c.getColumnIndexOrThrow(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR)), + ) + } + + /// Writes the file into place, checking its SHA-256 on the way; a wrong file is + /// thrown away. + private suspend fun install(input: InputStream, progress: Boolean) { + dir.mkdirs() + val digest = MessageDigest.getInstance("SHA-256") + var done = 0L + part.outputStream().use { out -> + val buf = ByteArray(256 * 1024) + var last = 0L + while (true) { + kotlin.coroutines.coroutineContext.ensureActive() + val n = input.read(buf) + if (n < 0) break + out.write(buf, 0, n) + digest.update(buf, 0, n) + done += n + if (progress && done - last > 512 * 1024) { + last = done + _state.value = NetState.Loading(done, spec.size) + } + } + } + val sum = digest.digest().joinToString("") { "%02x".format(it) } + if (sum != spec.sha256 || done != spec.size) { + part.delete() + throw Failure(NetProblem.Corrupt) + } + if (!part.renameTo(file)) throw IOException("cannot move the file into place") + } + + /// The space the app can take, with the caches the system would clear for it. Asked + /// of filesDir, which always exists: a folder not made yet answers 0. + private fun freeSpace(): Long = try { + val storage = context.getSystemService(StorageManager::class.java) + storage.getAllocatableBytes(storage.getUuidForPath(context.filesDir)) + } catch (e: IOException) { + context.filesDir.usableSpace + } + + private fun online(): Boolean { + val cm = context.getSystemService(ConnectivityManager::class.java) ?: return true + val caps = cm.getNetworkCapabilities(cm.activeNetwork) ?: return false + return caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) + } + + private companion object { + const val KEY = "download" + const val NO_DOWNLOAD = -1L + } +} diff --git a/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/data/EngineFiles.kt b/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/data/EngineFiles.kt index 8b0eed9..b078696 100644 --- a/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/data/EngineFiles.kt +++ b/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/data/EngineFiles.kt @@ -1,280 +1,55 @@ package io.github.vrubelroman.chesspenguin.data -import android.app.DownloadManager import android.content.Context -import android.net.ConnectivityManager -import android.net.NetworkCapabilities -import android.net.Uri -import android.os.storage.StorageManager import io.github.vrubelroman.chesspenguin.BuildConfig import io.github.vrubelroman.chesspenguin.R import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.Job -import kotlinx.coroutines.delay -import kotlinx.coroutines.ensureActive -import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow -import kotlinx.coroutines.flow.asStateFlow -import kotlinx.coroutines.isActive -import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext import java.io.File -import java.io.IOException -import java.io.InputStream -import java.security.MessageDigest - -/// Why the network of the engine is not there. -enum class NetProblem { NoInternet, Interrupted, NoSpace, Corrupt } - -sealed interface NetState { - data object Missing : NetState - data class Loading(val done: Long, val total: Long) : NetState - data class Failed(val problem: NetProblem) : NetState - data object Ready : NetState -} /// Stockfish and its network (android-ui.md §8). The executable is a "library" of the /// APK; the network is a file in the app's storage: copied from the APK in the "full" -/// build, downloaded on request in the "light" one, checked by its SHA-256 either way. -/// -/// The download is the system's (DownloadManager): it goes on with the app closed, -/// waits for the network and resumes, and shows its progress in a notification. Its -/// id is kept, so the app picks the download up again when it starts. -class EngineFiles(private val context: Context, private val scope: CoroutineScope) { - private val dir = File(context.filesDir, "engine") - val net = File(dir, BuildConfig.NET_NAME) - private val part = File(dir, BuildConfig.NET_NAME + ".part") - private val prefs = context.getSharedPreferences("engine", Context.MODE_PRIVATE) - private val downloads get() = context.getSystemService(DownloadManager::class.java) +/// build, downloaded on request in the "light" one, checked by its SHA-256 either way +/// ([CheckedDownload]). +class EngineFiles(private val context: Context, scope: CoroutineScope) { + private val download = CheckedDownload( + context, + scope, + FileSpec( + dir = "engine", + name = BuildConfig.NET_NAME, + url = BuildConfig.NET_URL, + size = BuildConfig.NET_SIZE, + sha256 = BuildConfig.NET_SHA256, + title = context.getString(R.string.download_title), + prefs = "engine", + ), + ) + val net: File get() = download.file /// The executable, unpacked by the installer (useLegacyPackaging). val executable: String get() = context.applicationInfo.nativeLibraryDir + "/libstockfish.so" - private val _state = MutableStateFlow(NetState.Missing) - val state: StateFlow = _state.asStateFlow() - private var job: Job? = null - - init { - // A network of another version of Stockfish (kept before an update, §25.6) is of - // no use to this one. - dir.listFiles()?.filter { it.name != net.name && it.name != part.name }?.forEach { it.delete() } - when { - installed() -> _state.value = NetState.Ready - download() != NO_DOWNLOAD -> { - _state.value = NetState.Loading(0, BuildConfig.NET_SIZE) - watch(download()) - } - } - } - - /// A network checked when it was written: the right size is enough later. - private fun installed() = net.length() == BuildConfig.NET_SIZE + val state: StateFlow get() = download.state val builtIn: Boolean get() = BuildConfig.NET_BUILT_IN /// True when the phone is on a metered (mobile) connection right now. - fun metered(): Boolean { - val cm = context.getSystemService(ConnectivityManager::class.java) ?: return false - val caps = cm.getNetworkCapabilities(cm.activeNetwork) ?: return false - return !caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED) - } + fun metered(): Boolean = download.metered() /// Gets the network ready: from the APK, or from the internet. fun prepare() { - if (_state.value == NetState.Ready || _state.value is NetState.Loading) return - if (builtIn) { - _state.value = NetState.Loading(0, BuildConfig.NET_SIZE) - job = scope.launch(Dispatchers.IO) { - val result = try { - dir.mkdirs() - context.assets.open(BuildConfig.NET_NAME).use { install(it) } - NetState.Ready - } catch (e: NetFailure) { - NetState.Failed(e.problem) - } catch (e: IOException) { - NetState.Failed(if (freeSpace() < BuildConfig.NET_SIZE) NetProblem.NoSpace else NetProblem.Interrupted) - } - if (isActive) _state.value = result - } - return - } - if (!online()) { - _state.value = NetState.Failed(NetProblem.NoInternet) - return - } - // The file is downloaded next to the app's files, then checked and moved in. - if (freeSpace() < 2 * BuildConfig.NET_SIZE) { - _state.value = NetState.Failed(NetProblem.NoSpace) - return - } - target()?.delete() - val request = DownloadManager.Request(Uri.parse(BuildConfig.NET_URL)) - .setTitle(context.getString(R.string.download_title)) - .setDestinationInExternalFilesDir(context, null, BuildConfig.NET_NAME) - .setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE) - .setAllowedOverMetered(true) - val id = try { - downloads.enqueue(request) - } catch (e: IllegalArgumentException) { - // No shared storage for the download (or the download service is off). - _state.value = NetState.Failed(NetProblem.Interrupted) - return - } - prefs.edit().putLong(KEY, id).apply() - _state.value = NetState.Loading(0, BuildConfig.NET_SIZE) - watch(id) + if (builtIn) download.installFrom { context.assets.open(BuildConfig.NET_NAME) } else download.download() } /// Keeps the network of the full build in the app's storage, so that it stays after /// the app is updated to the light build (android-ui.md §25.6). False when it could /// not (no space): the light build then offers the download, as always. - suspend fun keepBuiltIn(): Boolean = withContext(Dispatchers.IO) { - if (!builtIn || installed()) return@withContext true - if (freeSpace() < 2 * BuildConfig.NET_SIZE) return@withContext false - try { - dir.mkdirs() - context.assets.open(BuildConfig.NET_NAME).use { install(it) } - _state.value = NetState.Ready - true - } catch (e: Exception) { - part.delete() - if (!installed()) _state.value = NetState.Missing - false - } - } + suspend fun keepBuiltIn(): Boolean = !builtIn || download.installNow { context.assets.open(BuildConfig.NET_NAME) } /// Stops a download and throws away what came. - fun cancel() { - job?.cancel() - val id = download() - if (id != NO_DOWNLOAD) downloads.remove(id) - forget() - part.delete() - if (!installed()) _state.value = NetState.Missing - } + fun cancel() = download.cancel() /// Removes a downloaded network (Settings → "Delete the engine"). - fun delete() { - cancel() - net.delete() - _state.value = NetState.Missing - } - - private class NetFailure(val problem: NetProblem) : Exception() - - private fun download(): Long = prefs.getLong(KEY, NO_DOWNLOAD) - - private fun forget() = prefs.edit().remove(KEY).apply() - - /// Where the system puts the downloaded file (the app's own external folder). - private fun target(): File? = context.getExternalFilesDir(null)?.let { File(it, BuildConfig.NET_NAME) } - - /// Follows a download of the system until it ends. The state is set on the main - /// thread, as "Cancel" sets it: after a cancel the watcher sets nothing more. - private fun watch(id: Long) { - job = scope.launch(Dispatchers.Main.immediate) { - while (isActive) { - val row = withContext(Dispatchers.IO) { progress(id) } - if (row == null) { - // Removed in the system's list of downloads. - forget() - _state.value = NetState.Missing - return@launch - } - when (row.status) { - DownloadManager.STATUS_SUCCESSFUL -> { - val result = withContext(Dispatchers.IO) { - try { - dir.mkdirs() - val file = target() ?: throw IOException("no external folder") - file.inputStream().use { install(it) } - NetState.Ready - } catch (e: NetFailure) { - NetState.Failed(e.problem) - } catch (e: IOException) { - NetState.Failed(if (freeSpace() < BuildConfig.NET_SIZE) NetProblem.NoSpace else NetProblem.Interrupted) - } - } - downloads.remove(id) - forget() - _state.value = result - return@launch - } - DownloadManager.STATUS_FAILED -> { - downloads.remove(id) - forget() - _state.value = NetState.Failed( - if (row.reason == DownloadManager.ERROR_INSUFFICIENT_SPACE) NetProblem.NoSpace else NetProblem.Interrupted, - ) - return@launch - } - else -> _state.value = NetState.Loading(row.done.coerceAtLeast(0), BuildConfig.NET_SIZE) - } - delay(500) - } - } - } - - private class Row(val status: Int, val reason: Int, val done: Long) - - private fun progress(id: Long): Row? = - downloads.query(DownloadManager.Query().setFilterById(id))?.use { c -> - if (!c.moveToFirst()) return null - Row( - c.getInt(c.getColumnIndexOrThrow(DownloadManager.COLUMN_STATUS)), - c.getInt(c.getColumnIndexOrThrow(DownloadManager.COLUMN_REASON)), - c.getLong(c.getColumnIndexOrThrow(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR)), - ) - } - - /// Writes the network into place, checking its SHA-256 on the way; a wrong file is - /// thrown away. - private suspend fun install(input: InputStream) { - val digest = MessageDigest.getInstance("SHA-256") - var done = 0L - part.outputStream().use { out -> - val buf = ByteArray(256 * 1024) - var last = 0L - while (true) { - kotlin.coroutines.coroutineContext.ensureActive() - val n = input.read(buf) - if (n < 0) break - out.write(buf, 0, n) - digest.update(buf, 0, n) - done += n - if (builtIn && done - last > 512 * 1024) { - last = done - _state.value = NetState.Loading(done, BuildConfig.NET_SIZE) - } - } - } - val sum = digest.digest().joinToString("") { "%02x".format(it) } - if (sum != BuildConfig.NET_SHA256 || done != BuildConfig.NET_SIZE) { - part.delete() - throw NetFailure(NetProblem.Corrupt) - } - if (!part.renameTo(net)) throw IOException("cannot move the network into place") - } - - /// The space the app can take, with the caches the system would clear for it. Asked - /// of filesDir, which always exists: a folder not made yet (the engine's, before the - /// first download) answers 0. - private fun freeSpace(): Long = try { - val storage = context.getSystemService(StorageManager::class.java) - storage.getAllocatableBytes(storage.getUuidForPath(context.filesDir)) - } catch (e: IOException) { - context.filesDir.usableSpace - } - - private fun online(): Boolean { - val cm = context.getSystemService(ConnectivityManager::class.java) ?: return true - val caps = cm.getNetworkCapabilities(cm.activeNetwork) ?: return false - return caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) - } - - private companion object { - const val KEY = "download" - const val NO_DOWNLOAD = -1L - } + fun delete() = download.delete() } diff --git a/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/data/MaiaFiles.kt b/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/data/MaiaFiles.kt new file mode 100644 index 0000000..18580d6 --- /dev/null +++ b/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/data/MaiaFiles.kt @@ -0,0 +1,24 @@ +package io.github.vrubelroman.chesspenguin.data + +import android.content.Context +import io.github.vrubelroman.chesspenguin.R +import kotlinx.coroutines.CoroutineScope + +/// Maia's weights (android-play.md §31.2): the small model (`maia3-5m.pt`, 21 MB) of a +/// pinned revision, downloaded on request from the authors' Hugging Face page — the +/// file is theirs, not shipped in the APK. The same file as the desktop app's. +class MaiaFiles(context: Context, scope: CoroutineScope) { + val download = CheckedDownload( + context, + scope, + FileSpec( + dir = "maia", + name = "maia3-5m.pt", + url = "https://huggingface.co/UofTCSSLab/Maia3-5M/resolve/b6559de2398d7140b985f28fd2c19fb5e47ddabe/maia3-5m.pt", + size = 20_968_049, + sha256 = "ba14208b2992d85502f5fb501934abf6aaaeb355e9f3fdf90e326911f562524f", + title = context.getString(R.string.maia_download_title), + prefs = "maia", + ), + ) +} diff --git a/androidApp/app/src/main/res/values-de/strings.xml b/androidApp/app/src/main/res/values-de/strings.xml index 88833cf..ae428a8 100644 --- a/androidApp/app/src/main/res/values-de/strings.xml +++ b/androidApp/app/src/main/res/values-de/strings.xml @@ -460,4 +460,5 @@ %1$d Durchgang %1$d Durchgänge + Maia für ChessPenguin diff --git a/androidApp/app/src/main/res/values-es/strings.xml b/androidApp/app/src/main/res/values-es/strings.xml index 7145a46..27d45f1 100644 --- a/androidApp/app/src/main/res/values-es/strings.xml +++ b/androidApp/app/src/main/res/values-es/strings.xml @@ -468,4 +468,5 @@ %1$d repasos %1$d repasos + Maia para ChessPenguin diff --git a/androidApp/app/src/main/res/values-fr/strings.xml b/androidApp/app/src/main/res/values-fr/strings.xml index 95fd11a..2d50bcd 100644 --- a/androidApp/app/src/main/res/values-fr/strings.xml +++ b/androidApp/app/src/main/res/values-fr/strings.xml @@ -468,4 +468,5 @@ %1$d passages %1$d passages + Maia pour ChessPenguin diff --git a/androidApp/app/src/main/res/values-it/strings.xml b/androidApp/app/src/main/res/values-it/strings.xml index 412f0ca..112e9bd 100644 --- a/androidApp/app/src/main/res/values-it/strings.xml +++ b/androidApp/app/src/main/res/values-it/strings.xml @@ -468,4 +468,5 @@ %1$d ripassi %1$d ripassi + Maia per ChessPenguin diff --git a/androidApp/app/src/main/res/values-kk/strings.xml b/androidApp/app/src/main/res/values-kk/strings.xml index dfd426e..0b40d63 100644 --- a/androidApp/app/src/main/res/values-kk/strings.xml +++ b/androidApp/app/src/main/res/values-kk/strings.xml @@ -461,4 +461,5 @@ %1$d рет %1$d рет + ChessPenguin үшін Maia diff --git a/androidApp/app/src/main/res/values-pt/strings.xml b/androidApp/app/src/main/res/values-pt/strings.xml index 1db920e..7fc38f9 100644 --- a/androidApp/app/src/main/res/values-pt/strings.xml +++ b/androidApp/app/src/main/res/values-pt/strings.xml @@ -469,4 +469,5 @@ %1$d passagens %1$d passagens + Maia para o ChessPenguin diff --git a/androidApp/app/src/main/res/values-ru/strings.xml b/androidApp/app/src/main/res/values-ru/strings.xml index 084641a..9533ec1 100644 --- a/androidApp/app/src/main/res/values-ru/strings.xml +++ b/androidApp/app/src/main/res/values-ru/strings.xml @@ -476,4 +476,5 @@ прохождений: %1$d прохождений: %1$d + Maia для ChessPenguin diff --git a/androidApp/app/src/main/res/values-uz/strings.xml b/androidApp/app/src/main/res/values-uz/strings.xml index c412b35..17c5683 100644 --- a/androidApp/app/src/main/res/values-uz/strings.xml +++ b/androidApp/app/src/main/res/values-uz/strings.xml @@ -459,4 +459,5 @@ %1$d marta %1$d marta + ChessPenguin uchun Maia diff --git a/androidApp/app/src/main/res/values/strings.xml b/androidApp/app/src/main/res/values/strings.xml index 528b828..e6a43ca 100644 --- a/androidApp/app/src/main/res/values/strings.xml +++ b/androidApp/app/src/main/res/values/strings.xml @@ -464,4 +464,5 @@ %1$d run %1$d runs + Maia for ChessPenguin