@echo off
setlocal

@REM @taskkill /F /IM ariganya.exe

set desktop_path=%~1
set version=%~2
set "source=%desktop_path%\%version%"
set "temp_path=%cd%\app_old_version"

powershell -Command "Stop-Process -Name "ariganya" -Force"

xcopy "%desktop_path%\*" "%temp_path%\" /E /Y /C /I
powershell -Command "Expand-Archive -Path '%desktop_path%\update.zip' -DestinationPath '%source%'"

if %errorlevel% neq 0 (
    xcopy "%temp_path%\*" "%desktop_path%\" /E /Y /C /I
) else (
    xcopy "%source%\*" "%desktop_path%" /E /Y /C /I
)

start "" "%desktop_path%\ariganya.exe"

endlocal
