Refactor LGHUB backup

This commit is contained in:
Manuel Thalmann 2023-06-08 18:04:03 +02:00
parent ba5ced058d
commit b1c27a982b

View file

@ -6,14 +6,18 @@ $null = New-Module {
function Invoke-BackupLGHub([Context] $context) { function Invoke-BackupLGHub([Context] $context) {
$hubName = "lghub.exe"; $hubName = "lghub.exe";
$mainProcesses = Get-Process | Where-Object { [System.IO.Path]::GetFileName($_.Path) -eq "$hubName" };
$lghub = $mainProcesses[0].Path; $mainProcess = Get-Process | Where-Object {
$hubProcesses = ($mainProcesses + (Get-Process | Where-Object { @("$hubName", "lghub_", "lghub_system_tray.exe") -contains [System.IO.Path]::GetFileName($_.Path) })); [System.IO.Path]::GetFileName($_.Path) -eq "$hubName" -and
$hubProcesses | Foreach-Object { $_.Kill() }; $_.Parent.ProcessName -eq "explorer"
};
$lghub = $mainProcess.Path;
$mainProcess | Foreach-Object { $_.Kill($true) };
$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 ($lghub) { if ($lghub) {
& "$lghub"; Start-Process $lghub;
} }
} }
} }