Release v0.5.0: isolate screenshot editor and support manifest-based updates
This commit is contained in:
+9
-3
@@ -2,12 +2,15 @@
|
||||
#include <windows.h>
|
||||
#include "resource.h"
|
||||
IDI_KSWITCHER ICON "kswitcher.ico"
|
||||
#ifdef KS_SCREENSHOT_RESOURCES
|
||||
IDI_SCREENSHOT_QUESTION ICON "icons/question.ico"
|
||||
IDC_SCREENSHOT_PENCIL CURSOR "icons/lucide/pencil.cur"
|
||||
#endif
|
||||
1 RT_MANIFEST "app.manifest"
|
||||
201 RCDATA "update.ps1"
|
||||
1 VERSIONINFO
|
||||
FILEVERSION 0,4,1,0
|
||||
PRODUCTVERSION 0,4,1,0
|
||||
FILEVERSION 0,5,0,0
|
||||
PRODUCTVERSION 0,5,0,0
|
||||
FILEOS VOS_NT_WINDOWS32
|
||||
FILETYPE VFT_APP
|
||||
BEGIN
|
||||
@@ -17,7 +20,7 @@ BEGIN
|
||||
BEGIN
|
||||
VALUE "FileDescription", "KSwitcher — native keyboard and clipboard utility"
|
||||
VALUE "ProductName", "KSwitcher"
|
||||
VALUE "FileVersion", "0.4.1"
|
||||
VALUE "FileVersion", "0.5.0"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
@@ -25,6 +28,7 @@ BEGIN
|
||||
VALUE "Translation", 0x409, 1200
|
||||
END
|
||||
END
|
||||
#ifdef KS_SCREENSHOT_RESOURCES
|
||||
300 ICON "icons/lucide/circle-dot-normal.ico"
|
||||
310 ICON "icons/lucide/circle-dot-active.ico"
|
||||
320 ICON "icons/lucide/circle-dot-disabled.ico"
|
||||
@@ -73,3 +77,5 @@ END
|
||||
405 ICON "icons/lucide/a-large-small-normal.ico"
|
||||
415 ICON "icons/lucide/a-large-small-active.ico"
|
||||
425 ICON "icons/lucide/a-large-small-disabled.ico"
|
||||
|
||||
#endif
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 56 KiB |
@@ -0,0 +1,14 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48">
|
||||
<defs>
|
||||
<linearGradient id="blue" x1="8" y1="4" x2="36" y2="44" gradientUnits="userSpaceOnUse">
|
||||
<stop stop-color="#38bdf8"/>
|
||||
<stop offset=".55" stop-color="#1687e8"/>
|
||||
<stop offset="1" stop-color="#2563eb"/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<circle cx="24" cy="25" r="21" fill="#1e40af" opacity=".12"/>
|
||||
<circle cx="24" cy="23" r="21" fill="url(#blue)"/>
|
||||
<circle cx="24" cy="23" r="20.5" fill="none" stroke="white" stroke-opacity=".25"/>
|
||||
<path d="M18 17.5c0-3.1 2.5-5 6-5s6 2 6 5c0 4.8-6 4.8-6 9" fill="none" stroke="white" stroke-width="3.5" stroke-linecap="round"/>
|
||||
<circle cx="24" cy="33" r="2" fill="white"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 711 B |
@@ -1,3 +1,4 @@
|
||||
#pragma once
|
||||
#define IDI_KSWITCHER 101
|
||||
#define IDI_SCREENSHOT_QUESTION 102
|
||||
#define IDC_SCREENSHOT_PENCIL 500
|
||||
|
||||
+77
-6
@@ -9,8 +9,8 @@ $ErrorActionPreference = 'Stop'
|
||||
Set-StrictMode -Version Latest
|
||||
|
||||
function Get-StableVersion([string]$Tag) {
|
||||
if ($Tag -notmatch '^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$') { return $null }
|
||||
try { return [version]($Tag -replace '^v','') } catch { return $null }
|
||||
if ($Tag -notmatch '^(?:v|release-v)?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$') { return $null }
|
||||
try { return [version]($Tag -replace '^(?:release-)?v','') } catch { return $null }
|
||||
}
|
||||
function Assert-ReleaseUrl([string]$Url) {
|
||||
$uri = [uri]$Url
|
||||
@@ -71,7 +71,7 @@ function Assert-Checksum([string]$Archive,[string]$Checksum) {
|
||||
finally { $sha.Dispose(); $stream.Dispose() }
|
||||
if ($actual -ne $expected) { throw 'Release checksum verification failed.' }
|
||||
}
|
||||
function Expand-Release([string]$Archive,[string]$Destination,[version]$Expected) {
|
||||
function Expand-LegacyRelease([string]$Archive,[string]$Destination,[version]$Expected) {
|
||||
Add-Type -AssemblyName System.IO.Compression.FileSystem
|
||||
$zip = [IO.Compression.ZipFile]::OpenRead($Archive)
|
||||
try {
|
||||
@@ -80,7 +80,7 @@ function Expand-Release([string]$Archive,[string]$Destination,[version]$Expected
|
||||
foreach ($entry in $zip.Entries) {
|
||||
$name = $entry.FullName.Replace('\','/')
|
||||
if ($name.EndsWith('/') -and $name -eq 'dictionaries/') { continue }
|
||||
if ($name -cnotmatch '^(KSwitcher(?:\.Config)?\.exe|LICENSE|json-LICENSE\.txt|README\.md|dictionaries/[a-zA-Z0-9_.-]+)$' -or
|
||||
if ($name -cnotmatch '^(KSwitcher(?:\.(?:Config|Screenshot))?\.exe|LICENSE|json-LICENSE\.txt|README\.md|dictionaries/[a-zA-Z0-9_.-]+)$' -or
|
||||
$name.EndsWith('/.') -or $name.EndsWith('/..') -or $name.EndsWith('.') -or
|
||||
(($entry.ExternalAttributes -shr 16) -band 0xF000) -eq 0xA000 -or !$seen.Add($name)) {
|
||||
throw "Unexpected or unsafe archive entry: $name"
|
||||
@@ -98,7 +98,7 @@ function Expand-Release([string]$Archive,[string]$Destination,[version]$Expected
|
||||
throw 'Incomplete release: KSwitcher.Config.exe'
|
||||
}
|
||||
} finally { $zip.Dispose() }
|
||||
foreach ($binary in @('KSwitcher.exe','KSwitcher.Config.exe')) {
|
||||
foreach ($binary in @('KSwitcher.exe','KSwitcher.Config.exe','KSwitcher.Screenshot.exe')) {
|
||||
$exe = Join-Path $Destination $binary
|
||||
if (!(Test-Path -LiteralPath $exe)) { continue }
|
||||
$version = [Diagnostics.FileVersionInfo]::GetVersionInfo($exe)
|
||||
@@ -112,6 +112,75 @@ function Expand-Release([string]$Archive,[string]$Destination,[version]$Expected
|
||||
[BitConverter]::ToUInt16($bytes,$pe+4) -ne 0x8664) { throw 'Release is not a Windows x64 executable.' }
|
||||
}
|
||||
}
|
||||
function Get-Sha256([IO.Stream]$Stream) {
|
||||
$sha=[Security.Cryptography.SHA256]::Create()
|
||||
try { return [BitConverter]::ToString($sha.ComputeHash($Stream)).Replace('-','').ToLowerInvariant() }
|
||||
finally { $sha.Dispose() }
|
||||
}
|
||||
function Assert-PackagePath([string]$Name) {
|
||||
if (!$Name -or $Name.Length -gt 220 -or $Name -match '[\\:<>"|?*]' -or $Name.StartsWith('/')) { throw "Unsafe package path: $Name" }
|
||||
$parts=$Name.Split('/')
|
||||
foreach ($part in $parts) {
|
||||
if (!$part -or $part -in @('.','..') -or $part -match '[. ]$|[\x00-\x1f]' -or
|
||||
$part -match '^(?i:CON|PRN|AUX|NUL|COM[0-9]|LPT[0-9])(?:\.|$)') { throw "Unsafe package path: $Name" }
|
||||
}
|
||||
if ($parts[0] -ieq 'data' -or $parts[0] -like '.kswitcher-*') { throw "Protected user path: $Name" }
|
||||
}
|
||||
function Expand-Release([string]$Archive,[string]$Destination,[version]$Expected) {
|
||||
Add-Type -AssemblyName System.IO.Compression.FileSystem
|
||||
$zip=[IO.Compression.ZipFile]::OpenRead($Archive)
|
||||
try {
|
||||
$manifests=@($zip.Entries | Where-Object FullName -CEQ 'release-files.json')
|
||||
if (!$manifests.Count) {
|
||||
if ($Expected -gt [version]'0.4.2') { throw 'Release manifest is missing.' }
|
||||
$zip.Dispose(); $zip=$null
|
||||
Expand-LegacyRelease $Archive $Destination $Expected
|
||||
return
|
||||
}
|
||||
if ($manifests.Count -ne 1 -or $manifests[0].Length -gt 256KB) { throw 'Invalid release manifest.' }
|
||||
$reader=[IO.StreamReader]::new($manifests[0].Open())
|
||||
try { $manifest=$reader.ReadToEnd() | ConvertFrom-Json } finally { $reader.Dispose() }
|
||||
if ($manifest.schema -ne 1 -or (Get-StableVersion $manifest.version) -ne $Expected -or
|
||||
@($manifest.files).Count -lt 1 -or @($manifest.files).Count -gt 1000) { throw 'Unsupported or mismatched release manifest.' }
|
||||
$declared=[Collections.Generic.Dictionary[string,object]]::new([StringComparer]::OrdinalIgnoreCase)
|
||||
foreach ($file in $manifest.files) {
|
||||
Assert-PackagePath $file.path
|
||||
if ($file.path -ieq 'release-files.json' -or $declared.ContainsKey($file.path) -or
|
||||
$file.sha256 -notmatch '^[a-fA-F0-9]{64}$' -or $file.size -lt 0 -or $file.size -gt 100MB) { throw 'Invalid manifest file entry.' }
|
||||
$declared.Add($file.path,$file)
|
||||
}
|
||||
if (!$declared.ContainsKey('KSwitcher.exe')) { throw 'Main executable is missing from the manifest.' }
|
||||
$seen=[Collections.Generic.HashSet[string]]::new([StringComparer]::OrdinalIgnoreCase)
|
||||
$total=0L
|
||||
foreach ($entry in $zip.Entries) {
|
||||
$name=$entry.FullName.Replace('\','/')
|
||||
if ($name.EndsWith('/')) { Assert-PackagePath $name.TrimEnd('/'); continue }
|
||||
Assert-PackagePath $name
|
||||
if (!$seen.Add($name) -or (($entry.ExternalAttributes -shr 16) -band 0xF000) -eq 0xA000) { throw 'Duplicate or linked archive entry.' }
|
||||
if ($name -ceq 'release-files.json') { continue }
|
||||
if (!$declared.ContainsKey($name)) { throw "Undeclared package file: $name" }
|
||||
$file=$declared[$name]
|
||||
if ($entry.Length -ne $file.size) { throw "Package file size mismatch: $name" }
|
||||
$total+=$entry.Length
|
||||
if ($total -gt 100MB -or $zip.Entries.Count -gt 1100) { throw 'Release expands beyond allowed limits.' }
|
||||
$stream=$entry.Open()
|
||||
try { $hash=Get-Sha256 $stream } finally { $stream.Dispose() }
|
||||
if ($hash -ne $file.sha256) { throw "Package file checksum mismatch: $name" }
|
||||
}
|
||||
if ($seen.Count -ne $declared.Count+1) { throw 'Archive does not contain every manifest file.' }
|
||||
[IO.Directory]::CreateDirectory($Destination) | Out-Null
|
||||
Assert-PlainDirectory $Destination
|
||||
foreach ($entry in $zip.Entries) {
|
||||
if ($entry.FullName.EndsWith('/')) { continue }
|
||||
$target=Join-Path $Destination $entry.FullName
|
||||
[IO.Directory]::CreateDirectory([IO.Path]::GetDirectoryName($target)) | Out-Null
|
||||
Assert-PlainDirectory ([IO.Path]::GetDirectoryName($target))
|
||||
[IO.Compression.ZipFileExtensions]::ExtractToFile($entry,$target,$false)
|
||||
}
|
||||
$info=[Diagnostics.FileVersionInfo]::GetVersionInfo((Join-Path $Destination 'KSwitcher.exe'))
|
||||
if ($info.ProductName -ne 'KSwitcher' -or (Get-StableVersion $info.FileVersion) -ne $Expected) { throw 'Main executable identity/version mismatch.' }
|
||||
} finally { if ($zip) { $zip.Dispose() } }
|
||||
}
|
||||
function Assert-PlainDirectory([string]$Directory) {
|
||||
$item = Get-Item -LiteralPath $Directory -Force
|
||||
while ($item) {
|
||||
@@ -124,7 +193,7 @@ function Install-Files([string]$Stage,[string]$Target,[string]$Backup,[Collectio
|
||||
foreach ($file in @(Get-ChildItem -LiteralPath $Stage -File -Recurse)) {
|
||||
$relative = $file.FullName.Substring($Stage.Length+1)
|
||||
$destination = Join-Path $Target $relative
|
||||
if ($relative.StartsWith('dictionaries\') -and (Test-Path -LiteralPath $destination)) { continue }
|
||||
if ($relative.StartsWith('dictionaries\',[StringComparison]::OrdinalIgnoreCase) -and (Test-Path -LiteralPath $destination)) { continue }
|
||||
[IO.Directory]::CreateDirectory([IO.Path]::GetDirectoryName($destination)) | Out-Null
|
||||
Assert-PlainDirectory ([IO.Path]::GetDirectoryName($destination))
|
||||
if (Test-Path -LiteralPath $destination) {
|
||||
@@ -177,6 +246,8 @@ try {
|
||||
Receive-File $release.checksum $checksum 64KB
|
||||
Assert-Checksum $archive $checksum
|
||||
Expand-Release $archive $stage (Get-StableVersion $release.version)
|
||||
$screenshotPath = [IO.Path]::GetFullPath((Join-Path $InstallDirectory 'KSwitcher.Screenshot.exe'))
|
||||
if (Get-Process 'KSwitcher.Screenshot' -ErrorAction SilentlyContinue | Where-Object { $_.Path -eq $screenshotPath }) { throw 'Close screenshot editors before installing an update.' }
|
||||
Write-Result @{state='prepared';version=$release.version}
|
||||
$ready.Set() | Out-Null
|
||||
if (!$parentProcess.WaitForExit(120000)) { throw 'KSwitcher did not exit; the installed files were not changed.' }
|
||||
|
||||
Reference in New Issue
Block a user