diff --git a/README.md b/README.md index ab53a21f2498b1b4a0e97d870eff64e2319c2472..19c96c8e6c47f3d04bb51be8e9b7d730da26ac11 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ | 回滚 | 待测试 | 逐版本更新时会备份每个版本,如果更新失败则逐版本回滚。 | | 驱动更新 | 支持 | 逐版本更新时会备份每个版本的驱动文件(.inf),如果更新失败则逐版本回滚。 | | 遗言 | 待测试 | 开机时和升级时会检查升级是否成功,如果失败则根据遗言还原之前的备份。遗言是更新之前就已经自动创建在C:\generalupdate_willmessages目录下的will_message.json文件。will_message.json的内容是持久化回滚备份的文件目录相关信息。(需要部署GeneralUpdate.SystemService系统服务) | -| 自定义方法列表 | 待测试 | 注入一个自定义方法集合,该集合会在更新启动前执行。执行自定义方法列表如果出现任何异常,将通过异常订阅通知。(推荐在更新之前检查当前软件环境) | +| 自定义方法列表 | 支持 | 注入一个自定义方法集合,该集合会在更新启动前执行。执行自定义方法列表如果出现任何异常,将通过异常订阅通知。(推荐在更新之前检查当前软件环境) | diff --git a/README_en.md b/README_en.md index a3b1c71a8c119f340732b702f425d6b8f467ff7f..ed1fc80c0da8d0adc52058aed6c2bc1828965fa9 100644 --- a/README_en.md +++ b/README_en.md @@ -29,7 +29,7 @@ | Restore | test | Each version is backed up during a version-by-version update and rolled back version-by-version if the update fails. | | Driver upgrade | yes | The driver file (.INF) of each version is backed up during the version-by-version update and is rolled back version-by-version if the update fails. | | Will message | test | The upgrade is checked for success at boot and upgrade, and if it fails, the previous backup is restored according to the last word. The last word is that the will_message.json file in the C:\generalupdate_willmessages directory was automatically created before the update. will_message.json is about the file directory of the persistent rollback backup.(need to deploy GeneralUpdate. SystemService system service) | -| A list of custom methods | test | Inject a custom collection of methods that are executed before the update starts. Execute a custom method list, and if there are any exceptions, you will be notified by exception subscription.(It is recommended to check the current software environment before updating) | +| A list of custom methods | 支持 | Inject a custom collection of methods that are executed before the update starts. Execute a custom method list, and if there are any exceptions, you will be notified by exception subscription.(It is recommended to check the current software environment before updating) | diff --git a/src/c#/GeneralUpdate.Api/Program.cs b/src/c#/GeneralUpdate.Api/Program.cs index 6e8fa59b5c50bb87a4d586d39b38c7c65875a94a..16c966a513d83e81054358aeb215dd860c0a64c8 100644 --- a/src/c#/GeneralUpdate.Api/Program.cs +++ b/src/c#/GeneralUpdate.Api/Program.cs @@ -36,7 +36,7 @@ var app = builder.Build(); app.MapGet("/versions/{clientType}/{clientVersion}/{clientAppKey}", (int clientType, string clientVersion, string clientAppKey, IUpdateService updateService) => { var versions = new List(); - var hash = "415eed05eb310f480d1e4d15516fa00e484ddb9f416908b217f17b782ded2030";//ɺõĸ°ļMD5룬Ϊظͻ˵ʱҪ֤ͬǷ + var hash = "28d10f1fc2a23dd1afe0af40d132b25c72ea56005963f653c27889f03d381c8d";//ɺõĸ°ļMD5룬Ϊظͻ˵ʱҪ֤ͬǷ var pubTime = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds(); string version = null; if (clientType == AppType.ClientApp) @@ -51,7 +51,7 @@ app.MapGet("/versions/{clientType}/{clientVersion}/{clientAppKey}", (int clientT version = "0.0.0.0"; //version = "9.9.9.9"; //Ϊ9óΪҪ } - var url = $"http://127.0.0.1/WpfClient_1_24.1.5.1218.zip";//°صַ + var url = $"http://192.168.1.7/WpfClient_1_24.1.5.1218.zip";//°صַ var name = "update"; versions.Add(new VersionDTO(hash, pubTime, version, url, name)); return updateService.Update(clientType, clientVersion, version, clientAppKey, GetAppSecretKey(), false, versions); diff --git a/src/c#/GeneralUpdate.Client/MySample.cs b/src/c#/GeneralUpdate.Client/MySample.cs index 0488921f7368c0a4bea873650dbb0271d2659027..c84093fd9eaf1ad1ef572e689d96af0de5f5b9ae 100644 --- a/src/c#/GeneralUpdate.Client/MySample.cs +++ b/src/c#/GeneralUpdate.Client/MySample.cs @@ -19,7 +19,7 @@ namespace GeneralUpdate.Client { #region 推送功能 - private const string baseUrl = @"http://127.0.0.1:5001"; + private const string baseUrl = @"http://127.0.0.1:5000"; private const string hubName = "versionhub"; internal MySample() @@ -72,7 +72,7 @@ namespace GeneralUpdate.Client .Option(UpdateOption.Encoding, Encoding.Default) .Option(UpdateOption.Format, Format.ZIP) //开启驱动更新 - .Option(UpdateOption.Drive, true) + //.Option(UpdateOption.Drive, true) //开启遗言功能,需要部署GeneralUpdate.SystemService Windows服务。 .Option(UpdateOption.WillMessage, true) .Strategy() diff --git a/src/c#/GeneralUpdate.Core/Bootstrap/AbstractBootstrap.cs b/src/c#/GeneralUpdate.Core/Bootstrap/AbstractBootstrap.cs index 2062880ed895d41ad842ca40208ca32cbf40092b..9b45207b8c84b9b0beb2f1ad5d27afc0d61cc9c9 100644 --- a/src/c#/GeneralUpdate.Core/Bootstrap/AbstractBootstrap.cs +++ b/src/c#/GeneralUpdate.Core/Bootstrap/AbstractBootstrap.cs @@ -63,8 +63,8 @@ namespace GeneralUpdate.Core.Bootstrap Packet.DownloadTimeOut = GetOption(UpdateOption.DownloadTimeOut); Packet.AppName = $"{Packet.AppName ?? GetOption(UpdateOption.MainApp)}{EXECUTABLE_FILE}"; Packet.TempPath = $"{FileUtil.GetTempDirectory(Packet.LastVersion)}{Path.DirectorySeparatorChar}"; - Packet.DriveEnabled = GetOption(UpdateOption.Drive); - Packet.WillMessageEnabled = GetOption(UpdateOption.WillMessage); + Packet.DriveEnabled = GetOption(UpdateOption.Drive) ?? false; + Packet.WillMessageEnabled = GetOption(UpdateOption.WillMessage) ?? false; var manager = new DownloadManager(Packet.TempPath, Packet.Format, Packet.DownloadTimeOut); manager.MultiAllDownloadCompleted += OnMultiAllDownloadCompleted; manager.MultiDownloadCompleted += OnMultiDownloadCompleted; @@ -156,10 +156,17 @@ namespace GeneralUpdate.Core.Bootstrap public virtual T GetOption(UpdateOption option) { - if (_options == null || _options.Count == 0) return default(T); - var val = _options[option]; - if (val != null) return (T)val.GetValue(); - return default(T); + try + { + if (_options == null || _options.Count == 0) return default(T); + var val = _options[option]; + if (val != null) return (T)val.GetValue(); + return default(T); + } + catch + { + return default(T); + } } #endregion Config option. diff --git a/src/c#/GeneralUpdate.Core/Bootstrap/UpdateOption.cs b/src/c#/GeneralUpdate.Core/Bootstrap/UpdateOption.cs index f093e351b1c9daf24713493fd7611b62dca0dab4..46e3c09a1a34900a81fd16357aec2115f2fe66a3 100644 --- a/src/c#/GeneralUpdate.Core/Bootstrap/UpdateOption.cs +++ b/src/c#/GeneralUpdate.Core/Bootstrap/UpdateOption.cs @@ -42,12 +42,12 @@ namespace GeneralUpdate.Core.Bootstrap /// /// Whether to enable the driver upgrade function. /// - public static readonly UpdateOption Drive = ValueOf("DRIVE"); + public static readonly UpdateOption Drive = ValueOf("DRIVE"); /// /// Whether open note function, if you want to start needs to be synchronized to deploy 'GeneralUpdate. SystemService' service. /// - public static readonly UpdateOption WillMessage = ValueOf("WILLMESSAGE"); + public static readonly UpdateOption WillMessage = ValueOf("WILLMESSAGE"); #endregion parameter configuration diff --git a/src/c#/GeneralUpdate.Core/Driver/CommandExecutor.cs b/src/c#/GeneralUpdate.Core/Driver/CommandExecutor.cs index 20055e5cda2d9a2c4ab16eea9c20cebff1c714fa..55faa1dd738b60f2ecc419535640f5f9d3180ad2 100644 --- a/src/c#/GeneralUpdate.Core/Driver/CommandExecutor.cs +++ b/src/c#/GeneralUpdate.Core/Driver/CommandExecutor.cs @@ -1,4 +1,5 @@ -using System; +using GeneralUpdate.Core.Exceptions; +using System; using System.Diagnostics; namespace GeneralUpdate.Core.Driver @@ -38,7 +39,7 @@ If possible, use pre-tested drivers that are proven to work. process.WaitForExit(); if (process.ExitCode != 0) - throw new Exception($"Operation failed code: {process.ExitCode}"); + ThrowExceptionUtility.Throw($"Operation failed code: {process.ExitCode}"); } } } diff --git a/src/c#/GeneralUpdate.Core/Driver/DriverInformation.cs b/src/c#/GeneralUpdate.Core/Driver/DriverInformation.cs index be975aaab77ba64e87d47da06ed4afc081d6e332..bf442b9255cc52b31cb569ee6a00d931cdfe486f 100644 --- a/src/c#/GeneralUpdate.Core/Driver/DriverInformation.cs +++ b/src/c#/GeneralUpdate.Core/Driver/DriverInformation.cs @@ -1,4 +1,5 @@ -using System; +using GeneralUpdate.Core.Exceptions; +using System; using System.Collections.Generic; using System.Linq; @@ -59,7 +60,7 @@ namespace GeneralUpdate.Core.Driver string.IsNullOrWhiteSpace(_information.OutPutDirectory) || !_information.Drivers.Any()) { - throw new InvalidOperationException("Cannot create DriverInformation, not all fields are set."); + ThrowExceptionUtility.ThrowIfNull("Cannot create DriverInformation, not all fields are set."); } return _information; diff --git a/src/c#/GeneralUpdate.Core/Driver/DriverProcessor.cs b/src/c#/GeneralUpdate.Core/Driver/DriverProcessor.cs index 88b254639c2113b7674140d8ae8ef785ac1bd75d..8923af2f7dd3dfd4efed6d5367db32a050b00cfb 100644 --- a/src/c#/GeneralUpdate.Core/Driver/DriverProcessor.cs +++ b/src/c#/GeneralUpdate.Core/Driver/DriverProcessor.cs @@ -8,7 +8,7 @@ namespace GeneralUpdate.Core.Driver /// public class DriverProcessor { - private List _commands = new List(); + private readonly List _commands = new List(); public void AddCommand(IDriverCommand command) { diff --git a/src/c#/GeneralUpdate.Core/Driver/InstallDriverCommand.cs b/src/c#/GeneralUpdate.Core/Driver/InstallDriverCommand.cs index 41c3f53cdc23a159253d610efac6f7c7cf0ef646..74e7a05a07e3677bd3842b9157ef17191cb3c7fe 100644 --- a/src/c#/GeneralUpdate.Core/Driver/InstallDriverCommand.cs +++ b/src/c#/GeneralUpdate.Core/Driver/InstallDriverCommand.cs @@ -1,4 +1,5 @@ -using System; +using GeneralUpdate.Core.Exceptions; +using System; using System.IO; using System.Text; @@ -38,7 +39,7 @@ namespace GeneralUpdate.Core.Driver { //restore all the drivers in the backup directory. new RestoreDriverCommand(_information).Execute(); - throw new Exception($"Failed to execute install command for {_information.InstallDirectory}", ex); + ThrowExceptionUtility.Throw($"Failed to execute install command for {_information.InstallDirectory}", ex); } } } diff --git a/src/c#/GeneralUpdate.Core/Driver/RestoreDriverCommand.cs b/src/c#/GeneralUpdate.Core/Driver/RestoreDriverCommand.cs index b2c5d83934ec4e2702a495ccd7e888124b5cd752..f36486cbc03ffd4016bd333c3fae1347339692f0 100644 --- a/src/c#/GeneralUpdate.Core/Driver/RestoreDriverCommand.cs +++ b/src/c#/GeneralUpdate.Core/Driver/RestoreDriverCommand.cs @@ -1,6 +1,7 @@ using System.IO; using System; using System.Text; +using GeneralUpdate.Core.Exceptions; namespace GeneralUpdate.Core.Driver { @@ -26,7 +27,7 @@ namespace GeneralUpdate.Core.Driver } catch (Exception ex) { - throw new Exception($"Failed to execute restore command for {_information.OutPutDirectory}", ex); + ThrowExceptionUtility.Throw($"Failed to execute restore command for {_information.OutPutDirectory}", ex); } } } diff --git a/src/c#/GeneralUpdate.Core/Exceptions/ThrowExceptionUtility.cs b/src/c#/GeneralUpdate.Core/Exceptions/ThrowExceptionUtility.cs index 088cd354e6aed7549a78557b7efdb9ce9b07d21b..a8bbea558c61a88f30d5812eede561e5108f1987 100644 --- a/src/c#/GeneralUpdate.Core/Exceptions/ThrowExceptionUtility.cs +++ b/src/c#/GeneralUpdate.Core/Exceptions/ThrowExceptionUtility.cs @@ -13,7 +13,11 @@ namespace GeneralUpdate.Core.Exceptions public static void ThrowFileNotFound(string file) => Throw($"File cannot be accessed {file}!"); - public static void ThrowIfNull()=> Throw("Parameter cannot be null"); + public static void ThrowIfNull(string errorMessage = null) + { + errorMessage = errorMessage ?? "Parameter cannot be null"; + Throw(errorMessage); + } /// /// Checks if an object is empty and throws an exception if it is diff --git a/src/c#/GeneralUpdate.Core/Pipelines/Middleware/MiddlewareExtensions.cs b/src/c#/GeneralUpdate.Core/Pipelines/Middleware/MiddlewareExtensions.cs index 4ffa3b163537e8da1a9a21c4b67d7e49f1bfbf3a..0fd56870c272e72d3ae7dd2e1f72bc6f813bb13e 100644 --- a/src/c#/GeneralUpdate.Core/Pipelines/Middleware/MiddlewareExtensions.cs +++ b/src/c#/GeneralUpdate.Core/Pipelines/Middleware/MiddlewareExtensions.cs @@ -17,7 +17,7 @@ namespace GeneralUpdate.Core.Pipelines.Middleware public static IPipelineBuilder UseMiddleware<[DynamicallyAccessedMembers(MiddlewareAccessibility)] TMiddleware>(this IPipelineBuilder pipeline) => pipeline.UseMiddleware(typeof(TMiddleware),true); - public static IPipelineBuilder UseMiddlewareIf<[DynamicallyAccessedMembers(MiddlewareAccessibility)] TMiddleware>(this IPipelineBuilder pipeline,bool condition) => pipeline.UseMiddleware(typeof(TMiddleware), condition); + public static IPipelineBuilder UseMiddlewareIf<[DynamicallyAccessedMembers(MiddlewareAccessibility)] TMiddleware>(this IPipelineBuilder pipeline,bool condition = false) => pipeline.UseMiddleware(typeof(TMiddleware), condition); public static IPipelineBuilder UseMiddleware( this IPipelineBuilder pipeline, diff --git a/src/c#/GeneralUpdate.Differential/Domain/Entity/.gitkeep b/src/c#/GeneralUpdate.Differential/Domain/Entity/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/c#/GeneralUpdate.Differential/GeneralUpdate.Differential.csproj b/src/c#/GeneralUpdate.Differential/GeneralUpdate.Differential.csproj index b39690182ab1d593e1c8b63cad920c0cfeaeacb5..00fffc8937275530eeed7553838a499711a6cf66 100644 --- a/src/c#/GeneralUpdate.Differential/GeneralUpdate.Differential.csproj +++ b/src/c#/GeneralUpdate.Differential/GeneralUpdate.Differential.csproj @@ -15,6 +15,7 @@ + @@ -27,6 +28,8 @@ + +