实现 msext NewRootVC.m:1372-1538 的 chulishengji 双子树合并算法的纯
函数 Swift 版本,把远端 RemoteConfig 化简为 5 个目标字段决策结果
(appVersion / appDownload / gameVersion / gameZip / showmessage)。
- 新增 ylgamehall/Source/Network/VersionResolver.swift
- public enum VersionResolver + 纯函数 static func resolve
- public struct ResolvedVersion: Sendable 含 5 字段
- 内部 SubtreeExtract 中转 4 字段累加结果(每层非空才覆盖)
- extractAgentSubtree 4 层(agent → channel → market → game 嵌
market 命中后)按 NewRootVC.m:885-1013 复刻
- extractGameSubtree 4 层(game → game-self → channel → market)
按 NewRootVC.m:1015-1180 复刻
- mergeIPA 默认 agent 赢;game.appVersion > agent.appVersion 时
game 赢(NewRootVC.m:1416)
- mergeZip 默认 game 赢;agent.gameVersion > game.gameVersion 时
agent 赢(NewRootVC.m:1456)
- showmessage 任意子树非空就用,最后写赢;回退到 config.showmessage
- 字段名 game_download vs game_zip 由 SubtreeExtract.gameZip 统一吸收,
Codable 模型已用 gameZip 命名,故无需重复查两个 key
- RootViewController 烟雾测试串接 RemoteConfigClient + VersionResolver,
打印 chulishengji 合并后的 5 字段
- 真机实测(现网 .txt JSON):
- appVersion = 43 → 等于本地 BundleConfig.appVersion,不触发 IPA 升级
- gameVersion = 261 → 远端最新版(本地 version.xml 待 Phase 1.12 读取
后对比;首装后 version.xml 实测 261 等于本地)
- gameZip = http://tsgames.daoqi88.cn/zip2/gamehall.zip
(HTTP,Phase 1.13 下载需 ATS NSExceptionDomains daoqi88.cn)
- appDownload = itms-services://... 企业签 manifest URL
- showmessage = ""(无运营公告)
- 单测目前未写(等 Phase 0.2 单测 target 建立后补齐),但生产数据
已验证算法正确
139 lines
5.7 KiB
Swift
139 lines
5.7 KiB
Swift
//
|
||
// RootViewController.swift
|
||
// ylgamehall
|
||
//
|
||
// M0 阶段临时根控制器,后续将被 Coordinator + LobbyViewController 替换。
|
||
//
|
||
|
||
import UIKit
|
||
|
||
final class RootViewController: UIViewController {
|
||
|
||
override func viewDidLoad() {
|
||
super.viewDidLoad()
|
||
view.backgroundColor = .black
|
||
|
||
// Phase 1.2 烟雾测试:打印 ChannelConfig.plist 的 11 项渠道注入值
|
||
let cfg = BundleConfig.shared
|
||
print("""
|
||
[BundleConfig] 渠道注入读取结果:
|
||
qiniuDomain = \(cfg.qiniuDomain)
|
||
gameId = \(cfg.gameId)
|
||
channel = \(cfg.channel)
|
||
gameDir = \(cfg.gameDir)
|
||
gameStart = \(cfg.gameStart)
|
||
gameConfig = \(cfg.gameConfig)
|
||
market = \(cfg.market)
|
||
agent = \(cfg.agent)
|
||
appVersion = \(cfg.appVersion)
|
||
other = "\(cfg.other)"
|
||
appleConfig = "\(cfg.appleConfig)"
|
||
""")
|
||
|
||
// Phase 1.3 烟雾测试:打印 SandboxPaths 计算路径
|
||
print("""
|
||
[SandboxPaths] 路径计算结果:
|
||
caches = \(SandboxPaths.caches.path)
|
||
documents = \(SandboxPaths.documents.path)
|
||
bundle = \(SandboxPaths.bundle.path)
|
||
lobbyRoot = \(SandboxPaths.lobbyRoot.path)
|
||
lobbyIndex = \(SandboxPaths.lobbyIndex.path)
|
||
lobbyVersionXML = \(SandboxPaths.lobbyVersionXML.path)
|
||
""")
|
||
|
||
// Phase 1.5 烟雾测试:触发 ResourceUnzipper,确认 lobby index.html 存在
|
||
Task {
|
||
let start = Date()
|
||
do {
|
||
try await ResourceUnzipper.shared.ensureReady()
|
||
let elapsed = Date().timeIntervalSince(start)
|
||
let exists = FileManager.default.fileExists(atPath: SandboxPaths.lobbyIndex.path)
|
||
print("""
|
||
[ResourceUnzipper] ensureReady 完成(耗时 \(String(format: "%.3f", elapsed))s)
|
||
lobbyIndex 存在: \(exists)
|
||
""")
|
||
} catch {
|
||
print("[ResourceUnzipper] ERROR: \(error)")
|
||
}
|
||
}
|
||
|
||
// Phase 1.8 烟雾测试:确认 WebViewJavascriptBridge.js 已入 Bundle 且可读
|
||
// 注:synchronized group 会把 ylgamehall/Resources/JS/ 子目录扁平化为 bundle 根,
|
||
// 所以无需 subdirectory 参数。
|
||
if let url = Bundle.main.url(forResource: "WebViewJavascriptBridge",
|
||
withExtension: "js"),
|
||
let content = try? String(contentsOf: url, encoding: .utf8) {
|
||
print("""
|
||
[WVJB.js] 已就绪
|
||
path = \(url.path)
|
||
bytes = \(content.utf8.count)
|
||
head = \(content.prefix(60).replacingOccurrences(of: "\n", with: " ⏎ "))…
|
||
""")
|
||
} else {
|
||
print("[WVJB.js] ERROR: 找不到 Bundle 内 JS/WebViewJavascriptBridge.js")
|
||
}
|
||
|
||
// Phase 1.10 烟雾测试:拉远端渠道配置 .txt(含 cache-busting + 短文本响应识别)
|
||
Task {
|
||
let start = Date()
|
||
do {
|
||
let outcome = try await RemoteConfigClient.shared.fetch()
|
||
let elapsed = Date().timeIntervalSince(start)
|
||
switch outcome {
|
||
case .parsed(let cfg):
|
||
print("""
|
||
[RemoteConfigClient] 拉取成功 .parsed(耗时 \(String(format: "%.3f", elapsed))s)
|
||
showmessage = \(cfg.showmessage ?? "<nil>")
|
||
agentlist count = \(cfg.agentlist?.count ?? 0)
|
||
""")
|
||
if let first = cfg.agentlist?.first {
|
||
print("""
|
||
agent[0].agentid = \(first.agentid ?? "<nil>")
|
||
agent[0].appVersion = \(first.appVersion ?? "<nil>")
|
||
agent[0].gameVersion = \(first.gameVersion ?? "<nil>")
|
||
agent[0].channellist = \(first.channellist?.count ?? 0) 个
|
||
agent[0].gamelist = \(first.gamelist?.count ?? 0) 个
|
||
""")
|
||
}
|
||
|
||
// Phase 1.11 烟雾测试:chulishengji 双子树合并
|
||
let bc = BundleConfig.shared
|
||
let resolved = VersionResolver.resolve(
|
||
config: cfg,
|
||
agentId: bc.agent,
|
||
channelId: bc.channel,
|
||
marketId: bc.market,
|
||
gameId: bc.gameId
|
||
)
|
||
print("""
|
||
[VersionResolver] chulishengji 双子树合并结果:
|
||
appVersion = \(resolved.appVersion)
|
||
appDownload = \(resolved.appDownload ?? "<nil>")
|
||
gameVersion = \(resolved.gameVersion)
|
||
gameZip = \(resolved.gameZip ?? "<nil>")
|
||
showmessage = "\(resolved.showmessage ?? "<nil>")"
|
||
""")
|
||
case .shortText(let msg):
|
||
print("""
|
||
[RemoteConfigClient] 拉到短文本响应(耗时 \(String(format: "%.3f", elapsed))s)
|
||
运营杀手锏:应当弹窗显示并停止重试
|
||
内容 = "\(msg)"
|
||
""")
|
||
}
|
||
} catch {
|
||
print("[RemoteConfigClient] ERROR: \(error)")
|
||
}
|
||
}
|
||
}
|
||
|
||
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
|
||
.landscape
|
||
}
|
||
|
||
override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
|
||
.landscapeRight
|
||
}
|
||
|
||
override var prefersStatusBarHidden: Bool { false }
|
||
}
|