forked from violetljj/blind-assist
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharchive_apk.ps1
More file actions
72 lines (63 loc) · 2.63 KB
/
Copy patharchive_apk.ps1
File metadata and controls
72 lines (63 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
param(
[string]$ApkPath = "app\build\outputs\apk\debug\app-debug.apk",
[string]$ArchiveDir = "E:\linnan\blind-assist-apk-archive\apks",
[switch]$Milestone,
[string]$MilestoneDir = "releases\apk"
)
$ErrorActionPreference = "Stop"
function Resolve-RepoPath([string]$Path) {
if ([System.IO.Path]::IsPathRooted($Path)) {
return $Path
}
return (Join-Path $PSScriptRoot "..\$Path")
}
function Get-VersionName {
$gradleFile = Join-Path $PSScriptRoot "..\app\build.gradle.kts"
$line = Select-String -LiteralPath $gradleFile -Pattern 'versionName\s*=\s*"([^"]+)"' | Select-Object -First 1
if ($line -and $line.Matches[0].Groups[1].Value) {
return $line.Matches[0].Groups[1].Value
}
return "unknown"
}
$repoRoot = (Resolve-Path -LiteralPath (Join-Path $PSScriptRoot "..")).Path
$resolvedApk = Resolve-RepoPath $ApkPath
if (-not (Test-Path -LiteralPath $resolvedApk)) {
throw "APK not found: $resolvedApk"
}
$resolvedApk = (Resolve-Path -LiteralPath $resolvedApk).Path
New-Item -ItemType Directory -Force -Path $ArchiveDir | Out-Null
$versionName = Get-VersionName
$timestamp = Get-Date -Format "yyyyMMdd-HHmmss"
$destName = "BlindAssist-v$versionName-debug-$timestamp.apk"
$archivePath = Join-Path $ArchiveDir $destName
Copy-Item -LiteralPath $resolvedApk -Destination $archivePath -Force
$hash = Get-FileHash -Algorithm SHA256 -LiteralPath $archivePath
$manifest = Join-Path (Split-Path -Parent $ArchiveDir) "APK_ARCHIVE_MANIFEST.csv"
if (-not (Test-Path -LiteralPath $manifest)) {
"Timestamp,FileName,SizeBytes,SHA256,SourcePath" | Out-File -FilePath $manifest -Encoding utf8
}
$size = (Get-Item -LiteralPath $archivePath).Length
"$timestamp,$destName,$size,$($hash.Hash),$resolvedApk" | Add-Content -Path $manifest -Encoding utf8
$result = [ordered]@{
archivePath = $archivePath
sizeBytes = $size
sha256 = $hash.Hash
manifest = $manifest
milestonePath = $null
}
if ($Milestone) {
$resolvedMilestoneDir = Resolve-RepoPath $MilestoneDir
New-Item -ItemType Directory -Force -Path $resolvedMilestoneDir | Out-Null
$milestonePath = Join-Path $resolvedMilestoneDir ("{0}.json" -f [System.IO.Path]::GetFileNameWithoutExtension($destName))
[pscustomobject]@{
schema = 'blindassist_apk_receipt_v1'
archived_at = (Get-Date).ToString('o')
file_name = $destName
size_bytes = $hashSize
sha256 = $hash.Hash
external_archive_path = $archivePath
source_path = $resolvedApk
} | ConvertTo-Json | Set-Content -LiteralPath $milestonePath -Encoding utf8
$result.milestoneReceiptPath = $milestonePath
}
$result | ConvertTo-Json -Depth 3