Enhance Windows MSI build script with improved error handling and database modes
Some checks failed
farmcontrol/farmcontrol-server/pipeline/head There was a failure building this commit
Some checks failed
farmcontrol/farmcontrol-server/pipeline/head There was a failure building this commit
- Added constants for Windows Installer OpenDatabase modes to clarify database access options. - Improved error handling in the Set-InstallerBinaryStream function to gracefully handle cases where the Binary table is empty. - Refactored the New-WrapperMsiDatabase function to ensure proper path handling and database creation, enhancing the robustness of the MSI generation process.
This commit is contained in:
parent
8783caa93c
commit
a4d8a501d1
@ -15,6 +15,11 @@ param(
|
|||||||
|
|
||||||
$ErrorActionPreference = "Stop"
|
$ErrorActionPreference = "Stop"
|
||||||
|
|
||||||
|
# Windows Installer OpenDatabase modes (winuser.h / MSI API).
|
||||||
|
$msiOpenDatabaseModeReadOnly = 0
|
||||||
|
$msiOpenDatabaseModeTransact = 1
|
||||||
|
$msiOpenDatabaseModeCreate = 3
|
||||||
|
|
||||||
function Get-MsiVersion {
|
function Get-MsiVersion {
|
||||||
param([string]$InputVersion)
|
param([string]$InputVersion)
|
||||||
|
|
||||||
@ -99,7 +104,11 @@ function Set-InstallerBinaryStream {
|
|||||||
)
|
)
|
||||||
|
|
||||||
$deleteSql = "DELETE FROM `Binary` WHERE `Name` = '$Name'"
|
$deleteSql = "DELETE FROM `Binary` WHERE `Name` = '$Name'"
|
||||||
|
try {
|
||||||
Invoke-InstallerExecute -Database $Database -Sql $deleteSql
|
Invoke-InstallerExecute -Database $Database -Sql $deleteSql
|
||||||
|
} catch {
|
||||||
|
# Ignore when the Binary table is empty on first insert.
|
||||||
|
}
|
||||||
|
|
||||||
$insertSql = "INSERT INTO `Binary` (`Name`, `Data`) VALUES (?, ?)"
|
$insertSql = "INSERT INTO `Binary` (`Name`, `Data`) VALUES (?, ?)"
|
||||||
$view = $Database.GetType().InvokeMember(
|
$view = $Database.GetType().InvokeMember(
|
||||||
@ -147,23 +156,19 @@ function New-WrapperMsiDatabase {
|
|||||||
[string]$UpgradeCodeValue
|
[string]$UpgradeCodeValue
|
||||||
)
|
)
|
||||||
|
|
||||||
if (Test-Path $OutputPath) {
|
$outputPath = [System.IO.Path]::GetFullPath($OutputPath)
|
||||||
Remove-Item -LiteralPath $OutputPath -Force
|
$outputDir = Split-Path $outputPath -Parent
|
||||||
}
|
|
||||||
|
|
||||||
$outputDir = Split-Path $OutputPath -Parent
|
|
||||||
if ($outputDir -and -not (Test-Path $outputDir)) {
|
if ($outputDir -and -not (Test-Path $outputDir)) {
|
||||||
New-Item -ItemType Directory -Path $outputDir -Force | Out-Null
|
New-Item -ItemType Directory -Path $outputDir -Force | Out-Null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Test-Path $outputPath) {
|
||||||
|
Remove-Item -LiteralPath $outputPath -Force
|
||||||
|
}
|
||||||
|
|
||||||
$installer = New-Object -ComObject WindowsInstaller.Installer
|
$installer = New-Object -ComObject WindowsInstaller.Installer
|
||||||
$database = $installer.GetType().InvokeMember(
|
# Mode 3 (create) is required for new databases; mode 1 (transact) only opens existing MSIs.
|
||||||
"OpenDatabase",
|
$database = $installer.OpenDatabase($outputPath, $msiOpenDatabaseModeCreate)
|
||||||
"InvokeMethod",
|
|
||||||
$null,
|
|
||||||
$installer,
|
|
||||||
@($OutputPath, 1)
|
|
||||||
)
|
|
||||||
|
|
||||||
Invoke-InstallerExecute -Database $database -Sql @"
|
Invoke-InstallerExecute -Database $database -Sql @"
|
||||||
CREATE TABLE `Property` (
|
CREATE TABLE `Property` (
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user