知了 Cicada · 任何会议和直播的实时字幕、同声传译、AI 会议纪要,Mac、Windows、Linux、Android 免费开源。Live subtitles, interpreting and meeting notes for any call or stream, on Mac, Windows, Linux and Android.
Swift androidlinuxlive-captionsmacosmeeting-notesmenubar-appsimultaneous-interpretationspeech-recognitionsubtitlesswiftswiftuitranslationwindows
feat(windows): Windows now shows a dot on the tray icon and a notification for a new version, and installs it in one click without a SmartScreen warning
wqugurua70eecbe0fbe
diff --git a/windows/src/Cicada.Core/Settings.cs b/windows/src/Cicada.Core/Settings.csindex b0b2786..bc58c5c 100644--- a/windows/src/Cicada.Core/Settings.cs+++ b/windows/src/Cicada.Core/Settings.cs@@ -44,6 +44,8 @@ public sealed class AppSettings[JsonPropertyName("silenceMinutes")] public double SilenceMinutes { get; set; } = 10;/// When GitHub Releases last answered an update check (UpdateChecker).[JsonPropertyName("updateLastChecked")] public DateTimeOffset? UpdateLastChecked { get; set; }+ /// The version the update notification was last shown for: one per version.+ [JsonPropertyName("updateNotified")] public string? UpdateNotified { get; set; }[JsonIgnore] public string TargetCode => Target == "system" ? Languages.FromSystem(CultureInfo.CurrentUICulture.Name) : Target;[JsonIgnore] public string NotesCode => NotesLanguage == "system" ? TargetCode : NotesLanguage;diff --git a/windows/src/Cicada.Core/UpdateChecker.cs b/windows/src/Cicada.Core/UpdateChecker.csindex 3e2a1a4..02b7022 100644--- a/windows/src/Cicada.Core/UpdateChecker.cs+++ b/windows/src/Cicada.Core/UpdateChecker.cs@@ -1,4 +1,5 @@using System.Runtime.InteropServices;+using System.Security.Cryptography;using System.Text.Json;using System.Text.Json.Serialization;@@ -12,8 +13,9 @@ namespace Cicada;/// when opened (older releases only have the zip).public sealed class UpdateChecker{- /// `Setup` is this PC's Cicada-Setup exe when the release has one; `Size` is the download's.- public sealed record Update(string Version, string Page, string? Zip, long Size, string? Setup = null)+ /// `Setup` is this PC's Cicada-Setup exe when the release has one; `Size` is the download's;+ /// `Checksums` the release's checksums.txt, which the in-app download is checked against.+ public sealed record Update(string Version, string Page, string? Zip, long Size, string? Setup = null, string? Checksums = null){public string? Download => Setup ?? Zip;}@@ -124,7 +126,8 @@ public sealed class UpdateCheckervar zip = r.Assets.FirstOrDefault(a => IsZip(a.Name, arch)) ?? (arch == "x64" ? null : r.Assets.FirstOrDefault(a => IsZip(a.Name, "x64")));var setup = r.Assets.FirstOrDefault(a => a.Name == SetupName(arch)) ?? (arch == "x64" ? null : r.Assets.FirstOrDefault(a => a.Name == SetupName("x64")));if (zip is null && setup is null) continue;- var u = new Update(r.TagName.TrimStart('v'), r.HtmlUrl, zip?.Url, (setup ?? zip)!.Size, setup?.Url);+ var sums = r.Assets.FirstOrDefault(a => a.Name == "checksums.txt");+ var u = new Update(r.TagName.TrimStart('v'), r.HtmlUrl, zip?.Url, (setup ?? zip)!.Size, setup?.Url, sums?.Url);if (best is null || IsNewer(u.Version, best.Version)) best = u;}return best;@@ -134,6 +137,88 @@ public sealed class UpdateChecker/// The installer's release asset: no version in the name, so the site's link never goes stale.public static string SetupName(string arch) => arch == "ARM64" ? "Cicada-Setup-arm64.exe" : "Cicada-Setup.exe";+ /// One notification per version (the version last told is kept in settings), and none while+ /// listening: the next stop tells. Full screen and screen sharing are Windows' Do Not Disturb.+ public static bool ShouldNotify(string version, string? notified, bool busy) => !busy && version != notified;++ /// The SHA-256 of `name` in a sha256sum listing ("<hex> <name>", or "<hex> *<name>").+ public static string? ChecksumFor(string text, string name)+ {+ foreach (var line in text.Split('\n'))+ {+ var parts = line.Trim().Split((char[]?)null, 2, StringSplitOptions.RemoveEmptyEntries);+ if (parts.Length == 2 && parts[1].TrimStart('*') == name) return parts[0].ToLowerInvariant();+ }+ return null;+ }++ /// Downloads the release's installer into a fresh temp folder and checks it against+ /// checksums.txt; returns its path. Fetched by the app, not the browser, the file carries no+ /// mark of the web, so SmartScreen doesn't stop the unsigned installer. Throws Failure (a+ /// string key) when there's nothing to install or the file doesn't match.+ public async Task<string> Download(Update u, Action<double>? progress = null)+ {+ if (u.Setup is null || u.Checksums is null) throw new Failure("这个版本没有可安装的文件");+ var name = Path.GetFileName(new Uri(u.Setup).LocalPath);+ var folder = Path.Combine(Path.GetTempPath(), $"CicadaUpdate-{u.Version}-{Guid.NewGuid():N}"[..40]);+ Directory.CreateDirectory(folder);+ var file = Path.Combine(folder, name);+ string? expected;+ try+ {+ expected = ChecksumFor(await Read(u.Checksums), name);+ await Fetch(u.Setup, file, u.Size, progress);+ }+ catch (Exception e) when (e is HttpRequestException or IOException or TaskCanceledException)+ {+ Log.Debug($"update: download failed {e.GetType().Name}");+ throw new Failure("下载失败");+ }+ string got;+ using (var f = File.OpenRead(file)) got = Convert.ToHexStringLower(await SHA256.HashDataAsync(f));+ if (expected is null || got != expected)+ {+ try { Directory.Delete(folder, true); } catch { }+ throw new Failure("下载的文件校验不通过");+ }+ Log.Debug($"update: downloaded {u.Version}, checksum ok");+ return file;+ }++ /// Removes installers left from earlier updates (each ~80 MB). Called at launch: by then the+ /// installer that ran has quit, or it's still letting go and the next launch gets it.+ public static void CleanDownloads(string? temp = null)+ {+ try+ {+ foreach (var d in Directory.GetDirectories(temp ?? Path.GetTempPath(), "CicadaUpdate-*"))+ try { Directory.Delete(d, true); } catch (Exception e) when (e is IOException or UnauthorizedAccessException) { }+ }+ catch (Exception e) when (e is IOException or UnauthorizedAccessException) { }+ }++ async Task Fetch(string url, string to, long expected, Action<double>? progress)+ {+ if (Uri.TryCreate(url, UriKind.Absolute, out var uri) && uri.IsFile) { File.Copy(uri.LocalPath, to, true); progress?.Invoke(1); return; }+ using var r = await http.GetAsync(url, HttpCompletionOption.ResponseHeadersRead);+ r.EnsureSuccessStatusCode();+ var total = r.Content.Headers.ContentLength ?? expected;+ await using var src = await r.Content.ReadAsStreamAsync();+ await using var dst = File.Create(to);+ var buffer = new byte[81920];+ long got = 0; int n, last = -1;+ while ((n = await src.ReadAsync(buffer)) > 0)+ {+ await dst.WriteAsync(buffer.AsMemory(0, n));+ got += n;+ // Whole percents only: each one re-renders the flyout and settings.+ if (total > 0 && (int)(got * 100 / total) is var pct && pct != last) { last = pct; progress?.Invoke(Math.Min(1, (double)got / total)); }+ }+ }++ /// Why installing didn't work: a shared string key, said to the user (the browser fallback opens).+ public sealed class Failure(string key) : Exception(key) { public string Key => Message; }+/// Dotted numeric versions: "2.10.0" is newer than "2.9.1".public static bool IsNewer(string a, string b){diff --git a/windows/src/Cicada/App.cs b/windows/src/Cicada/App.csindex 3e5d3d7..84cfff6 100644--- a/windows/src/Cicada/App.cs+++ b/windows/src/Cicada/App.cs@@ -76,6 +76,9 @@ sealed class Controllerstring? fakeMic;readonly Forms.NotifyIcon tray = new();System.Drawing.Icon? idleIcon, liveIcon;+ /// The installer's download progress (0…1) while an update is being fetched, and why the last one failed.+ public double? UpdateProgress { get; private set; }+ public string? UpdateFailure { get; private set; }Action? balloonClicked;Hotkey? hotkey;TrayFlyout? flyout;@@ -136,6 +139,7 @@ sealed class ControllerLog.Debug($"audio: speakers {Endpoints.Default(Endpoints.Flow.Render)?.Name ?? "none"}, mic {Endpoints.Microphone()?.Name ?? "none"}, cable {(Endpoints.Cable() is null ? "absent" : "present")}");DebugServer.Start(this);// A dev build isn't what a release replaces: it checks only when pointed at a test feed.+ UpdateChecker.CleanDownloads();if (!Paths.Dev || Environment.GetEnvironmentVariable("CICADA_UPDATE_FEED") is { Length: > 0 }) { checksUpdates = true; Updates.Start(); }var watch = new DispatcherTimer { Interval = TimeSpan.FromSeconds(2) };watch.Tick += (_, _) => _ = WatchEnd();@@ -174,7 +178,19 @@ sealed class Controller});/// Only update news re-renders settings: Changed fires on every line heard.- void UpdatesChanged() => Dispatch.BeginInvoke(() => { Changed(); settingsWindow?.UpdatesChanged(); });+ void UpdatesChanged() => Dispatch.BeginInvoke(() => { Changed(); settingsWindow?.UpdatesChanged(); NotifyUpdate(); });++ /// One Windows notification per version, for people who never open the tray panel; a click+ /// installs. Held while listening or speaking: StopListening tells.+ void NotifyUpdate()+ {+ if (Updates.Available is not { } u) return;+ if (!UpdateChecker.ShouldNotify(u.Version, Settings.UpdateNotified, Listen.Listening || Speak.State is not (SpeakEngine.Phase.Idle or SpeakEngine.Phase.Failed))) return;+ Settings.UpdateNotified = u.Version;+ Settings.Save();+ Toast(LF("知了有新版本 %@", u.Version), u.Setup is not null ? L("点按安装,完成后自动重新打开") : L("点按下载"), InstallUpdate);+ Log.Debug($"update: notified {u.Version}");+ }// MARK: Tray (the Mac's menu bar panel)@@ -224,8 +240,10 @@ sealed class Controllervoid UpdateTray(){- tray.Icon = Listen.Listening ? liveIcon : idleIcon;- tray.Text = Listen.Listening ? L("知了") + " · " + L("正在听") : L("知了");+ // The same orange dot says 正在听 or 有新版本 (the Mac's badge); listening wins.+ tray.Icon = Listen.Listening || Updates.Available is not null ? liveIcon : idleIcon;+ tray.Text = Listen.Listening ? L("知了") + " · " + L("正在听")+ : Updates.Available is { } u ? L("知了") + " · " + LF("有新版本 %@", u.Version) : L("知了");}public void ShowFlyout()@@ -259,7 +277,7 @@ sealed class Controllerelse menu.Items.Add(Item(L("开始听"), () => _ = ToggleListening(), Hotkey.Label.Replace('+', ' ')));menu.Items.Add(Settings.View == "subtitles" ? Item(L("换成纪要"), () => SetView("notes")) : Item(L("换成字幕条"), () => SetView("subtitles")));menu.Items.Add(new Separator());- if (Updates.Available is { } update) menu.Items.Add(Item(LF("有新版本 %@", update.Version), DownloadUpdate, ink: Palette.AccentText));+ if (Updates.Available is { } update) menu.Items.Add(Item(LF("有新版本 %@", update.Version), InstallUpdate, ink: Palette.AccentText));menu.Items.Add(Item(L("会议记录"), () => ShowRecords()));menu.Items.Add(Item(L("设置"), ShowSettings));menu.Items.Add(new Separator());@@ -329,6 +347,7 @@ sealed class ControllerAutoEnded = auto;await Listen.Stop(endedAt);Changed();+ NotifyUpdate(); // held while the meeting was onif (id is not null) _ = TellWhenNotesReady(id);}@@ -611,8 +630,34 @@ sealed class Controller// MARK: Updates- /// 下载: the browser fetches this PC's zip (or opens the release page when there is none).- /// Replacing the app in place comes later.+ /// 安装: Cicada downloads the installer itself and checks it against checksums.txt, then opens+ /// it; its 更新知了 window quits this copy, replaces it and reopens (--updated). A release with+ /// only the zip, or a failed download, falls back to the browser.+ public async void InstallUpdate()+ {+ if (Updates.Available is not { } u || UpdateProgress is not null) return;+ if (u.Setup is null) { DownloadUpdate(); return; }+ UpdateProgress = 0; UpdateFailure = null;+ UpdatesChanged();+ try+ {+ var exe = await Updates.Download(u, p => Dispatch.BeginInvoke(() => { UpdateProgress = p; UpdatesChanged(); }));+ UpdateProgress = null;+ UpdatesChanged();+ Log.Debug($"update: opening the installer for {u.Version}");+ System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(exe) { UseShellExecute = true });+ }+ catch (Exception e)+ {+ UpdateProgress = null;+ UpdateFailure = e is UpdateChecker.Failure f ? L(f.Key) : L("更新包无效");+ Log.Debug($"update: in-app install failed ({e.GetType().Name}), opening the download");+ UpdatesChanged();+ DownloadUpdate();+ }+ }++ /// 下载: the browser fetches this PC's installer or zip (or opens the release page when there is none).public void DownloadUpdate(){if (Updates.Available is not { } u) return;@@ -786,6 +831,7 @@ static class DebugServercase "endkeep": app.KeepRecording(); break;case "quit": _ = app.Quit(); break;case "updatefeed": app.Updates.Feed = arg; _ = app.CheckForUpdates(); break;+ case "updateinstall": app.InstallUpdate(); break;case "checkupdate": _ = app.CheckForUpdates(); break;case "state": break;default: return new JsonObject { ["error"] = $"unknown command {parts[0]}" };diff --git a/windows/src/Cicada/SettingsWindow.cs b/windows/src/Cicada/SettingsWindow.csindex 8983946..470d208 100644--- a/windows/src/Cicada/SettingsWindow.cs+++ b/windows/src/Cicada/SettingsWindow.cs@@ -83,7 +83,7 @@ sealed class SettingsWindow : Windowstring? shownPage;/// What to do with the download: the installer upgrades itself; an older release has only the zip.- public static string UpdateHint(UpdateChecker.Update u) => u.Setup is not null ? L("下载后打开,知了会自己更新") : L("下载后解压,替换旧的知了");+ public static string UpdateHint(UpdateChecker.Update u) => u.Setup is not null ? L("安装后自动重新打开") : L("下载后解压,替换旧的知了");static FrameworkElement Credit() { var t = Ui.Helper(L("说话人识别用 WeSpeaker 的声纹模型(CC BY 4.0)")); t.Margin = new Thickness(6, 0, 0, 0); return t; }@@ -96,7 +96,10 @@ sealed class SettingsWindow : Window// The Mac's AppRows version row: what the last check found, and 检查更新 or 下载.string? UpdateDetail(){- if (app.Updates.Available is { } u) return LF("有新版本 %@", u.Version) + " · " + UpdateHint(u);+ if (app.Updates.Available is { } u)+ return app.UpdateProgress is { } p ? LF("正在下载 %@:%lld%%", u.Version, (long)(p * 100))+ : app.UpdateFailure is { } f ? LF("没能自动更新:%@", f)+ : LF("有新版本 %@", u.Version) + " · " + UpdateHint(u);if (app.UpdateCheck is { } c) return c;if (app.Updates.LastChecked is not { } d) return null;var local = d.ToLocalTime();@@ -106,7 +109,11 @@ sealed class SettingsWindow : WindowFrameworkElement UpdateControl(){if (app.Updates.Available is not null)- return Ui.Row(12, Ui.LinkText(L("更新说明"), app.OpenReleaseNotes), Ui.Button(L("下载"), app.DownloadUpdate, Ui.Kind.Primary, height: 32));+ {+ var install = Ui.Button(app.Updates.Available.Setup is null ? L("下载") : L("安装并重新打开"), app.InstallUpdate, Ui.Kind.Primary, height: 32);+ install.IsEnabled = app.UpdateProgress is null;+ return Ui.Row(12, Ui.LinkText(L("更新说明"), app.OpenReleaseNotes), install);+ }var check = Ui.Button(L("检查更新"), () => _ = app.CheckForUpdates(), height: 32);check.IsEnabled = app.UpdateCheck != L("正在检查…");return check;diff --git a/windows/src/Cicada/Strings/en.lproj/Windows.strings b/windows/src/Cicada/Strings/en.lproj/Windows.stringsindex 62ff727..1b6315f 100644--- a/windows/src/Cicada/Strings/en.lproj/Windows.strings+++ b/windows/src/Cicada/Strings/en.lproj/Windows.strings@@ -220,7 +220,6 @@"复制知了" = "Copy Cicada";"在开始菜单里放入口" = "Add it to the Start menu";"登记到“设置 › 应用”,以后从那里卸载" = "Add it to Settings › Apps, to uninstall from there";-"下载后打开,知了会自己更新" = "Open it and Cicada updates itself";"还差 %@ 步就能用" = "Almost ready: %@ to go";"知了把电脑里放出来的会议声音变成字幕和纪要。" = "Cicada turns the meeting audio your PC plays into subtitles and notes.";"key 已加密存在这台电脑上" = "Your key is encrypted on this PC";@@ -246,3 +245,4 @@"第 4 步再用" = "Used in step 4";"对方听到译文" = "They hear the translation";"会议里对方说的话从电脑扬声器放出来,字幕和纪要都从这里来。Windows 上不用授权。" = "What others say in a meeting comes out of your PC's speakers. Subtitles and notes come from there. No permission needed on Windows.";+"点按下载" = "Click to download.";diff --git a/windows/src/Cicada/Strings/ja.lproj/Windows.strings b/windows/src/Cicada/Strings/ja.lproj/Windows.stringsindex 5180127..d7eddc0 100644--- a/windows/src/Cicada/Strings/ja.lproj/Windows.strings+++ b/windows/src/Cicada/Strings/ja.lproj/Windows.strings@@ -220,7 +220,6 @@"复制知了" = "Cicada をコピー";"在开始菜单里放入口" = "スタートメニューに追加";"登记到“设置 › 应用”,以后从那里卸载" = "「設定 › アプリ」に登録(ここからアンインストールできます)";-"下载后打开,知了会自己更新" = "開くと Cicada が自動で更新します";"还差 %@ 步就能用" = "あと %@ ステップで使えます";"知了把电脑里放出来的会议声音变成字幕和纪要。" = "Cicada は PC から流れる会議の音声を字幕とメモにします。";"key 已加密存在这台电脑上" = "キーはこの PC に暗号化して保存されています";@@ -246,3 +245,4 @@"第 4 步再用" = "ステップ 4 で使います";"对方听到译文" = "相手に翻訳が届く";"会议里对方说的话从电脑扬声器放出来,字幕和纪要都从这里来。Windows 上不用授权。" = "会議で相手が話す声は PC のスピーカーから流れます。字幕とメモはそこから作られます。Windows では許可は不要です。";+"点按下载" = "クリックでダウンロード";diff --git a/windows/src/Cicada/Strings/ko.lproj/Windows.strings b/windows/src/Cicada/Strings/ko.lproj/Windows.stringsindex 76ad79a..018c5dc 100644--- a/windows/src/Cicada/Strings/ko.lproj/Windows.strings+++ b/windows/src/Cicada/Strings/ko.lproj/Windows.strings@@ -220,7 +220,6 @@"复制知了" = "Cicada 복사";"在开始菜单里放入口" = "시작 메뉴에 추가";"登记到“设置 › 应用”,以后从那里卸载" = "설정 › 앱에 등록 (여기서 제거할 수 있어요)";-"下载后打开,知了会自己更新" = "열면 Cicada가 스스로 업데이트해요";"还差 %@ 步就能用" = "%@단계만 더 하면 돼요";"知了把电脑里放出来的会议声音变成字幕和纪要。" = "Cicada는 PC에서 나오는 회의 소리를 자막과 회의록으로 바꿔요.";"key 已加密存在这台电脑上" = "키는 이 PC에 암호화되어 저장돼요";@@ -246,3 +245,4 @@"第 4 步再用" = "4단계에서 사용";"对方听到译文" = "상대가 번역을 들어요";"会议里对方说的话从电脑扬声器放出来,字幕和纪要都从这里来。Windows 上不用授权。" = "회의에서 상대가 하는 말은 PC 스피커로 나와요. 자막과 회의록은 여기서 만들어져요. Windows에서는 권한이 필요 없어요.";+"点按下载" = "클릭하면 다운로드합니다";diff --git a/windows/src/Cicada/TrayFlyout.cs b/windows/src/Cicada/TrayFlyout.csindex 1450d25..59785b0 100644--- a/windows/src/Cicada/TrayFlyout.cs+++ b/windows/src/Cicada/TrayFlyout.cs@@ -76,14 +76,19 @@ sealed class TrayFlyout : Windowvar head = Ui.Spread(title, Ui.IconButton(Icons.Gear, L("打开设置"), () => Do(app.ShowSettings), Palette.Body, 36, 18));stack.Children.Add(head);- // A newer release (the Mac's UpdateBanner): the browser downloads this PC's zip.+ // A newer release (the Mac's UpdateBanner), right under the header: Cicada downloads the+ // installer, checks it and opens it.if (app.Updates.Available is { } update){var size = update.Size > 0 ? $"{update.Size / 1_048_576.0:0} MB · " : "";+ var detail = app.UpdateProgress is { } p0 ? LF("正在下载 %@:%lld%%", update.Version, (long)(p0 * 100))+ : app.UpdateFailure is { } f ? LF("没能自动更新:%@。已打开下载页", f)+ : size + SettingsWindow.UpdateHint(update);var text = Ui.Stack(2, Ui.Text(LF("新版本 %@", update.Version), 13, Palette.Ink, Palette.Strong, wrap: false),- Ui.Text(size + SettingsWindow.UpdateHint(update), 11, Palette.Secondary),+ Ui.Text(detail, 11, Palette.Secondary),Ui.LinkText(L("更新说明"), () => Do(app.OpenReleaseNotes), 11));- var download = Ui.Button(L("下载"), () => Do(app.DownloadUpdate), Ui.Kind.Standard, height: 30);+ var download = Ui.Button(update.Setup is null ? L("下载") : app.UpdateFailure is null ? L("安装") : L("重试"), app.InstallUpdate, Ui.Kind.Primary, height: 30);+ download.IsEnabled = app.UpdateProgress is null;var dock = new DockPanel();DockPanel.SetDock(download, Dock.Right);download.VerticalAlignment = VerticalAlignment.Center; download.Margin = new Thickness(10, 0, 0, 0);diff --git a/windows/tests/Cicada.Tests/Program.cs b/windows/tests/Cicada.Tests/Program.csindex 3079d6a..78092b6 100644--- a/windows/tests/Cicada.Tests/Program.cs+++ b/windows/tests/Cicada.Tests/Program.cs@@ -890,6 +890,38 @@ static class TestsCheck(!UpdateChecker.IsNewer("1.3.9", "1.4.0"), "older");}+ public static void UpdateNotifiesOncePerVersionWhenIdle()+ {+ Check(UpdateChecker.ShouldNotify("1.1.0", null, false), "first time");+ Check(UpdateChecker.ShouldNotify("1.2.0", "1.1.0", false), "a newer version");+ Check(!UpdateChecker.ShouldNotify("1.1.0", "1.1.0", false), "already told");+ Check(!UpdateChecker.ShouldNotify("1.1.0", null, true), "held while listening");+ Equal("ab12", UpdateChecker.ChecksumFor("ff00 Cicada-1.1.0-Windows-x64.zip\nAB12 *Cicada-Setup.exe\n", "Cicada-Setup.exe"), "sha256sum line");+ Equal(null, UpdateChecker.ChecksumFor("ff00 Cicada-Setup-arm64.exe", "Cicada-Setup.exe"), "other file");+ }++ /// The in-app download: the installer is kept only when it matches checksums.txt.+ public static async Task UpdateDownloadChecksTheInstaller()+ {+ var dir = Directory.CreateTempSubdirectory("cicada-upd-").FullName;+ var exe = Path.Combine(dir, "Cicada-Setup.exe");+ File.WriteAllText(exe, "installer");+ var sha = Convert.ToHexStringLower(System.Security.Cryptography.SHA256.HashData(File.ReadAllBytes(exe)));+ File.WriteAllText(Path.Combine(dir, "checksums.txt"), $"{sha} Cicada-Setup.exe\n");+ File.WriteAllText(Path.Combine(dir, "bad.txt"), "0000 Cicada-Setup.exe\n");+ var checker = new UpdateChecker(null, _ => { });+ var u = new UpdateChecker.Update("1.1.0", "https://example.com", null, 9, new Uri(exe).AbsoluteUri, new Uri(Path.Combine(dir, "checksums.txt")).AbsoluteUri);+ var got = await checker.Download(u);+ Equal("installer", File.ReadAllText(got), "downloaded copy");+ Check(got != exe && Path.GetFileName(got) == "Cicada-Setup.exe", "into its own folder, same name");+ try { await checker.Download(u with { Checksums = new Uri(Path.Combine(dir, "bad.txt")).AbsoluteUri }); throw new Exception("bad checksum accepted"); }+ catch (UpdateChecker.Failure f) { Equal("下载的文件校验不通过", f.Key, "bad checksum refused"); }+ try { await checker.Download(u with { Setup = null }); throw new Exception("zip-only accepted"); }+ catch (UpdateChecker.Failure f) { Equal("这个版本没有可安装的文件", f.Key, "nothing to install"); }+ UpdateChecker.CleanDownloads(Path.GetDirectoryName(Path.GetDirectoryName(got)));+ Check(!File.Exists(got), "left-over installer removed");+ }+public static void UpdateSkipsReleasesWithoutAWindowsZip(){var list = UpdateChecker.Decode($"[{Rel("v1.6.0", "Cicada-1.6.0-macOS-AppleSilicon.zip")},{Rel("v1.5.0", "Cicada-1.5.0-Windows-x64.zip", "Cicada-1.5.0-Windows-ARM64.zip")}]")!;