feat: fix bug
Build / build (push) Successful in 10m28s

This commit is contained in:
2026-06-10 10:13:47 +07:00
parent 55ab8136f3
commit ee390c249a
5 changed files with 106 additions and 50 deletions
+2 -3
View File
@@ -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)
}
+42
View File
@@ -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"
}
}
@@ -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<UpdateFeatures?>(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)
}
}
+2 -2
View File
@@ -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"
}
+2 -2
View File
@@ -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"
}