forked from jcholly/CatchmentTool
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuild-Distribution.ps1
More file actions
173 lines (149 loc) · 5.98 KB
/
Copy pathBuild-Distribution.ps1
File metadata and controls
173 lines (149 loc) · 5.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
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
# Build-Distribution.ps1
# Creates a distribution package for the Catchment Delineation Tool
#
# Usage:
# .\Build-Distribution.ps1 # Build only
# .\Build-Distribution.ps1 -Install # Build and install locally
# .\Build-Distribution.ps1 -Version "1.2.0" # Build with version
param(
[string]$Configuration = "Release",
[string]$Version = "1.0.0",
[switch]$Install, # If set, also installs to ApplicationPlugins folder
[switch]$SkipBuild # Skip C# build (use existing DLL)
)
$ErrorActionPreference = "Stop"
# Paths
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$CSharpDir = Join-Path $ScriptDir "CSharp"
$PythonDir = Join-Path $ScriptDir "Python"
$DistDir = Join-Path $ScriptDir "Distribution"
$BundleDir = Join-Path $DistDir "CatchmentTool.bundle"
$ContentsDir = Join-Path $BundleDir "Contents"
$BinDir = Join-Path $CSharpDir "bin"
$DataDir = Join-Path $ContentsDir "Data"
Write-Host ""
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " Catchment Tool - Build Distribution" -ForegroundColor Cyan
Write-Host " Version: $Version" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
# Step 1: Build the C# project
if (-not $SkipBuild) {
Write-Host "[1/5] Building C# project..." -ForegroundColor Yellow
Push-Location $CSharpDir
try {
dotnet build -c $Configuration
if ($LASTEXITCODE -ne 0) {
throw "Build failed"
}
Write-Host " Build successful" -ForegroundColor Green
}
finally {
Pop-Location
}
} else {
Write-Host "[1/5] Skipping build (using existing DLL)" -ForegroundColor Gray
}
# Step 2: Create distribution folders
Write-Host "[2/5] Creating distribution folders..." -ForegroundColor Yellow
$PythonContentsDir = Join-Path $ContentsDir "Python"
# Clean and recreate Contents folder
if (Test-Path $ContentsDir) {
Remove-Item $ContentsDir -Recurse -Force
}
New-Item -ItemType Directory -Path $ContentsDir -Force | Out-Null
New-Item -ItemType Directory -Path $PythonContentsDir -Force | Out-Null
New-Item -ItemType Directory -Path $DataDir -Force | Out-Null
Write-Host " Folders created" -ForegroundColor Green
# Step 3: Copy files
Write-Host "[3/5] Copying files..." -ForegroundColor Yellow
# Copy DLL
$dllSource = Join-Path $BinDir "CatchmentTool.dll"
if (Test-Path $dllSource) {
Copy-Item $dllSource -Destination $ContentsDir -Force
Write-Host " [OK] CatchmentTool.dll" -ForegroundColor Gray
} else {
Write-Host " [X] CatchmentTool.dll not found at $dllSource" -ForegroundColor Red
exit 1
}
# Copy Newtonsoft.Json if present
$jsonDll = Join-Path $BinDir "Newtonsoft.Json.dll"
if (Test-Path $jsonDll) {
Copy-Item $jsonDll -Destination $ContentsDir -Force
Write-Host " [OK] Newtonsoft.Json.dll" -ForegroundColor Gray
}
# Copy all Python files
$pythonFiles = @(
"catchment_delineation.py",
"dem_utils.py",
"run_delineation.py",
"requirements.txt",
"config_template.json"
)
foreach ($file in $pythonFiles) {
$srcFile = Join-Path $PythonDir $file
if (Test-Path $srcFile) {
Copy-Item $srcFile -Destination $PythonContentsDir -Force
Write-Host " [OK] $file" -ForegroundColor Gray
}
}
# Create .gitkeep in Data folder
"" | Out-File (Join-Path $DataDir ".gitkeep") -Encoding UTF8
Write-Host " Files copied" -ForegroundColor Green
# Step 4: Update PackageContents.xml with version
Write-Host "[4/5] Updating package metadata..." -ForegroundColor Yellow
$packageXmlPath = Join-Path $BundleDir "PackageContents.xml"
if (Test-Path $packageXmlPath) {
$xml = Get-Content $packageXmlPath -Raw
$xml = $xml -replace 'Version="[^"]*"', "Version=`"$Version`""
$xml | Set-Content $packageXmlPath -Encoding UTF8
Write-Host " Updated version to $Version" -ForegroundColor Gray
}
# Step 5: Create ZIP archive
Write-Host "[5/5] Creating ZIP archive..." -ForegroundColor Yellow
$zipName = "CatchmentTool-v$Version.zip"
$zipPath = Join-Path $DistDir $zipName
if (Test-Path $zipPath) {
Remove-Item $zipPath -Force
}
# Include all distribution files
$itemsToZip = @(
(Join-Path $DistDir "README.md"),
(Join-Path $DistDir "Install.bat"),
(Join-Path $DistDir "Uninstall.bat"),
$BundleDir
) | Where-Object { Test-Path $_ }
Compress-Archive -Path $itemsToZip -DestinationPath $zipPath -Force
$zipSize = [math]::Round((Get-Item $zipPath).Length / 1MB, 2)
Write-Host " Created: $zipName ($zipSize MB)" -ForegroundColor Green
# Optional: Install to ApplicationPlugins
if ($Install) {
Write-Host ""
Write-Host "[INSTALL] Installing to ApplicationPlugins..." -ForegroundColor Yellow
$appPlugins = "C:\ProgramData\Autodesk\ApplicationPlugins"
$targetBundle = Join-Path $appPlugins "CatchmentTool.bundle"
if (-not (Test-Path $appPlugins)) {
New-Item -ItemType Directory -Path $appPlugins -Force | Out-Null
}
if (Test-Path $targetBundle) {
Remove-Item $targetBundle -Recurse -Force
}
Copy-Item $BundleDir -Destination $appPlugins -Recurse -Force
Write-Host " Installed to: $targetBundle" -ForegroundColor Green
Write-Host " Restart Civil 3D to load the plugin" -ForegroundColor Cyan
}
Write-Host ""
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " Distribution complete!" -ForegroundColor Green
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "Distribution package:" -ForegroundColor White
Write-Host " $zipPath" -ForegroundColor Yellow
Write-Host ""
Write-Host "To share with others:" -ForegroundColor White
Write-Host " 1. Send them the ZIP file" -ForegroundColor Gray
Write-Host " 2. They extract it anywhere" -ForegroundColor Gray
Write-Host " 3. They right-click Install.bat -> Run as Administrator" -ForegroundColor Gray
Write-Host ""
Write-Host "To install locally:" -ForegroundColor White
Write-Host " .\Build-Distribution.ps1 -Install" -ForegroundColor Gray