@echo off
setlocal
set this=%~dp0
set thisn=%~nx0
set name=AddOnStudio

if '%1' == 'run' (goto USER)
if '%1' == '/aselevated' (goto ADMIN)
start %name%updateu cmd %thisn% run
goto :EOF

:USER
%name%update cmd %thisn%
FOR %%X IN ("%this%*%name%.exe") DO @CALL :RESETUSER "%%X"
pause
goto :EOF

:RESETUSER
set file=%~n1
set app=%this%%file%.exe
echo.
echo Cleaning %file% for user
echo.
pushd %this%
echo "%app%" /ResetUserData
"%app%" /AsClean /ResetUserData
echo "%app%" /Setup /ResetSkipPkgs
"%app%" /AsClean
echo.
echo %file% user clean is complete
echo.
popd
goto :EOF

:ADMIN
echo %this%%thisn%
echo.
echo This will remove all configuration for %name%, including all user settings.
echo.
echo Click close to abort.
pause
FOR %%X IN ("%this%*%name%.exe") DO @CALL :RESETADMIN "%%X"
copy /Y /B reset.cmd reset_init.cmd
goto :EOF

:RESETADMIN
set file=%~n1
set app=%this%%file%.exe
echo.
echo Cleaning %file%
echo.
pushd %this%
echo "%app%" /ResetUserData
"%app%" /AsElevated /AsClean /ResetUserData
echo "%app%" /Setup /ResetSkipPkgs
"%app%" /AsElevated /AsClean /Setup /ResetSkipPkgs
echo.
echo %file% clean is complete
echo.
popd
goto :EOF

