From ee390c249a8c04110a1a19a179ccf538cbc402c3 Mon Sep 17 00:00:00 2001 From: AzenKain Date: Wed, 10 Jun 2026 10:13:47 +0700 Subject: [PATCH] feat: fix bug --- app/build.gradle.kts | 5 +- app/src/main/assets/version.json | 42 ++++++++ .../firefly_go_android/MainActivity.kt | 101 ++++++++++-------- app/src/main/res/raw/app_version_json.json | 4 +- script/release.json | 4 +- 5 files changed, 106 insertions(+), 50 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 1cad631..5f5ebc8 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -22,8 +22,8 @@ android { applicationId = "com.kain344.firefly_go_android" minSdk = 24 targetSdk = 35 - versionCode = 1 - versionName = "1.0" + versionCode = 2 + versionName = "1.0.1" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" @@ -100,4 +100,3 @@ dependencies { implementation(libs.slf4j.android) } - diff --git a/app/src/main/assets/version.json b/app/src/main/assets/version.json index b34e697..5e89b13 100644 --- a/app/src/main/assets/version.json +++ b/app/src/main/assets/version.json @@ -6,6 +6,13 @@ "lua_url": "https://autopatchos.starrails.com/lua/BetaLive/output_15242148_d40f856defc0_599b68a0adf7bd", "ifix_url": "https://autopatchos.starrails.com/ifix/BetaLive/output_15265964_799df4f0ecef_5a94550ba64cff" }, + "CNBETAAndroid4.3.52": { + "asset_bundle_url": "https://autopatchos.starrails.com/asb/BetaLive/output_15305566_fea016d35145_54bbf8ab4009f5", + "asset_bundle_url_b": "https://autopatchos.starrails.com/asb/BetaLive/output_15305566_fea016d35145_54bbf8ab4009f5", + "ex_resource_url": "https://autopatchos.starrails.com/design_data/BetaLive/output_15318724_a7af31327e74_b3328eb95329b2", + "lua_url": "https://autopatchos.starrails.com/lua/BetaLive/output_15305751_09783637ccc4_d16f9c81138ab3", + "ifix_url": "https://autopatchos.starrails.com/ifix/BetaLive/output_15265964_799df4f0ecef_5a94550ba64cff" + }, "CNBETAWin4.3.51": { "asset_bundle_url": "https://autopatchos.starrails.com/asb/BetaLive/output_15261247_f6e6db2125cf_369da465b36faf", "asset_bundle_url_b": "https://autopatchos.starrails.com/asb/BetaLive/output_15235885_6091fd15561a_83828f542dc1f3", @@ -13,6 +20,13 @@ "lua_url": "https://autopatchos.starrails.com/lua/BetaLive/output_15242148_d40f856defc0_599b68a0adf7bd", "ifix_url": "https://autopatchos.starrails.com/ifix/BetaLive/output_15265964_799df4f0ecef_5a94550ba64cff" }, + "CNBETAWin4.3.52": { + "asset_bundle_url": "https://autopatchos.starrails.com/asb/BetaLive/output_15305566_fea016d35145_54bbf8ab4009f5", + "asset_bundle_url_b": "https://autopatchos.starrails.com/asb/BetaLive/output_15305566_fea016d35145_54bbf8ab4009f5", + "ex_resource_url": "https://autopatchos.starrails.com/design_data/BetaLive/output_15318724_a7af31327e74_b3328eb95329b2", + "lua_url": "https://autopatchos.starrails.com/lua/BetaLive/output_15305751_09783637ccc4_d16f9c81138ab3", + "ifix_url": "https://autopatchos.starrails.com/ifix/BetaLive/output_15265964_799df4f0ecef_5a94550ba64cff" + }, "CNBETAiOS4.3.51": { "asset_bundle_url": "https://autopatchos.starrails.com/asb/BetaLive/output_15261247_f6e6db2125cf_369da465b36faf", "asset_bundle_url_b": "https://autopatchos.starrails.com/asb/BetaLive/output_15235885_6091fd15561a_83828f542dc1f3", @@ -20,6 +34,13 @@ "lua_url": "https://autopatchos.starrails.com/lua/BetaLive/output_15242148_d40f856defc0_599b68a0adf7bd", "ifix_url": "https://autopatchos.starrails.com/ifix/BetaLive/output_15265964_799df4f0ecef_5a94550ba64cff" }, + "CNBETAiOS4.3.52": { + "asset_bundle_url": "https://autopatchos.starrails.com/asb/BetaLive/output_15305566_fea016d35145_54bbf8ab4009f5", + "asset_bundle_url_b": "https://autopatchos.starrails.com/asb/BetaLive/output_15305566_fea016d35145_54bbf8ab4009f5", + "ex_resource_url": "https://autopatchos.starrails.com/design_data/BetaLive/output_15318724_a7af31327e74_b3328eb95329b2", + "lua_url": "https://autopatchos.starrails.com/lua/BetaLive/output_15305751_09783637ccc4_d16f9c81138ab3", + "ifix_url": "https://autopatchos.starrails.com/ifix/BetaLive/output_15265964_799df4f0ecef_5a94550ba64cff" + }, "OSBETAAndroid4.3.51": { "asset_bundle_url": "https://autopatchos.starrails.com/asb/BetaLive/output_15261247_f6e6db2125cf_369da465b36faf", "asset_bundle_url_b": "https://autopatchos.starrails.com/asb/BetaLive/output_15235885_6091fd15561a_83828f542dc1f3", @@ -27,6 +48,13 @@ "lua_url": "https://autopatchos.starrails.com/lua/BetaLive/output_15242148_d40f856defc0_599b68a0adf7bd", "ifix_url": "https://autopatchos.starrails.com/ifix/BetaLive/output_15265964_799df4f0ecef_5a94550ba64cff" }, + "OSBETAAndroid4.3.52": { + "asset_bundle_url": "https://autopatchos.starrails.com/asb/BetaLive/output_15305566_fea016d35145_54bbf8ab4009f5", + "asset_bundle_url_b": "https://autopatchos.starrails.com/asb/BetaLive/output_15305566_fea016d35145_54bbf8ab4009f5", + "ex_resource_url": "https://autopatchos.starrails.com/design_data/BetaLive/output_15318724_a7af31327e74_b3328eb95329b2", + "lua_url": "https://autopatchos.starrails.com/lua/BetaLive/output_15305751_09783637ccc4_d16f9c81138ab3", + "ifix_url": "https://autopatchos.starrails.com/ifix/BetaLive/output_15265964_799df4f0ecef_5a94550ba64cff" + }, "OSBETAWin4.3.51": { "asset_bundle_url": "https://autopatchos.starrails.com/asb/BetaLive/output_15261247_f6e6db2125cf_369da465b36faf", "asset_bundle_url_b": "https://autopatchos.starrails.com/asb/BetaLive/output_15235885_6091fd15561a_83828f542dc1f3", @@ -34,11 +62,25 @@ "lua_url": "https://autopatchos.starrails.com/lua/BetaLive/output_15242148_d40f856defc0_599b68a0adf7bd", "ifix_url": "https://autopatchos.starrails.com/ifix/BetaLive/output_15265964_799df4f0ecef_5a94550ba64cff" }, + "OSBETAWin4.3.52": { + "asset_bundle_url": "https://autopatchos.starrails.com/asb/BetaLive/output_15305566_fea016d35145_54bbf8ab4009f5", + "asset_bundle_url_b": "https://autopatchos.starrails.com/asb/BetaLive/output_15305566_fea016d35145_54bbf8ab4009f5", + "ex_resource_url": "https://autopatchos.starrails.com/design_data/BetaLive/output_15318724_a7af31327e74_b3328eb95329b2", + "lua_url": "https://autopatchos.starrails.com/lua/BetaLive/output_15305751_09783637ccc4_d16f9c81138ab3", + "ifix_url": "https://autopatchos.starrails.com/ifix/BetaLive/output_15265964_799df4f0ecef_5a94550ba64cff" + }, "OSBETAiOS4.3.51": { "asset_bundle_url": "https://autopatchos.starrails.com/asb/BetaLive/output_15261247_f6e6db2125cf_369da465b36faf", "asset_bundle_url_b": "https://autopatchos.starrails.com/asb/BetaLive/output_15235885_6091fd15561a_83828f542dc1f3", "ex_resource_url": "https://autopatchos.starrails.com/design_data/BetaLive/output_15265964_c2fbb1eb05fc_f2238199ee2b6e", "lua_url": "https://autopatchos.starrails.com/lua/BetaLive/output_15242148_d40f856defc0_599b68a0adf7bd", "ifix_url": "https://autopatchos.starrails.com/ifix/BetaLive/output_15265964_799df4f0ecef_5a94550ba64cff" + }, + "OSBETAiOS4.3.52": { + "asset_bundle_url": "https://autopatchos.starrails.com/asb/BetaLive/output_15305566_fea016d35145_54bbf8ab4009f5", + "asset_bundle_url_b": "https://autopatchos.starrails.com/asb/BetaLive/output_15305566_fea016d35145_54bbf8ab4009f5", + "ex_resource_url": "https://autopatchos.starrails.com/design_data/BetaLive/output_15318724_a7af31327e74_b3328eb95329b2", + "lua_url": "https://autopatchos.starrails.com/lua/BetaLive/output_15305751_09783637ccc4_d16f9c81138ab3", + "ifix_url": "https://autopatchos.starrails.com/ifix/BetaLive/output_15265964_799df4f0ecef_5a94550ba64cff" } } \ No newline at end of file diff --git a/app/src/main/java/com/example/firefly_go_android/MainActivity.kt b/app/src/main/java/com/example/firefly_go_android/MainActivity.kt index 21483d9..5c9b2d9 100644 --- a/app/src/main/java/com/example/firefly_go_android/MainActivity.kt +++ b/app/src/main/java/com/example/firefly_go_android/MainActivity.kt @@ -92,33 +92,53 @@ class MainActivity : ComponentActivity() { if (!dataDir.exists()) dataDir.mkdirs() val sharedPrefs = getSharedPreferences("AppPrefs", MODE_PRIVATE) - val currentVersion = try { - if (Build.VERSION.SDK_INT >= 33) { - packageManager.getPackageInfo(packageName, android.content.pm.PackageManager.PackageInfoFlags.of(0)).longVersionCode - } else { - @Suppress("DEPRECATION") - packageManager.getPackageInfo(packageName, 0).versionCode.toLong() + + // Lấy thông tin Package + val packageInfo = if (Build.VERSION.SDK_INT >= 33) { + packageManager.getPackageInfo(packageName, android.content.pm.PackageManager.PackageInfoFlags.of(0)) + } else { + @Suppress("DEPRECATION") + packageManager.getPackageInfo(packageName, 0) + } + + val currentVersionCode = if (Build.VERSION.SDK_INT >= 33) packageInfo.longVersionCode else packageInfo.versionCode.toLong() + val currentLastUpdateTime = packageInfo.lastUpdateTime + + val savedVersionCode = sharedPrefs.getLong("last_version_code", 0L) + val savedLastUpdateTime = sharedPrefs.getLong("last_update_time", 0L) + + val isFolderEmpty = dataDir.listFiles()?.isEmpty() ?: true + + val shouldOverride = currentVersionCode > savedVersionCode || + currentLastUpdateTime > savedLastUpdateTime || + isFolderEmpty + + Log.i("AppUpdate", "Code: $currentVersionCode, LastUpdate: $currentLastUpdateTime") + Log.i("AppUpdate", "SavedCode: $savedVersionCode, SavedUpdate: $savedLastUpdateTime") + Log.i("AppUpdate", "Should Override: $shouldOverride") + + if (copyRawToFile(this, dataDir, shouldOverride)) { + if (shouldOverride) { + sharedPrefs.edit() + .putLong("last_version_code", currentVersionCode) + .putLong("last_update_time", currentLastUpdateTime) + .apply() + Log.i("AppUpdate", "Updated SharedPreferences with new version and time") + } + } + + val jsonString = try { + resources.openRawResource(R.raw.app_version_json).use { input -> + input.bufferedReader().use { it.readText() } } } catch (e: Exception) { - 1L - } - val lastVersion = sharedPrefs.getLong("last_version_code", 0L) - val shouldOverride = currentVersion > lastVersion - - copyRawToFile(dataDir, shouldOverride) - - if (shouldOverride) { - sharedPrefs.edit().putLong("last_version_code", currentVersion).apply() + "{}" } - val jsonString = resources.openRawResource(R.raw.app_version_json).use { input -> - input.bufferedReader().use { it.readText() } - } - - val jsonObject = JSONObject(jsonString) - val latestVersion = jsonObject.getString("latest_version") - val changelog = jsonObject.getString("changelog") - val apkUrl = jsonObject.getString("apk_url") + val jsonObject = if (jsonString.isNotEmpty()) JSONObject(jsonString) else JSONObject() + val latestVersion = jsonObject.optString("latest_version", "1.0.0") + val changelog = jsonObject.optString("changelog", "") + val apkUrl = jsonObject.optString("apk_url", "") val appVersion = AppVersion(latestVersion, changelog, apkUrl) @@ -182,27 +202,26 @@ fun requestStoragePermission(context: Context) { } } } -fun copyRawToFile(targetDir: File, override: Boolean = false): Boolean { +fun copyRawToFile(context: Context, targetDir: File, override: Boolean = false): Boolean { val files = listOf( - "assets/data-in-game.json" to "data-in-game.json", - "assets/freesr-data.json" to "freesr-data.json", - "assets/version.json" to "version.json" + "data-in-game.json" to "data-in-game.json", + "freesr-data.json" to "freesr-data.json", + "version.json" to "version.json" ) return try { if (!targetDir.exists()) targetDir.mkdirs() - for ((assetPath, name) in files) { - val outFile = File(targetDir, name) + for ((assetFile, outName) in files) { + val outFile = File(targetDir, outName) - if (outFile.exists() && !override) continue + if (outFile.exists() && !override) { + Log.i("CopyRaw", "Skipping $outName (already exists and no override)") + continue + } - val inputStream = - MainActivity::class.java.classLoader - ?.getResourceAsStream(assetPath) - ?: return false - - inputStream.use { input -> + Log.i("CopyRaw", "Copying $assetFile to ${outFile.absolutePath} (Override: $override)") + context.assets.open(assetFile).use { input -> FileOutputStream(outFile).use { output -> input.copyTo(output) output.fd.sync() @@ -212,6 +231,7 @@ fun copyRawToFile(targetDir: File, override: Boolean = false): Boolean { true } catch (e: Exception) { + Log.e("CopyRaw", "Error copying asset file: ${e.message}", e) false } } @@ -471,7 +491,7 @@ fun ServerControlScreen(appDataPath: String, dataDir: File, appVersion: AppVersi onClick = { showResetDialog = false try { - copyRawToFile(dataDir, true) + copyRawToFile(context, dataDir, true) Toast.makeText(context, "Data has been reset successfully", Toast.LENGTH_SHORT).show() } catch (e: Exception) { Toast.makeText(context, "Reset failed: ${e.message}", Toast.LENGTH_SHORT).show() @@ -655,7 +675,7 @@ fun AutoUpdateDialog( val context = LocalContext.current val autoUpdaterManager = AutoUpdaterManager(context) var update by remember { mutableStateOf(null) } - var progress by remember { mutableIntStateOf(0) } + var progress by remember { mutableStateOf(0) } var showDialog by remember { mutableStateOf(false) } var isDownloading by remember { mutableStateOf(false) } var downloadComplete by remember { mutableStateOf(false) } @@ -697,11 +717,6 @@ fun AutoUpdateDialog( LaunchedEffect(progress) { if (progress >= 100 && isDownloading) { downloadComplete = true - - removeFile(dataDir, "data-in-game.json" ) - removeFile(dataDir, "freesr-data.json") - removeFile(dataDir, "version.json") - delay(500) } } diff --git a/app/src/main/res/raw/app_version_json.json b/app/src/main/res/raw/app_version_json.json index 993d901..bae4686 100644 --- a/app/src/main/res/raw/app_version_json.json +++ b/app/src/main/res/raw/app_version_json.json @@ -1,5 +1,5 @@ { - "latest_version": "4.3.2-01", + "latest_version": "4.3.2-02", "changelog": "UPDATE: 4.3.5X", - "apk_url": "https://git.kain.io.vn/Firefly-Shelter/FireflyGo_Android/releases/download/4.3.2-01/firefly_go_android.apk" + "apk_url": "https://git.kain.io.vn/Firefly-Shelter/FireflyGo_Android/releases/download/4.3.2-02/firefly_go_android.apk" } \ No newline at end of file diff --git a/script/release.json b/script/release.json index 68b99de..b5e6c07 100644 --- a/script/release.json +++ b/script/release.json @@ -1,4 +1,4 @@ { - "tag": "4.3.2-01", - "title": "PreBuild Version 4.3.52 - 01" + "tag": "4.3.2-02", + "title": "PreBuild Version 4.3.52 - 02" }