update.bat 2.57 KB
@echo off
rem Update StoreEdge to the latest version in the cloud console (program code only: edgeclient\).
rem Double-click it. It asks for administrator rights (needed to restart the service), then:
rem   1. asks the cloud for the latest version and compares it with the version on this computer
rem   2. downloads the update package, checks sha256, unpacks it to app\<version>\ and test-runs it
rem   3. restarts this folder's service (StoreEdge / StoreEdge-dev ...) and waits until the new version is connected to the cloud
rem If the new version fails to connect 3 starts in a row, the service rolls back to the previous version by itself.
rem   update.bat --check   only show the versions, install nothing
rem   update.bat --yes     do not ask when the service is busy with a task (the task is interrupted)
setlocal
net session >nul 2>&1
if not errorlevel 1 goto admin
echo Asking for administrator rights (needed to restart the service) ...
if "%~1"=="" goto elevate_noargs
powershell -NoProfile -Command "Start-Process -FilePath '%~f0' -ArgumentList '%*' -Verb RunAs"
goto elevated
:elevate_noargs
powershell -NoProfile -Command "Start-Process -FilePath '%~f0' -Verb RunAs"
:elevated
if not errorlevel 1 exit /b 0
echo [ERROR] Could not get administrator rights. Right-click update.bat and choose "Run as administrator".
pause
exit /b 1

:admin
rem update the installed copy: this folder if it is an installed instance (config.ini + python38), otherwise the
rem default install folder. With several instances (StoreEdge, StoreEdge-dev ...) run the update.bat inside the
rem instance folder: only that instance and its own service are updated.
set "EDGE_HOME=%~dp0"
if exist "%EDGE_HOME%config.ini" if exist "%EDGE_HOME%python38\python.exe" goto home_ok
if exist "C:\autoRestore\StoreEdge\StoreEdge.exe" set "EDGE_HOME=C:\autoRestore\StoreEdge\"
:home_ok
cd /d "%EDGE_HOME%"
if exist "python38\python.exe" goto run
echo [ERROR] python38 folder not found in %EDGE_HOME% . Install StoreEdge first (install.bat).
pause
exit /b 3
:run
if exist config.ini goto cfg_ok
echo [ERROR] config.ini not found in %EDGE_HOME% . Run install.bat first.
pause
exit /b 3
:cfg_ok
set PYTHONNOUSERSITE=1
rem From here on everything is ONE block: cmd reads the whole block before running it, so the update may replace
rem this very file (root files are synced from the new version) without cmd running half a line of the new file.
setlocal EnableDelayedExpansion
(
  python38\python.exe main.py update %*
  set RC=!errorlevel!
  echo.
  echo ===== exit code !RC!  ^(0=ok 2=failed 3=config error^)   folder: %EDGE_HOME% =====
  pause
  exit /b !RC!
)