diff --git a/src/c#/GeneralUpdate.Bowl/GeneralUpdate.Bowl.csproj b/src/c#/GeneralUpdate.Bowl/GeneralUpdate.Bowl.csproj
index db1aa75d..2b03c3a8 100644
--- a/src/c#/GeneralUpdate.Bowl/GeneralUpdate.Bowl.csproj
+++ b/src/c#/GeneralUpdate.Bowl/GeneralUpdate.Bowl.csproj
@@ -18,8 +18,8 @@
netstandard2.0;
-
-
+
+
@@ -65,6 +65,7 @@
+
diff --git a/src/c#/GeneralUpdate.ClientCore/GeneralUpdate.ClientCore.csproj b/src/c#/GeneralUpdate.ClientCore/GeneralUpdate.ClientCore.csproj
index c265d3d8..9907131b 100644
--- a/src/c#/GeneralUpdate.ClientCore/GeneralUpdate.ClientCore.csproj
+++ b/src/c#/GeneralUpdate.ClientCore/GeneralUpdate.ClientCore.csproj
@@ -63,6 +63,7 @@
+
@@ -83,9 +84,9 @@
-
-
-
+
+
+
diff --git a/src/c#/GeneralUpdate.Common/GeneralUpdate.Common.csproj b/src/c#/GeneralUpdate.Common/GeneralUpdate.Common.csproj
index 7673c882..a63235db 100644
--- a/src/c#/GeneralUpdate.Common/GeneralUpdate.Common.csproj
+++ b/src/c#/GeneralUpdate.Common/GeneralUpdate.Common.csproj
@@ -18,9 +18,9 @@
netstandard2.0;
-
-
-
+
+
+
diff --git a/src/c#/GeneralUpdate.Common/Internal/Bootstrap/UpdateOption.cs b/src/c#/GeneralUpdate.Common/Internal/Bootstrap/UpdateOption.cs
index 97675362..2cca3a9d 100644
--- a/src/c#/GeneralUpdate.Common/Internal/Bootstrap/UpdateOption.cs
+++ b/src/c#/GeneralUpdate.Common/Internal/Bootstrap/UpdateOption.cs
@@ -3,6 +3,7 @@
using System.Diagnostics.Contracts;
using System.Text;
using System.Threading;
+using GeneralUpdate.Common.Shared.Object.Enum;
namespace GeneralUpdate.Common.Internal.Bootstrap
{
@@ -47,6 +48,11 @@ private class UpdateOptionPool : ConstantPool
///
public static readonly UpdateOption BackUp = ValueOf("BACKUP");
+ ///
+ /// Specifies the update execution mode.
+ ///
+ public static readonly UpdateOption Mode = ValueOf("MODE");
+
internal UpdateOption(int id, string name)
: base(id, name) { }
diff --git a/src/c#/GeneralUpdate.Common/Shared/Object/Enum/UpdateMode.cs b/src/c#/GeneralUpdate.Common/Shared/Object/Enum/UpdateMode.cs
new file mode 100644
index 00000000..cd05d00a
--- /dev/null
+++ b/src/c#/GeneralUpdate.Common/Shared/Object/Enum/UpdateMode.cs
@@ -0,0 +1,7 @@
+namespace GeneralUpdate.Common.Shared.Object.Enum;
+
+public enum UpdateMode
+{
+ Default = 0,
+ Scripts = 1
+}
\ No newline at end of file
diff --git a/src/c#/GeneralUpdate.Core/GeneralUpdate.Core.csproj b/src/c#/GeneralUpdate.Core/GeneralUpdate.Core.csproj
index 69deec57..ac296dd1 100644
--- a/src/c#/GeneralUpdate.Core/GeneralUpdate.Core.csproj
+++ b/src/c#/GeneralUpdate.Core/GeneralUpdate.Core.csproj
@@ -68,6 +68,7 @@
+
@@ -91,9 +92,9 @@
-
-
-
+
+
+
diff --git a/src/c#/GeneralUpdate.Core/GeneralUpdateBootstrap.cs b/src/c#/GeneralUpdate.Core/GeneralUpdateBootstrap.cs
index fa53ba0d..32c49505 100644
--- a/src/c#/GeneralUpdate.Core/GeneralUpdateBootstrap.cs
+++ b/src/c#/GeneralUpdate.Core/GeneralUpdateBootstrap.cs
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
+using System.IO;
+using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
@@ -14,30 +16,211 @@
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;
using GeneralUpdate.Core.Strategys;
namespace GeneralUpdate.Core
{
public class GeneralUpdateBootstrap : AbstractBootstrap
{
- private readonly GlobalConfigInfo _configInfo;
+ private GlobalConfigInfo _configInfo = new();
private IStrategy? _strategy;
+ private Func? _customSkipOption;
public GeneralUpdateBootstrap()
+ {
+ InitializeFromEnvironment();
+ }
+
+ #region Launch
+
+ public override async Task LaunchAsync()
+ {
+ GeneralTracer.Debug("GeneralUpdateBootstrap Launch.");
+ StrategyFactory();
+
+ switch (GetOption(UpdateOption.Mode) ?? UpdateMode.Default)
+ {
+ case UpdateMode.Default:
+ ApplyRuntimeOptions();
+ _strategy!.Create(_configInfo);
+ await DownloadAsync();
+ await _strategy.ExecuteAsync();
+ break;
+
+ case UpdateMode.Scripts:
+ await ExecuteWorkflowAsync();
+ break;
+
+ default:
+ throw new ArgumentOutOfRangeException();
+ }
+
+ return this;
+ }
+
+ #endregion
+
+ #region Configuration
+
+ public GeneralUpdateBootstrap SetConfig(Configinfo configInfo)
+ {
+ _configInfo = new GlobalConfigInfo
+ {
+ MainAppName = configInfo.MainAppName,
+ InstallPath = configInfo.InstallPath,
+ ClientVersion = configInfo.ClientVersion,
+ UpdateLogUrl = configInfo.UpdateLogUrl,
+ AppSecretKey = configInfo.AppSecretKey,
+ TempPath = StorageManager.GetTempDirectory("upgrade_temp"),
+ ReportUrl = configInfo.ReportUrl,
+ UpdateUrl = configInfo.UpdateUrl,
+ Scheme = configInfo.Scheme,
+ Token = configInfo.Token,
+ ProductId = configInfo.ProductId,
+ DriveEnabled = GetOption(UpdateOption.Drive) ?? false,
+ PatchEnabled = GetOption(UpdateOption.Patch) ?? true,
+ Script = configInfo.Script
+ };
+
+ // Copy blacklist-related configuration if explicitly provided.
+ if (configInfo.BlackFiles != null)
+ {
+ _configInfo.BlackFiles = configInfo.BlackFiles;
+ }
+
+ if (configInfo.BlackFormats != null)
+ {
+ _configInfo.BlackFormats = configInfo.BlackFormats;
+ }
+
+ if (configInfo.SkipDirectorys != null)
+ {
+ _configInfo.SkipDirectorys = configInfo.SkipDirectorys;
+ }
+ InitBlackList();
+ return this;
+ }
+
+ public GeneralUpdateBootstrap SetFieldMappings(Dictionary fieldMappings)
+ {
+ _configInfo.FieldMappings = fieldMappings;
+ return this;
+ }
+
+ public GeneralUpdateBootstrap SetCustomSkipOption(Func? func)
+ {
+ _customSkipOption = func;
+ return this;
+ }
+
+ #endregion
+
+ #region Workflow
+
+ private async Task ExecuteWorkflowAsync()
+ {
+ try
+ {
+ var mainResp = await VersionService.Validate(
+ _configInfo.UpdateUrl,
+ _configInfo.ClientVersion,
+ AppType.ClientApp,
+ _configInfo.AppSecretKey,
+ GetPlatform(),
+ _configInfo.ProductId,
+ _configInfo.Scheme,
+ _configInfo.Token);
+
+ _configInfo.IsMainUpdate = CheckUpgrade(mainResp);
+
+ if (CanSkip(CheckForcibly(mainResp.Body)))
+ return;
+
+ InitBlackList();
+ ApplyRuntimeOptions();
+
+ _configInfo.TempPath = StorageManager.GetTempDirectory("main_temp");
+ _configInfo.BackupDirectory = Path.Combine(
+ _configInfo.InstallPath,
+ $"{StorageManager.DirectoryName}{_configInfo.ClientVersion}");
+
+ _configInfo.UpdateVersions = mainResp.Body!
+ .OrderBy(x => x.ReleaseDate)
+ .ToList();
+
+ if (GetOption(UpdateOption.BackUp) ?? true)
+ {
+ StorageManager.Backup(
+ _configInfo.InstallPath,
+ _configInfo.BackupDirectory,
+ BlackListManager.Instance.SkipDirectorys);
+ }
+
+ _strategy!.Create(_configInfo);
+
+ if (_configInfo.IsMainUpdate)
+ {
+ await DownloadAsync();
+ await _strategy.ExecuteAsync();
+ }
+ else
+ {
+ _strategy.StartApp();
+ }
+ }
+ catch (Exception ex)
+ {
+ GeneralTracer.Error(
+ "The ExecuteWorkflowAsync method in the GeneralUpdateBootstrap class throws an exception.",
+ ex);
+ EventManager.Instance.Dispatch(this, new ExceptionEventArgs(ex, ex.Message));
+ }
+ }
+
+ #endregion
+
+ #region Download
+
+ private async Task DownloadAsync()
+ {
+ var manager = new DownloadManager(
+ _configInfo.TempPath,
+ _configInfo.Format,
+ _configInfo.DownloadTimeOut);
+
+ manager.MultiAllDownloadCompleted += OnMultiAllDownloadCompleted;
+ manager.MultiDownloadCompleted += OnMultiDownloadCompleted;
+ manager.MultiDownloadError += OnMultiDownloadError;
+ manager.MultiDownloadStatistics += OnMultiDownloadStatistics;
+
+ foreach (var version in _configInfo.UpdateVersions)
+ manager.Add(new DownloadTask(manager, version));
+
+ await manager.LaunchTasksAsync();
+ }
+
+ #endregion
+
+ #region Helpers
+
+ private void InitializeFromEnvironment()
{
var json = Environments.GetEnvironmentVariable("ProcessInfo");
- if (string.IsNullOrWhiteSpace(json))
- throw new ArgumentException("json environment variable is not defined");
-
- var processInfo = JsonSerializer.Deserialize(json, ProcessInfoJsonContext.Default.ProcessInfo);
- if (processInfo == null)
- throw new ArgumentException("ProcessInfo object cannot be null!");
-
- BlackListManager.Instance?.AddBlackFileFormats(processInfo.BlackFileFormats);
- BlackListManager.Instance?.AddBlackFiles(processInfo.BlackFiles);
- BlackListManager.Instance?.AddSkipDirectorys(processInfo.SkipDirectorys);
-
- _configInfo = new()
+ if (string.IsNullOrWhiteSpace(json)) return;
+
+ var processInfo = JsonSerializer.Deserialize(
+ json,
+ ProcessInfoJsonContext.Default.ProcessInfo);
+
+ if (processInfo == null) return;
+
+ BlackListManager.Instance.AddBlackFileFormats(processInfo.BlackFileFormats);
+ BlackListManager.Instance.AddBlackFiles(processInfo.BlackFiles);
+ BlackListManager.Instance.AddSkipDirectorys(processInfo.SkipDirectorys);
+
+ _configInfo = new GlobalConfigInfo
{
MainAppName = processInfo.AppName,
InstallPath = processInfo.InstallPath,
@@ -60,99 +243,113 @@ public GeneralUpdateBootstrap()
};
}
- public override async Task LaunchAsync()
+ private void ApplyRuntimeOptions()
{
- GeneralTracer.Debug("GeneralUpdateBootstrap Launch.");
- StrategyFactory();
- var manager =
- new DownloadManager(_configInfo.TempPath, _configInfo.Format, _configInfo.DownloadTimeOut);
- manager.MultiAllDownloadCompleted += OnMultiAllDownloadCompleted;
- manager.MultiDownloadCompleted += OnMultiDownloadCompleted;
- manager.MultiDownloadError += OnMultiDownloadError;
- manager.MultiDownloadStatistics += OnMultiDownloadStatistics;
- foreach (var versionInfo in _configInfo.UpdateVersions)
- {
- manager.Add(new DownloadTask(manager, versionInfo));
- }
-
- await manager.LaunchTasksAsync();
- return this;
+ _configInfo.Encoding = GetOption(UpdateOption.Encoding) ?? Encoding.Default;
+ _configInfo.Format = GetOption(UpdateOption.Format) ?? Format.ZIP;
+ var downloadTimeoutOption = GetOption(UpdateOption.DownloadTimeOut);
+ _configInfo.DownloadTimeOut = downloadTimeoutOption ?? 60;
+ _configInfo.DriveEnabled = GetOption(UpdateOption.Drive) ?? false;
+ _configInfo.PatchEnabled = GetOption(UpdateOption.Patch) ?? true;
}
- #region public method
-
- public GeneralUpdateBootstrap SetFieldMappings(Dictionary fieldMappings)
+ private void InitBlackList()
{
- _configInfo.FieldMappings = fieldMappings;
- return this;
+ BlackListManager.Instance.AddBlackFiles(_configInfo.BlackFiles);
+ BlackListManager.Instance.AddBlackFileFormats(_configInfo.BlackFormats);
+ BlackListManager.Instance.AddSkipDirectorys(_configInfo.SkipDirectorys);
}
- public GeneralUpdateBootstrap AddListenerMultiAllDownloadCompleted(
- Action
-
+
all
diff --git a/src/c#/GeneralUpdate.Upgrad/Program.cs b/src/c#/GeneralUpdate.Upgrad/Program.cs
index 0db425ea..8ff0c8f6 100644
--- a/src/c#/GeneralUpdate.Upgrad/Program.cs
+++ b/src/c#/GeneralUpdate.Upgrad/Program.cs
@@ -4,6 +4,7 @@
using GeneralUpdate.Common.Internal;
using GeneralUpdate.Common.Internal.Bootstrap;
using GeneralUpdate.Common.Shared.Object;
+using GeneralUpdate.Common.Shared.Object.Enum;
using GeneralUpdate.Core;
using GeneralUpdate.Core.Driver;
@@ -18,6 +19,25 @@ static async Task Main(string[] args)
Console.WriteLine($"升级程序初始化,{DateTime.Now}!");
Console.WriteLine("当前运行目录:" + Thread.GetDomain().BaseDirectory);
await Task.Delay(2000);
+ var configinfo = new Configinfo
+ {
+ //configinfo.UpdateLogUrl = "https://www.baidu.com";
+ ReportUrl = "http://127.0.0.1:5000/Upgrade/Report",
+ UpdateUrl = "http://127.0.0.1:5000/Upgrade/Verification",
+ AppName = "GeneralUpdate.Upgrad.exe",
+ MainAppName = "GeneralUpdate.Client.exe",
+ InstallPath = Thread.GetDomain().BaseDirectory,
+ //configinfo.Bowl = "Generalupdate.CatBowl.exe";
+ //当前客户端的版本号
+ ClientVersion = "1.0.0.0",
+ //当前升级端的版本号
+ UpgradeClientVersion = "1.0.0.0",
+ //产品id
+ ProductId = "2d974e2a-31e6-4887-9bb1-b4689e98c77a",
+ //应用密钥
+ AppSecretKey = "dfeb5833-975e-4afb-88f1-6278ee9aeff6",
+ Script = "linux/script.shell"
+ };
_ = await new GeneralUpdateBootstrap()
//单个或多个更新包下载速度、剩余下载事件、当前下载版本信息通知事件
.AddListenerMultiDownloadStatistics(OnMultiDownloadStatistics)
@@ -29,11 +49,15 @@ static async Task Main(string[] args)
.AddListenerMultiDownloadError(OnMultiDownloadError)
//整个更新过程出现的任何问题都会通过这个事件通知
.AddListenerException(OnException)
+ .SetConfig(configinfo)
//设置字段映射表,用于解析所有驱动包的信息的字符串
//.SetFieldMappings(fieldMappingsCN)
//是否开启驱动更新
//.Option(UpdateOption.Drive, true)
//.Option(UpdateOption.Patch, false)
+ .Option(UpdateOption.DownloadTimeOut, 60)
+ .Option(UpdateOption.Encoding, Encoding.UTF8)
+ .Option(UpdateOption.Mode, UpdateMode.Scripts)
.LaunchAsync();
Console.WriteLine($"升级程序已启动,{DateTime.Now}!");
}