- tweak: some information for updater

This commit is contained in:
2025-05-01 21:03:55 +03:00
parent 6a7d1f144c
commit d887b2ada1
4 changed files with 82 additions and 20 deletions

View File

@@ -14,10 +14,10 @@
mc:Ignorable="d" d:DesignWidth="400" d:DesignHeight="225"
x:Class="Nebula.UpdateResolver.MainWindow"
Title="Nebula.UpdateResolver">
<Grid ColumnDefinitions="*" RowDefinitions="*,40">
<Grid ColumnDefinitions="*" RowDefinitions="*,30">
<Image Grid.Row="0" Source="Assets/back.gif" Grid.RowSpan="2"/>
<Border
Padding="5"
BorderThickness="0,3,0,0"
CornerRadius="0"
Grid.Column="0"
@@ -34,7 +34,10 @@
<GradientStop Color="#442222" Offset="1.0" />
</LinearGradientBrush>
</Border.BorderBrush>
<Label HorizontalAlignment="Center" VerticalAlignment="Center">Hello</Label>
<Panel>
<Label HorizontalAlignment="Left" VerticalAlignment="Center" FontSize="10" Name="ProgressLabel"/>
<Label HorizontalAlignment="Right" VerticalAlignment="Center" FontSize="10" Name="PercentLabel"/>
</Panel>
</Border>
</Grid>
</Window>

View File

@@ -1,12 +1,17 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Avalonia.Controls;
using Nebula.Shared.FileApis;
using Nebula.Shared.FileApis.Interfaces;
using Nebula.Shared.Models;
using Nebula.Shared.Services;
using Tmds.DBus.Protocol;
namespace Nebula.UpdateResolver;
@@ -15,52 +20,88 @@ public partial class MainWindow : Window
private readonly ConfigurationService _configurationService;
private readonly RestService _restService;
private readonly HttpClient _httpClient = new HttpClient();
public IReadWriteFileApi FileApi { get; set; }
public FileApi FileApi { get; set; }
public MainWindow(FileService fileService, ConfigurationService configurationService, RestService restService)
{
_configurationService = configurationService;
_restService = restService;
InitializeComponent();
FileApi = fileService.CreateFileApi("app");
FileApi = (FileApi)fileService.CreateFileApi("app");
Start();
}
private async Task DownloadFiles()
private async Task Start()
{
var info = await EnsureFiles();
Log("Downloading files...");
foreach (var file in info.ToDelete)
{
Log("Deleting " + file.Path);
FileApi.Remove(file.Path);
}
var loadedManifest = info.FilesExist;
Save(loadedManifest);
var count = info.ToDownload.Count;
var resolved = 0;
foreach (var file in info.ToDownload)
{
using var response = _httpClient.GetAsync(
using var response = await _httpClient.GetAsync(
_configurationService.GetConfigValue(UpdateConVars.UpdateCacheUrl)
+ "/" + file.Hash
);
response.Result.EnsureSuccessStatusCode();
await using var stream = await response.Result.Content.ReadAsStreamAsync();
+ "/" + file.Hash);
response.EnsureSuccessStatusCode();
await using var stream = await response.Content.ReadAsStreamAsync();
FileApi.Save(file.Path, stream);
resolved++;
Log("Saving " + file.Path, (int)(resolved/(float)count*100f));
loadedManifest.Add(file);
Save(loadedManifest);
}
Log("Download finished. Running launcher...");
var process = Process.Start(new ProcessStartInfo
{
FileName = "dotnet.exe",
Arguments = Path.Join(FileApi.RootPath,"Nebula.Launcher.dll"),
CreateNoWindow = true,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
StandardOutputEncoding = Encoding.UTF8
});
Thread.Sleep(2000);
Environment.Exit(0);
}
private async Task<ManifestEnsureInfo> EnsureFiles()
{
Log("Ensuring launcher manifest...");
var manifest = await _restService.GetAsync<LauncherManifest>(
_configurationService.GetConfigValue(UpdateConVars.UpdateCacheUrl)!, CancellationToken.None);
new Uri(_configurationService.GetConfigValue(UpdateConVars.UpdateCacheUrl)! + "/manifest.json"), CancellationToken.None);
var toDownload = new HashSet<LauncherManifestEntry>();
var toDelete = new HashSet<LauncherManifestEntry>();
var filesExist = new HashSet<LauncherManifestEntry>();
Log("Manifest loaded!");
if (_configurationService.TryGetConfigValue(UpdateConVars.CurrentLauncherManifest, out var currentManifest))
{
Log("Delta manifest loaded!");
foreach (var file in currentManifest.Entries)
{
if(!manifest.Entries.Contains(file))
if (!manifest.Entries.Contains(file))
toDelete.Add(file);
else
filesExist.Add(file);
}
foreach (var file in manifest.Entries)
@@ -71,12 +112,29 @@ public partial class MainWindow : Window
}
else
{
_configurationService.SetConfigValue(UpdateConVars.CurrentLauncherManifest, manifest);
toDownload = manifest.Entries;
}
return new ManifestEnsureInfo(toDownload, toDelete);
Log("Saving launcher manifest...");
return new ManifestEnsureInfo(toDownload, toDelete, filesExist);
}
private void Log(string message, int percentage = 0)
{
ProgressLabel.Content = message;
if (percentage == 0)
PercentLabel.Content = "";
else
PercentLabel.Content = percentage + "%";
Console.WriteLine(message);
}
private void Save(HashSet<LauncherManifestEntry> entries)
{
_configurationService.SetConfigValue(UpdateConVars.CurrentLauncherManifest, new LauncherManifest(entries));
}
}
public record struct ManifestEnsureInfo(HashSet<LauncherManifestEntry> ToDownload, HashSet<LauncherManifestEntry> ToDelete);
public record struct ManifestEnsureInfo(HashSet<LauncherManifestEntry> ToDownload, HashSet<LauncherManifestEntry> ToDelete, HashSet<LauncherManifestEntry> FilesExist);

View File

@@ -6,8 +6,8 @@ namespace Nebula.UpdateResolver;
public static class UpdateConVars
{
public static readonly ConVar<Uri> UpdateCacheUrl =
ConVarBuilder.Build<Uri>("update.url",new Uri("https://cinka.ru/nebula-launcher/files/publish/release"));
public static readonly ConVar<string> UpdateCacheUrl =
ConVarBuilder.Build<string>("update.url","https://cinka.ru/nebula-launcher/files/publish/release");
public static readonly ConVar<LauncherManifest> CurrentLauncherManifest =
ConVarBuilder.Build<LauncherManifest>("update.manifest");
}

View File

@@ -1,3 +1,4 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AFrozenDictionary_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F89dff9063ddb01ff8125b579122b88bf4de94526490d77bcbbef7d0ee662a_003FFrozenDictionary_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AParallel_002EForEachAsync_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fc1d1ed6be2d5d4de542b4af5b36e82f6d1d1a389a35a4e4f9748d137d1c651_003FParallel_002EForEachAsync_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AServiceCollectionContainerBuilderExtensions_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fa8ceca48b7b645dd875a40ee6d28725416d08_003F1b_003F6cd78dc8_003FServiceCollectionContainerBuilderExtensions_002Ecs/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary>