@echo off
setlocal enableextensions
title JG Music Tools — Install
cd /d "%~dp0"

echo.
echo ============================================
echo   JG Music Tools v1.76R - Installer
echo ============================================
echo.
echo This will install JG Music Tools to:
echo   %LOCALAPPDATA%\JG Music Tools\
echo.
echo And create:
echo   - Start Menu shortcut
echo   - Desktop shortcut
echo   - Uninstall entry in Add/Remove Programs
echo.
echo Press any key to install, or close this window to cancel.
pause >nul

set "DEST=%LOCALAPPDATA%\JG Music Tools"
echo Copying files to %DEST% ...
if exist "%DEST%" (
  echo Removing existing install...
  rmdir /s /q "%DEST%"
)
mkdir "%DEST%"
xcopy /e /i /h /q "%~dp0*" "%DEST%\" >nul

echo Creating Start Menu shortcut...
powershell -nologo -noprofile -command ^
  "$s=(New-Object -COM WScript.Shell).CreateShortcut('%APPDATA%\Microsoft\Windows\Start Menu\Programs\JG Music Tools.lnk');$s.TargetPath='%DEST%\JG Music Tools.exe';$s.WorkingDirectory='%DEST%';$s.IconLocation='%DEST%\JG Music Tools.exe,0';$s.Save()"

echo Creating Desktop shortcut...
powershell -nologo -noprofile -command ^
  "$s=(New-Object -COM WScript.Shell).CreateShortcut([Environment]::GetFolderPath('Desktop')+'\JG Music Tools.lnk');$s.TargetPath='%DEST%\JG Music Tools.exe';$s.WorkingDirectory='%DEST%';$s.IconLocation='%DEST%\JG Music Tools.exe,0';$s.Save()"

echo Registering uninstaller in Add/Remove Programs...
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall\JGMusicTools" /f /v DisplayName /d "JG Music Tools" >nul
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall\JGMusicTools" /f /v DisplayVersion /d "1.76R" >nul
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall\JGMusicTools" /f /v Publisher /d "Jeremy Gaisin" >nul
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall\JGMusicTools" /f /v InstallLocation /d "%DEST%" >nul
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall\JGMusicTools" /f /v UninstallString /d "\"%DEST%\Uninstall JG Music Tools.bat\"" >nul
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall\JGMusicTools" /f /v DisplayIcon /d "%DEST%\JG Music Tools.exe" >nul
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall\JGMusicTools" /f /v NoModify /t REG_DWORD /d 1 >nul
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall\JGMusicTools" /f /v NoRepair /t REG_DWORD /d 1 >nul

echo.
echo ============================================
echo   Install complete!
echo ============================================
echo.
echo Launch from Start Menu, Desktop, or %DEST%\JG Music Tools.exe
echo.
echo To uninstall later, use Add/Remove Programs (it's listed as "JG Music Tools").
echo.
echo Launching now...
start "" "%DEST%\JG Music Tools.exe"
timeout /t 3 >nul
exit /b 0
