-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuildModZip.ps1
More file actions
132 lines (111 loc) · 3.98 KB
/
Copy pathBuildModZip.ps1
File metadata and controls
132 lines (111 loc) · 3.98 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
#!powershell.exe -ExecutionPolicy Bypass -File
param (
[string] $Mode,
[string] $Configuration
)
# Normalize params
if ($Configuration -ne 'Debug' -and $Configuration -ne 'Release')
{
Write-Error "Invalid configuration specified. Use 'Debug' or 'Release'."
Write-Host "Usage: .\BuildModZip.ps1 <pvp|coop> <Debug|Release>"
Exit 1
}
if ($Mode -ne 'coop' -and $Mode -ne 'pvp')
{
Write-Error "Invalid mode specified. Use 'coop' or 'pvp'."
Write-Host "Usage: .\BuildModZip.ps1 <coop|pvp> <Debug|Release>"
Exit 1
}
$Mods = @('Sdk')
# Source the helper (expects Get-ModFiles and CopyFiles)
. ./BuildInfo.ps1
# 1. Build solution
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
$solutionPath = Join-Path $scriptDir "$solutionName.sln"
if (-not (Test-Path $solutionPath))
{
Write-Error "Solution file not found at $solutionPath"
exit 1
}
Write-Output "Building solution $solutionPath in configuration $Configuration..."
# UseBuildTimestamp makes Directory.Build.props stamp a time-based version, so every ZIP is newer
# than the last one. The SDK build does not pass it and stays on the static version.
$buildOutput = dotnet build $solutionPath -c $Configuration -v minimal /t:Rebuild -p:UseBuildTimestamp=true | Tee-Object -FilePath 'build.log'
# 2. Extract version number from build output
$pattern = '\s*Build Version:\s*(?<ver>\d+(\.\d+){3})'
$match = $buildOutput | Select-String -Pattern $pattern -AllMatches
if (-not $match)
{
Write-Error "Could not find 'Build Version' in build output."
exit 1
}
$version = $match[0].Matches[0].Groups['ver'].Value
Write-Output "Extracted version: $version"
# 3. Prepare temporary output directory
$outputRoot = Join-Path $scriptDir 'Output'
if (-not (Test-Path $outputRoot))
{
New-Item -ItemType Directory -Path $outputRoot -Force | Out-Null
}
$zipBase = "$zipName-$version"
$destRoot = Join-Path $outputRoot $zipBase
New-Item -ItemType Directory -Path $destRoot -Force | Out-Null
# 4. Build combined file list across variants
$allFiles = @()
foreach ($p in $Mods)
{
$lists = Get-ModFiles -Mod $p -Configuration $Configuration
$allFiles += $lists.Mod
}
# Append non-SDK mod files
if ($Mode -eq 'coop')
{
$allFiles += @(
@(@("manifest.json"), "WukongMP-co-op-mod/Content", "Mods/WukongMp.Coop"),
@(@("WukongMp.Coop.dll"), "WukongMP-co-op-mod/WukongMp.Coop/bin/$Configuration/netstandard2.0", "Mods/WukongMp.Coop"),
@(@("WukongMp.Coop.Common.dll"), "WukongMP-co-op-mod/WukongMp.Coop/bin/$Configuration/netstandard2.0", "Mods/WukongMp.Coop"),
@(@("ArchiveSaveFile.1.sav"), "WukongMP-co-op-mod/Content", "Mods/WukongMp.Coop")
)
} else {
$allFiles += @(
@(@("manifest.json"), "WukongMP-PvP-mod/Content", "Mods/WukongMp.Pvp"),
@(@("WukongMp.PvP.dll"), "WukongMP-PvP-mod/WukongMp.Pvp/bin/$Configuration/netstandard2.0", "Mods/WukongMp.Pvp"),
@(@("ArchiveSaveFile.0.sav"), "WukongMP-PvP-mod/Content", "Mods/WukongMp.Pvp"),
@(@("ArchiveSaveFile.1.sav"), "WukongMP-PvP-mod/Content", "Mods/WukongMp.Pvp"),
@(@("ArchiveSaveFile.2.sav"), "WukongMP-PvP-mod/Content", "Mods/WukongMp.Pvp")
)
}
# Create destination directories
foreach ($item in $allFiles)
{
$destDir = Join-Path $destRoot $item[2]
if (-not (Test-Path $destDir))
{
New-Item -ItemType Directory -Path $destDir -Force | Out-Null
}
}
# 5. Perform copies
foreach ($item in $allFiles)
{
$files = $item[0]
$sourceDir = $item[1]
$destDir = Join-Path $destRoot $item[2]
CopyFiles $files $sourceDir $destDir
}
# 6. Zip files (single 7Z containing all variants)
$zipPath = Join-Path $outputRoot "$zipBase.7z"
if (Test-Path $zipPath)
{
Remove-Item $zipPath -Force
}
7z a -t7z -mx=9 -ms=on -mmt=on $zipPath (Join-Path $destRoot '*')
Write-Output "Created $( Split-Path $zipPath -Leaf )"
# 7. Open explorer to the output directory
if ($PSVersionTable.PSEdition -eq 'Core')
{
Start-Process "explorer.exe" -ArgumentList $outputRoot
}
else
{
Invoke-Item $outputRoot
}