@echo off
setlocal EnableDelayedExpansion

echo Installing OptimalDocManager...
echo.

echo Creating desktop shortcut to application...
powershell -Command "$WshShell = New-Object -ComObject WScript.Shell; $Shortcut = $WshShell.CreateShortcut([Environment]::GetFolderPath('Desktop') + '\OptimalDocManager.lnk'); $Shortcut.TargetPath = '%~dp0OptimalDocManager\OptimalDocManager.exe'; $Shortcut.WorkingDirectory = '%~dp0OptimalDocManager'; $Shortcut.Save()"

if exist "%~dp0README.md" (
  echo Creating desktop shortcut to README...
  powershell -Command "$WshShell = New-Object -ComObject WScript.Shell; $Shortcut = $WshShell.CreateShortcut([Environment]::GetFolderPath('Desktop') + '\OptimalDocManager README.lnk'); $Shortcut.TargetPath = '%~dp0README.md'; $Shortcut.WorkingDirectory = '%~dp0'; $Shortcut.Save()"
)

echo Creating Start Menu shortcuts...
powershell -Command "$Programs = [Environment]::GetFolderPath('Programs'); $Dir = Join-Path $Programs 'OptimalDocManager'; New-Item -ItemType Directory -Path $Dir -Force | Out-Null; $WshShell = New-Object -ComObject WScript.Shell; $S1 = $WshShell.CreateShortcut((Join-Path $Dir 'OptimalDocManager.lnk')); $S1.TargetPath = '%~dp0OptimalDocManager\OptimalDocManager.exe'; $S1.WorkingDirectory = '%~dp0OptimalDocManager'; $S1.Save()"

if exist "%~dp0README.md" (
  powershell -Command "$Programs = [Environment]::GetFolderPath('Programs'); $Dir = Join-Path $Programs 'OptimalDocManager'; $WshShell = New-Object -ComObject WScript.Shell; $S2 = $WshShell.CreateShortcut((Join-Path $Dir 'README.lnk')); $S2.TargetPath = '%~dp0README.md'; $S2.WorkingDirectory = '%~dp0'; $S2.Save()"
)

echo Installation completed!
echo You can now launch OptimalDocManager from your desktop or from this folder.
pause
