Skip to content

Commit

Permalink
Delete old launcher after downloading new one
Browse files Browse the repository at this point in the history
  • Loading branch information
Drombeys committed Jan 11, 2024
1 parent 1d00f35 commit 71c862d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
37 changes: 23 additions & 14 deletions src/ImeSense.Launchers.Belarus.Updater/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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) {
Expand All @@ -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!");

Expand Down

0 comments on commit 71c862d

Please sign in to comment.