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>
这个提交包含在:
父节点
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? {
|
||||||
|
for (dir in CONFIG_DIRS) {
|
||||||
|
// 优先 config.xuqmconfig 或 config.xuqm
|
||||||
|
for (name in listOf("config.xuqmconfig", "config.xuqm")) {
|
||||||
|
val path = "$dir/$name"
|
||||||
try {
|
try {
|
||||||
context.assets.open(CONFIG_PATH).close()
|
context.assets.open(path).close()
|
||||||
return CONFIG_PATH
|
return path
|
||||||
} catch (_: Exception) {
|
} catch (_: Exception) { /* not found */ }
|
||||||
// Try downloaded filenames such as appName.xuqmconfig.
|
|
||||||
}
|
}
|
||||||
return runCatching {
|
// 否则取第一个 .xuqmconfig
|
||||||
context.assets.list(CONFIG_DIR)
|
val found = runCatching {
|
||||||
|
context.assets.list(dir)
|
||||||
?.firstOrNull { it.endsWith(".xuqmconfig", ignoreCase = true) }
|
?.firstOrNull { it.endsWith(".xuqmconfig", ignoreCase = true) }
|
||||||
?.let { "$CONFIG_DIR/$it" }
|
?.let { "$dir/$it" }
|
||||||
}.getOrNull()
|
}.getOrNull()
|
||||||
|
if (found != null) return found
|
||||||
|
}
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
正在加载...
在新工单中引用
屏蔽一个用户