-
-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathupdate-arma-scripts.ps1
More file actions
284 lines (249 loc) · 11.6 KB
/
Copy pathupdate-arma-scripts.ps1
File metadata and controls
284 lines (249 loc) · 11.6 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# Arma Reforger Scripts and Configs Extractor
# This script extracts .pak files from Arma Reforger and copies the needed files to the project
param(
[switch]$SkipExtraction = $false,
# Human-readable version label (e.g. "1.8.0") recorded in the tree's .version.json
# and used to name the archive folder when this version is later superseded.
[string]$VersionLabel = ""
)
# Paths configuration
$pakEntpackerExe = "N:\Temp\PakEntpacker\PakEntpacker.exe"
$armaReforgerAddons = "N:\Program Files (x86)\Steam\steamapps\common\Arma Reforger\addons"
$targetPath = "N:\Projects\Arma 4\ArmaReforger"
$tempExtractPath = "N:\Temp\ArmaReforgerExtract"
$versionsPath = "N:\Projects\Arma 4\ArmaReforger.versions"
$appManifest = "N:\Program Files (x86)\Steam\steamapps\appmanifest_1874880.acf"
$markerName = ".version.json"
# Directories to copy (source pak dir -> folders to copy)
# Format: "addonDir/extractedFolder" = @("folder1", "folder2", ...)
# The extractedFolder name corresponds to the .pak file name (e.g., "data" -> "data.pak")
# Ordered: later paks layer over earlier ones, so merge order must be preserved
$extractionMap = [ordered]@{
"data/data" = @("AI")
"data/data007" = @("Configs", "Language","scripts","Prefabs","PrefabsEditable")
"data/data010" = @("UI")
"core/data" = @("scripts", "ui", "configs")
}
Write-Host "==================================================" -ForegroundColor Cyan
Write-Host "Arma Reforger Scripts & Configs Update Tool" -ForegroundColor Cyan
Write-Host "==================================================" -ForegroundColor Cyan
Write-Host ""
# Verify PakEntpacker exists
if (-not (Test-Path $pakEntpackerExe)) {
Write-Host "ERROR: PakEntpacker.exe not found at: $pakEntpackerExe" -ForegroundColor Red
exit 1
}
# Verify Arma Reforger addons directory exists
if (-not (Test-Path $armaReforgerAddons)) {
Write-Host "ERROR: Arma Reforger addons directory not found at: $armaReforgerAddons" -ForegroundColor Red
exit 1
}
# Read the installed build id from the Steam app manifest (changes on every game update)
$newBuildId = $null
if (Test-Path $appManifest) {
$manifestContent = Get-Content $appManifest -Raw
if ($manifestContent -match '"buildid"\s+"(\d+)"') {
$newBuildId = $Matches[1]
Write-Host "Installed Arma Reforger build id: $newBuildId" -ForegroundColor Gray
}
}
if (-not $newBuildId) {
Write-Host "WARNING: Could not read buildid from $appManifest - version tracking will be incomplete" -ForegroundColor Yellow
}
Write-Host ""
# Extract .pak files
if (-not $SkipExtraction) {
Write-Host "Step 1: Extracting .pak files..." -ForegroundColor Yellow
Write-Host ""
# Build list of unique pak files to extract from extractionMap
$pakFilesToExtract = @{}
foreach ($mapKey in $extractionMap.Keys) {
$parts = $mapKey -split '/'
$addonDir = $parts[0]
$extractedFolder = $parts[1]
$pakFileName = "$extractedFolder.pak"
if (-not $pakFilesToExtract.ContainsKey($addonDir)) {
$pakFilesToExtract[$addonDir] = @()
}
if ($pakFilesToExtract[$addonDir] -notcontains $pakFileName) {
$pakFilesToExtract[$addonDir] += $pakFileName
}
}
foreach ($addonDir in $pakFilesToExtract.Keys) {
$pakDir = Join-Path $armaReforgerAddons $addonDir
foreach ($pakFileName in $pakFilesToExtract[$addonDir]) {
$pakFilePath = Join-Path $pakDir $pakFileName
if (Test-Path $pakFilePath) {
Write-Host " Extracting $pakFileName..." -ForegroundColor Gray
# Create temp directory for this pak file
$tempPakDir = Join-Path $tempExtractPath ([System.IO.Path]::GetFileNameWithoutExtension($pakFileName))
if (Test-Path $tempPakDir) {
Remove-Item -Path $tempPakDir -Recurse -Force
}
New-Item -Path $tempPakDir -ItemType Directory -Force | Out-Null
# Copy pak file to temp
$tempPakFile = Join-Path $tempPakDir $pakFileName
Copy-Item -Path $pakFilePath -Destination $tempPakFile -Force
# Extract in temp directory
Push-Location $tempPakDir
& $pakEntpackerExe
$exitCode = $LASTEXITCODE
Pop-Location
if ($exitCode -ne 0) {
Write-Host " WARNING: PakEntpacker returned error code $exitCode" -ForegroundColor Yellow
}
# Move extracted folder back to original location
$extractedFolderName = [System.IO.Path]::GetFileNameWithoutExtension($pakFileName)
$tempExtractedFolder = Join-Path $tempPakDir $extractedFolderName
$finalExtractedFolder = Join-Path $pakDir $extractedFolderName
if (Test-Path $tempExtractedFolder) {
# Remove old extracted folder if exists
if (Test-Path $finalExtractedFolder) {
Remove-Item -Path $finalExtractedFolder -Recurse -Force
}
# Move extracted content to final location
Move-Item -Path $tempExtractedFolder -Destination $finalExtractedFolder -Force
Write-Host " Success!" -ForegroundColor Green
} else {
Write-Host " ERROR: Extraction failed - no output folder created" -ForegroundColor Red
}
# Clean up temp directory
Remove-Item -Path $tempPakDir -Recurse -Force -ErrorAction SilentlyContinue
} else {
Write-Host " WARNING: PAK file not found: $pakFilePath" -ForegroundColor Yellow
}
}
}
Write-Host ""
Write-Host " Extraction complete!" -ForegroundColor Green
Write-Host ""
} else {
Write-Host "Step 1: Skipping extraction (using existing extracted files)" -ForegroundColor Yellow
Write-Host ""
}
# Archive or clean target directory
Write-Host "Step 2: Archiving/cleaning target directory..." -ForegroundColor Yellow
if (Test-Path $targetPath) {
$oldMarkerPath = Join-Path $targetPath $markerName
$oldMarker = $null
if (Test-Path $oldMarkerPath) {
try {
$oldMarker = Get-Content $oldMarkerPath -Raw | ConvertFrom-Json
} catch {
Write-Host " WARNING: Could not parse existing $markerName - treating tree as unlabeled" -ForegroundColor Yellow
}
}
$sameBuild = $oldMarker -and $newBuildId -and ($oldMarker.buildId -eq $newBuildId)
if ($sameBuild) {
# Re-extraction of the same game build: replace in place, no archive
Write-Host " Same build ($newBuildId) already extracted - replacing in place (no archive)" -ForegroundColor Gray
Remove-Item -Path $targetPath -Recurse -Force -ErrorAction Stop
Write-Host " Old files removed!" -ForegroundColor Green
} else {
# New game build (or unversioned tree): keep the old tree as a version archive
if ($oldMarker -and $oldMarker.label) {
$archiveName = $oldMarker.label
} elseif ($oldMarker -and $oldMarker.buildId) {
$archiveName = "build-$($oldMarker.buildId)"
} else {
$archiveName = "unlabeled-" + (Get-Item $targetPath).LastWriteTime.ToString('yyyy-MM-dd')
}
$archiveName = $archiveName -replace '[^\w\.\-]', '_'
$archivePath = Join-Path $versionsPath $archiveName
if (Test-Path $archivePath) {
$archivePath = "$archivePath-" + (Get-Date -Format 'yyyyMMdd-HHmmss')
}
if (-not (Test-Path $versionsPath)) {
New-Item -Path $versionsPath -ItemType Directory -Force | Out-Null
}
Write-Host " Archiving previous version to: $archivePath" -ForegroundColor Gray
Move-Item -Path $targetPath -Destination $archivePath -Force -ErrorAction Stop
Write-Host " Previous version archived!" -ForegroundColor Green
}
} else {
Write-Host " Target directory doesn't exist yet" -ForegroundColor Gray
}
Write-Host ""
# Copy files to target
Write-Host "Step 3: Copying files to project..." -ForegroundColor Yellow
Write-Host ""
$totalCopied = 0
$totalFailed = 0
$foldersProcessed = @{}
foreach ($entry in $extractionMap.GetEnumerator()) {
$sourcePath = Join-Path $armaReforgerAddons $entry.Key
foreach ($folder in $entry.Value) {
$sourceFolder = Join-Path $sourcePath $folder
$targetFolder = Join-Path $targetPath $folder
if (Test-Path $sourceFolder) {
$isFirstCopy = -not $foldersProcessed.ContainsKey($folder)
if ($isFirstCopy) {
Write-Host " Copying $folder..." -ForegroundColor Gray
$foldersProcessed[$folder] = $true
} else {
Write-Host " Merging additional $folder content..." -ForegroundColor Gray
}
Write-Host " From: $sourceFolder" -ForegroundColor DarkGray
Write-Host " To: $targetFolder" -ForegroundColor DarkGray
try {
if ($isFirstCopy) {
# First copy - copy the whole folder
Copy-Item -Path $sourceFolder -Destination $targetFolder -Recurse -Force -ErrorAction Stop
$fileCount = (Get-ChildItem -Path $targetFolder -Recurse -File).Count
Write-Host " Success! ($fileCount files)" -ForegroundColor Green
$totalCopied++
} else {
# Merge - copy contents into existing folder
$sourceFolderContents = Join-Path $sourceFolder "*"
Copy-Item -Path $sourceFolderContents -Destination $targetFolder -Recurse -Force -ErrorAction Stop
Write-Host " Merged successfully!" -ForegroundColor Green
}
}
catch {
Write-Host " ERROR: Failed to copy - $($_.Exception.Message)" -ForegroundColor Red
if ($isFirstCopy) {
$totalFailed++
}
}
}
else {
Write-Host " WARNING: Source folder not found: $sourceFolder" -ForegroundColor Yellow
$totalFailed++
}
Write-Host ""
}
}
# Write version marker into the freshly extracted tree
Write-Host "Step 4: Writing version marker..." -ForegroundColor Yellow
if (Test-Path $targetPath) {
if (-not $VersionLabel) {
if ($newBuildId) {
$VersionLabel = "build-$newBuildId"
} else {
$VersionLabel = "unlabeled-" + (Get-Date -Format 'yyyy-MM-dd')
}
}
$marker = [ordered]@{
buildId = $newBuildId
label = $VersionLabel
extracted = (Get-Date -Format 'yyyy-MM-dd HH:mm:ss')
source = $armaReforgerAddons
}
$markerPath = Join-Path $targetPath $markerName
$marker | ConvertTo-Json | Set-Content -Path $markerPath -Encoding UTF8
Write-Host " Wrote $markerPath (label: $VersionLabel, build: $newBuildId)" -ForegroundColor Green
} else {
Write-Host " WARNING: Target directory missing - nothing extracted?" -ForegroundColor Yellow
}
Write-Host ""
# Summary
Write-Host "==================================================" -ForegroundColor Cyan
Write-Host "Summary" -ForegroundColor Cyan
Write-Host "==================================================" -ForegroundColor Cyan
Write-Host "Folders copied successfully: $totalCopied" -ForegroundColor Green
if ($totalFailed -gt 0) {
Write-Host "Folders failed/not found: $totalFailed" -ForegroundColor Yellow
}
Write-Host ""
Write-Host "Update complete! ArmaReforger reference tree is now: $VersionLabel (build $newBuildId)" -ForegroundColor Green
Write-Host ""