feat(sdk-core): ConfigFileReader 新增 assets/config/ 目录支持

对齐 RN SDK 的 src/assets/config/ 目录约定:
搜索顺序:config/config.xuqmconfig → config/*.xuqmconfig → xuqm/config.xuqm → xuqm/*.xuqmconfig
旧路径 assets/xuqm/ 保持兼容。

Co-Authored-By: Claude <noreply@anthropic.com>
这个提交包含在:
XuqmGroup 2026-06-18 15:06:40 +08:00
父节点 ba6de0a5fd
当前提交 75c1d77965

查看文件

@ -5,21 +5,24 @@ import android.util.Log
import com.google.gson.Gson import com.google.gson.Gson
/** /**
* Reads and decrypts the init config file from assets/xuqm/. * Reads and decrypts the init config file from assets.
* Looks for config.xuqm first, then falls back to any *.xuqmconfig file. *
* This is used by XuqmSDK.autoInitialize() and does NOT depend on sdk-license. * 搜索顺序对齐 RN SDK src/assets/config/
* 1. assets/config/config.xuqmconfig config.xuqm
* 2. assets/config/*.xuqmconfig取第一个
* 3. assets/xuqm/config.xuqm旧路径兼容
* 4. assets/xuqm/*.xuqmconfig旧路径兼容
*/ */
internal object ConfigFileReader { internal object ConfigFileReader {
private const val TAG = "XuqmSDK" private const val TAG = "XuqmSDK"
private const val CONFIG_PATH = "xuqm/config.xuqm" private val CONFIG_DIRS = listOf("config", "xuqm")
private const val CONFIG_DIR = "xuqm"
private val gson = Gson() private val gson = Gson()
fun read(context: Context): ConfigFile? { fun read(context: Context): ConfigFile? {
return try { return try {
val path = findConfigPath(context) ?: run { val path = findConfigPath(context) ?: run {
Log.w(TAG, "No config file found in assets/$CONFIG_DIR/") Log.w(TAG, "No config file found in assets/{config,xuqm}/")
return null return null
} }
Log.d(TAG, "Reading config file: $path") Log.d(TAG, "Reading config file: $path")
@ -39,16 +42,23 @@ internal object ConfigFileReader {
} }
private fun findConfigPath(context: Context): String? { private fun findConfigPath(context: Context): String? {
try { for (dir in CONFIG_DIRS) {
context.assets.open(CONFIG_PATH).close() // 优先 config.xuqmconfig 或 config.xuqm
return CONFIG_PATH for (name in listOf("config.xuqmconfig", "config.xuqm")) {
} catch (_: Exception) { val path = "$dir/$name"
// Try downloaded filenames such as appName.xuqmconfig. try {
context.assets.open(path).close()
return path
} catch (_: Exception) { /* not found */ }
}
// 否则取第一个 .xuqmconfig
val found = runCatching {
context.assets.list(dir)
?.firstOrNull { it.endsWith(".xuqmconfig", ignoreCase = true) }
?.let { "$dir/$it" }
}.getOrNull()
if (found != null) return found
} }
return runCatching { return null
context.assets.list(CONFIG_DIR)
?.firstOrNull { it.endsWith(".xuqmconfig", ignoreCase = true) }
?.let { "$CONFIG_DIR/$it" }
}.getOrNull()
} }
} }