# 从已安装 TNG 的手机 pull 完整 split APK，供另一台 adb install-multiple
$ErrorActionPreference = "Stop"
$adb = "C:\Users\Administrator\AppData\Local\Android\Sdk\platform-tools\adb.exe"
$pkg = "my.com.tngdigital.ewallet"
$outDir = Join-Path (Split-Path -Parent $PSScriptRoot) "reverse\dumps\tng_splits"

$paths = & $adb shell pm path $pkg 2>$null
if (-not $paths) {
    Write-Host "设备未安装 $pkg" -ForegroundColor Red
    Write-Host "请先在已装 TNG 的手机（如 Pixel 6）上 USB 调试连接。"
    exit 1
}

New-Item -ItemType Directory -Force -Path $outDir | Out-Null
Remove-Item "$outDir\*.apk" -Force -ErrorAction SilentlyContinue

$i = 0
foreach ($line in $paths) {
    if ($line -match "package:(.+)") {
        $remote = $Matches[1].Trim()
        $name = Split-Path $remote -Leaf
        if ($name -eq "base.apk") { $local = Join-Path $outDir "base.apk" }
        else { $local = Join-Path $outDir $name }
        Write-Host "Pull $remote -> $local"
        & $adb pull $remote $local
        $i++
    }
}

Write-Host "`n已 pull $i 个 APK 到 $outDir" -ForegroundColor Green
Write-Host "安装到另一台手机:"
Write-Host "  adb install-multiple -r $outDir\*.apk"
