setlocal ENABLEDELAYEDEXPANSION

set PROGRAMID=Stagsi
set PROGRAMDATE=2024-02-13

if "%1" == "/1" goto :1
if "%1" == "/2" goto :2

rem When doing an 1) attended 2) update...
if "%SUP_HIDDEN%" == "" ^
if "%FRESH%" == "" (
  Sup /pipe - "%~dpf0" /1
  if !errorlevel! equ -8462 (
    rem Note: Windows services normally don't have access to the desktop
    rem and can't show messages but Supper's mbox has MB_SERVICE_NOTIFICATION
    rem so no need to check for SUP_USER==S and /service:launch it.
    "%~dp0Supper" mbox OC! "%PROGRAMTITLE%" $2
    if errorlevel 1 (
      rem User has decided to stay on the old (current) version.
      rem If this is a regular automatic update then skip over this update
      rem to avoid nagging him about the license until next release.
      if not "%SUP_URL%" == "" Sup /pipe - "%~dpf0" /2 "%SUP_URL%"
      exit /b 1
    )
  )
)

exit /b 0

:1
rem License is first searched in the per-user location, then program-wise.
set FILE=%APPDATA%\Soletude\Stagsi\Stagsi.lic
if not exist "%FILE%" set FILE=.\Stagsi.lic
if exist "%FILE%" (
  "%~dp0Supper" licdate "%FILE%" %PROGRAMDATE%
  if !errorlevel! equ -1 exit /b -8462
)
exit /b -8269

:2
reg add HKCU\Software\Soletude\Sup\%PROGRAMID% ^
  /v SkipArchiveURL /t REG_MULTI_SZ /d "%2" /f /reg:32
exit /b
