@echo off

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

:: cleanup registry
REG DELETE "HKEY_CURRENT_USER\Software\FBReader" /f
REG COPY "HKEY_CURRENT_USER\Software\FBReader_backup" "HKEY_CURRENT_USER\Software\FBReader" /s /f
REG DELETE "HKEY_CURRENT_USER\Software\FBReader_backup" /f

MKDIR "%~dp0.FBREADER"
COPY "%HOMEDRIVE%\%HOMEPATH%\.FBREADER\*.*" "%~dp0.FBREADER"

RMDIR /S /Q "%HOMEDRIVE%\%HOMEPATH%\.FBREADER"
MOVE "%HOMEDRIVE%\%HOMEPATH%\.FBREADER_backup" "%HOMEDRIVE%\%HOMEPATH%\.FBREADER"