diff --git a/openless-all/app/scripts/windows-ime-build.ps1 b/openless-all/app/scripts/windows-ime-build.ps1 new file mode 100644 index 00000000..33aa38a5 --- /dev/null +++ b/openless-all/app/scripts/windows-ime-build.ps1 @@ -0,0 +1,55 @@ +param( + [ValidateSet("Debug", "Release")] + [string]$Configuration = "Release" +) + +$ErrorActionPreference = "Stop" + +function Find-MSBuild { + $cmd = Get-Command MSBuild.exe -ErrorAction SilentlyContinue + if ($cmd) { + return $cmd.Source + } + + $vswhere = Join-Path ${env:ProgramFiles(x86)} "Microsoft Visual Studio\Installer\vswhere.exe" + if (Test-Path $vswhere) { + $found = & $vswhere -latest -products * -requires Microsoft.Component.MSBuild -find "MSBuild\Current\Bin\MSBuild.exe" 2>$null | + Select-Object -First 1 + if ($found -and (Test-Path $found)) { + return $found + } + } + + $candidates = @( + "${env:ProgramFiles}\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe", + "${env:ProgramFiles}\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\MSBuild.exe" + ) + foreach ($candidate in $candidates) { + if (Test-Path $candidate) { + return $candidate + } + } + + throw "MSBuild.exe not found. Install Visual Studio Build Tools or run from Developer PowerShell." +} + +$appRoot = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path +$solution = Join-Path $appRoot "windows-ime\OpenLessIme.sln" +$dll = Join-Path $appRoot "windows-ime\x64\$Configuration\OpenLessIme.dll" +$msbuild = Find-MSBuild + +if (-not (Test-Path $solution)) { + throw "Solution not found: $solution" +} + +Write-Host "[build] $Configuration x64" +& $msbuild $solution /p:Configuration=$Configuration /p:Platform=x64 +if ($LASTEXITCODE -ne 0) { + throw "OpenLessIme build failed with exit code $LASTEXITCODE" +} + +if (-not (Test-Path $dll)) { + throw "OpenLessIme.dll was not produced: $dll" +} + +Write-Host "[ok] $dll" diff --git a/openless-all/app/scripts/windows-ime-register.ps1 b/openless-all/app/scripts/windows-ime-register.ps1 new file mode 100644 index 00000000..ce012685 --- /dev/null +++ b/openless-all/app/scripts/windows-ime-register.ps1 @@ -0,0 +1,29 @@ +param( + [ValidateSet("Debug", "Release")] + [string]$Configuration = "Release" +) + +$ErrorActionPreference = "Stop" + +function Get-Regsvr32x64 { + $sysnative = Join-Path $env:WINDIR "Sysnative\regsvr32.exe" + if (Test-Path $sysnative) { + return $sysnative + } + return (Join-Path $env:WINDIR "System32\regsvr32.exe") +} + +$appRoot = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path +$dll = Join-Path $appRoot "windows-ime\x64\$Configuration\OpenLessIme.dll" + +if (-not (Test-Path $dll)) { + & (Join-Path $PSScriptRoot "windows-ime-build.ps1") -Configuration $Configuration +} + +$regsvr32 = Get-Regsvr32x64 +& $regsvr32 /s $dll +if ($LASTEXITCODE -ne 0) { + throw "regsvr32 failed with exit code $LASTEXITCODE" +} + +Write-Host "[ok] OpenLess TSF IME registered" diff --git a/openless-all/app/scripts/windows-ime-unregister.ps1 b/openless-all/app/scripts/windows-ime-unregister.ps1 new file mode 100644 index 00000000..1e2a9532 --- /dev/null +++ b/openless-all/app/scripts/windows-ime-unregister.ps1 @@ -0,0 +1,30 @@ +param( + [ValidateSet("Debug", "Release")] + [string]$Configuration = "Release" +) + +$ErrorActionPreference = "Stop" + +function Get-Regsvr32x64 { + $sysnative = Join-Path $env:WINDIR "Sysnative\regsvr32.exe" + if (Test-Path $sysnative) { + return $sysnative + } + return (Join-Path $env:WINDIR "System32\regsvr32.exe") +} + +$appRoot = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path +$dll = Join-Path $appRoot "windows-ime\x64\$Configuration\OpenLessIme.dll" + +if (-not (Test-Path $dll)) { + Write-Host "[skip] OpenLessIme.dll not found: $dll" + exit 0 +} + +$regsvr32 = Get-Regsvr32x64 +& $regsvr32 /u /s $dll +if ($LASTEXITCODE -ne 0) { + throw "regsvr32 /u failed with exit code $LASTEXITCODE" +} + +Write-Host "[ok] OpenLess TSF IME unregistered" diff --git a/openless-all/app/scripts/windows-preflight.ps1 b/openless-all/app/scripts/windows-preflight.ps1 index edee735e..1176f335 100644 --- a/openless-all/app/scripts/windows-preflight.ps1 +++ b/openless-all/app/scripts/windows-preflight.ps1 @@ -1,5 +1,5 @@ param( - [ValidateSet("all", "msvc", "gnu")] + [ValidateSet("all", "msvc", "gnu", "ime")] [string]$Toolchain = "all" ) @@ -17,6 +17,34 @@ function Test-Command($Name) { return $false } +function Find-MSBuild { + $cmd = Get-Command MSBuild.exe -ErrorAction SilentlyContinue + if ($cmd) { + return $cmd.Source + } + + $vswhere = Join-Path ${env:ProgramFiles(x86)} "Microsoft Visual Studio\Installer\vswhere.exe" + if (Test-Path $vswhere) { + $found = & $vswhere -latest -products * -requires Microsoft.Component.MSBuild -find "MSBuild\Current\Bin\MSBuild.exe" 2>$null | + Select-Object -First 1 + if ($found -and (Test-Path $found)) { + return $found + } + } + + $candidates = @( + "${env:ProgramFiles}\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe", + "${env:ProgramFiles}\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\MSBuild.exe" + ) + foreach ($candidate in $candidates) { + if (Test-Path $candidate) { + return $candidate + } + } + + return $null +} + function Find-Kernel32Lib { $kitsRoot = Join-Path ${env:ProgramFiles(x86)} "Windows Kits\10\Lib" if (-not (Test-Path $kitsRoot)) { @@ -100,6 +128,28 @@ if ($Toolchain -eq "all" -or $Toolchain -eq "gnu") { } } +if ($Toolchain -eq "all" -or $Toolchain -eq "ime") { + Write-Host "" + Write-Host "== Windows IME route ==" + $msbuild = Find-MSBuild + if ($msbuild) { + Write-Host "[ok] MSBuild.exe -> $msbuild" + } else { + Write-Host "[missing] MSBuild.exe" + Write-Host "[hint] Install Visual Studio Build Tools workload 'Desktop development with C++'." + $failed = $true + } + + $kernel32 = Find-Kernel32Lib + if ($kernel32) { + Write-Host "[ok] kernel32.lib -> $kernel32" + } else { + Write-Host "[missing] kernel32.lib" + Write-Host "[hint] Install a Windows 10/11 SDK with x64 libraries." + $failed = $true + } +} + if ($failed) { exit 1 }