-
Notifications
You must be signed in to change notification settings - Fork 7
Add self-updater: in-app update check and one-click updates #96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ae7d963
Add self-updater: release check, digest-verified one-click update (#95)
kelchm a7898fb
Harden self-updater per adversarial review
kelchm 954cda8
Address PR review feedback
kelchm 92effa7
Merge branch 'main' into feat/self-updater
kelchm bb46dcc
Address PR review feedback (round 2)
kelchm 3303bbe
Rework the update banner layout
kelchm 15cece6
Re-check for updates daily while SimHub runs
kelchm e782066
Tighten update UI copy
kelchm 1b6811e
Move the update banner into the About section
kelchm bd97a6e
Two-column top row: DEVICE STATUS and ABOUT side by side
kelchm a39e121
Changelog: automatic update checks and one-click updates
kelchm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net48</TargetFramework> | ||
| <OutputType>Library</OutputType> | ||
| <RootNamespace>FanaBridge.Updater</RootNamespace> | ||
| <AssemblyName>FanaBridge.Updater</AssemblyName> | ||
| <Description>FanaBridge self-updater (SimHub-free): release feed, download verification, in-place file swap</Description> | ||
| <Product>FanaBridge</Product> | ||
| <Copyright>Copyright (c) 2026</Copyright> | ||
| <GenerateAssemblyInfo>true</GenerateAssemblyInfo> | ||
| <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath> | ||
| <DebugType>embedded</DebugType> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <!-- Provides .NET Framework 4.8 reference assemblies for builds without VS --> | ||
| <PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" PrivateAssets="all" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <!-- Resolved from the SimHub install so runtime assembly identities match | ||
| the ones SimHub loads; never copied (SimHub ships it). Newtonsoft is | ||
| the updater's only external reference — no SimHub.* assemblies and no | ||
| FanaBridge.Core, by design: this project is an isolated audit boundary | ||
| for the code that downloads releases and rewrites files next to | ||
| SimHub.exe. --> | ||
| <Reference Include="Newtonsoft.Json"> | ||
| <HintPath>$(SimHubDir)Newtonsoft.Json.dll</HintPath> | ||
| <Private>false</Private> | ||
| </Reference> | ||
| <!-- Framework assembly (zip extraction); not an external dependency. --> | ||
| <Reference Include="System.IO.Compression" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <InternalsVisibleTo Include="FanaBridge.Tests" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,203 @@ | ||
| #nullable enable | ||
| using System; | ||
| using System.Text.RegularExpressions; | ||
| using Newtonsoft.Json.Linq; | ||
|
|
||
| namespace FanaBridge.Updater | ||
| { | ||
| /// <summary> | ||
| /// Parsed GitHub release metadata used by the self-updater. A release can be | ||
| /// reportable to the user even when it cannot be self-installed (missing zip asset | ||
| /// or digest → notify-only with a manual download link). | ||
| /// </summary> | ||
| public sealed class ReleaseInfo | ||
| { | ||
| /// <summary>GitHub tag name, e.g. <c>v0.7.0</c>.</summary> | ||
| public string TagName { get; } | ||
|
|
||
| /// <summary>Version string with a leading <c>v</c>/<c>V</c> stripped, e.g. <c>0.7.0</c>.</summary> | ||
| public string Version { get; } | ||
|
|
||
| /// <summary>HTML URL of the release page (manual download fallback).</summary> | ||
| public string HtmlUrl { get; } | ||
|
|
||
| /// <summary>Exact zip asset name when found, otherwise null.</summary> | ||
| public string? ZipName { get; } | ||
|
|
||
| /// <summary>browser_download_url of the zip asset when found.</summary> | ||
| public string? ZipUrl { get; } | ||
|
|
||
| /// <summary>Asset size in bytes from the API, or 0 when unknown.</summary> | ||
| public long ZipSizeBytes { get; } | ||
|
|
||
| /// <summary> | ||
| /// 64 lowercase hex characters of the asset's GitHub <c>digest</c> field, | ||
| /// without the <c>sha256:</c> prefix; null when missing or malformed. | ||
| /// </summary> | ||
| public string? DigestHex { get; } | ||
|
|
||
| /// <summary>True when zip URL and a valid digest are both present for self-install.</summary> | ||
| public bool CanSelfInstall { get; } | ||
|
|
||
| /// <summary>Human-readable reason when <see cref="CanSelfInstall"/> is false; null otherwise.</summary> | ||
| public string? InstallBlockedReason { get; } | ||
|
|
||
| /// <summary>Creates an immutable release snapshot.</summary> | ||
| public ReleaseInfo( | ||
| string tagName, | ||
| string version, | ||
| string htmlUrl, | ||
| string? zipName, | ||
| string? zipUrl, | ||
| long zipSizeBytes, | ||
| string? digestHex, | ||
| bool canSelfInstall, | ||
| string? installBlockedReason) | ||
| { | ||
| TagName = tagName ?? throw new ArgumentNullException(nameof(tagName)); | ||
| Version = version ?? throw new ArgumentNullException(nameof(version)); | ||
| HtmlUrl = htmlUrl ?? throw new ArgumentNullException(nameof(htmlUrl)); | ||
| ZipName = zipName; | ||
| ZipUrl = zipUrl; | ||
| ZipSizeBytes = zipSizeBytes; | ||
| DigestHex = digestHex; | ||
| CanSelfInstall = canSelfInstall; | ||
| InstallBlockedReason = installBlockedReason; | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Parses GitHub Releases API JSON into <see cref="ReleaseInfo"/>. | ||
| /// Note: GET /repos/{owner}/{repo}/releases/latest excludes drafts and prereleases | ||
| /// by GitHub semantics — that is intentional for the self-updater feed. | ||
| /// </summary> | ||
| public static class ReleaseFeed | ||
| { | ||
| // GitHub asset digests are "sha256:" + 64 hex digits (immutable upload-time hash). | ||
| private static readonly Regex DigestPattern = | ||
| new Regex(@"^sha256:([0-9a-fA-F]{64})$", RegexOptions.CultureInvariant | RegexOptions.Compiled); | ||
|
|
||
| /// <summary> | ||
| /// Parses a GET /repos/{owner}/{repo}/releases/latest response body. | ||
| /// Returns null with a non-null error ONLY for structurally unusable | ||
| /// responses (malformed JSON, missing/unparseable tag_name, missing html_url). | ||
| /// A parseable release with a missing/ambiguous zip asset or a missing/ | ||
| /// malformed digest returns a <see cref="ReleaseInfo"/> with | ||
| /// <see cref="ReleaseInfo.CanSelfInstall"/>=false and a human-readable | ||
| /// <see cref="ReleaseInfo.InstallBlockedReason"/> (notify-only mode), NOT an error. | ||
| /// </summary> | ||
| public static ReleaseInfo? Parse(string json, out string? error) | ||
| { | ||
| error = null; | ||
| if (string.IsNullOrWhiteSpace(json)) | ||
| { | ||
| error = "Release feed response is empty."; | ||
| return null; | ||
| } | ||
|
|
||
| JObject root; | ||
| try | ||
| { | ||
| root = JObject.Parse(json); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| error = "Release feed JSON is malformed: " + ex.Message; | ||
| return null; | ||
| } | ||
|
|
||
| string? tagName = root.Value<string>("tag_name"); | ||
| if (string.IsNullOrWhiteSpace(tagName)) | ||
| { | ||
| error = "Release feed is missing tag_name."; | ||
| return null; | ||
| } | ||
|
|
||
| // Normalize before deriving anything: stray whitespace would poison | ||
| // the asset-name match and the UI version string, while TryParse | ||
| // (which trims internally) would still succeed. | ||
| tagName = tagName!.Trim(); | ||
|
|
||
| // Version string for the UI/asset name: strip a single leading v/V only. | ||
| string version = tagName; | ||
| if (version.Length > 0 && (version[0] == 'v' || version[0] == 'V')) | ||
| version = version.Substring(1); | ||
|
|
||
| if (!UpdateVersion.TryParse(tagName, out _)) | ||
| { | ||
| error = "Release feed tag_name is not a parseable version: " + tagName; | ||
| return null; | ||
| } | ||
|
|
||
| string? htmlUrl = root.Value<string>("html_url"); | ||
| if (string.IsNullOrWhiteSpace(htmlUrl)) | ||
| { | ||
| error = "Release feed is missing html_url."; | ||
| return null; | ||
| } | ||
|
|
||
| string expectedZip = "FanaBridge-" + version + ".zip"; | ||
| string? zipName = null; | ||
| string? zipUrl = null; | ||
| long zipSize = 0; | ||
| string? digestRaw = null; | ||
|
|
||
| JToken? assetsToken = root["assets"]; | ||
| if (assetsToken is JArray assets) | ||
| { | ||
| foreach (JToken asset in assets) | ||
| { | ||
| if (asset is not JObject ao) | ||
| continue; | ||
| string? name = ao.Value<string>("name"); | ||
| // Exact asset name — GitHub enforces unique names per release. | ||
| if (!string.Equals(name, expectedZip, StringComparison.Ordinal)) | ||
| continue; | ||
|
|
||
| zipName = name; | ||
| zipUrl = ao.Value<string>("browser_download_url"); | ||
| // Defensive: a non-numeric "size" must degrade to unknown, not | ||
| // throw out of the parse contract. | ||
| JToken? sizeToken = ao["size"]; | ||
| zipSize = sizeToken != null && sizeToken.Type == JTokenType.Integer | ||
| ? (long)sizeToken | ||
| : 0; | ||
| digestRaw = ao.Value<string>("digest"); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| string? digestHex = null; | ||
| string? blocked = null; | ||
|
|
||
| if (zipName == null || string.IsNullOrWhiteSpace(zipUrl)) | ||
| { | ||
| blocked = "Release asset '" + expectedZip + "' was not found; open the release page to install manually."; | ||
| } | ||
| else | ||
| { | ||
| Match m = DigestPattern.Match(digestRaw ?? string.Empty); | ||
| if (!m.Success) | ||
| { | ||
| blocked = "Release asset digest is missing or malformed; open the release page to install manually."; | ||
| } | ||
| else | ||
| { | ||
| digestHex = m.Groups[1].Value.ToLowerInvariant(); | ||
| } | ||
| } | ||
|
|
||
| bool canInstall = blocked == null && digestHex != null && !string.IsNullOrWhiteSpace(zipUrl); | ||
| return new ReleaseInfo( | ||
| tagName: tagName, | ||
| version: version, | ||
| htmlUrl: htmlUrl!, | ||
| zipName: zipName, | ||
| zipUrl: zipUrl, | ||
| zipSizeBytes: zipSize, | ||
| digestHex: digestHex, | ||
| canSelfInstall: canInstall, | ||
| installBlockedReason: canInstall ? null : blocked); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.