fix readme
This commit is contained in:
1 parent
51a2ca3f8c
commit
61a03b5957
22 files changed
+3234
-71
No files matched your search
@@ -43,16 +43,41 @@ class UpdateRepository(private val context: Context) {
|
||||
|
||||
fun isServerInstalled(): Boolean {
|
||||
val ppsrFile = File(context.filesDir, "server/build/build/ppsr.pyc")
|
||||
return ppsrFile.exists() && ppsrFile.length() > 0
|
||||
if (!ppsrFile.exists() || ppsrFile.length() < 16) return false
|
||||
|
||||
// Check if build code matches current APK
|
||||
val installedBuildCode = prefs.getInt("installed_build_code", -1)
|
||||
if (installedBuildCode != com.gacy.android.BuildConfig.VERSION_CODE) {
|
||||
return false
|
||||
}
|
||||
|
||||
// Validate that python bytecode magic is genuine Python 3.14: [43, 14, 13, 10]
|
||||
try {
|
||||
ppsrFile.inputStream().use { stream ->
|
||||
val magic = ByteArray(4)
|
||||
if (stream.read(magic) == 4) {
|
||||
if (magic[0] != 43.toByte() || magic[1] != 14.toByte() || magic[2] != 13.toByte() || magic[3] != 10.toByte()) {
|
||||
return false // Incompatible bytecode from old install, force refresh!
|
||||
}
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
} catch (_: Exception) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
suspend fun ensureServerInstalled(): Boolean = withContext(Dispatchers.IO) {
|
||||
suspend fun ensureServerInstalled(force: Boolean = false): Boolean = withContext(Dispatchers.IO) {
|
||||
val ppsrFile = File(context.filesDir, "server/build/build/ppsr.pyc")
|
||||
if (ppsrFile.exists() && ppsrFile.length() > 0) {
|
||||
if (!force && isServerInstalled()) {
|
||||
return@withContext true
|
||||
}
|
||||
|
||||
try {
|
||||
com.gacy.android.CrashTracker.breadcrumb(context, "UpdateRepository: ensureServerInstalled start (force=$force)")
|
||||
val stagingDir = File(context.filesDir, "server/staging")
|
||||
val targetServerDir = File(context.filesDir, "server/build/build")
|
||||
|
||||
@@ -60,6 +85,7 @@ class UpdateRepository(private val context: Context) {
|
||||
stagingDir.mkdirs()
|
||||
|
||||
// 1. Extract build.zip from bundled assets
|
||||
com.gacy.android.CrashTracker.breadcrumb(context, "UpdateRepository: extracting build.zip")
|
||||
extractAssetZip("build.zip", stagingDir)
|
||||
|
||||
val stagedBuildDir = File(stagingDir, "build")
|
||||
@@ -67,12 +93,25 @@ class UpdateRepository(private val context: Context) {
|
||||
|
||||
// 2. Extract runtime packages into effective directory
|
||||
try {
|
||||
com.gacy.android.CrashTracker.breadcrumb(context, "UpdateRepository: extracting packages.zip")
|
||||
extractAssetZip("packages.zip", effectiveStagedDir)
|
||||
} catch (e: Exception) {
|
||||
com.gacy.android.CrashTracker.breadcrumb(context, "UpdateRepository: packages.zip notice: ${e.message}")
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
// Keep the player's settings when refreshing the bundled server.
|
||||
for (name in listOf("persistent.json", "config.json")) {
|
||||
val existing = File(targetServerDir, "misc/$name")
|
||||
if (existing.isFile) {
|
||||
val destination = File(effectiveStagedDir, "misc/$name")
|
||||
destination.parentFile?.mkdirs()
|
||||
existing.copyTo(destination, overwrite = true)
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Move/Rename into place
|
||||
com.gacy.android.CrashTracker.breadcrumb(context, "UpdateRepository: moving to target directory")
|
||||
if (targetServerDir.exists()) {
|
||||
targetServerDir.deleteRecursively()
|
||||
}
|
||||
@@ -85,9 +124,16 @@ class UpdateRepository(private val context: Context) {
|
||||
}
|
||||
if (stagingDir.exists()) stagingDir.deleteRecursively()
|
||||
|
||||
setInstalledVersion("4.6.53-embedded")
|
||||
prefs.edit()
|
||||
.putInt("installed_build_code", com.gacy.android.BuildConfig.VERSION_CODE)
|
||||
.putString(PREF_INSTALLED_VERSION, "4.6.53-embedded-py314")
|
||||
.apply()
|
||||
|
||||
setInstalledVersion("4.6.53-embedded-py314")
|
||||
com.gacy.android.CrashTracker.breadcrumb(context, "UpdateRepository: ensureServerInstalled finished success=${ppsrFile.exists()}")
|
||||
return@withContext ppsrFile.exists()
|
||||
} catch (e: Exception) {
|
||||
com.gacy.android.CrashTracker.breadcrumb(context, "UpdateRepository: ensureServerInstalled error: ${e.message}")
|
||||
e.printStackTrace()
|
||||
return@withContext false
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user