Skip to content
Draft
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
6 changes: 6 additions & 0 deletions TarkovMonitor/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@
<setting name="floatingTimerPanelShowRunThrough" serializeAs="String">
<value>True</value>
</setting>
<setting name="lastSeenReleaseTag" serializeAs="String">
<value />
</setting>
<setting name="lastSeenReleaseAssetUpdatedAt" serializeAs="String">
<value />
</setting>
</TarkovMonitor.Properties.Settings>
</userSettings>
</configuration>
24 changes: 24 additions & 0 deletions TarkovMonitor/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions TarkovMonitor/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,11 @@
<Setting Name="floatingTimerPanelShowRunThrough" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="lastSeenReleaseTag" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="lastSeenReleaseAssetUpdatedAt" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
</Settings>
</SettingsFile>
31 changes: 29 additions & 2 deletions TarkovMonitor/UpdateCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ internal interface IGitHubAPI
}

private static readonly string repo = "the-hideout/TarkovMonitor";
private static readonly string releaseAssetName = "TarkovMonitor.zip";
private static readonly System.Timers.Timer updateCheckTimer;

private static readonly IGitHubAPI api = RestService.For<IGitHubAPI>($"https://api.github.com/repos/{repo}");
Expand Down Expand Up @@ -41,9 +42,28 @@ public static async void CheckForNewVersion()
var release = await api.GetLatestRelease();
Version remoteVersion = new Version(release.tag_name);
Version localVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version ?? throw new Exception("Could not retrieve version from assembly");
//System.Diagnostics.Debug.WriteLine(localVersion.ToString());
string assetUpdatedAt = release.assets?.FirstOrDefault(asset => asset.name == releaseAssetName)?.updated_at ?? "";

if (localVersion.CompareTo(remoteVersion) == -1)
var settings = Properties.Settings.Default;
// An absent asset timestamp carries no information, so it must never read as a change.
bool assetUpdatedAtKnown = assetUpdatedAt != "";
bool sameReleaseAsLastCheck = settings.lastSeenReleaseTag == release.tag_name;
bool assetUpdatedAtChanged = assetUpdatedAtKnown && settings.lastSeenReleaseAssetUpdatedAt != assetUpdatedAt;

// Remember what the latest release looked like, so replacing its asset later is detectable.
if (assetUpdatedAtKnown && (!sameReleaseAsLastCheck || assetUpdatedAtChanged))
{
settings.lastSeenReleaseTag = release.tag_name;
settings.lastSeenReleaseAssetUpdatedAt = assetUpdatedAt;
settings.Save();
}

// The download can be re-uploaded in place (a hotfix published under the same tag),
// which leaves the version unchanged; a changed asset timestamp means the build we
// are running was replaced. Only notified once, since there is nothing left to compare.
bool runningBuildWasReplaced = sameReleaseAsLastCheck && assetUpdatedAtChanged && localVersion == remoteVersion;

if (localVersion < remoteVersion || runningBuildWasReplaced)
{
NewVersion?.Invoke(null, new() { Version = remoteVersion, Uri = new(release.html_url) });
}
Expand All @@ -62,6 +82,13 @@ public class ReleaseData
{
public string tag_name { get; set; }
public string html_url { get; set; }
public List<ReleaseAsset>? assets { get; set; }
}

public class ReleaseAsset
{
public string? name { get; set; }
public string? updated_at { get; set; }
}
}

Expand Down
Loading