tasklist | find "Launcher.exe"
if %errorlevel% equ 0 (
	taskkill /F /IM Launcher.exe
	timeout 2
)

rmdir "%LocalAppData%\4Game" /S /Q
rmdir "%LocalAppData%\4Game_LLC" /S /Q
rmdir "%ProgramData%\4Game" /S /Q
rmdir "%ProgramData%\Innova" /S /Q
rmdir "%ProgramFiles(x86)%\4Game" /S /Q

mklink /J "%LocalAppData%\4Game" "%~dp0ICafeCloud\LocalAppData\4Game"
mklink /J "%LocalAppData%\4Game_LLC" "%~dp0ICafeCloud\LocalAppData\4Game_LLC"
mklink /J "%ProgramData%\4Game" "%~dp0ICafeCloud\ProgramData\4Game"
mklink /J "%ProgramData%\Innova" "%~dp0ICafeCloud\ProgramData\Innova"
mklink /J "%ProgramFiles(x86)%\4Game" "%~dp0ICafeCloud\ProgramFiles-x86\4Game"

rem clear the cached 4Game login without dropping the folders themselves
2>nul rmdir "%~dp0ICafeCloud\LocalAppData\4Game\4game_cis\CEF\global\Local Storage\leveldb" /S /Q
2>nul del /f /q "%~dp0ICafeCloud\ProgramData\4Game\4game_cis\accounts-live.db"

Reg.exe add "HKLM\SOFTWARE\WOW6432Node\4Game LLC\4game_cis" /f /v "OldGamesTaken" /t REG_DWORD /d 0
Reg.exe add "HKLM\SOFTWARE\WOW6432Node\4Game LLC\4game_cis" /f /v "Path" /t REG_SZ /d "%~dp0ICafeCloud\ProgramFiles-x86\4Game\4game_cis"
Reg.exe add "HKLM\SOFTWARE\WOW6432Node\4Game LLC\4game_cis" /f /v "LauncherRegion" /t REG_SZ /d "ru"
Reg.exe add "HKLM\SOFTWARE\WOW6432Node\4Game LLC\4game_cis" /f /v "CodeSignRegion" /t REG_SZ /d "cis"
Reg.exe add "HKLM\SOFTWARE\WOW6432Node\4Game LLC\4game_cis" /f /v "PassedRegionalSplitting" /t REG_DWORD /d 1
Reg.exe add "HKLM\SOFTWARE\WOW6432Node\4Game LLC\4game_cis" /f /v "NeedOldLauncherDataTransfer" /t REG_DWORD /d 0
Reg.exe add "HKLM\SOFTWARE\WOW6432Node\4Game LLC\4game_cis" /f /v "IsInstalledAfterPublisherSplit" /t REG_DWORD /d 1
Reg.exe add "HKLM\SOFTWARE\WOW6432Node\4Game LLC\4game_cis" /f /v "RepairedGameRepositories" /t REG_SZ /d "live;"

Reg.exe add "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\4game_cis" /f /v "DisplayName" /t REG_SZ /d "4Game CIS"
Reg.exe add "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\4game_cis" /f /v "Publisher" /t REG_SZ /d "4Game LLC"
Reg.exe add "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\4game_cis" /f /v "ShortcutName" /t REG_SZ /d "4Game CIS"
Reg.exe add "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\4game_cis" /f /v "InstallLocation" /t REG_SZ /d "%~dp0ICafeCloud\ProgramFiles-x86\4Game\4game_cis"
Reg.exe add "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\4game_cis" /f /v "DisplayIcon" /t REG_SZ /d "%~dp0ICafeCloud\ProgramFiles-x86\4Game\4game_cis\4Game CIS.exe"
Reg.exe add "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\4game_cis" /f /v "UninstallString" /t REG_SZ /d "\"C:\Windows\System32\cmd.exe\" /c  \"  \"%~dp0ICafeCloud\ProgramFiles-x86\4Game\4game_cis\4Game CIS.exe\" uninstall && rd /s/q \"%~dp0ICafeCloud\ProgramFiles-x86\4Game\4game_cis\" \" "

rem ==== restore the per-game 4game_cis_ uninstall entries exported by PostUpdate.bat ====
rem the exported paths only resolve once the junctions above exist - keep this block after them
set "FOURGAME_REGDIR=%~dp0ICafeCloud\Registry"
if exist "%FOURGAME_REGDIR%\" for %%F in ("%FOURGAME_REGDIR%\*.reg") do reg import "%%F"

Reg.exe add "HKCR\forgame-cis" /f /ve /t REG_SZ /d "URL:forgame-cis"
Reg.exe add "HKCR\forgame-cis" /f /v "URL Protocol" /t REG_SZ /d ""
Reg.exe add "HKCR\forgame-cis\DefaultIcon" /f /ve /t REG_SZ /d "4Game CIS.exe,1"
Reg.exe add "HKCR\forgame-cis\shell\open\command" /f /ve /t REG_SZ /d "\"%~dp0ICafeCloud\ProgramFiles-x86\4Game\4game_cis\4Game CIS.exe\" \"%1\""
