diff --git a/i18n/en/Tooltips.resx b/i18n/en/Tooltips.resx index 3be6f60e..af279970 100644 --- a/i18n/en/Tooltips.resx +++ b/i18n/en/Tooltips.resx @@ -919,7 +919,7 @@ Try this file again now Select Sequence to choose one Address of the Chronos Server, such as https://nas.local:8443 - Server, sign in, bandwidth, startup, tray + Server, sign in, bandwidth, startup, tray, updates Show the first file that failed · press Enter on it to try again Check the server certificate and sign in Sign out and forget the saved token @@ -929,6 +929,17 @@ Add every file to one existing sequence The server splits the files into sessions and creates the sequences Remember this certificate; trust it only if the fingerprint matches the one on the server + A newer Chronos release exists · Download fetches the setup + Stop the download; Download resumes it later from where it stopped + Ask the public releases page for a newer version · a few seconds + Look for a newer Chronos release when the Uploader starts · skipped when Chronos Desktop is installed alongside, whose own notice covers the same setup + Download the setup, check it against the release's SHA-256 list and show it in Explorer · {0} + Open the page of this release in the browser + Download the portable zip, check it against the release's SHA-256 list and show it in Explorer · {0} + The releases page could not be reached · try again later + Show the verified zip in Explorer; close Chronos and the Uploader and unpack it over this folder to upgrade. The data folder is kept + Show the verified setup in Explorer; close the Uploader and run it to upgrade. Queue and settings are kept + You run the newest stable release Your user name on the Chronos Server Checked every {0}; a file is uploaded once it has stopped growing · click to change or remove The folder cannot be reached; it is checked again every {0} · click to change or remove diff --git a/i18n/en/Uploader.resx b/i18n/en/Uploader.resx index 320070df..8a1a72ab 100644 --- a/i18n/en/Uploader.resx +++ b/i18n/en/Uploader.resx @@ -103,6 +103,21 @@ Compare this fingerprint with the one shown on the server.long Trust this server? {0}/s + Version {0} available + Cancel + Check now + Check on start + Checking… + Download + Download failed + Downloading {0:P0} + Check failed + Downloading… + Download not verified + Version {0} downloaded + Show setup + Updates + Up to date {0} · every {1} Every {0} every {0} diff --git a/i18n/it/Tooltips.it.resx b/i18n/it/Tooltips.it.resx index 4a6a5ca8..ad0b1452 100644 --- a/i18n/it/Tooltips.it.resx +++ b/i18n/it/Tooltips.it.resx @@ -1016,7 +1016,7 @@ Riprova subito questo file Seleziona Sequenza per sceglierne una Indirizzo del Chronos Server, ad esempio https://nas.local:8443 - Server, accesso, banda, avvio, area di notifica + Server, accesso, banda, avvio, area di notifica, aggiornamenti Mostra il primo file non riuscito · premi Invio per riprovarlo Controlla il certificato del server e accedi Esci e dimentica il token salvato @@ -1026,6 +1026,17 @@ Aggiungi tutti i file a una sequenza esistente Il server divide i file in sessioni e crea le sequenze Ricorda questo certificato; accettalo solo se l'impronta coincide con quella sul server + Esiste una versione più recente di Chronos · Scarica prende l'installer + Interrompe il download; Scarica lo riprende in seguito dal punto in cui si è fermato + Chiede alla pagina pubblica delle versioni se ne esiste una più recente · pochi secondi + Cerca una versione più recente di Chronos all'avvio dell'Uploader · saltato quando accanto è installato Chronos Desktop, il cui avviso copre lo stesso installer + Scarica l'installer, lo confronta con l'elenco SHA-256 della versione e lo mostra in Esplora file · {0} + Apre la pagina di questa versione nel browser + Scarica lo zip portatile, lo confronta con l'elenco SHA-256 della versione e lo mostra in Esplora file · {0} + Non è stato possibile raggiungere la pagina delle versioni · riprova più tardi + Mostra in Esplora file lo zip verificato; chiudi Chronos e l'Uploader ed estrailo sopra questa cartella per aggiornare. La cartella dei dati resta invariata + Mostra in Esplora file l'installer verificato; chiudi l'Uploader ed eseguilo per aggiornare. Coda e impostazioni restano invariate + Usi la versione stabile più recente Il tuo nome utente sul Chronos Server Controllata ogni {0}; un file viene inviato quando smette di crescere · fai clic per modificare o rimuovere La cartella non è raggiungibile; viene ricontrollata ogni {0} · fai clic per modificare o rimuovere diff --git a/i18n/it/Uploader.it.resx b/i18n/it/Uploader.it.resx index c32430fd..5487e793 100644 --- a/i18n/it/Uploader.it.resx +++ b/i18n/it/Uploader.it.resx @@ -101,6 +101,21 @@ Confronta questa impronta con quella mostrata sul server. Accettare questo server? {0}/s + Versione {0} disponibile + Annulla + Verifica ora + Verifica all'avvio + Verifica in corso… + Scarica + Download non riuscito + Download in corso {0:P0} + Verifica non riuscita + Download in corso… + Download non verificato + Versione {0} scaricata + Mostra installer + Aggiornamenti + Aggiornato {0} · ogni {1} Ogni {0} ogni {0} diff --git a/src/Chronos.Uploader/App.xaml.cs b/src/Chronos.Uploader/App.xaml.cs index dfd00a06..8c222ec2 100644 --- a/src/Chronos.Uploader/App.xaml.cs +++ b/src/Chronos.Uploader/App.xaml.cs @@ -82,6 +82,7 @@ public partial class App : Application UpdateTray(); UpdateDiscovery(); if (command.Paths.Count > 0) _ = _vm.EnqueueAsync(command.Paths); + _ = _vm.Updates.CheckOnStartAsync(_environment.HasDesktopBeside); if (command.StartInTray && _settings.MinimizeToTray) return; if (command.StartInTray) _window!.WindowState = WindowState.Minimized; @@ -122,7 +123,10 @@ public partial class App : Application var startup = new RunKeyStartupRegistration(); startup.Refresh(); var dialogs = new UploaderDialogs(); - _vm = new MainViewModel(new UploaderServices(settings, SaveSettings, _session, _queue, _engine, startup, dialogs, _watch, _memory, environment.LogDirectory)); + _vm = new MainViewModel(new UploaderServices(settings, SaveSettings, _session, _queue, _engine, startup, dialogs, _watch, _memory, environment.LogDirectory) + { + Updates = UploaderUpdates.Host(environment.IsPortable), + }); _window = new Shell.MainWindow(_vm, settings); dialogs.Owner = _window; MainWindow = _window; diff --git a/src/Chronos.Uploader/DesignTime/SampleData.cs b/src/Chronos.Uploader/DesignTime/SampleData.cs index 8664e9be..9d1f9b32 100644 --- a/src/Chronos.Uploader/DesignTime/SampleData.cs +++ b/src/Chronos.Uploader/DesignTime/SampleData.cs @@ -1,6 +1,7 @@ using System.ComponentModel; using System.Globalization; using System.Runtime.CompilerServices; +using Chronos.Core.Updates; using Chronos.Protocol; using Chronos.Uploader.Infrastructure; using Chronos.Uploader.Server; @@ -19,6 +20,7 @@ public sealed class SampleData { private const int FileCount = 4_812; private const long FileSize = 20_000_000; + private const string RunningVersion = "1.0.0"; /// The sample's "now" (when the failed file failed): fixed, so the screenshots are the same on any day. private static readonly DateTime Now = new(2026, 9, 28, 19, 2, 0, DateTimeKind.Utc); @@ -51,7 +53,11 @@ public sealed class SampleData _session.BandwidthLimit = Settings.BandwidthLimit; _vm = new MainViewModel(new UploaderServices( Settings, () => { }, _session, _queue, new SampleEngine(_queue), startup ?? new SampleStartup(), new UploaderDialogs(), - new WatchFolderService(memory, _queue.ContainsPath), memory, string.Empty)); + new WatchFolderService(memory, _queue.ContainsPath), memory, string.Empty) + { + // A fixed running version, so the update notice reads the same whatever this build's version is. + Updates = UploaderUpdates.Offline(RunningVersion), + }); foreach (var w in _vm.WatchFolders) w.IsAvailable = true; // A disconnected drive: its chip shows the hollow ring and wraps to a second line. _vm.WatchFolders[^1].IsAvailable = false; @@ -79,6 +85,20 @@ public sealed class SampleData _vm.RefreshQueue(); } + /// The settings panel's update notice: a newer release with its setup and checksums, so Download is offered. + public void ShowUpdate() + { + const string Base = "https://gitea.example/BalboSoft/Chronos/releases/download/v1.1.0/"; + _vm!.Updates.SetResult(new ReleaseInfo(new Version(1, 1, 0), "v1.1.0", "https://gitea.example/BalboSoft/Chronos/releases/tag/v1.1.0") + { + Assets = + [ + new ReleaseAsset("Chronos-Setup-1.1.0.exe", Base + "Chronos-Setup-1.1.0.exe", 92_400_000), + new ReleaseAsset(UpdateDownload.ChecksumsName, Base + UpdateDownload.ChecksumsName, 300), + ], + }); + } + private void FillQueue() { var batch = new UploadBatch { Id = Guid.CreateVersion7(), Mode = UploadTargetMode.Sessions }; diff --git a/src/Chronos.Uploader/Infrastructure/UploaderEnvironment.cs b/src/Chronos.Uploader/Infrastructure/UploaderEnvironment.cs index 4d84a28b..c54c8f6c 100644 --- a/src/Chronos.Uploader/Infrastructure/UploaderEnvironment.cs +++ b/src/Chronos.Uploader/Infrastructure/UploaderEnvironment.cs @@ -9,9 +9,14 @@ namespace Chronos.Uploader.Infrastructure; /// public sealed class UploaderEnvironment { - private UploaderEnvironment(string dataDirectory) + /// The desktop program's file name; the single setup installs it in the Uploader's own folder. + public const string DesktopExecutable = "Chronos.exe"; + + private UploaderEnvironment(string dataDirectory, bool isPortable, bool hasDesktopBeside) { DataDirectory = dataDirectory; + IsPortable = isPortable; + HasDesktopBeside = hasDesktopBeside; Directory.CreateDirectory(DataDirectory); Directory.CreateDirectory(LogDirectory); } @@ -19,6 +24,15 @@ public sealed class UploaderEnvironment public string DataDirectory { get; } public string LogDirectory => Path.Combine(DataDirectory, "logs"); + /// A portable copy (portable.txt beside the executable): its update is the portable zip, not the setup. + public bool IsPortable { get; } + + /// + /// Chronos Desktop sits in the same folder: its own update notice covers the same setup, so the Uploader skips its + /// start-up check (Check now still works). + /// + public bool HasDesktopBeside { get; } + /// Settings, DPAPI-protected token and trusted certificate fingerprints. public string SettingsPath => Path.Combine(DataDirectory, "uploader.json"); @@ -31,8 +45,12 @@ public sealed class UploaderEnvironment public static UploaderEnvironment Detect() { var exeDir = AppContext.BaseDirectory; - if (File.Exists(Path.Combine(exeDir, "portable.txt"))) return new UploaderEnvironment(Path.Combine(exeDir, "data")); + var desktop = IsDesktopBeside(exeDir); + if (File.Exists(Path.Combine(exeDir, "portable.txt"))) return new UploaderEnvironment(Path.Combine(exeDir, "data"), isPortable: true, desktop); var local = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); - return new UploaderEnvironment(Path.Combine(local, "Chronos")); + return new UploaderEnvironment(Path.Combine(local, "Chronos"), isPortable: false, desktop); } + + /// True when is in . + public static bool IsDesktopBeside(string folder) => File.Exists(Path.Combine(folder, DesktopExecutable)); } diff --git a/src/Chronos.Uploader/Infrastructure/UploaderSettings.cs b/src/Chronos.Uploader/Infrastructure/UploaderSettings.cs index 0bcb3cf9..cd48f102 100644 --- a/src/Chronos.Uploader/Infrastructure/UploaderSettings.cs +++ b/src/Chronos.Uploader/Infrastructure/UploaderSettings.cs @@ -27,6 +27,10 @@ public sealed class UploaderSettings public int BandwidthLimit { get; set; } public bool MinimizeToTray { get; set; } = true; + + /// Look for a newer Chronos release on start (opt-out, BRIEF §18); a 1.0 file without the key keeps it on. + public bool CheckForUpdates { get; set; } = true; + public bool DeleteAfterUpload { get; set; } public UploadTargetMode Target { get; set; } = UploadTargetMode.Sessions; public Guid? TargetSequenceId { get; set; } diff --git a/src/Chronos.Uploader/Infrastructure/UploaderUpdates.cs b/src/Chronos.Uploader/Infrastructure/UploaderUpdates.cs new file mode 100644 index 00000000..6d7d8f3a --- /dev/null +++ b/src/Chronos.Uploader/Infrastructure/UploaderUpdates.cs @@ -0,0 +1,46 @@ +using System.IO; +using System.Net.Http; +using System.Reflection; +using Chronos.Core.Updates; +using Chronos.Ui.Updates; +using Chronos.Uploader.Interop; + +namespace Chronos.Uploader.Infrastructure; + +/// +/// The Uploader's side of the shared update notice (BRIEF §18, owner review 5): the same releases feed, the same single +/// setup (or the portable zip of a portable copy) and the same %TEMP%\Chronos\updates folder as the desktop. +/// +public static class UploaderUpdates +{ + private static readonly Lazy Http = new(() => new HttpClient { Timeout = TimeSpan.FromSeconds(20) }); + + /// Update packages are large: their download fails when it stalls (), never after a fixed total time. + private static readonly Lazy DownloadHttp = new(() => new HttpClient { Timeout = Timeout.InfiniteTimeSpan }); + + /// The informational version of this build, such as "1.1.0" or "1.1.0-rc.1". + public static string VersionText { get; } = + typeof(UploaderUpdates).Assembly.GetCustomAttribute()?.InformationalVersion ?? "0.0.0"; + + /// The live host: the public releases repository, the shell's browser and Explorer. + public static UpdateHost Host(bool portable) => + Host(Http.Value, DownloadHttp.Value, ProductLinks.Repository, VersionText, portable, UpdateDownload.Root(Path.GetTempPath()), ShellActions.OpenUrl, + ShellActions.Reveal); + + /// A host over the given clients and releases repository ("https://host/owner/name"); tests pass a fake transport. + public static UpdateHost Host(HttpClient http, HttpClient downloadHttp, string repository, string versionText, bool portable, string downloadRoot, + Action openUrl, Action reveal) => + new(UpdateCheck.RunningVersion(versionText), IsCapture: false, portable, + ct => UpdateCheck.FetchAsync(http, ProductLinks.StableReleasesApiOf(repository), repository, versionText, ct), + (release, progress, ct) => UpdateDownload.DownloadAsync(downloadHttp, release, portable, downloadRoot, versionText, progress, UpdateDownload.IdleTimeout, ct), + openUrl, reveal) + { + RunningIsPrerelease = UpdateCheck.IsPrerelease(versionText), + }; + + /// A host that never touches the network or the shell (--capture, design time). + public static UpdateHost Offline(string versionText) => + new(UpdateCheck.RunningVersion(versionText), IsCapture: true, IsPortable: false, + _ => Task.FromResult(null), (_, _, _) => Task.FromException(new InvalidOperationException("No download in a capture run.")), + _ => { }, _ => { }); +} diff --git a/src/Chronos.Uploader/Interop/ShellActions.cs b/src/Chronos.Uploader/Interop/ShellActions.cs new file mode 100644 index 00000000..d49327c4 --- /dev/null +++ b/src/Chronos.Uploader/Interop/ShellActions.cs @@ -0,0 +1,55 @@ +using System.ComponentModel; +using System.Diagnostics; +using System.IO; +using System.Runtime.InteropServices; +using Chronos.Core.Diagnostics; + +namespace Chronos.Uploader.Interop; + +/// +/// The two shell actions of the update notice (BRIEF §8.6): open an https link in the browser and show a file selected +/// in Explorer. Nothing else is started; the verified setup is run by the user. +/// +public static partial class ShellActions +{ + /// Opens an absolute https link with the shell's "open" verb; anything else is ignored. + public static void OpenUrl(string url) + { + if (!Uri.TryCreate(url, UriKind.Absolute, out var uri) || uri.Scheme != Uri.UriSchemeHttps) return; + try + { + using var _ = Process.Start(new ProcessStartInfo(uri.AbsoluteUri) { UseShellExecute = true, Verb = "open" }); + } + catch (Exception ex) when (ex is Win32Exception or InvalidOperationException) + { + Log.Warning("shell", $"The shell could not open {uri.AbsoluteUri}", ex); + } + } + + /// Shows the file selected in its Explorer folder (SHOpenFolderAndSelectItems); a missing file is ignored. + public static void Reveal(string path) + { + if (string.IsNullOrWhiteSpace(path) || !File.Exists(path)) return; + var full = Path.GetFullPath(path); + if (SHParseDisplayName(full, 0, out var itemList, 0, out _) < 0) + { + Log.Warning("shell", $"Explorer could not show {full}"); + return; + } + try + { + // With no child items the absolute ID list names the item to select; Explorer opens its parent. + if (SHOpenFolderAndSelectItems(itemList, 0, 0, 0) < 0) Log.Warning("shell", $"Explorer could not show {full}"); + } + finally + { + Marshal.FreeCoTaskMem(itemList); + } + } + + [LibraryImport("shell32.dll", StringMarshalling = StringMarshalling.Utf16)] + private static partial int SHParseDisplayName(string name, nint bindContext, out nint itemIdList, uint attributesIn, out uint attributesOut); + + [LibraryImport("shell32.dll")] + private static partial int SHOpenFolderAndSelectItems(nint folder, uint count, nint items, uint flags); +} diff --git a/src/Chronos.Uploader/Shell/MainViewModel.cs b/src/Chronos.Uploader/Shell/MainViewModel.cs index 0dbdd83d..43aa2c0d 100644 --- a/src/Chronos.Uploader/Shell/MainViewModel.cs +++ b/src/Chronos.Uploader/Shell/MainViewModel.cs @@ -7,8 +7,10 @@ using System.Windows.Input; using System.Windows.Threading; using Chronos.Core.Diagnostics; using Chronos.Core.Localization; +using Chronos.Core.Updates; using Chronos.Ui.Controls; using Chronos.Ui.Mvvm; +using Chronos.Ui.Updates; using Chronos.Uploader.Infrastructure; using Chronos.Uploader.Server; using Chronos.Uploader.Sources; @@ -32,7 +34,11 @@ public sealed record UploaderServices( IUploaderDialogs Dialogs, WatchFolderService Watch, ProcessedFileMemory Memory, - string LogDirectory); + string LogDirectory) +{ + /// The update notice's network and shell; null never touches either (capture, tests). + public UpdateHost? Updates { get; init; } +} /// State of the uploader window (BRIEF §15, mockup Uploader.html). public sealed class MainViewModel : LocalizedViewModel @@ -65,6 +71,8 @@ public sealed class MainViewModel : LocalizedViewModel if (e.PropertyName == nameof(ConnectViewModel.IsSigningIn)) OnPropertyChanged(nameof(IsConnectVisible)); }; foreach (var w in services.Settings.WatchFolders) WatchFolders.Add(NewWatchFolder(w.Path, w.IntervalSeconds)); + Updates = new UpdatesViewModel(services.Updates ?? UploaderUpdates.Offline(UploaderUpdates.VersionText), services.Settings, services.SaveSettings); + Updates.Found += OnUpdateFound; OpenSettingsCommand = new RelayCommand(() => IsSettingsOpen = true); CloseSettingsCommand = new RelayCommand(() => IsSettingsOpen = false); @@ -105,6 +113,9 @@ public sealed class MainViewModel : LocalizedViewModel public ConnectViewModel Connect { get; } + /// The Updates row of the settings panel. + public UpdatesViewModel Updates { get; } + /// In-window notifications; the window forwards them to its . public ObservableCollection PendingToasts { get; } = []; @@ -416,6 +427,8 @@ public sealed class MainViewModel : LocalizedViewModel _s.Session.PropertyChanged -= OnSessionChanged; _s.Session.SessionEnded -= OnSessionEnded; _s.Engine.Drained -= OnDrained; + Updates.Found -= OnUpdateFound; + Updates.Dispose(); base.Dispose(); } @@ -592,6 +605,11 @@ public sealed class MainViewModel : LocalizedViewModel if (confirmed > 0) UploadsCompleted?.Invoke(confirmed); } + /// The start-up check found a newer release: one sentence, and Download as its action. + private void OnUpdateFound(ReleaseInfo release) => + ShowToast(Loc.L("Uploader.Updates.Available", UpdateCheck.Display(release.Version)), Loc.L("Uploader.Updates.Download"), + Updates.DownloadToolTip, Updates.DownloadCommand); + /// One sentence and at most one action; marks a failure or refusal, which screen readers say at once. private void ShowToast(string title, string? actionText = null, string? actionToolTip = null, ICommand? action = null, bool isError = false) => PendingToasts.Add(new Toast { Title = title, ActionText = actionText, ActionToolTip = actionToolTip, ActionCommand = action, IsError = isError }); diff --git a/src/Chronos.Uploader/Shell/MainWindow.xaml b/src/Chronos.Uploader/Shell/MainWindow.xaml index c4b92715..b2735e5d 100644 --- a/src/Chronos.Uploader/Shell/MainWindow.xaml +++ b/src/Chronos.Uploader/Shell/MainWindow.xaml @@ -471,6 +471,8 @@ + + @@ -501,6 +503,26 @@ ToolTip="{l:Loc Tooltips.Uploader.DeleteSource}" VerticalAlignment="Center"> + + + + + + + +