SparkControl_API/CreateZipFile.ps1
2025-03-27 16:01:28 +08:00

64 lines
2.1 KiB
PowerShell

try
{
# see https://stackoverflow.com/questions/9948517/how-to-stop-a-powershell-script-on-the-first-error
$ErrorActionPreference = "Stop"
Add-Type -A System.IO.Compression.FileSystem
# Write-Host ('OS Tmp Dir: ' + $env:TEMP )
# create tmo dir
$tmpDir = $env:TEMP + [guid]::NewGuid()
Write-Host ('Use tmp-dir: ' + $tmpDir)
New-Item -ItemType Directory -Force -Path $tmpDir
# copy Sample App source code files to tmp dir
Copy-Item $($PSScriptRoot + "\*.cs") -Destination $tmpDir
Copy-Item $($PSScriptRoot + "\*.config") -Destination $tmpDir
Copy-Item $($PSScriptRoot + "\*.csproj") -Destination $tmpDir
Copy-Item $($PSScriptRoot + "\*.sln") -Destination $tmpDir
Copy-Item $($PSScriptRoot + "\*.txt") -Destination $tmpDir
Copy-Item $($PSScriptRoot + "\Properties") -Destination $tmpDir -Recurse
# copy Automation Interface docu to tmp dir
# -> PDF is currently not included into ZIP file
# $aiDocuFileName = Resolve-Path -Path $($PSScriptRoot + "\..\..\Production\Automation\AutomationInterface\Doc\AutomationInterfaceManual.pdf")
# Write-Host ('aiDocuFileName : ' + $aiDocuFileName )
# Copy-Item $aiDocuFileName -Destination $tmpDir
# create zip file
$zipFileName = $PSScriptRoot + "\SampleApp.zip"
Write-Host ('zipFileName: ' + $zipFileName )
if (Test-Path $zipFileName)
{
Write-Host("Delete already available .zip file...")
Remove-Item -Recurse -Force $zipFileName
}
# ...and create it
[IO.Compression.ZipFile]::CreateFromDirectory($tmpDir, $zipFileName)
# delete temp directory
Write-Host ('Del tmp folder : ' + $tmpDir )
Remove-Item -Recurse -Force $tmpDir
Write-Host('')
Write-Host('')
Write-Host('##############################################################################')
Write-Host('Successfully created Sample Application .zip file: ' + $zipFileName)
Write-Host('##############################################################################')
exit $LASTEXITCODE
}
catch
{
Write-Error('ERROR: ' + $_.Exception)
exit $LASTEXITCODE
}