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
88 changes: 16 additions & 72 deletions src/c#/GeneralUpdate.ClientCore/Strategys/LinuxStrategy.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using GeneralUpdate.ClientCore.Pipeline;
using GeneralUpdate.Common.FileBasic;
using GeneralUpdate.Common.Internal;
using GeneralUpdate.Common.Internal.Bootstrap;
using GeneralUpdate.Common.Internal.Event;
using GeneralUpdate.Common.Internal.Pipeline;
using GeneralUpdate.Common.Internal.Strategy;
using GeneralUpdate.Common.Shared;
using GeneralUpdate.Common.Shared.Object;
using GeneralUpdate.Common.Shared.Object.Enum;
using GeneralUpdate.Common.Shared.Service;

namespace GeneralUpdate.ClientCore.Strategys;

Expand All @@ -21,76 +17,24 @@ namespace GeneralUpdate.ClientCore.Strategys;
/// </summary>
public class LinuxStrategy : AbstractStrategy
{
private GlobalConfigInfo _configinfo = new();

public override void Create(GlobalConfigInfo parameter) => _configinfo = parameter;

public override async Task ExecuteAsync()
protected override PipelineContext CreatePipelineContext(VersionInfo version, string patchPath)
{
try
{
var status = ReportType.None;
var patchPath = StorageManager.GetTempDirectory(Patchs);
foreach (var version in _configinfo.UpdateVersions)
{
try
{
var context = new PipelineContext();
//Common
context.Add("ZipFilePath",
Path.Combine(_configinfo.TempPath, $"{version.Name}{_configinfo.Format}"));
//hash middleware
context.Add("Hash", version.Hash);
//zip middleware
context.Add("Format", _configinfo.Format);
context.Add("Name", version.Name);
context.Add("Encoding", _configinfo.Encoding);
//patch middleware
context.Add("SourcePath", _configinfo.InstallPath);
context.Add("PatchPath", patchPath);
context.Add("PatchEnabled", _configinfo.PatchEnabled);
//blacklist
context.Add("BlackFiles", _configinfo.BlackFiles);
context.Add("BlackFileFormats", _configinfo.BlackFormats);
context.Add("SkipDirectorys", _configinfo.SkipDirectorys);

var pipelineBuilder = new PipelineBuilder(context)
.UseMiddlewareIf<PatchMiddleware>(_configinfo.PatchEnabled)
.UseMiddleware<CompressMiddleware>()
.UseMiddleware<HashMiddleware>();
await pipelineBuilder.Build();
status = ReportType.Success;
}
catch (Exception e)
{
status = ReportType.Failure;
GeneralTracer.Error("The ExecuteAsync method in the GeneralUpdate.ClientCore.LinuxStrategy class throws an exception.", e);
EventManager.Instance.Dispatch(this, new ExceptionEventArgs(e, e.Message));
}
finally
{
await VersionService.Report(_configinfo.ReportUrl
, version.RecordId
, status
, version.AppType
, _configinfo.Scheme
, _configinfo.Token);
}
}

if (!string.IsNullOrEmpty(_configinfo.UpdateLogUrl))
{
OpenBrowser(_configinfo.UpdateLogUrl);
}
var context = base.CreatePipelineContext(version, patchPath);

// Add ClientCore-specific context items (blacklists for Linux)
context.Add("BlackFiles", _configinfo.BlackFiles);
context.Add("BlackFileFormats", _configinfo.BlackFormats);
context.Add("SkipDirectorys", _configinfo.SkipDirectorys);

return context;
}

Clear(patchPath);
Clear(_configinfo.TempPath);
}
catch (Exception e)
{
GeneralTracer.Error("The ExecuteAsync method in the GeneralUpdate.ClientCore.LinuxStrategy class throws an exception." , e);
EventManager.Instance.Dispatch(this, new ExceptionEventArgs(e, e.Message));
}
protected override PipelineBuilder BuildPipeline(PipelineContext context)
{
return new PipelineBuilder(context)
.UseMiddlewareIf<PatchMiddleware>(_configinfo.PatchEnabled)
.UseMiddleware<CompressMiddleware>()
.UseMiddleware<HashMiddleware>();
}

public override void StartApp()
Expand Down
82 changes: 14 additions & 68 deletions src/c#/GeneralUpdate.ClientCore/Strategys/WindowsStrategy.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using GeneralUpdate.ClientCore.Pipeline;
using GeneralUpdate.Common.FileBasic;
using GeneralUpdate.Common.Internal;
using GeneralUpdate.Common.Internal.Bootstrap;
using GeneralUpdate.Common.Internal.Event;
using GeneralUpdate.Common.Internal.Pipeline;
using GeneralUpdate.Common.Internal.Strategy;
using GeneralUpdate.Common.Shared;
using GeneralUpdate.Common.Shared.Object;
using GeneralUpdate.Common.Shared.Object.Enum;
using GeneralUpdate.Common.Shared.Service;

namespace GeneralUpdate.ClientCore.Strategys;

Expand All @@ -21,72 +17,22 @@ namespace GeneralUpdate.ClientCore.Strategys;
/// </summary>
public class WindowsStrategy : AbstractStrategy
{
private GlobalConfigInfo _configinfo = new();

public override void Create(GlobalConfigInfo parameter) => _configinfo = parameter;

public override async Task ExecuteAsync()
protected override PipelineContext CreatePipelineContext(VersionInfo version, string patchPath)
{
try
{
var status = ReportType.None;
var patchPath = StorageManager.GetTempDirectory(Patchs);
foreach (var version in _configinfo.UpdateVersions)
{
try
{
var context = new PipelineContext();
//Common
context.Add("ZipFilePath",
Path.Combine(_configinfo.TempPath, $"{version.Name}{_configinfo.Format}"));
//hash middleware
context.Add("Hash", version.Hash);
//zip middleware
context.Add("Format", _configinfo.Format);
context.Add("Name", version.Name);
context.Add("Encoding", _configinfo.Encoding);
//patch middleware
context.Add("SourcePath", _configinfo.InstallPath);
context.Add("PatchPath", patchPath);
context.Add("PatchEnabled", _configinfo.PatchEnabled);

var pipelineBuilder = new PipelineBuilder(context)
.UseMiddlewareIf<PatchMiddleware>(_configinfo.PatchEnabled)
.UseMiddleware<CompressMiddleware>()
.UseMiddleware<HashMiddleware>();
await pipelineBuilder.Build();
status = ReportType.Success;
}
catch (Exception e)
{
status = ReportType.Failure;
GeneralTracer.Error("The ExecuteAsync method in the GeneralUpdate.ClientCore.WindowsStrategy class throws an exception.", e);
EventManager.Instance.Dispatch(this, new ExceptionEventArgs(e, e.Message));
}
finally
{
await VersionService.Report(_configinfo.ReportUrl
, version.RecordId
, status
, version.AppType
, _configinfo.Scheme
, _configinfo.Token);
}
}

if (!string.IsNullOrEmpty(_configinfo.UpdateLogUrl))
{
OpenBrowser(_configinfo.UpdateLogUrl);
}
var context = base.CreatePipelineContext(version, patchPath);

// Add ClientCore-specific context items (blacklists are not needed for Windows in Core)
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment incorrectly states "blacklists are not needed for Windows in Core" when it should say "blacklists are not needed for Windows in ClientCore". The word "Core" at the end refers to GeneralUpdate.Core, but this class is in GeneralUpdate.ClientCore.

Suggested change
// Add ClientCore-specific context items (blacklists are not needed for Windows in Core)
// Add ClientCore-specific context items (blacklists are not needed for Windows in ClientCore)

Copilot uses AI. Check for mistakes.
// Keeping this override to maintain extensibility

return context;
}

Clear(patchPath);
Clear(_configinfo.TempPath);
}
catch (Exception e)
{
GeneralTracer.Error("The ExecuteAsync method in the GeneralUpdate.ClientCore.WindowsStrategy class throws an exception." , e);
EventManager.Instance.Dispatch(this, new ExceptionEventArgs(e, e.Message));
}
protected override PipelineBuilder BuildPipeline(PipelineContext context)
{
return new PipelineBuilder(context)
.UseMiddlewareIf<PatchMiddleware>(_configinfo.PatchEnabled)
.UseMiddleware<CompressMiddleware>()
.UseMiddleware<HashMiddleware>();
}

public override void StartApp()
Expand Down
114 changes: 112 additions & 2 deletions src/c#/GeneralUpdate.Common/Internal/Strategy/AbstractStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,131 @@
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using GeneralUpdate.Common.FileBasic;
using GeneralUpdate.Common.Internal.Event;
using GeneralUpdate.Common.Internal.Pipeline;
using GeneralUpdate.Common.Shared;
using GeneralUpdate.Common.Shared.Object;
using GeneralUpdate.Common.Shared.Object.Enum;
using GeneralUpdate.Common.Shared.Service;

namespace GeneralUpdate.Common.Internal.Strategy
{
public abstract class AbstractStrategy : IStrategy
{
protected const string Patchs = "patchs";
protected GlobalConfigInfo _configinfo = new();

public virtual void Execute() => throw new NotImplementedException();

public virtual void StartApp() => throw new NotImplementedException();

public virtual Task ExecuteAsync() => throw new NotImplementedException();
public virtual async Task ExecuteAsync()
{
try
{
var status = ReportType.None;
var patchPath = StorageManager.GetTempDirectory(Patchs);
foreach (var version in _configinfo.UpdateVersions)
{
try
{
var context = CreatePipelineContext(version, patchPath);
var pipelineBuilder = BuildPipeline(context);
await pipelineBuilder.Build();
status = ReportType.Success;
}
catch (Exception e)
{
status = ReportType.Failure;
HandleExecuteException(e);
}
finally
{
await VersionService.Report(_configinfo.ReportUrl
, version.RecordId
, status
, version.AppType
, _configinfo.Scheme
, _configinfo.Token);
}
}

if (!string.IsNullOrEmpty(_configinfo.UpdateLogUrl))
{
OpenBrowser(_configinfo.UpdateLogUrl);
}

Clear(patchPath);
Clear(_configinfo.TempPath);
OnExecuteComplete();
}
catch (Exception e)
{
HandleExecuteException(e);
}
}

public virtual void Create(GlobalConfigInfo parameter) => _configinfo = parameter;

/// <summary>
/// Creates the pipeline context with common and platform-specific parameters.
/// Override this method to add platform-specific context parameters.
/// </summary>
protected virtual PipelineContext CreatePipelineContext(VersionInfo version, string patchPath)
{
var context = new PipelineContext();
// Common parameters
context.Add("ZipFilePath", Path.Combine(_configinfo.TempPath, $"{version.Name}{_configinfo.Format}"));
// Hash middleware
context.Add("Hash", version.Hash);
// Zip middleware
context.Add("Format", _configinfo.Format);
context.Add("Name", version.Name);
context.Add("Encoding", _configinfo.Encoding);
// Patch middleware
context.Add("SourcePath", _configinfo.InstallPath);
context.Add("PatchPath", patchPath);
context.Add("PatchEnabled", _configinfo.PatchEnabled);

return context;
}

/// <summary>
/// Builds the pipeline with middleware components.
/// Override this method to customize the pipeline for specific platforms.
/// </summary>
protected abstract PipelineBuilder BuildPipeline(PipelineContext context);

/// <summary>
/// Called after ExecuteAsync completes successfully.
/// Override this method to add platform-specific post-execution logic.
/// </summary>
protected virtual void OnExecuteComplete()
{
// Default implementation does nothing
}

public virtual void Create(GlobalConfigInfo parameter) => throw new NotImplementedException();
/// <summary>
/// Handles exceptions during execution.
/// Override this method to customize error handling.
/// </summary>
protected virtual void HandleExecuteException(Exception e)
{
var className = GetType().Name;
GeneralTracer.Error($"Exception in {className}.ExecuteAsync method.", e);
EventManager.Instance.Dispatch(this, new ExceptionEventArgs(e, e.Message));
}

/// <summary>
/// Checks if a file exists at the specified path.
/// </summary>
protected static string CheckPath(string path, string name)
{
if (string.IsNullOrWhiteSpace(path) || string.IsNullOrWhiteSpace(name))
return string.Empty;
var tempPath = Path.Combine(path, name);
return File.Exists(tempPath) ? tempPath : string.Empty;
}

protected static void OpenBrowser(string url)
{
Expand Down
Loading
Loading