chore: first version

This commit is contained in:
JNIH
2026-07-30 18:39:38 +02:00
commit c953ca8460
54 changed files with 4197 additions and 0 deletions
+14
View File
@@ -0,0 +1,14 @@
@echo off
setlocal
pwsh -NoProfile -ExecutionPolicy Bypass -File "%~dp0Build-OlivePackage.ps1" %*
set "OLIVE_EXIT_CODE=%ERRORLEVEL%"
echo.
if "%OLIVE_EXIT_CODE%"=="0" (
echo Build completed successfully.
) else (
echo Build failed with exit code %OLIVE_EXIT_CODE%.
)
echo Press Enter to close this window.
pause >nul
exit /b %OLIVE_EXIT_CODE%
+114
View File
@@ -0,0 +1,114 @@
param(
[string]$Configuration = "Release",
[string]$Platform = "x64",
[string]$CertificateSubject = "CN=OlivePrivate",
[string]$CertificatePassword = "Embargo-Boned-Flight6",
[switch]$Yes
)
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$scriptRoot = Split-Path -Parent $PSCommandPath
$repoRoot = Split-Path -Parent $scriptRoot
$projectPath = Join-Path $repoRoot "Olive\Olive.csproj"
$manifestPath = Join-Path $repoRoot "Olive\Package.appxmanifest"
$packageRoot = Join-Path $repoRoot "dist\OlivePackage"
$privateRoot = Join-Path $repoRoot "dist\private"
$certPath = Join-Path $packageRoot "OlivePrivate.cer"
$pfxPath = Join-Path $privateRoot "OlivePrivate.pfx"
function Write-Step([string]$Message) {
Write-Host "==> $Message" -ForegroundColor Cyan
}
function Confirm-Continue {
if ($Yes) {
return
}
Write-Host "This script will:" -ForegroundColor Yellow
Write-Host "- create or reuse a CurrentUser code-signing certificate: $CertificateSubject"
Write-Host "- export a private PFX to: $pfxPath"
Write-Host "- export a public CER to: $certPath"
Write-Host "- build and sign the Olive MSIX"
Write-Host "- prepare a shareable folder: $packageRoot"
$answer = Read-Host "Continue? Type YES"
if ($answer -ne "YES") {
throw "Cancelled by user."
}
}
Confirm-Continue
if (-not (Test-Path -LiteralPath $projectPath)) {
throw "Project not found: $projectPath"
}
if (-not (Test-Path -LiteralPath $manifestPath)) {
throw "Manifest not found: $manifestPath"
}
[xml]$manifest = Get-Content -LiteralPath $manifestPath
$packageVersion = $manifest.Package.Identity.Version
New-Item -ItemType Directory -Force -Path $packageRoot | Out-Null
New-Item -ItemType Directory -Force -Path $privateRoot | Out-Null
Write-Step "Creating or reusing signing certificate"
$cert = Get-ChildItem Cert:\CurrentUser\My | Where-Object { $_.Subject -eq $CertificateSubject } | Select-Object -First 1
if ($null -eq $cert) {
$cert = New-SelfSignedCertificate `
-Type Custom `
-Subject $CertificateSubject `
-KeyUsage DigitalSignature `
-FriendlyName "Olive private signing" `
-CertStoreLocation "Cert:\CurrentUser\My" `
-TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.3")
}
Write-Step "Exporting certificate files"
$securePassword = ConvertTo-SecureString $CertificatePassword -AsPlainText -Force
Export-Certificate -Cert $cert -FilePath $certPath -Force | Out-Null
Export-PfxCertificate -Cert $cert -FilePath $pfxPath -Password $securePassword -Force | Out-Null
Write-Step "Publishing signed MSIX"
dotnet publish $projectPath `
-c $Configuration `
-p:Platform=$Platform `
-p:GenerateAppxPackageOnBuild=true `
-p:AppxPackageSigningEnabled=true `
-p:PackageCertificateThumbprint=$($cert.Thumbprint)
if ($LASTEXITCODE -ne 0) {
throw "dotnet publish failed with exit code $LASTEXITCODE."
}
Write-Step "Copying MSIX to dist"
$publishOutput = Join-Path $repoRoot "Olive\bin\$Platform\$Configuration\net10.0-windows10.0.22621.0\win-$Platform"
$expectedMsix = Join-Path $publishOutput "Olive_${packageVersion}_${Platform}.msix"
$msix = if (Test-Path -LiteralPath $expectedMsix) {
Get-Item -LiteralPath $expectedMsix
} else {
Get-ChildItem -Path (Join-Path $repoRoot "Olive\AppPackages") -Filter "Olive_${packageVersion}_${Platform}.msix" -Recurse |
Sort-Object LastWriteTime -Descending |
Select-Object -First 1
}
if ($null -eq $msix) {
throw "No MSIX package was generated for version $packageVersion and platform $Platform."
}
Get-ChildItem -Path $packageRoot -Filter "*.msix" | Remove-Item -Force
Copy-Item -LiteralPath $msix.FullName -Destination (Join-Path $packageRoot $msix.Name) -Force
Copy-Item -LiteralPath (Join-Path $scriptRoot "Install-Olive.ps1") -Destination (Join-Path $packageRoot "Install-Olive.ps1") -Force
Copy-Item -LiteralPath (Join-Path $scriptRoot "Uninstall-Olive.ps1") -Destination (Join-Path $packageRoot "Uninstall-Olive.ps1") -Force
Copy-Item -LiteralPath (Join-Path $scriptRoot "Install-Olive.cmd") -Destination (Join-Path $packageRoot "Install-Olive.cmd") -Force
Copy-Item -LiteralPath (Join-Path $scriptRoot "Uninstall-Olive.cmd") -Destination (Join-Path $packageRoot "Uninstall-Olive.cmd") -Force
Write-Host ""
Write-Host "Package ready:" -ForegroundColor Green
Write-Host $packageRoot
Write-Host ""
Write-Host "Share this folder with your friends: dist\OlivePackage" -ForegroundColor Green
Write-Host "Do not share this private signing file unless you really mean it: $pfxPath" -ForegroundColor Yellow
+22
View File
@@ -0,0 +1,22 @@
@echo off
setlocal
net session >nul 2>&1
if not "%ERRORLEVEL%"=="0" (
echo Olive install requires administrator rights to trust the MSIX signing certificate.
echo Requesting administrator rights...
powershell -NoProfile -ExecutionPolicy Bypass -Command "Start-Process -FilePath '%ComSpec%' -ArgumentList '/k ""%~f0"" %*' -Verb RunAs"
exit /b 0
)
pwsh -NoProfile -ExecutionPolicy Bypass -File "%~dp0Install-Olive.ps1" %*
set "OLIVE_EXIT_CODE=%ERRORLEVEL%"
echo.
if "%OLIVE_EXIT_CODE%"=="0" (
echo Install completed successfully.
) else (
echo Install failed with exit code %OLIVE_EXIT_CODE%.
)
echo Press Enter to close this window.
pause >nul
exit /b %OLIVE_EXIT_CODE%
+83
View File
@@ -0,0 +1,83 @@
param(
[switch]$UseAddAppxPackage,
[switch]$Yes
)
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$scriptRoot = Split-Path -Parent $PSCommandPath
$msix = Get-ChildItem -Path $scriptRoot -Filter "*.msix" | Sort-Object LastWriteTime -Descending | Select-Object -First 1
$cert = Get-ChildItem -Path $scriptRoot -Filter "*.cer" | Sort-Object LastWriteTime -Descending | Select-Object -First 1
function Test-IsAdministrator {
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = [Security.Principal.WindowsPrincipal]::new($identity)
return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
function Confirm-Continue {
if ($Yes) {
return
}
Write-Host "This script will install Olive for the current Windows user." -ForegroundColor Yellow
Write-Host "It will import the public certificate into Cert:\LocalMachine\Root. Administrator rights are required."
Write-Host "It will open the MSIX package found next to this script."
Write-Host "It will not configure your Klipy API key. You do that later in Olive settings."
$answer = Read-Host "Continue? Type YES"
if ($answer -ne "YES") {
throw "Cancelled by user."
}
}
function Wait-ForCertificate {
param(
[string]$Thumbprint,
[int]$TimeoutSeconds = 10
)
$deadline = (Get-Date).AddSeconds($TimeoutSeconds)
do {
$root = Get-ChildItem Cert:\LocalMachine\Root | Where-Object { $_.Thumbprint -eq $Thumbprint } | Select-Object -First 1
if ($null -ne $root) {
return
}
Start-Sleep -Milliseconds 300
} while ((Get-Date) -lt $deadline)
throw "Certificate was imported, but Windows did not report it in Cert:\LocalMachine\Root before timeout."
}
if ($null -eq $msix) {
throw "No .msix file found next to this script."
}
if ($null -eq $cert) {
throw "No .cer certificate found next to this script."
}
if (-not (Test-IsAdministrator)) {
throw "Administrator rights are required to import the Olive signing certificate into Cert:\LocalMachine\Root. Run Install-Olive.cmd, or start PowerShell as administrator."
}
Confirm-Continue
Write-Host "==> Importing certificate into LocalMachine Root" -ForegroundColor Cyan
Import-Certificate -FilePath $cert.FullName -CertStoreLocation Cert:\LocalMachine\Root | Out-Null
$trustedCert = [System.Security.Cryptography.X509Certificates.X509Certificate2]::new($cert.FullName)
Wait-ForCertificate -Thumbprint $trustedCert.Thumbprint
if ($UseAddAppxPackage) {
Write-Host "==> Installing MSIX with Add-AppxPackage" -ForegroundColor Cyan
Add-AppxPackage -Path $msix.FullName
} else {
Write-Host "==> Opening MSIX with Windows App Installer" -ForegroundColor Cyan
Start-Process -FilePath $msix.FullName -Wait
}
Write-Host ""
Write-Host "Olive install flow completed." -ForegroundColor Green
Write-Host "Restart PowerToys, open Command Palette, launch 'Klipy GIF Picker', then set the Klipy API key in Olive settings."
+22
View File
@@ -0,0 +1,22 @@
@echo off
setlocal
net session >nul 2>&1
if not "%ERRORLEVEL%"=="0" (
echo Olive uninstall requires administrator rights to remove the trusted MSIX certificate.
echo Requesting administrator rights...
powershell -NoProfile -ExecutionPolicy Bypass -Command "Start-Process -FilePath '%ComSpec%' -ArgumentList '/k ""%~f0"" %*' -Verb RunAs"
exit /b 0
)
pwsh -NoProfile -ExecutionPolicy Bypass -File "%~dp0Uninstall-Olive.ps1" %*
set "OLIVE_EXIT_CODE=%ERRORLEVEL%"
echo.
if "%OLIVE_EXIT_CODE%"=="0" (
echo Uninstall completed successfully.
) else (
echo Uninstall failed with exit code %OLIVE_EXIT_CODE%.
)
echo Press Enter to close this window.
pause >nul
exit /b %OLIVE_EXIT_CODE%
+110
View File
@@ -0,0 +1,110 @@
param(
[string]$CertificateSubject = "CN=OlivePrivate",
[switch]$RemoveCertificate,
[switch]$KeepCertificate,
[switch]$KeepUserData,
[switch]$Yes
)
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
function Confirm-Continue {
$removeCertificateNow = $RemoveCertificate -or -not $KeepCertificate
$removeUserDataNow = -not $KeepUserData
if ($Yes) {
return
}
Write-Host "This script will uninstall Olive for the current Windows user." -ForegroundColor Yellow
if ($removeCertificateNow) {
Write-Host "It will also remove certificates with subject: $CertificateSubject"
} else {
Write-Host "It will keep the trusted certificate because -KeepCertificate was used."
}
if ($removeUserDataNow) {
Write-Host "It will also remove Olive local settings and cached GIFs."
} else {
Write-Host "It will keep Olive local settings and cached GIFs because -KeepUserData was used."
}
$answer = Read-Host "Continue? Type YES"
if ($answer -ne "YES") {
throw "Cancelled by user."
}
}
function Remove-DirectoryIfExists {
param([string]$Path)
if ([string]::IsNullOrWhiteSpace($Path) -or -not (Test-Path -LiteralPath $Path)) {
return
}
Write-Host "==> Removing directory $Path" -ForegroundColor Cyan
Remove-Item -LiteralPath $Path -Recurse -Force
}
function Test-IsAdministrator {
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = [Security.Principal.WindowsPrincipal]::new($identity)
return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
function Remove-CertificatesBySubject {
param(
[string]$StorePath,
[string]$Subject
)
if (-not (Test-Path -LiteralPath $StorePath)) {
return
}
Get-ChildItem $StorePath | Where-Object { $_.Subject -eq $Subject } | ForEach-Object {
Write-Host "==> Removing certificate $($_.Thumbprint) from $StorePath" -ForegroundColor Cyan
Remove-Item -LiteralPath $_.PSPath -Force
}
}
if (($RemoveCertificate -or -not $KeepCertificate) -and -not (Test-IsAdministrator)) {
throw "Administrator rights are required to remove the Olive signing certificate from Cert:\LocalMachine\Root. Run Uninstall-Olive.cmd, or use -KeepCertificate."
}
Confirm-Continue
$packages = @(Get-AppxPackage -Name Olive)
$packageFamilyNames = @($packages | ForEach-Object { $_.PackageFamilyName } | Sort-Object -Unique)
if ($packages.Count -eq 0) {
Write-Host "Olive is not installed for the current user." -ForegroundColor Yellow
} else {
foreach ($package in $packages) {
Write-Host "==> Removing package $($package.PackageFullName)" -ForegroundColor Cyan
Remove-AppxPackage -Package $package.PackageFullName
}
}
if (-not $KeepUserData) {
$localAppData = [Environment]::GetFolderPath([Environment+SpecialFolder]::LocalApplicationData)
$userDataPaths = @(
(Join-Path $localAppData "Olive"),
(Join-Path $localAppData "Microsoft\PowerToys\CommandPalette\Extensions\Olive"),
(Join-Path $localAppData "Microsoft\PowerToys\CommandPalette\Settings\Olive"),
(Join-Path $localAppData "Microsoft\PowerToys\CommandPalette\Olive")
)
foreach ($packageFamilyName in $packageFamilyNames) {
$userDataPaths += Join-Path $localAppData "Packages\$packageFamilyName"
}
foreach ($path in ($userDataPaths | Sort-Object -Unique)) {
Remove-DirectoryIfExists -Path $path
}
}
if ($RemoveCertificate -or -not $KeepCertificate) {
Remove-CertificatesBySubject -StorePath "Cert:\LocalMachine\Root" -Subject $CertificateSubject
}
Write-Host ""
Write-Host "Olive uninstall completed." -ForegroundColor Green