Implement file version checking for updater (#499)

* Implement file version checking for updater

* Increment version
This commit is contained in:
2023-11-23 18:17:58 +01:00
committed by GitHub
parent 9fe4be0467
commit f788a10879
5 changed files with 42 additions and 8 deletions
@@ -52,5 +52,5 @@ public sealed class LauncherOptions
[JsonProperty(nameof(BetaUpdate))]
[OptionName(Name = "Beta Update", Description = "If true, the launcher will use the new update procedure")]
public bool BetaUpdate { get; set; } = true;
public bool BetaUpdate { get; set; } = false;
}
+1 -1
View File
@@ -12,7 +12,7 @@
<LangVersion>preview</LangVersion>
<ApplicationIcon>Daybreak.ico</ApplicationIcon>
<IncludePackageReferencesDuringMarkupCompilation>true</IncludePackageReferencesDuringMarkupCompilation>
<Version>0.9.8.154</Version>
<Version>0.9.8.155</Version>
<EnableWindowsTargeting>true</EnableWindowsTargeting>
<UserSecretsId>cfb2a489-db80-448d-a969-80270f314c46</UserSecretsId>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
@@ -4,15 +4,12 @@ using Daybreak.Models.Github;
using Daybreak.Models.Progress;
using Daybreak.Services.Downloads;
using Daybreak.Services.Notifications;
using Daybreak.Services.Privilege;
using Daybreak.Services.Registry;
using Daybreak.Services.Updater.Models;
using Daybreak.Services.Updater.PostUpdate;
using Daybreak.Views;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Core.Extensions;
using System.Diagnostics;
@@ -22,11 +19,9 @@ using System.Linq;
using System.Net.Http;
using System.Net.Http.Json;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using static Daybreak.Utils.NativeMethods;
using Version = Daybreak.Models.Versioning.Version;
namespace Daybreak.Services.Updater;
@@ -212,7 +207,41 @@ internal sealed class ApplicationUpdater : IApplicationUpdater
.Where(m =>
{
var fileInfo = new FileInfo(m.RelativePath!);
return !fileInfo.Exists || fileInfo.Length != m.Size;
if (!fileInfo.Exists)
{
return true;
}
if (fileInfo.Length != m.Size)
{
return true;
}
try
{
var info = FileVersionInfo.GetVersionInfo(fileInfo.FullName);
if (info is null && m.VersionInfo is null)
{
return false;
}
if (info is null && m.VersionInfo is not null)
{
return true;
}
if (info is not null && m.VersionInfo is null)
{
return false;
}
return m.VersionInfo!.CompareTo(info!.ProductVersion) > 0;
}
catch
{
return false;
}
})
.Where(m =>
{
@@ -11,4 +11,7 @@ internal sealed class Metadata
[JsonProperty(nameof(Size))]
public int Size { get; set; }
[JsonProperty(nameof(VersionInfo))]
public string? VersionInfo { get; set; }
}
+2
View File
@@ -15,10 +15,12 @@ function Get-FileMetadata {
Set-Location -Path .\Publish
$relativePath = Resolve-Path -Path $Path -Relative
Set-Location -Path $currentLocation
$versionInfo = $fileInfo.VersionInfo.ProductVersion
return @{
Name = $fileInfo.Name
Size = $fileInfo.Length
RelativePath = $relativePath.trim(".\\")
VersionInfo = $versionInfo
}
}