Add a script for restoring LGHub

This commit is contained in:
Manuel Thalmann 2023-06-30 14:10:31 +02:00
parent fb3ec54c13
commit 9aa9ad4558

View file

@ -3,19 +3,38 @@
$null = New-Module { $null = New-Module {
$path = "$env:LOCALAPPDATA/LGHUB"; $path = "$env:LOCALAPPDATA/LGHUB";
$softwareName = "LGHub"; $softwareName = "LGHub";
[string]$lghubPath;
function Backup-LogitechGHUB([Context] $context) { function Get-LogitechGHUBName() {
$hubName = "lghub.exe"; return "lghub.exe";
$hubPath = $(Get-Process | Where-Object { [System.IO.Path]::GetFileName($_.Path) -eq $hubName })[0].Path; }
function Stop-LogitechGHUB() {
[OutputType([string])]
param();
$hubName = Get-LogitechGHUBName;
$lghubPath = $(Get-Process | Where-Object { [System.IO.Path]::GetFileName($_.Path) -eq $hubName })[0].Path;
$mainProcesses = Get-Process | Where-Object { @($hubName, "lghub_system_tray.exe") -contains [System.IO.Path]::GetFileName($_.Path) -and $( $mainProcesses = Get-Process | Where-Object { @($hubName, "lghub_system_tray.exe") -contains [System.IO.Path]::GetFileName($_.Path) -and $(
$_.Parent.ProcessName -eq "explorer" -or $null -eq $_.Parent) }; $_.Parent.ProcessName -eq "explorer" -or $null -eq $_.Parent) };
$mainProcesses | Foreach-Object { $_.Kill($true) }; $null = $mainProcesses | Foreach-Object { $_.Kill($true) };
return $lghubPath;
}
function Backup-LogitechGHUB([Context] $context) {
$hubPath = Stop-LogitechGHUB;
$context.Backup($path, $context.SoftwareArchive($softwareName), @("-i!settings.db", "-i!icon_cache")); $context.Backup($path, $context.SoftwareArchive($softwareName), @("-i!settings.db", "-i!icon_cache"));
if ($hubPath) { if ($hubPath) {
Start-Process $hubPath; Start-Process $hubPath;
} }
} }
function Restore-LogitechGHUB([Context] $context) {
choco install -y lghub;
$hubPath = Stop-LogitechGHUB;
$context.Restore($context.SoftwareArchive($softwareName), $path);
Start-Process $hubPath;
}
} }