@echo off
setlocal

set "APP_NAME=ATLAS Backup"
set "EXE_NAME=AutoBackupPro.exe"
set "ICO_NAME=AutoBackupPro.ico"
set "SCRIPT_DIR=%~dp0"
set "TARGET=%SCRIPT_DIR%%EXE_NAME%"
set "ICON=%SCRIPT_DIR%%ICO_NAME%"

if not exist "%TARGET%" (
  echo Cannot find %EXE_NAME% in this folder.
  pause
  exit /b 1
)

powershell -NoProfile -ExecutionPolicy Bypass -Command "$ErrorActionPreference='Stop'; $target=$env:TARGET; $work=$env:SCRIPT_DIR; $icon=$env:ICON; if(-not (Test-Path -LiteralPath $icon)){ $icon=$target }; $wsh=New-Object -ComObject WScript.Shell; $desktop=[Environment]::GetFolderPath('Desktop'); $shortcut=$wsh.CreateShortcut((Join-Path $desktop 'ATLAS Backup.lnk')); $shortcut.TargetPath=$target; $shortcut.WorkingDirectory=$work; $shortcut.IconLocation=$icon; $shortcut.Save(); $programs=[Environment]::GetFolderPath('Programs'); $folder=Join-Path $programs 'Toonetic ATLAS'; New-Item -ItemType Directory -Path $folder -Force | Out-Null; $start=$wsh.CreateShortcut((Join-Path $folder 'ATLAS Backup.lnk')); $start.TargetPath=$target; $start.WorkingDirectory=$work; $start.IconLocation=$icon; $start.Save(); $uninstall=$wsh.CreateShortcut((Join-Path $folder 'Uninstall ATLAS Backup.lnk')); $uninstall.TargetPath='powershell.exe'; $uninstall.Arguments='-NoProfile -ExecutionPolicy Bypass -File ""' + (Join-Path $work 'uninstall.ps1') + '""'; $uninstall.WorkingDirectory=$work; $uninstall.IconLocation=$icon; $uninstall.Save();"

if errorlevel 1 (
  echo Shortcut creation failed.
  pause
  exit /b 1
)

echo ATLAS Backup shortcut created on Desktop and Start Menu.
pause
