$ErrorActionPreference = "Stop"

$appDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$desktop = [Environment]::GetFolderPath("Desktop")
$shortcutPath = Join-Path $desktop "Flux Analyzer.lnk"
$exePath = Join-Path $appDir "FluxAnalyzer.exe"
$vbsPath = Join-Path $appDir "Launch Flux.vbs"
$batPath = Join-Path $appDir "Start-FluxAnalyzer.bat"
$iconPath = Join-Path $appDir "logo.ico"

if (Test-Path $exePath) {
  $target = $exePath
  $arguments = ""
} elseif (Test-Path $vbsPath) {
  $target = "$env:WINDIR\System32\wscript.exe"
  $arguments = "`"$vbsPath`""
} else {
  $target = $batPath
  $arguments = ""
}

$shell = New-Object -ComObject WScript.Shell
$shortcut = $shell.CreateShortcut($shortcutPath)
$shortcut.TargetPath = $target
$shortcut.Arguments = $arguments
$shortcut.WorkingDirectory = $appDir
$shortcut.Description = "Flux Analyzer"
if (Test-Path $iconPath) {
  $shortcut.IconLocation = $iconPath
}
$shortcut.Save()

Write-Host "Desktop shortcut created:"
Write-Host $shortcutPath
