Evan's Blog
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.

上游 GitHub
READ-ONLY MIRROR

README、源码与 Release 已保存到本站;源码视图固定到 commit a37d6c4b。

main/ root
a37d6c4b· 固定源码快照
build-installer.ps15.3 KB
1[CmdletBinding(DefaultParameterSetName = 'Signed')]
2param(
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'
16Set-StrictMode -Version Latest
17
18function 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 = $PSScriptRoot
35$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)
45if (-not $versionMatch.Success) {
46 throw 'The package version could not be read from Cargo.toml.'
47}
48$version = $versionMatch.Groups[1].Value
49$signedBuild = $PSCmdlet.ParameterSetName -eq 'Signed'
50if (-not $signedBuild -and -not $Unsigned) {
51 throw 'Unsigned packaging must be explicitly enabled with -Unsigned.'
52}
53$signTool = $null
54if ($signedBuild) {
55 $kitsRoot = (Get-ItemProperty -LiteralPath `
56 'HKLM:\SOFTWARE\Microsoft\Windows Kits\Installed Roots').KitsRoot10
57 $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 1
63 if (-not $signTool) {
64 throw 'signtool.exe was not found in the Windows SDK.'
65 }
66}
67
68& cargo.exe build --release --bins --locked
69if ($LASTEXITCODE -ne 0) {
70 throw "cargo build failed with exit code $LASTEXITCODE"
71}
72
73$driverArguments = @{}
74if ($signedBuild) {
75 $driverArguments.SigningCertificateThumbprint =
76 $SigningCertificateThumbprint
77}
78& (Join-Path $repository 'build-driver.ps1') @driverArguments
79if ($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 $InnoCompiler
92)
93foreach ($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]::UTF8
101)
102if ($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
110if ($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 $binary
116 if ($LASTEXITCODE -ne 0) {
117 throw "Signing $binary failed with exit code $LASTEXITCODE"
118 }
119 }
120}
121
122New-Item -ItemType Directory -Path $installer -Force | Out-Null
123$packageSuffix = if ($signedBuild) { '' } else { '-unsigned' }
124$package = Join-Path $installer "SBMS-Setup-$version-x64$packageSuffix.exe"
125if (Test-Path -LiteralPath $package) {
126 Remove-Item -LiteralPath $package -Force
127}
128$versionDefinition = "/DAppVersion=$version"
129$compilerArguments = @($versionDefinition)
130if ($signedBuild) {
131 $compilerArguments += (
132 '/Ssbmssign=$q{0}$q sign /sha1 {1} /fd SHA256 $f' -f
133 $signTool, $SigningCertificateThumbprint
134 )
135}
136else {
137 $compilerArguments += '/DUnsignedBuild=1'
138 $compilerArguments += '/DOutputSuffix=-unsigned'
139}
140$compilerArguments += $manifest
141& $InnoCompiler @compilerArguments
142if ($LASTEXITCODE -ne 0) {
143 throw "ISCC failed with exit code $LASTEXITCODE"
144}
145
146if (-not (Test-Path -LiteralPath $package)) {
147 throw "Installer output is missing: $package"
148}
149if ($signedBuild) {
150 foreach ($binary in @(
151 (Join-Path $release 'sbms.exe'),
152 (Join-Path $release 'sbms-tray.exe'),
153 $package
154 )) {
155 & $signTool verify /pa $binary
156 if ($LASTEXITCODE -ne 0) {
157 throw "Signature verification failed for $binary"
158 }
159 }
160}
161$hash = Get-Sha256Hex -LiteralPath $package
162$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)
166Write-Host "installer_package=$package"
167Write-Host "installer_signed=$signedBuild"
168Write-Host "installer_sha256=$hash"
169Write-Host "installer_sha256_file=$hashFile"
170