Implement autostart functionality, ZIP packaging, and related installation scripts; update documentation and tests
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
param([string]$InstallDirectory = (Join-Path $env:LOCALAPPDATA 'Programs\MusicBridge'), [switch]$NoShortcut)
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$target = [IO.Path]::GetFullPath($InstallDirectory).TrimEnd('\')
|
||||
$source = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot 'app'))
|
||||
if (!(Test-Path -LiteralPath (Join-Path $source 'MusicBridge.Agent.exe'))) { throw 'Package is incomplete: app\MusicBridge.Agent.exe is missing.' }
|
||||
if ($target -eq $source -or $target.StartsWith($source + '\', [StringComparison]::OrdinalIgnoreCase)) { throw 'Choose an install directory outside the package app directory.' }
|
||||
$parent = Split-Path $target -Parent
|
||||
if (!$parent -or $target -eq [IO.Path]::GetPathRoot($target)) { throw 'Unsafe install directory.' }
|
||||
New-Item -ItemType Directory -Path $target -Force | Out-Null
|
||||
$marker = Join-Path $target '.musicbridge-install'
|
||||
if ((Get-ChildItem -LiteralPath $target -Force | Measure-Object).Count -gt 0 -and !(Test-Path -LiteralPath $marker)) { throw 'Directory is not a MusicBridge installation. Choose an empty directory.' }
|
||||
$exe = Join-Path $target 'MusicBridge.Agent.exe'
|
||||
if (Test-Path -LiteralPath $exe) {
|
||||
try { $probe = [IO.File]::Open($exe, 'Open', 'ReadWrite', 'None'); $probe.Dispose() }
|
||||
catch { throw 'Close MusicBridge from its tray menu before updating.' }
|
||||
}
|
||||
# Copy without deleting unrelated files. Existing user identity lives outside this directory.
|
||||
Copy-Item -Path (Join-Path $source '*') -Destination $target -Recurse -Force
|
||||
Copy-Item -LiteralPath (Join-Path $PSScriptRoot 'Uninstall.ps1') -Destination $target -Force
|
||||
Copy-Item -LiteralPath (Join-Path $PSScriptRoot 'Firewall.ps1') -Destination $target -Force
|
||||
Set-Content -LiteralPath $marker -Value 'MusicBridge per-user installation v1' -Encoding UTF8
|
||||
if (!$NoShortcut) {
|
||||
$shell = New-Object -ComObject WScript.Shell
|
||||
$shortcut = $shell.CreateShortcut((Join-Path ([Environment]::GetFolderPath('Programs')) 'MusicBridge.lnk'))
|
||||
$shortcut.TargetPath = $exe
|
||||
$shortcut.Arguments = '--tray --lan'
|
||||
$shortcut.WorkingDirectory = $target
|
||||
$shortcut.Save()
|
||||
}
|
||||
Write-Host "Installed: $exe"
|
||||
Write-Host 'Open MusicBridge from Start. Autostart can be enabled from the tray menu.'
|
||||
Reference in New Issue
Block a user