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
8 changes: 8 additions & 0 deletions src/c#/GeneralUpdate.Core/Configuration/VersionEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,12 @@ public class VersionEntry : VersionIdentity
/// </summary>
[JsonPropertyName("fallbackFullHash")]
public string? FallbackFullHash { get; set; }

/// <summary>
/// The version string of the fallback full replacement package.
/// Used by <see cref="Strategy.AbstractStrategy"/> to skip chain packages
/// already covered by a previous fallback.
/// </summary>
[JsonPropertyName("fallbackFullVersion")]
public string? FallbackFullVersion { get; set; }
}
3 changes: 2 additions & 1 deletion src/c#/GeneralUpdate.Core/Download/DownloadPlanBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ public static DownloadPlan Build(
{
FallbackFullName = match.Name,
FallbackFullUrl = match.Url,
FallbackFullHash = match.SHA256
FallbackFullHash = match.SHA256,
FallbackFullVersion = match.Version
};
}
return chain;
Expand Down
1 change: 1 addition & 0 deletions src/c#/GeneralUpdate.Core/Download/Models/DownloadAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public record DownloadAsset(
string? FallbackFullName = null,
string? FallbackFullUrl = null,
string? FallbackFullHash = null,
string? FallbackFullVersion = null,
bool IsForcibly = false,
bool IsFreeze = false,
int RecordId = 0,
Expand Down
26 changes: 26 additions & 0 deletions src/c#/GeneralUpdate.Core/Strategy/AbstractStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using GeneralUpdate.Core.Event;
using GeneralUpdate.Core.Pipeline;
using GeneralUpdate.Core.Configuration;
using GeneralUpdate.Core.Utilities;

using GeneralUpdate.Core.Hooks;
using IUpdateReporter = GeneralUpdate.Core.Download.Reporting.IUpdateReporter;
Expand Down Expand Up @@ -146,8 +147,25 @@ public virtual async Task ExecuteAsync()
AllPackagesSucceeded = true;
var status = ReportType.None;
patchRoot = StorageManager.GetTempDirectory(Patchs);

// Track the highest version already applied via full-package fallback,
// so subsequent chain packages covered by that version are skipped.
SemVersion? fallbackEffectiveVersion = null;

foreach (var version in _configinfo.UpdateVersions)
{
// When a previous chain package fell back to a full package,
// the application is already at or beyond that full version.
// Skip any remaining chain packages whose version is ≤ the
// fallback version — applying them would be redundant.
if (fallbackEffectiveVersion != null
&& version.PackageType == (int)PackageType.Chain
&& Semver.TryParse(version.Version, out var versionSv)
&& versionSv <= fallbackEffectiveVersion)
{
GeneralTracer.Info($"AbstractStrategy.ExecuteAsync: skipping {version.Version} ({version.Name}) — already covered by fallback full package v{fallbackEffectiveVersion}.");
continue;
}
Comment on lines +161 to +168
try
{
// Use a version-specific subdirectory under patchRoot so that
Expand Down Expand Up @@ -193,6 +211,14 @@ public virtual async Task ExecuteAsync()
var fallbackBuilder = BuildPipeline(fallbackContext);
await fallbackBuilder.Build();
status = ReportType.Success;
// Record the fallback full package version so subsequent
// chain packages ≤ this version are skipped.
if (!string.IsNullOrEmpty(version.FallbackFullVersion)
&& Semver.TryParse(version.FallbackFullVersion, out var ffv)
&& (fallbackEffectiveVersion == null || ffv > fallbackEffectiveVersion))
{
fallbackEffectiveVersion = ffv;
}
Comment on lines +216 to +221
}
catch (Exception e)
{
Expand Down
3 changes: 2 additions & 1 deletion src/c#/GeneralUpdate.Core/Strategy/ClientStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,8 @@ async Task DownloadAndApplyAsync(Download.Models.DownloadPlan plan, UpdateScenar
PackageType = a.PackageType,
FallbackFullName = a.FallbackFullName,
FallbackFullUrl = a.FallbackFullUrl,
FallbackFullHash = a.FallbackFullHash
FallbackFullHash = a.FallbackFullHash,
FallbackFullVersion = a.FallbackFullVersion
}).ToList();

var uVersions = dVersions.Where(v => v.AppType == (int)AppType.Upgrade).ToList();
Expand Down
8 changes: 5 additions & 3 deletions tests/ClientTest/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using GeneralUpdate.Core.Event;
using GeneralUpdate.Core.Hooks;
using GeneralUpdate.Core.Security;
using GeneralUpdate.Core.Pipeline;
using GeneralUpdate.Core.Configuration;
Comment on lines +10 to +11

try
{
Expand Down Expand Up @@ -87,6 +89,7 @@ static async Task RunUpdateTestAsync()
}
})
.SetOption(Option.AppType, AppType.Client)
.UseDiffPipeline(builder => builder.WithStopOnFirstError(true))
.Hooks<ClientTestHooks>()
.AddListenerMultiDownloadStatistics(OnDownloadStatistics)
.AddListenerMultiDownloadCompleted(OnDownloadCompleted)
Expand Down Expand Up @@ -140,7 +143,7 @@ static void OnUpdateInfo(object sender, UpdateInfoEventArgs e)
{
foreach (var vi in e.Info.Body)
{
var mode = vi.IsCrossVersion == true ? "CVP" : "Chain";
var mode = vi.PackageType == (int)PackageType.Full ? "Full" : "Chain";
var appType = vi.AppType switch
{
1 => "Client",
Expand All @@ -149,8 +152,7 @@ static void OnUpdateInfo(object sender, UpdateInfoEventArgs e)
};
Console.WriteLine($" - [{mode}] {vi.Version} ({vi.Name}) [{vi.Size} bytes] " +
$"AppType={appType} " +
$"{(vi.IsForcibly == true ? "(forced)" : "")}" +
$"{(!string.IsNullOrEmpty(vi.FromVersion) ? $" from={vi.FromVersion}" : "")}");
$"{(vi.IsForcibly == true ? "(forced)" : "")}");
}
}
else
Expand Down
2 changes: 2 additions & 0 deletions tests/UpgradeTest/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using GeneralUpdate.Core.Download;
using GeneralUpdate.Core.Event;
using GeneralUpdate.Core.Hooks;
using GeneralUpdate.Core.Pipeline;

try
{
Expand Down Expand Up @@ -41,6 +42,7 @@ static async Task RunStandardUpgradeAsync()

await new GeneralUpdateBootstrap()
.SetOption(Option.AppType, AppType.Upgrade)
.UseDiffPipeline(builder => builder.WithStopOnFirstError(true))
.Hooks<UpgradeTestHooks>()
.AddListenerMultiDownloadStatistics(OnDownloadStatistics)
.AddListenerMultiDownloadCompleted(OnDownloadCompleted)
Expand Down