:: TLauncher runs in Java environment
taskkill /f /im javaw.exe /t
taskkill /f /im java.exe /t

rmdir "%~dp0ICafeCloud\AppData\tlauncher\cache" /S /Q
rmdir "%~dp0ICafeCloud\AppData\tlauncher\logs" /S /Q
rmdir "%~dp0saves" /S /Q
rmdir "%~dp0logs" /S /Q

del "%~dp0TlauncherProfiles.json" /Q
del "%~dp0usercache.json" /Q
del "%~dp0worlds.json" /Q

rmdir "%AppData%\.minecraft" /S /Q
rmdir "%AppData%\.tlauncher" /S /Q
mklink /J "%AppData%\.minecraft" "%~dp0"
mklink /J "%AppData%\.tlauncher" "%~dp0ICafeCloud\AppData\tlauncher"

set "TlauncherConfigFile=%AppData%\.tlauncher\tlauncher-2.0.properties"
set "TlauncherNewGamePath=%AppData%\.minecraft"
set "TlauncherNewGamePath=%TlauncherNewGamePath:\=\\%"
set "TlauncherNewGamePath=%TlauncherNewGamePath::=\:%"

if exist "%TlauncherConfigFile%" (
	powershell -NoProfile -Command "(Get-Content '%TlauncherConfigFile%') -replace '^minecraft\.gamedir=.*', 'minecraft.gamedir=%TlauncherNewGamePath%' | Set-Content '%TlauncherConfigFile%'"
)

setlocal
REM set java
set "JAVAPATH=%~dp0runtime\java-runtime-delta\windows\java-runtime-delta"
set "JAVABIN=%JAVAPATH%\bin"
set "JVM_DLL=%JAVABIN%\server\jvm.dll"

reg query "HKLM\SOFTWARE\JavaSoft\Java Runtime Environment\1.8" >nul 2>&1
if errorlevel 1 (
    reg add "HKLM\SOFTWARE\JavaSoft\Java Runtime Environment" /v "CurrentVersion" /d "1.8" /f
    reg add "HKLM\SOFTWARE\JavaSoft\Java Runtime Environment\1.8" /v "JavaHome" /d "%JAVAPATH%" /f
    reg add "HKLM\SOFTWARE\JavaSoft\Java Runtime Environment\1.8" /v "RuntimeLib" /d "%JVM_DLL%" /f
)
