@echo on

:: save registry
REGEDIT /S /E "%~dp0settings.reg" "HKEY_CURRENT_USER\Software\KC Softwares\SUMo"

:: cleanup registry
REG DELETE "HKEY_CURRENT_USER\Software\KC Softwares\SUMo" /f
REG COPY "HKEY_CURRENT_USER\Software\KC Softwares\SUMo_backup" "HKEY_CURRENT_USER\Software\KC Softwares\SUMo" /s /f
REG DELETE "HKEY_CURRENT_USER\Software\KC Softwares" /v "SUMo" /f
REG DELETE "HKEY_CURRENT_USER\Software\KC Softwares\SUMo_backup" /f

:: save portable settings files
MKDIR "%~dp0SUMo"
XCOPY "%AppData%\KC Softwares\SUMo\*.*" "%~dp0SUMo" /S /E /Y
RMDIR "%AppData%\KC Softwares\SUMo" /S /Q

:: restore local settings files
MOVE "%AppData%\KC Softwares\SUMo_backup" "%AppData%\KC Softwares\SUMo"

:: remove KC Softwares directory if empty
RMDIR "%AppData%\KC Softwares" /Q