net stop GameLoopService /y >nul 2>&1
taskkill /f /im GameLoop.exe /t

REM Record the newest version number for the GameLoop link created by PostUpdate
set "gl_rec_file=%~dp0GameLoop\Application\gl_version.txt"
set "gl_out_file=%TEMP%\gl_maxver.txt"
del /f /q "%gl_out_file%" >nul 2>&1
powershell -NoProfile -Command "Get-ChildItem -LiteralPath '%~dp0GameLoop\Application' -Directory -Name | Where-Object { $_ -match '^\d+(\.\d+)+$' } | Sort-Object { [version]$_ } -Descending | Select-Object -First 1 | Out-File -Encoding ASCII -FilePath '%gl_out_file%'"
set "gl_max="
if exist "%gl_out_file%" set /p gl_max=<"%gl_out_file%"
del /f /q "%gl_out_file%" >nul 2>&1

if defined gl_max >"%gl_rec_file%" echo %gl_max%

rmdir "%~dp0ICafeCloud" /S /Q 2>nul
rmdir "%~dp0GameLoop\Image" /S /Q 2>nul
rmdir "%~dp0GameLoopData" /S /Q 2>nul

xcopy "%ProgramData%\Tencent\qimei" "%~dp0ICafeCloud\ProgramData\Tencent\qimei" /E /I /Y

if not exist "pkg_match_only.dat" (
    type nul > "pkg_match_only.dat"
)
