-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathZip-FarmDashboardMod.ps1
More file actions
168 lines (142 loc) · 6.99 KB
/
Copy pathZip-FarmDashboardMod.ps1
File metadata and controls
168 lines (142 loc) · 6.99 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
<#
.SYNOPSIS
Builds FS25_FarmDashboard.zip containing only modDesc.xml, icon_FarmDashboard.dds (if present), and the src\ tree - nothing else.
.DESCRIPTION
Reads from FS25_FarmDashboard_Mod\ only:
modDesc.xml, icon_FarmDashboard.dds (optional), src\
Zip layout is **flat at archive root** (Giants resolves `sourceFile` paths like `src/FarmDashboard.lua` from there):
modDesc.xml, icon_FarmDashboard.dds, src/..., l10n/...
Run tools\Convert-ModIconToDds.mjs after editing icon.png (composites onto tools\modIcon_BG512.png; 512×512 DXT1, icon_modName.dds).
Do not add other repo files (e.g. stray zips, README) - only modDesc, icon, src, l10n.
IMPORTANT: Do not use Compress-Archive for FS mods. On Windows it writes zip entry names with
backslashes (src\collectors\Foo.lua). The GIANTS engine resolves extraSourceFiles using forward
slashes (src/collectors/Foo.lua), so "Can't load resource" appears and the mod never runs.
This script uses ZipArchive + CreateEntryFromFile with '/' entry names (POSIX paths inside the zip).
-VersionOverride stamps modDesc.xml + FarmDashboard.VERSION in a **staging copy** only.
Working-tree RF edition (e.g. 5.0.0.1) is left unchanged. Use for classic public zips
(e.g. 3.4.0.7) without switching the local RF deploy line.
.EXAMPLE
Set-Location "...\MAIN CODEBASE\FarmHub"
.\tools\Zip-FarmDashboardMod.ps1
.EXAMPLE
.\tools\Zip-FarmDashboardMod.ps1 -VersionOverride 3.4.0.7
.EXAMPLE
.\tools\Zip-FarmDashboardMod.ps1 -CopyTo "C:\Users\Graham\Documents\FS25_FarmDashboard.zip"
#>
[CmdletBinding()]
param(
[string] $RepoRoot = "",
[string] $OutZipName = "FS25_FarmDashboard.zip",
[string] $CopyTo = "",
# Stamp this version into the zip only (does not edit the working tree).
[string] $VersionOverride = ""
)
$ErrorActionPreference = "Stop"
if (-not $RepoRoot) {
$RepoRoot = Split-Path -Parent $PSScriptRoot
}
$ModSource = Join-Path $RepoRoot "FS25_FarmDashboard_Mod"
$DestZip = Join-Path $RepoRoot "FS25_FarmDashboard_Mod\$OutZipName"
$SrcTree = Join-Path $ModSource "src"
$ModDesc = Join-Path $ModSource "modDesc.xml"
$IconDds = Join-Path $ModSource "icon_FarmDashboard.dds"
if (-not (Test-Path -LiteralPath $ModSource -PathType Container)) {
throw "Mod folder not found: $ModSource"
}
if (-not (Test-Path -LiteralPath $ModDesc)) {
throw "Missing modDesc.xml: $ModDesc"
}
if (-not (Test-Path -LiteralPath $SrcTree -PathType Container)) {
throw "Missing src folder: $SrcTree"
}
$PackRoot = $ModSource
$Staging = $null
if ($VersionOverride) {
if ($VersionOverride -notmatch '^\d+(\.\d+){1,3}$') {
throw "VersionOverride must look like 3.4.0.7 (got: $VersionOverride)"
}
$Staging = Join-Path $env:TEMP ("FarmDashModPack_" + [guid]::NewGuid().ToString("N"))
New-Item -ItemType Directory -Path $Staging -Force | Out-Null
Copy-Item -LiteralPath $ModDesc -Destination (Join-Path $Staging "modDesc.xml") -Force
if (Test-Path -LiteralPath $IconDds) {
Copy-Item -LiteralPath $IconDds -Destination (Join-Path $Staging "icon_FarmDashboard.dds") -Force
}
Copy-Item -LiteralPath $SrcTree -Destination (Join-Path $Staging "src") -Recurse -Force
$l10nSrc = Join-Path $ModSource "l10n"
if (Test-Path -LiteralPath $l10nSrc -PathType Container) {
Copy-Item -LiteralPath $l10nSrc -Destination (Join-Path $Staging "l10n") -Recurse -Force
}
$stagedDesc = Join-Path $Staging "modDesc.xml"
$descText = [System.IO.File]::ReadAllText($stagedDesc)
$descText = [regex]::Replace($descText, '(?s)(<!--\s*FS25 FarmDashboard\s*\|\s*modDesc\.xml\s*\|\s*)v[\d.]+', "`${1}v$VersionOverride")
$descText = [regex]::Replace($descText, '(<version>)[^<]+(</version>)', "`${1}$VersionOverride`${2}")
[System.IO.File]::WriteAllText($stagedDesc, $descText)
$stagedLua = Join-Path $Staging "src\FarmDashboard.lua"
if (-not (Test-Path -LiteralPath $stagedLua)) {
throw "Missing FarmDashboard.lua in staging: $stagedLua"
}
$luaText = [System.IO.File]::ReadAllText($stagedLua)
$luaText = [regex]::Replace($luaText, '(FarmDashboard\.VERSION\s*=\s*")[^"]+(")', "`${1}$VersionOverride`${2}")
[System.IO.File]::WriteAllText($stagedLua, $luaText)
$PackRoot = $Staging
Write-Host "VersionOverride $VersionOverride applied in staging (working tree unchanged)"
}
if (Test-Path -LiteralPath $DestZip) {
Remove-Item -LiteralPath $DestZip -Force
}
Add-Type -AssemblyName System.IO.Compression
Add-Type -AssemblyName System.IO.Compression.FileSystem
$rootNorm = $PackRoot.TrimEnd('\', '/')
$packDesc = Join-Path $PackRoot "modDesc.xml"
$packIcon = Join-Path $PackRoot "icon_FarmDashboard.dds"
$packSrc = Join-Path $PackRoot "src"
$zip = [System.IO.Compression.ZipFile]::Open($DestZip, [System.IO.Compression.ZipArchiveMode]::Create)
try {
[System.IO.Compression.ZipFileExtensions]::CreateEntryFromFile($zip, $packDesc, "modDesc.xml") | Out-Null
if (Test-Path -LiteralPath $packIcon) {
[System.IO.Compression.ZipFileExtensions]::CreateEntryFromFile($zip, $packIcon, "icon_FarmDashboard.dds") | Out-Null
} else {
Write-Warning "icon_FarmDashboard.dds not in mod folder - zip will omit it. Run tools\Convert-ModIconToDds.mjs (needs icon.png source in mod folder)."
}
Get-ChildItem -LiteralPath $packSrc -Recurse -File | ForEach-Object {
$full = $_.FullName
if (-not $full.StartsWith($rootNorm, [StringComparison]::OrdinalIgnoreCase)) {
throw "Unexpected path under src: $full"
}
$rel = $full.Substring($rootNorm.Length).TrimStart('\', '/').Replace('\', '/')
[System.IO.Compression.ZipFileExtensions]::CreateEntryFromFile($zip, $full, $rel) | Out-Null
}
foreach ($extraDir in @("l10n")) {
$extraPath = Join-Path $PackRoot $extraDir
if (-not (Test-Path -LiteralPath $extraPath -PathType Container)) { continue }
Get-ChildItem -LiteralPath $extraPath -Recurse -File | ForEach-Object {
$full = $_.FullName
$rel = $full.Substring($rootNorm.Length).TrimStart('\', '/').Replace('\', '/')
[System.IO.Compression.ZipFileExtensions]::CreateEntryFromFile($zip, $full, $rel) | Out-Null
}
}
} finally {
$zip.Dispose()
if ($Staging -and (Test-Path -LiteralPath $Staging)) {
Remove-Item -LiteralPath $Staging -Recurse -Force -ErrorAction SilentlyContinue
}
}
if (-not (Test-Path -LiteralPath $DestZip)) {
throw "Zip was not created: $DestZip"
}
Write-Host "Wrote: $DestZip (modDesc.xml, icon, src/, l10n/ - POSIX paths inside zip)"
if (-not $CopyTo) {
if ($env:FARMDASH_BUILD_OUTPUT) {
$CopyTo = Join-Path $env:FARMDASH_BUILD_OUTPUT $OutZipName
} else {
$CopyTo = Join-Path $env:USERPROFILE "Documents\FarmDash Final Output\$OutZipName"
}
}
if ($CopyTo) {
$destParent = Split-Path -Parent $CopyTo
if ($destParent -and -not (Test-Path -LiteralPath $destParent)) {
New-Item -ItemType Directory -Path $destParent -Force | Out-Null
}
Copy-Item -LiteralPath $DestZip -Destination $CopyTo -Force
Write-Host "Copied to: $CopyTo"
}