@echo off
rem SOPWOW Recorder - setup for Windows (Chrome and Edge)
rem
rem Double-clickable on purpose: a .ps1 opens in Notepad on a default Windows 11
rem and "Run with PowerShell" is buried under "Show more options". This uses
rem curl and tar, both built into Windows 10 and 11, so there is no execution
rem policy to argue with.
setlocal
title SOPWOW Recorder - setup

set "ZIP=https://dl.sopwow.com/SOPWOW-Recorder.zip"
set "PARENT=%LOCALAPPDATA%\SOPWOW"
set "FOLDER=%PARENT%\SOPWOW-Recorder"
set "TMPZIP=%TEMP%\SOPWOW-Recorder.zip"

echo.
echo   SOPWOW Recorder - setup
echo   ----------------------------------------------
echo.
echo   Downloading the recorder...

curl -fsSL "%ZIP%" -o "%TMPZIP%"
if errorlevel 1 goto nodownload

if exist "%FOLDER%" rmdir /s /q "%FOLDER%"
if not exist "%PARENT%" mkdir "%PARENT%"
tar -xf "%TMPZIP%" -C "%PARENT%"
del "%TMPZIP%" >nul 2>&1

if not exist "%FOLDER%\manifest.json" goto noextract

<nul set /p "=%FOLDER%" | clip

echo   [ok] Installed to %FOLDER%
echo        Leave it there - your browser loads it from that folder every time it starts.
echo        Windows hides AppData, so you will not see it in File Explorer. You do not need to.
echo.
echo   ----------------------------------------------
echo   Three steps left, in your browser:
echo.
echo     1. Go to  edge://extensions   or  chrome://extensions
echo     2. Turn on Developer mode, then click Load unpacked
echo     3. Press Ctrl+V to paste the folder, then Enter
echo.
echo   The folder is already on your clipboard.
echo   Then click the SOPWOW icon, choose Options, and paste your token.
echo   ----------------------------------------------
echo.
pause
exit /b 0

:nodownload
echo.
echo   [x] Could not download it. Check your connection and try again.
echo       Or install by hand: https://sopwow.com/install
echo.
pause
exit /b 1

:noextract
echo.
echo   [x] Could not unpack the recorder into %FOLDER%
echo       If it is already loaded, close your browser and run this again.
echo.
pause
exit /b 1
