-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBuild-CPP.ps1
More file actions
661 lines (537 loc) · 23.1 KB
/
Build-CPP.ps1
File metadata and controls
661 lines (537 loc) · 23.1 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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
#usage -----> powershell -ExecutionPolicy Bypass -Command "& {. .\Build-CPP.ps1; Dist -major 1 -minor 0 -patch 0}"
$msbuild = "C:\Program Files\Microsoft Visual Studio\2022\Community\Msbuild\Current\Bin\MSBuild.exe"
function Add-RMSkinFooter {
param(
[Parameter(Mandatory = $true)][string]$ZipPath
)
if (!(Test-Path $ZipPath)) {
throw "ZIP file not found: $ZipPath"
}
$zipSize = [long](Get-Item $ZipPath).Length
try {
# Use the GitHub Actions method that works
$sizeBytes = [System.BitConverter]::GetBytes($zipSize)
Add-Content -Path $ZipPath -Value $sizeBytes -Encoding Byte
$flags = [byte]0
Add-Content -Path $ZipPath -Value $flags -Encoding Byte
$rmskin = [string]"RMSKIN`0"
Add-Content -Path $ZipPath -Value $rmskin -NoNewLine -Encoding ASCII
Write-Host "Added RMSKIN footer using GitHub Actions method" -ForegroundColor Green
return
}
catch {
Write-Host "GitHub Actions method failed, trying FileStream..." -ForegroundColor Yellow
}
try {
$fileStream = [System.IO.File]::OpenWrite($ZipPath)
$fileStream.Seek(0, [System.IO.SeekOrigin]::End)
$sizeBytes = [System.BitConverter]::GetBytes($zipSize)
$fileStream.Write($sizeBytes, 0, $sizeBytes.Length)
$flagByte = [byte]0
$fileStream.WriteByte($flagByte)
$rmskinBytes = [System.Text.Encoding]::ASCII.GetBytes("RMSKIN`0")
$fileStream.Write($rmskinBytes, 0, $rmskinBytes.Length)
$fileStream.Close()
$fileStream.Dispose()
Write-Host "Added RMSKIN footer using FileStream method" -ForegroundColor Green
}
catch {
if ($fileStream) {
$fileStream.Close()
$fileStream.Dispose()
}
throw "Failed to add RMSKIN footer: $_"
}
}
function BumpVersion {
param(
[Parameter(Mandatory = $true)][string]$ver
)
$skinDefPath = Join-Path (Get-Location).Path "Resources\skin_definition.json"
if (!(Test-Path $skinDefPath)) {
throw "skin_definition.json not found at: $skinDefPath"
}
$skinDef = Get-Content $skinDefPath -Raw | ConvertFrom-Json
$skinDef.version = $ver
($skinDef | ConvertTo-Json -Depth 10) | Set-Content $skinDefPath -Encoding UTF8
Write-Host "Bumped skin_definition.json to version $ver" -ForegroundColor Green
}
function New-Package {
param(
[Parameter(Mandatory = $true)][string]$RootConfig,
[string]$OutPath,
[string]$OutDirectory,
[string]$OutFile,
[switch]$Quiet
)
$skinDefPath = Join-Path (Get-Location).Path "Resources\skin_definition.json"
if (!(Test-Path $skinDefPath)) {
throw "skin_definition.json not found at: $skinDefPath"
}
$skinDef = Get-Content $skinDefPath -Raw | ConvertFrom-Json
$pwdRoot = (Get-Location).Path
$skinDir = if ($skinDef.skinDir) { Join-Path $pwdRoot $skinDef.skinDir } else { Join-Path $pwdRoot "." }
if (!(Test-Path $skinDir)) {
throw "skinDir '$skinDir' does not exist."
}
$temp = Join-Path ([System.IO.Path]::GetTempPath()) ([System.Guid]::NewGuid().ToString())
New-Item -ItemType Directory -Path $temp -Force | Out-Null
if (-not $Quiet) { Write-Host "Using temp directory: $temp" -ForegroundColor Gray }
$iniLines = @()
$iniLines += "[rmskin]"
if ($skinDef.name) { $iniLines += "Name=$($skinDef.name)" }
if ($skinDef.version) { $iniLines += "Version=$($skinDef.version)" }
if ($skinDef.author) { $iniLines += "Author=$($skinDef.author)" }
if ($skinDef.minimumVersion) { $iniLines += "MinimumVersion=$($skinDef.minimumVersion)" }
if ($skinDef.minimumWindows) { $iniLines += "MinimumWindows=$($skinDef.minimumWindows)" }
if ($skinDef.load) { $iniLines += "Load=$($skinDef.load)" }
if ($skinDef.loadType) { $iniLines += "LoadType=$($skinDef.loadType)" }
foreach ($prop in $skinDef.PSObject.Properties.Name) {
if ($prop -in @("name","version","author","minimumVersion","minimumWindows","load","loadType","plugins","skinDir","output","headerImage","variableFiles","configPrefix")) { continue }
$val = $skinDef.$prop
if ($val) { $iniLines += "$prop=$val" }
}
$iniContent = $iniLines -join "`r`n"
$iniPath = Join-Path $temp "RMSKIN.ini"
# Use ASCII encoding without trailing newline like GitHub Actions
$iniContent | Set-Content -Path $iniPath -Encoding ASCII -NoNewline
if (-not $Quiet) { Write-Host "Created RMSKIN.ini" -ForegroundColor Cyan }
$skinstemp = Join-Path $temp "Skins"
New-Item -ItemType Directory -Path $skinstemp -Force | Out-Null
$destSkinRoot = Join-Path $skinstemp $RootConfig
New-Item -ItemType Directory -Path $destSkinRoot -Force | Out-Null
$rootConfigPath = Join-Path $skinDir $RootConfig
try {
$rootConfigPath = [System.IO.Path]::GetFullPath($rootConfigPath)
} catch {
$cleanRoot = ($RootConfig -replace '^[.][\\/]+','')
$rootConfigPath = Join-Path $skinDir $cleanRoot
}
if (!(Test-Path $rootConfigPath)) {
throw "RootConfig path '$rootConfigPath' not found."
}
$excluded = @(".git", ".gitignore")
$itemsToCopy = Get-ChildItem -Path $rootConfigPath -Recurse | Where-Object {
$relativePath = $_.FullName.Substring($rootConfigPath.Length + 1)
$shouldExclude = $false
foreach ($exclude in $excluded) {
if ($relativePath -like "*$exclude*" -or $_.Name -eq $exclude) {
$shouldExclude = $true
break
}
}
-not $shouldExclude
}
foreach ($item in $itemsToCopy) {
$relativePath = $item.FullName.Substring($rootConfigPath.Length + 1)
$destinationPath = Join-Path $destSkinRoot $relativePath
$destinationDir = Split-Path $destinationPath -Parent
if (!(Test-Path $destinationDir)) {
New-Item -ItemType Directory -Path $destinationDir -Force | Out-Null
}
if (-not $item.PSIsContainer) {
Copy-Item -Path $item.FullName -Destination $destinationPath -Force
}
}
if (-not $Quiet) { Write-Host "Copied skin files from $rootConfigPath" -ForegroundColor Cyan }
$pluginsTemp = Join-Path $temp "Plugins"
$pluginsTemp32 = Join-Path $pluginsTemp "32bit"
$pluginsTemp64 = Join-Path $pluginsTemp "64bit"
New-Item -ItemType Directory -Path $pluginsTemp -Force | Out-Null
New-Item -ItemType Directory -Path $pluginsTemp32 -Force | Out-Null
New-Item -ItemType Directory -Path $pluginsTemp64 -Force | Out-Null
if ($skinDef.plugins) {
if (-not $Quiet) { Write-Host "Collecting plugins..." -ForegroundColor Cyan }
foreach ($plugin in $skinDef.plugins) {
$x32path = $plugin.x32
$x64path = $plugin.x64
if ($x32path) {
if ($x32path -notmatch '^[A-Za-z]:\\') {
$x32path = Join-Path $pwdRoot $x32path
}
if (Test-Path $x32path) {
if ((Get-Item $x32path).PSIsContainer) {
Get-ChildItem -Path $x32path -Filter *.dll -Recurse | ForEach-Object {
Copy-Item -Path $_.FullName -Destination $pluginsTemp32 -Force
}
} else {
Copy-Item -Path $x32path -Destination $pluginsTemp32 -Force
}
if (-not $Quiet) { Write-Host "Copied x32 plugin from $x32path" }
} else {
if (-not $Quiet) { Write-Host "x32 plugin path not found: $x32path" -ForegroundColor Yellow }
}
}
if ($x64path) {
if ($x64path -notmatch '^[A-Za-z]:\\') {
$x64path = Join-Path $pwdRoot $x64path
}
if (Test-Path $x64path) {
if ((Get-Item $x64path).PSIsContainer) {
Get-ChildItem -Path $x64path -Filter *.dll -Recurse | ForEach-Object {
Copy-Item -Path $_.FullName -Destination $pluginsTemp64 -Force
}
} else {
Copy-Item -Path $x64path -Destination $pluginsTemp64 -Force
}
if (-not $Quiet) { Write-Host "Copied x64 plugin from $x64path" }
} else {
if (-not $Quiet) { Write-Host "x64 plugin path not found: $x64path" -ForegroundColor Yellow }
}
}
}
}
if ($skinDef.headerImage) {
$header = $skinDef.headerImage
if ($header -notmatch '^[A-Za-z]:\\') {
$possible = Join-Path $pwdRoot $header
if (Test-Path $possible) { $header = $possible }
}
if (Test-Path $header) {
Copy-Item -Path $header -Destination (Join-Path $temp "RMSKIN.bmp") -Force
if (-not $Quiet) { Write-Host "Copied header image" -ForegroundColor Cyan }
} else {
if (-not $Quiet) { Write-Host "Header image not found: $header" -ForegroundColor Yellow }
}
}
if (-not $Quiet) {
Write-Host "`nTemp directory contents:" -ForegroundColor Gray
Get-ChildItem -Path $temp -Recurse | ForEach-Object {
$relativePath = $_.FullName.Substring($temp.Length + 1)
Write-Host " $relativePath" -ForegroundColor Gray
}
}
$zipPath = Join-Path $temp "skin.zip"
if (Test-Path $zipPath) { Remove-Item $zipPath -Force }
$tempContents = Get-ChildItem -Path $temp -Exclude "*.zip", "*.rmskin"
if ($tempContents.Count -eq 0) {
throw "No content found in temp directory to package"
}
if (-not $Quiet) { Write-Host "Creating ZIP archive..." -ForegroundColor Cyan }
Compress-Archive -Path $tempContents.FullName -DestinationPath $zipPath -Force -CompressionLevel Optimal
if (!(Test-Path $zipPath)) {
throw "Failed to create ZIP archive"
}
$zipInfo = Get-Item $zipPath
if ($zipInfo.Length -eq 0) {
throw "ZIP archive is empty (0 bytes)"
}
if (-not $Quiet) { Write-Host "ZIP created successfully ($($zipInfo.Length) bytes)" -ForegroundColor Cyan }
Add-RMSkinFooter -ZipPath $zipPath
if (-not $Quiet) { Write-Host "Added RMSKIN footer to ZIP" -ForegroundColor Cyan }
$filename = $skinDef.name
if ($skinDef.version) { $filename += " $($skinDef.version)" }
$filename += ".rmskin"
if ($skinDef.output) {
$outCandidate = $skinDef.output
if ($outCandidate -notmatch '^[A-Za-z]:\\') { $outCandidate = Join-Path $pwdRoot $outCandidate }
$OutputPath = $outCandidate
} elseif ($OutPath) {
$OutputPath = $OutPath
} else {
$dir = $env:USERPROFILE + "\Desktop"
if ($OutDirectory) { $dir = $OutDirectory }
$OutputPath = Join-Path $dir $filename
}
$interimRmskin = Join-Path $temp "skin.rmskin"
Move-Item -Path $zipPath -Destination $interimRmskin -Force
if (!(Test-Path $interimRmskin)) {
throw "Failed to create RMSKIN file"
}
$rmskinInfo = Get-Item $interimRmskin
if ($rmskinInfo.Length -eq 0) {
throw "RMSKIN file is empty (0 bytes)"
}
$outDirPath = Split-Path $OutputPath -Parent
if (!(Test-Path $outDirPath)) { New-Item -ItemType Directory -Path $outDirPath -Force | Out-Null }
if (Test-Path $OutputPath) { Remove-Item $OutputPath -Force }
Move-Item -Path $interimRmskin -Destination $OutputPath -Force
try {
Remove-Item -Path $temp -Recurse -Force
} catch {
if (-not $Quiet) { Write-Host "Warning: Could not clean up temp directory: $temp" -ForegroundColor Yellow }
}
if (!(Test-Path $OutputPath)) {
throw "Final RMSKIN file was not created at: $OutputPath"
}
$finalInfo = Get-Item $OutputPath
if ($finalInfo.Length -eq 0) {
throw "Final RMSKIN file is empty (0 bytes): $OutputPath"
}
if (-not $Quiet) {
Write-Host "Created RMSKIN at: $OutputPath ($($finalInfo.Length) bytes)" -ForegroundColor Green
}
return $OutputPath
}
function New-PluginZip {
param(
[Parameter(Mandatory = $true)][string]$Name,
[Parameter(Mandatory = $true)][string]$Version,
[string]$OutputDirectory = ".\dist"
)
$zipName = "$($Name)_v$($Version)_x64_x86_dll.zip"
$zipPath = Join-Path $OutputDirectory $zipName
# Remove existing zip if it exists
if (Test-Path $zipPath) {
Remove-Item $zipPath -Force
}
# Check if plugin directories exist and have DLLs
$x64Path = Join-Path $OutputDirectory "x64"
$x32Path = Join-Path $OutputDirectory "x32"
$foldersToZip = @()
if (Test-Path $x64Path) {
$x64Dlls = Get-ChildItem -Path $x64Path -Filter "*.dll" -File
if ($x64Dlls.Count -gt 0) {
$foldersToZip += $x64Path
Write-Host "Found $($x64Dlls.Count) x64 plugin(s)" -ForegroundColor Cyan
}
}
if (Test-Path $x32Path) {
$x32Dlls = Get-ChildItem -Path $x32Path -Filter "*.dll" -File
if ($x32Dlls.Count -gt 0) {
$foldersToZip += $x32Path
Write-Host "Found $($x32Dlls.Count) x32 plugin(s)" -ForegroundColor Cyan
}
}
if ($foldersToZip.Count -eq 0) {
Write-Host "No plugin DLLs found to zip" -ForegroundColor Yellow
return $null
}
# Create the zip file with folder structure
try {
Compress-Archive -Path $foldersToZip -DestinationPath $zipPath -Force -CompressionLevel Optimal
if (Test-Path $zipPath) {
$zipInfo = Get-Item $zipPath
Write-Host "Created plugin ZIP: $zipName ($($zipInfo.Length) bytes)" -ForegroundColor Green
return $zipPath
} else {
Write-Host "Failed to create plugin ZIP file" -ForegroundColor Red
return $null
}
}
catch {
Write-Host "Error creating plugin ZIP: $_" -ForegroundColor Red
return $null
}
}
function Build-Architecture {
param(
[Parameter(Mandatory = $true)][string]$Platform,
[Parameter(Mandatory = $true)][string]$SolutionFile
)
Write-Host "Building $Platform architecture..." -ForegroundColor Yellow
$buildArgs = @(
$SolutionFile
"/p:Configuration=Release"
"/p:Platform=$Platform"
"/m" # Multi-processor build
"/v:minimal" # Minimal verbosity
)
& $msbuild $buildArgs
if ($LASTEXITCODE -ne 0) {
Write-Host "MSBuild failed for $Platform with exit code $LASTEXITCODE" -ForegroundColor Red
return $false
}
Write-Host "$Platform build completed successfully" -ForegroundColor Green
return $true
}
function Find-BuiltDll {
param(
[Parameter(Mandatory = $true)][string]$Architecture,
[Parameter(Mandatory = $true)][string]$ProjectName
)
# Map MSBuild platform names to folder names that are actually used
$platformMapping = @{
"x64" = @("x64")
"x86" = @("x86", "x32", "Win32") # x86 can output to multiple folder names
"Win32" = @("x86", "x32", "Win32") # Win32 also maps to these folders
}
$searchFolders = $platformMapping[$Architecture]
if (-not $searchFolders) {
Write-Host "Unknown architecture: $Architecture" -ForegroundColor Red
return $null
}
# Build search paths for all possible folder names
$searchPaths = @()
foreach ($folder in $searchFolders) {
$searchPaths += @(
".\$ProjectName\$folder\Release\$ProjectName.dll",
".\$ProjectName\bin\$folder\Release\$ProjectName.dll",
".\$ProjectName\bin\Release\$ProjectName.dll",
".\bin\$folder\Release\$ProjectName.dll",
".\bin\Release\$ProjectName.dll",
".\$folder\Release\$ProjectName.dll",
".\Release\$ProjectName.dll"
)
}
# Also check for .NET builds
$netSearchPaths = Get-ChildItem ".\$ProjectName\bin\Release\net*\$ProjectName.dll" -ErrorAction SilentlyContinue |
Select-Object -First 1 -ExpandProperty FullName
if ($netSearchPaths) {
$searchPaths += $netSearchPaths
}
foreach ($path in $searchPaths) {
if (Test-Path $path) {
Write-Host "Found $Architecture DLL at: $path" -ForegroundColor Cyan
return $path
}
}
Write-Host "No $Architecture DLL found in expected locations" -ForegroundColor Yellow
Write-Host "Searched paths:" -ForegroundColor Gray
foreach ($path in $searchPaths) {
Write-Host " $path" -ForegroundColor Gray
}
return $null
}
function Copy-DllToStandardizedFolder {
param(
[Parameter(Mandatory = $true)][string]$SourcePath,
[Parameter(Mandatory = $true)][string]$Architecture,
[Parameter(Mandatory = $true)][string]$DistPath
)
# Map MSBuild platforms to standardized folder names
$folderMapping = @{
"x64" = "x64"
"x86" = "x32"
"Win32" = "x32"
}
$targetFolder = $folderMapping[$Architecture]
if (-not $targetFolder) {
Write-Host "Unknown architecture: $Architecture" -ForegroundColor Red
return $false
}
$targetPath = Join-Path $DistPath $targetFolder
# Ensure target directory exists
if (!(Test-Path $targetPath)) {
New-Item -ItemType Directory -Path $targetPath -Force | Out-Null
}
try {
Copy-Item -Path $SourcePath -Destination $targetPath -Force
Write-Host "Copied $Architecture build to $targetFolder folder: $SourcePath" -ForegroundColor Green
return $true
}
catch {
Write-Host "Failed to copy $Architecture build: $_" -ForegroundColor Red
return $false
}
}
function Dist {
param (
[Parameter(Mandatory = $true)][int16]$major,
[Parameter(Mandatory = $true)][int16]$minor,
[Parameter(Mandatory = $true)][int16]$patch
)
$solutionFile = ".\WebView2-Plugin.sln"
$projectName = "WebView2"
if (!(Test-Path $solutionFile)) {
throw "Solution file not found: $solutionFile"
}
if (Test-Path $msbuild) {
Write-Host "Starting build process..." -ForegroundColor Yellow
# Clean previous builds
Write-Host "Cleaning previous builds..." -ForegroundColor Gray
& $msbuild $solutionFile /t:Clean /p:Configuration=Release /v:minimal
# Build both architectures - using x64 and Win32
$x64Success = Build-Architecture -Platform "x64" -SolutionFile $solutionFile
$x86Success = Build-Architecture -Platform "Win32" -SolutionFile $solutionFile
# If neither build succeeded, throw an error
if (-not $x64Success -and -not $x86Success) {
throw "Both x64 and x86 builds failed"
}
if (-not $x64Success) {
Write-Host "Warning: x64 build failed, continuing with x86 only" -ForegroundColor Yellow
}
if (-not $x86Success) {
Write-Host "Warning: x86 build failed, continuing with x64 only" -ForegroundColor Yellow
}
} else {
Write-Host "MSBuild not found at $msbuild - skipping build step" -ForegroundColor Yellow
}
# Clean and prepare dist directory with standardized folder names
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue .\dist
New-Item -ItemType Directory -Path ".\dist\x64" -Force | Out-Null
New-Item -ItemType Directory -Path ".\dist\x32" -Force | Out-Null
$ver = "$($major).$($minor).$($patch)"
BumpVersion $ver
# Find and copy built DLLs to standardized folders
$builtX64 = Find-BuiltDll -Architecture "x64" -ProjectName $projectName
$builtX86 = Find-BuiltDll -Architecture "x86" -ProjectName $projectName
$x64Copied = $false
$x86Copied = $false
if ($builtX64) {
$x64Copied = Copy-DllToStandardizedFolder -SourcePath $builtX64 -Architecture "x64" -DistPath ".\dist"
} else {
Write-Host "x64 build not found at expected paths." -ForegroundColor Yellow
}
if ($builtX86) {
$x86Copied = Copy-DllToStandardizedFolder -SourcePath $builtX86 -Architecture "x86" -DistPath ".\dist"
} else {
Write-Host "x86 build not found at expected paths." -ForegroundColor Yellow
}
# Verify at least one architecture was copied successfully
$x64Files = Get-ChildItem ".\dist\x64\*.dll" -ErrorAction SilentlyContinue
$x32Files = Get-ChildItem ".\dist\x32\*.dll" -ErrorAction SilentlyContinue
if (-not $x64Files -and -not $x32Files) {
throw "No DLL files found in either x64 or x32 dist directories. Build may have failed."
}
# Update skin definition with plugin paths (always use standardized folder names)
$skinDefPath = Join-Path (Get-Location).Path "Resources\skin_definition.json"
if (Test-Path $skinDefPath) {
$skinDef = Get-Content $skinDefPath -Raw | ConvertFrom-Json
if ($skinDef.plugins) {
foreach ($p in $skinDef.plugins) {
if ($p.name -and $p.name -match "$projectName|WebView|WebView.dll|$projectName.dll") {
# Only set paths for architectures that were successfully copied
if ($x32Files) { $p.x32 = ".\dist\x32" }
if ($x64Files) { $p.x64 = ".\dist\x64" }
}
}
($skinDef | ConvertTo-Json -Depth 10) | Set-Content $skinDefPath -Encoding UTF8
}
}
# Determine root config
$skinDef = Get-Content $skinDefPath -Raw | ConvertFrom-Json
$root = $null
if ($skinDef.load) {
$root = ($skinDef.load -split "[\\/]+")[0]
}
if (-not $root) { throw "Could not determine root config from skin_definition.json load field." }
# Create plugin ZIP file
$pluginZip = New-PluginZip -Name $skinDef.name -Version $ver
if ($pluginZip) {
try {
$pluginZipFullPath = [System.IO.Path]::GetFullPath($pluginZip)
} catch {
$pluginZipFullPath = (Resolve-Path $pluginZip -ErrorAction SilentlyContinue).Path
if (-not $pluginZipFullPath) {
$pluginZipFullPath = $pluginZip
}
}
Write-Host "Plugin ZIP created at: $pluginZipFullPath" -ForegroundColor Green
}
# Create RMSKIN package
$output = New-Package -RootConfig $root
try {
$outputFullPath = [System.IO.Path]::GetFullPath($output)
} catch {
$outputFullPath = (Resolve-Path $output -ErrorAction SilentlyContinue).Path
if (-not $outputFullPath) {
$outputFullPath = $output
}
}
Write-Host "RMSKIN packaged: $outputFullPath" -ForegroundColor Green
Write-Host "`nBuild completed successfully!" -ForegroundColor Green
Write-Host "Output files:" -ForegroundColor White
if ($pluginZip) {
Write-Host " - Plugin DLLs: $pluginZipFullPath" -ForegroundColor Gray
}
Write-Host " - RMSKIN package: $outputFullPath" -ForegroundColor Gray
# Summary of what was built
Write-Host "`nBuild Summary:" -ForegroundColor White
if ($x64Files) {
Write-Host " - x64 plugins: $($x64Files.Count) file(s)" -ForegroundColor Gray
}
if ($x32Files) {
Write-Host " - x32 plugins: $($x32Files.Count) file(s)" -ForegroundColor Gray
}
}