From 75c1d7796570f5cd6ae8c497a6b00f6e359a8cc4 Mon Sep 17 00:00:00 2001 From: XuqmGroup Date: Thu, 18 Jun 2026 15:06:40 +0800 Subject: [PATCH] =?UTF-8?q?feat(sdk-core):=20ConfigFileReader=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=20assets/config/=20=E7=9B=AE=E5=BD=95=E6=94=AF?= =?UTF-8?q?=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 对齐 RN SDK 的 src/assets/config/ 目录约定: 搜索顺序:config/config.xuqmconfig → config/*.xuqmconfig → xuqm/config.xuqm → xuqm/*.xuqmconfig 旧路径 assets/xuqm/ 保持兼容。 Co-Authored-By: Claude --- .../com/xuqm/sdk/internal/ConfigFileReader.kt | 42 ++++++++++++------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/sdk-core/src/main/java/com/xuqm/sdk/internal/ConfigFileReader.kt b/sdk-core/src/main/java/com/xuqm/sdk/internal/ConfigFileReader.kt index b3d2fd6..24f7131 100644 --- a/sdk-core/src/main/java/com/xuqm/sdk/internal/ConfigFileReader.kt +++ b/sdk-core/src/main/java/com/xuqm/sdk/internal/ConfigFileReader.kt @@ -5,21 +5,24 @@ import android.util.Log import com.google.gson.Gson /** - * Reads and decrypts the init config file from assets/xuqm/. - * 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. + * Reads and decrypts the init config file from assets. + * + * 搜索顺序(对齐 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 { private const val TAG = "XuqmSDK" - private const val CONFIG_PATH = "xuqm/config.xuqm" - private const val CONFIG_DIR = "xuqm" + private val CONFIG_DIRS = listOf("config", "xuqm") private val gson = Gson() fun read(context: Context): ConfigFile? { return try { 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 } Log.d(TAG, "Reading config file: $path") @@ -39,16 +42,23 @@ internal object ConfigFileReader { } private fun findConfigPath(context: Context): String? { - try { - context.assets.open(CONFIG_PATH).close() - return CONFIG_PATH - } catch (_: Exception) { - // Try downloaded filenames such as appName.xuqmconfig. + for (dir in CONFIG_DIRS) { + // 优先 config.xuqmconfig 或 config.xuqm + for (name in listOf("config.xuqmconfig", "config.xuqm")) { + val path = "$dir/$name" + 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 { - context.assets.list(CONFIG_DIR) - ?.firstOrNull { it.endsWith(".xuqmconfig", ignoreCase = true) } - ?.let { "$CONFIG_DIR/$it" } - }.getOrNull() + return null } }