EvanZhu0721 / 公开仓库
SBMS
SBMS complete the calculation rules for the default logical desktop topology relationship and the physical dimensions of the displays in the Windows multi-screen collaboration system.
文件
.githubassetsdocsdriverexamplesinstallerLICENSESsrctestsui.gitignore79 Bbuild-driver.ps15.3 KBbuild-installer.ps15.3 KBbuild.rs229 BCargo.lock147.3 KBCargo.toml1.6 KBLICENSE34.3 KBNOTICE.md1.2 KBREADME.md5.9 KBREADME.zh-CN.md5.2 KBrust-toolchain.toml124 Bbuild-installer.ps15.3 KB
1
[CmdletBinding(DefaultParameterSetName = 'Signed')]2
param(3
[Parameter(Mandatory = $true, ParameterSetName = 'Signed')]4
[ValidatePattern('^[0-9A-Fa-f]{40}$')]5
[string]$SigningCertificateThumbprint,6
7
[Parameter(Mandatory = $true, ParameterSetName = 'Unsigned')]8
[switch]$Unsigned,9
10
[string]$InnoCompiler = (11
Join-Path $env:LOCALAPPDATA 'Programs\Inno Setup 6\ISCC.exe'12
)13
)14
15
$ErrorActionPreference = 'Stop'16
Set-StrictMode -Version Latest17
18
function Get-Sha256Hex {19
param([Parameter(Mandatory)][string]$LiteralPath)20
21
$algorithm = [Security.Cryptography.SHA256]::Create()22
$stream = [IO.File]::OpenRead($LiteralPath)23
try {24
return [BitConverter]::ToString(25
$algorithm.ComputeHash($stream)26
).Replace('-', '')27
}28
finally {29
$stream.Dispose()30
$algorithm.Dispose()31
}32
}33
34
$repository = $PSScriptRoot35
$release = Join-Path $repository 'target\release'36
$driver = Join-Path $repository 'target\driver'37
$installer = Join-Path $repository 'target\installer'38
$manifest = Join-Path $repository 'installer\SBMS.iss'39
$cargoManifest = Join-Path $repository 'Cargo.toml'40
$cargoText = [IO.File]::ReadAllText($cargoManifest, [Text.Encoding]::UTF8)41
$versionMatch = [regex]::Match(42
$cargoText,43
'(?m)^version\s*=\s*"([^"]+)"'44
)45
if (-not $versionMatch.Success) {46
throw 'The package version could not be read from Cargo.toml.'47
}48
$version = $versionMatch.Groups[1].Value49
$signedBuild = $PSCmdlet.ParameterSetName -eq 'Signed'50
if (-not $signedBuild -and -not $Unsigned) {51
throw 'Unsigned packaging must be explicitly enabled with -Unsigned.'52
}53
$signTool = $null54
if ($signedBuild) {55
$kitsRoot = (Get-ItemProperty -LiteralPath `56
'HKLM:\SOFTWARE\Microsoft\Windows Kits\Installed Roots').KitsRoot1057
$signTool = Get-ChildItem -LiteralPath (Join-Path $kitsRoot 'bin') -Directory |58
Where-Object { [version]::TryParse($_.Name, [ref]([version]$null)) } |59
Sort-Object { [version]$_.Name } -Descending |60
ForEach-Object { Join-Path $_.FullName 'x64\signtool.exe' } |61
Where-Object { Test-Path -LiteralPath $_ } |62
Select-Object -First 163
if (-not $signTool) {64
throw 'signtool.exe was not found in the Windows SDK.'65
}66
}67
68
& cargo.exe build --release --bins --locked69
if ($LASTEXITCODE -ne 0) {70
throw "cargo build failed with exit code $LASTEXITCODE"71
}72
73
$driverArguments = @{}74
if ($signedBuild) {75
$driverArguments.SigningCertificateThumbprint =76
$SigningCertificateThumbprint77
}78
& (Join-Path $repository 'build-driver.ps1') @driverArguments79
if ($LASTEXITCODE -ne 0) {80
throw "build-driver.ps1 failed with exit code $LASTEXITCODE"81
}82
83
$required = @(84
(Join-Path $release 'sbms.exe'),85
(Join-Path $release 'sbms-tray.exe'),86
(Join-Path $driver 'SBMSIndirectDisplay.inf'),87
(Join-Path $driver 'SBMSIndirectDisplay.dll'),88
(Join-Path $driver 'SBMSIndirectDisplay.cat'),89
$manifest,90
(Join-Path $repository 'installer\manage-sunshine-instance.ps1'),91
$InnoCompiler92
)93
foreach ($path in $required) {94
if (-not (Test-Path -LiteralPath $path)) {95
throw "Required installer input is missing: $path"96
}97
}98
$infText = [IO.File]::ReadAllText(99
(Join-Path $driver 'SBMSIndirectDisplay.inf'),100
[Text.Encoding]::UTF8101
)102
if ($infText -notmatch (103
'(?m)^DriverVer=\d{2}/\d{2}/\d{4},' +104
[regex]::Escape("$version.0") +105
'\s*$'106
)) {107
throw "Driver version does not match Cargo package version $version."108
}109
110
if ($signedBuild) {111
foreach ($binary in @(112
(Join-Path $release 'sbms.exe'),113
(Join-Path $release 'sbms-tray.exe')114
)) {115
& $signTool sign /sha1 $SigningCertificateThumbprint /fd SHA256 $binary116
if ($LASTEXITCODE -ne 0) {117
throw "Signing $binary failed with exit code $LASTEXITCODE"118
}119
}120
}121
122
New-Item -ItemType Directory -Path $installer -Force | Out-Null123
$packageSuffix = if ($signedBuild) { '' } else { '-unsigned' }124
$package = Join-Path $installer "SBMS-Setup-$version-x64$packageSuffix.exe"125
if (Test-Path -LiteralPath $package) {126
Remove-Item -LiteralPath $package -Force127
}128
$versionDefinition = "/DAppVersion=$version"129
$compilerArguments = @($versionDefinition)130
if ($signedBuild) {131
$compilerArguments += (132
'/Ssbmssign=$q{0}$q sign /sha1 {1} /fd SHA256 $f' -f133
$signTool, $SigningCertificateThumbprint134
)135
}136
else {137
$compilerArguments += '/DUnsignedBuild=1'138
$compilerArguments += '/DOutputSuffix=-unsigned'139
}140
$compilerArguments += $manifest141
& $InnoCompiler @compilerArguments142
if ($LASTEXITCODE -ne 0) {143
throw "ISCC failed with exit code $LASTEXITCODE"144
}145
146
if (-not (Test-Path -LiteralPath $package)) {147
throw "Installer output is missing: $package"148
}149
if ($signedBuild) {150
foreach ($binary in @(151
(Join-Path $release 'sbms.exe'),152
(Join-Path $release 'sbms-tray.exe'),153
$package154
)) {155
& $signTool verify /pa $binary156
if ($LASTEXITCODE -ne 0) {157
throw "Signature verification failed for $binary"158
}159
}160
}161
$hash = Get-Sha256Hex -LiteralPath $package162
$hashFile = "$package.sha256"163
$hashLine = "$hash $([IO.Path]::GetFileName($package))`n"164
$utf8 = New-Object Text.UTF8Encoding($false)165
[IO.File]::WriteAllText($hashFile, $hashLine, $utf8)166
Write-Host "installer_package=$package"167
Write-Host "installer_signed=$signedBuild"168
Write-Host "installer_sha256=$hash"169
Write-Host "installer_sha256_file=$hashFile"170