diff --git a/src/ImeSense.Launchers.Belarus.Avalonia/ViewModels/MainWindowViewModel.cs b/src/ImeSense.Launchers.Belarus.Avalonia/ViewModels/MainWindowViewModel.cs index 635f0b0..2e0accd 100644 --- a/src/ImeSense.Launchers.Belarus.Avalonia/ViewModels/MainWindowViewModel.cs +++ b/src/ImeSense.Launchers.Belarus.Avalonia/ViewModels/MainWindowViewModel.cs @@ -56,8 +56,10 @@ public async Task InitializeAsync() { if (!isLauncherReleaseCurrent) { var path = Path.Combine(FileLocations.BaseDirectory, FileNamesStorage.SBLauncherUpdater); - var updater = Core.Launcher.Launch(path); + var updater = Launcher.Launch(path); updater?.Start(); + + return; } } catch (Exception ex) { _logger.LogError("{Message}", ex.Message); diff --git a/src/ImeSense.Launchers.Belarus.Updater/Program.cs b/src/ImeSense.Launchers.Belarus.Updater/Program.cs index 399ac50..b00961d 100644 --- a/src/ImeSense.Launchers.Belarus.Updater/Program.cs +++ b/src/ImeSense.Launchers.Belarus.Updater/Program.cs @@ -12,21 +12,12 @@ foreach (var process in Process.GetProcessesByName("SBLauncher")) { process.Kill(); } - //foreach (var process in Process.GetProcessesByName("SBLauncher-x86")) { - // process.Kill(); - //} - //foreach (var process in Process.GetProcessesByName("SBLauncher-x64")) { - // process.Kill(); - //} - Console.WriteLine($"Start update"); - var filePath = Path.Combine(FileLocations.BaseDirectory, "SBLauncher.exe"); - if (File.Exists(filePath)) { - File.Delete(filePath); - } + Console.WriteLine($"Start update"); + var appName = "SBLauncher.exe"; using var httpClient = new HttpClient(); - httpClient.BaseAddress = new Uri("https://api.github.com/repos/imesense/belarus-launcher/"); + httpClient.BaseAddress = new Uri("https://api.github.com/repos/Paliverse/DualSenseX/"); httpClient.DefaultRequestHeaders.Accept.Clear(); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/vnd.github.v3+json")); httpClient.DefaultRequestHeaders.Add("User-Agent", ".NET Foundation Repository Reporter"); @@ -35,7 +26,7 @@ var lastRelease = await gitHubService.GetLastReleaseAsync() ?? throw new NullReferenceException("Latest release is null!"); - var sblauncher = lastRelease.Assets?.FirstOrDefault(x => x.Name.Equals("SBLauncher.exe")) + var sblauncher = lastRelease.Assets?.FirstOrDefault(x => x.Name.Equals(appName)) ?? throw new NullReferenceException("SBLauncher asset is null!"); if (sblauncher.BrowserDownloadUrl == null) { @@ -45,8 +36,26 @@ Console.WriteLine($"SBLauncher is {percentage}% downloaded"); }); + var pathDownloadFolder = Path.Combine(FileLocations.BaseDirectory, "temp"); + var fileDownloadPath = Path.Combine(pathDownloadFolder, appName); + + if (!Directory.Exists(pathDownloadFolder)) { + Directory.CreateDirectory(pathDownloadFolder); + } + var download = new FileDownloadManager(null, httpClient); - await download.DownloadAsync(sblauncher.BrowserDownloadUrl, filePath, progress); + await download.DownloadAsync(sblauncher.BrowserDownloadUrl, fileDownloadPath, progress); + + var filePath = Path.Combine(FileLocations.BaseDirectory, appName); + + if (File.Exists(filePath)) { + File.Delete(filePath); + } + File.Move(fileDownloadPath, filePath); + + if (Directory.Exists(pathDownloadFolder)) { + Directory.Delete(pathDownloadFolder); + } Console.WriteLine($"Finish!");