Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

### Added
- **Automatic update checks and one-click updates.** FanaBridge now checks GitHub for new releases and offers to install them, with a restart of SimHub to finish. Can be turned off in About. ([#96](https://github.com/kelchm/FanaBridge/pull/96), closes [#95](https://github.com/kelchm/FanaBridge/issues/95))
- **A wheel's segment display can now be left to another application.** Display Mode "None" stops FanaBridge writing to it, so Fanatec's own software can drive the display while FanaBridge keeps the LEDs. The option previously existed only for the legacy page of ITM wheels. ([#97](https://github.com/kelchm/FanaBridge/pull/97))

### Fixed
Expand Down
6 changes: 3 additions & 3 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
<Target Name="CopyToSimHub" AfterTargets="Build" DependsOnTargets="MergePlugin"
Condition="'$(IsSimHubPlugin)' == 'true' and '$(InstallToSimHub)' == 'true'">
<Copy SourceFiles="$(TargetDir)merged\$(TargetFileName)" DestinationFolder="$(SimHubDir)" SkipUnchangedFiles="true" />
<!-- Clean up a satellite left by an earlier two-DLL dev install; the
merged plugin no longer references it, so a stale copy is inert but
<!-- Clean up satellites left by an earlier multi-DLL dev install; the
merged plugin no longer references them, so a stale copy is inert but
confusing. -->
<Delete Files="$(SimHubDir)FanaBridge.Core.dll" ContinueOnError="true" />
<Delete Files="$(SimHubDir)FanaBridge.Core.dll;$(SimHubDir)FanaBridge.Updater.dll" ContinueOnError="true" />
<Message Importance="high" Text="Installed $(TargetFileName) (merged) → $(SimHubDir)" />
</Target>

Expand Down
15 changes: 15 additions & 0 deletions FanaBridge.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FanaBridge", "src\FanaBridg
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FanaBridge.Core", "src\FanaBridge.Core\FanaBridge.Core.csproj", "{C7D9EB13-5A46-6180-BC2D-3E4F5A6B7C8D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FanaBridge.Updater", "src\FanaBridge.Updater\FanaBridge.Updater.csproj", "{E8F1AC35-7D68-4A02-9E5F-6B7C8D9EAF01}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FanaBridge.Tests", "tests\FanaBridge.Tests\FanaBridge.Tests.csproj", "{59946302-1B57-4599-BFF0-94607AF98C6E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{A5B7C9D1-3E24-4F68-9A0B-1C2D3E4F5A6B}"
Expand Down Expand Up @@ -47,6 +49,18 @@ Global
{C7D9EB13-5A46-6180-BC2D-3E4F5A6B7C8D}.Release|x64.Build.0 = Release|Any CPU
{C7D9EB13-5A46-6180-BC2D-3E4F5A6B7C8D}.Release|x86.ActiveCfg = Release|Any CPU
{C7D9EB13-5A46-6180-BC2D-3E4F5A6B7C8D}.Release|x86.Build.0 = Release|Any CPU
{E8F1AC35-7D68-4A02-9E5F-6B7C8D9EAF01}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E8F1AC35-7D68-4A02-9E5F-6B7C8D9EAF01}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E8F1AC35-7D68-4A02-9E5F-6B7C8D9EAF01}.Debug|x64.ActiveCfg = Debug|Any CPU
{E8F1AC35-7D68-4A02-9E5F-6B7C8D9EAF01}.Debug|x64.Build.0 = Debug|Any CPU
{E8F1AC35-7D68-4A02-9E5F-6B7C8D9EAF01}.Debug|x86.ActiveCfg = Debug|Any CPU
{E8F1AC35-7D68-4A02-9E5F-6B7C8D9EAF01}.Debug|x86.Build.0 = Debug|Any CPU
{E8F1AC35-7D68-4A02-9E5F-6B7C8D9EAF01}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E8F1AC35-7D68-4A02-9E5F-6B7C8D9EAF01}.Release|Any CPU.Build.0 = Release|Any CPU
{E8F1AC35-7D68-4A02-9E5F-6B7C8D9EAF01}.Release|x64.ActiveCfg = Release|Any CPU
{E8F1AC35-7D68-4A02-9E5F-6B7C8D9EAF01}.Release|x64.Build.0 = Release|Any CPU
{E8F1AC35-7D68-4A02-9E5F-6B7C8D9EAF01}.Release|x86.ActiveCfg = Release|Any CPU
{E8F1AC35-7D68-4A02-9E5F-6B7C8D9EAF01}.Release|x86.Build.0 = Release|Any CPU
{59946302-1B57-4599-BFF0-94607AF98C6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{59946302-1B57-4599-BFF0-94607AF98C6E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{59946302-1B57-4599-BFF0-94607AF98C6E}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand All @@ -66,6 +80,7 @@ Global
GlobalSection(NestedProjects) = preSolution
{77D40755-B5B5-4C53-BD35-1CDEF35AF422} = {A5B7C9D1-3E24-4F68-9A0B-1C2D3E4F5A6B}
{C7D9EB13-5A46-6180-BC2D-3E4F5A6B7C8D} = {A5B7C9D1-3E24-4F68-9A0B-1C2D3E4F5A6B}
{E8F1AC35-7D68-4A02-9E5F-6B7C8D9EAF01} = {A5B7C9D1-3E24-4F68-9A0B-1C2D3E4F5A6B}
{59946302-1B57-4599-BFF0-94607AF98C6E} = {B6C8DA02-4F35-5079-AB1C-2D3E4F5A6B7C}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
Expand Down
40 changes: 40 additions & 0 deletions src/FanaBridge.Updater/FanaBridge.Updater.csproj
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>
203 changes: 203 additions & 0 deletions src/FanaBridge.Updater/ReleaseFeed.cs
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;
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

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);
}
}
}
Loading
Loading