PortValhalla/scripts/Windows/Software/LGHub/Install.ps1

55 lines
1.9 KiB
PowerShell
Raw Normal View History

2023-07-12 20:37:31 +00:00
#!/bin/pwsh
2024-08-07 19:05:32 +00:00
. "$PSScriptRoot/../../../Common/Scripts/Context.ps1";
2023-06-07 18:56:40 +00:00
2023-06-08 00:28:33 +00:00
$null = New-Module {
$path = "$env:LOCALAPPDATA/LGHUB";
$softwareName = "LGHub";
2023-06-30 12:10:31 +00:00
[string]$lghubPath;
2023-06-08 00:28:33 +00:00
2023-06-30 12:10:31 +00:00
function Get-LogitechGHUBName() {
2024-03-24 12:47:53 +00:00
return "lghub_system_tray.exe";
2023-06-30 12:10:31 +00:00
}
function Stop-LogitechGHUB() {
[OutputType([string])]
param();
Write-Host "Killing Logitech G HUB process";
2023-06-30 12:10:31 +00:00
$hubName = Get-LogitechGHUBName;
$lghubPath = $(Get-Process | Where-Object { [System.IO.Path]::GetFileName($_.Path) -eq $hubName })[0].Path;
2023-06-08 16:04:03 +00:00
$mainProcesses = Get-Process | Where-Object { @("lghub_agent.exe", $hubName) -contains [System.IO.Path]::GetFileName($_.Path) -and $(
2023-06-09 16:51:20 +00:00
$_.Parent.ProcessName -eq "explorer" -or $null -eq $_.Parent) };
2023-06-08 16:04:03 +00:00
2023-06-30 12:10:31 +00:00
$null = $mainProcesses | Foreach-Object { $_.Kill($true) };
return $lghubPath;
}
function Backup-LogitechGHUB([Context] $context) {
Write-Host "Backing Up Logitech G HUB";
2023-06-30 12:10:31 +00:00
$hubPath = Stop-LogitechGHUB;
Write-Information "Backing up important files";
2023-06-08 00:29:09 +00:00
$context.Backup($path, $context.SoftwareArchive($softwareName), @("-i!settings.db", "-i!icon_cache"));
2023-06-08 00:28:33 +00:00
2023-06-09 16:51:20 +00:00
if ($hubPath) {
Write-Information "Restarting Logitech G HUB";
2023-06-09 16:51:20 +00:00
Start-Process $hubPath;
2023-06-08 00:28:33 +00:00
}
}
2023-06-30 12:10:31 +00:00
function Restore-LogitechGHUB([Context] $context) {
Write-Host "Restoring Logitech G HUB";
Write-Information "Installing the app";
2023-07-20 13:48:49 +00:00
choco install -y --ignore-checksums lghub;
2023-06-30 12:10:31 +00:00
$hubPath = Stop-LogitechGHUB;
Write-Information "Removing existing settings";
Remove-Item "$path/settings.*";
Write-Information "Restoring important files";
2023-06-30 12:10:31 +00:00
$context.Restore($context.SoftwareArchive($softwareName), $path);
2023-07-16 10:46:00 +00:00
Write-Information "Deleting desktop icon";
$context.RemoveDesktopIcon("*G HUB*");
Write-Information "Restarting Logitech G HUB";
2023-06-30 12:10:31 +00:00
Start-Process $hubPath;
}
2023-06-07 18:56:40 +00:00
}