Last active
July 5, 2020 02:24
-
-
Save InfinityGhost/c6461a53a3b60f8549fe28c7e517d4f1 to your computer and use it in GitHub Desktop.
OpenTabletDriver Windows Installer (PowerShell)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[string] $repo = "InfinityGhost/OpenTabletDriver" | |
[string] $repoUrl = "https://github.com/$repo" | |
[string] $srcUrl = "$repoUrl.git" | |
[string] $src = "$PWD/src" | |
[string] $build = "$PWD/build" | |
[string] $bin = "$PWD/OpenTabletDriver" | |
[string] $daemonbin = "$bin/OpenTabletDriver.Daemon/OpenTabletDriver.Daemon.exe" | |
[string] $daemonlnk = "$env:APPDATA/Microsoft/Windows/Start Menu/Programs/Startup/OpenTabletDriver.Daemon.lnk" | |
[string] $appbin = "$bin/OpenTabletDriver.UX.Wpf/OpenTabletDriver.UX.Wpf.exe" | |
[string] $applnk = "$PWD/OpenTabletDriver.lnk" | |
[string] $configurations = "$bin/OpenTabletDriver.Daemon/Configurations" | |
function new-shortcut([string] $binFile, [string] $shortcutPath, [String] $appArgs = "") { | |
$WshShell = New-Object -comObject WScript.Shell | |
$Shortcut = $WshShell.CreateShortcut($shortcutPath) | |
$Shortcut.TargetPath = $binFile | |
$Shortcut.Arguments = $appArgs | |
$Shortcut.Save() | |
} | |
function get-sdk() { | |
if (Get-Command dotnet) { | |
Write-Host ".NET Core SDK found, skipping SDK install." | |
} | |
else { | |
Write-Host "Installing .NET Core SDK..." | |
[string] $sdkinstaller = "./sdkinstall.ps1" | |
Invoke-WebRequest 'https://dot.net/v1/dotnet-install.ps1' -UseBasicParsing -OutFile $sdkinstaller | |
& $sdkinstaller -Version 'latest' | |
Remove-Item $sdkinstaller | |
} | |
} | |
function download() { | |
Write-Host "Determining latest release..." | |
$releasesApi = "https://api.github.com/repos/$repo/releases" | |
$tag = (Invoke-WebRequest $releasesApi -UseBasicParsing | ConvertFrom-Json)[0].tag_name | |
Write-Host "Downloading latest release ($tag)..." | |
$filename = "OpenTabletDriver.win-x64" | |
$zip = "$build/$filename.zip" | |
New-Item -ItemType Directory -Force -Path $build | Out-Null | |
Invoke-WebRequest "https://github.com/$repo/releases/download/$tag/$filename.zip" -OutFile $zip -UseBasicParsing | |
Write-Host "Decompressing release..." | |
Expand-Archive $zip -Force -DestinationPath $bin | |
} | |
function build() { | |
get-sdk | |
Write-Host "Cloning $srcUrl into $src" | |
git clone $srcUrl $src | |
Write-Host "Building OpenTabletDriver..." | |
dotnet build --runtime win-x64 --configuration Release --output "$build/daemon" "$src/OpenTabletDriver.Daemon/OpenTabletDriver.Daemon.csproj" | |
dotnet build --runtime win-x64 --configuration Release --output "$build/wpf" "$src/OpenTabletDriver.UX.Wpf/OpenTabletDriver.UX.Wpf.csproj" | |
Write-Host "Moving all build files to binary directory..." | |
New-Item -Path $bin -ItemType Directory | Out-Null | |
Move-Item "$build/daemon" "$bin/OpenTabletDriver.Daemon" | |
Move-Item "$build/wpf" "$bin/OpenTabletDriver.UX.Wpf" | |
Write-Host "Copying configurations from source code directory..." | |
Copy-Item "$src/TabletDriverLib/Configurations" $configurations -Recurse | |
} | |
function clean() { | |
if (Test-Path -Path $src) { | |
Write-Host "Cleaning up source directory..." | |
Remove-Item $src -Recurse -Force | Out-Null | |
} | |
if (Test-Path -Path $build) { | |
Write-Host "Cleaning up build directory..." | |
Remove-Item $build -Recurse -Force | Out-Null | |
} | |
} | |
function install ([bool] $buildfromsource = $false) { | |
if (Test-Path $bin) { | |
Write-Host "OpenTabletDriver is already installed, reinstalling." | |
uninstall | |
} | |
clean | |
if ($buildfromsource) { | |
build | |
} | |
else { | |
download | |
} | |
new-shortcut $daemonbin $daemonlnk "-c ""$configurations""" | |
new-shortcut $appbin $applnk | |
clean | |
} | |
function uninstall { | |
clean | |
if (Test-Path $bin) { | |
Write-Host "Removing all binaries..." | |
Remove-Item $bin -Recurse -Force | |
} | |
if (Test-Path $applnk) { | |
Write-Host "Removing app shortcut..." | |
Remove-Item $applnk -Force | |
} | |
if (Test-Path $daemonlnk) { | |
Write-Host "Removing daemon shortcut..." | |
Remove-Item $daemonlnk -Force | |
} | |
} | |
switch ($args[0]) { | |
"install" { | |
install $false | |
} | |
"install-git" { | |
install $true | |
} | |
"uninstall" { | |
uninstall | |
} | |
"update" { | |
uninstall | |
install $false | |
} | |
"clean" { | |
clean | |
} | |
"build" { | |
build | |
} | |
"download" { | |
download | |
} | |
Default { | |
Write-Host "Valid commands:" | |
Write-Host " -> install" | |
Write-Host " | Installs the latest binary release. This includes the recommended service." | |
Write-Host " -> install-git" | |
Write-Host " | Installs the latest git commit. This includes the recommended service." | |
Write-Host " -> uninstall" | |
Write-Host " | Uninstalls the service (if installed) and deletes binaries." | |
Write-Host " -> update" | |
Write-Host " | Updates to the latest binary release" | |
Write-Host " -> clean" | |
Write-Host " | Cleans up after download or build." | |
Write-Host " -> build" | |
Write-Host " | Compiles the latest git commit into binaries." | |
Write-Host " -> download" | |
Write-Host " | Downloads the latest binary release." | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment