rework autoupdate to script only

zoom fix
This commit is contained in:
Alex Bezdieniezhnykh
2025-07-06 23:22:21 +03:00
parent 75d3a2412f
commit 6229ca8a03
12 changed files with 179 additions and 80 deletions
-6
View File
@@ -46,11 +46,5 @@ public partial class App
host.Services.GetRequiredService<Login>().Show();
}
//AFter:
//_loaderClient.Login(credentials);
//_loaderClient.Dispose();
}
+8 -1
View File
@@ -24,7 +24,6 @@
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.5" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="9.0.5" />
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.5" />
<PackageReference Include="NetMQ" Version="4.0.1.13" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="9.0.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="9.0.1" />
@@ -37,6 +36,14 @@
<Content Include="loaderconfig.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Remove="updater.cmd" />
<Content Include="updater.cmd">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Azaion.Common\Azaion.Common.csproj" />
</ItemGroup>
</Project>
+22 -28
View File
@@ -6,6 +6,7 @@ using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using Azaion.Common;
using MessagePack;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
@@ -57,22 +58,34 @@ public partial class Login
TbStatus.Foreground = Brushes.Black;
var installerVersion = await GetInstallerVer();
var localVersion = GetLocalVer();
var credsEncrypted = Security.Encrypt(creds);
if (installerVersion > localVersion)
{
TbStatus.Text = $"Updating from {localVersion} to {installerVersion}...";
await DownloadAndRunInstaller();
TbStatus.Text = $"Installed {installerVersion}!";
var (installerName, stream) = await _azaionApi.DownloadInstaller(_dirConfig?.SuiteInstallerDirectory ?? "");
var localFileStream = new FileStream(installerName, FileMode.Create, FileAccess.Write);
await stream.CopyToAsync(localFileStream);
localFileStream.Close();
stream.Close();
Process.Start(new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = $"/c updater.cmd {Process.GetCurrentProcess().Id} {installerName} {Constants.AZAION_SUITE_EXE} \"{credsEncrypted}\""
});
}
else
{
TbStatus.Text = "Your version is up to date!";
Process.Start(Constants.AZAION_SUITE_EXE, $"-e {creds.Email} -p {creds.Password}");
await Task.Delay(800);
TbStatus.Text = "Loading...";
while (!Process.GetProcessesByName(Constants.INFERENCE_EXE).Any())
await Task.Delay(500);
await Task.Delay(1500);
Process.Start(Constants.AZAION_SUITE_EXE, $"-c {credsEncrypted}");
await Task.Delay(800);
TbStatus.Text = "Loading...";
while (!Process.GetProcessesByName(Constants.INFERENCE_EXE).Any())
await Task.Delay(500);
await Task.Delay(1500);
}
Close();
}
catch (Exception exception)
@@ -146,26 +159,7 @@ public partial class Login
throw;
}
}
private async Task DownloadAndRunInstaller()
{
var (installerName, stream) = await _azaionApi.DownloadInstaller(_dirConfig?.SuiteInstallerDirectory ?? "");
var localFileStream = new FileStream(installerName, FileMode.Create, FileAccess.Write);
await stream.CopyToAsync(localFileStream);
localFileStream.Close();
stream.Close();
var processInfo = new ProcessStartInfo(installerName)
{
UseShellExecute = true,
Arguments = "/VERYSILENT"
};
var process = Process.Start(processInfo);
await process!.WaitForExitAsync();
File.Delete(installerName);
}
private async Task<Version> GetInstallerVer()
{
TbStatus.Text = "Checking for the newer version...";
+39
View File
@@ -0,0 +1,39 @@
@echo off
setlocal
REM Verify that all four arguments were provided
if "%~4"=="" (
echo Error: Missing arguments.
echo Usage: %0 ^<parent_pid^> ^<installer_path^> ^<app_path^> ^<encrypted_creds^>
exit /b 1
)
set "PARENT_PID=%1"
set "INSTALLER_PATH=%2"
set "MAIN_APP_PATH=%3"
set "CREDS=%~4"
:WAIT_FOR_PARENT_EXIT
echo Waiting for parent process (PID: %PARENT_PID%) to close...
tasklist /fi "pid eq %PARENT_PID%" | find "%PARENT_PID%" >nul
if %errorlevel% == 0 (
timeout /t 1 /nobreak >nul
goto WAIT_FOR_PARENT_EXIT
)
start "" /wait "%INSTALLER_PATH%" /VERYSILENT
del "%INSTALLER_PATH%"
echo Installed new version %INSTALLER_PATH%
start "" "%MAIN_APP_PATH%" -c "%CREDS%"
echo Loading...
:WAIT_FOR_APP_START
timeout /t 1 /nobreak >nul
tasklist /fi "imagename eq azaion-inference.exe" | find "azaion-inference.exe" >nul
if %errorlevel% neq 0 goto WAIT_FOR_APP_START
timeout /t 5 /nobreak >nul
echo Process started.
endlocal