From 5bdcda75313bb4182b840b99afa74c3ddcbc49aa Mon Sep 17 00:00:00 2001 From: Juster Zhu Date: Sat, 23 Dec 2023 20:07:35 +0800 Subject: [PATCH 1/3] update readme --- README.md | 2 +- README_en.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bc33e58..83bff3e 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ | 黑名单 | 支持 | 在更新过程中会跳过黑名单中的文件列表和文件扩展名列表。 | | OSS | 支持 | 极简化更新,是一套独立的更新机制。只需要在文件服务器中放置version.json的版本配置文件。组件会根据配置文件中的版本信息进行更新下载。(支持Windows,MAUI Android) | | 回滚 | 待测试 | 逐版本更新时会备份每个版本,如果更新失败则逐版本回滚。 | -| 驱动更新 | 待测试 | 逐版本更新时会备份每个版本的驱动文件(.inf),如果更新失败则逐版本回滚。 | +| 驱动更新 | 支持 | 逐版本更新时会备份每个版本的驱动文件(.inf),如果更新失败则逐版本回滚。 | | 遗言 | 待测试 | 开机时和升级时会检查升级是否成功,如果失败则根据遗言还原之前的备份。遗言是更新之前就已经自动创建在C:\generalupdate_willmessages目录下的will_message.json文件。will_message.json的内容是持久化回滚备份的文件目录相关信息。(需要部署GeneralUpdate.SystemService系统服务) | | 自定义方法列表 | 待测试 | 注入一个自定义方法集合,该集合会在更新启动前执行。执行自定义方法列表如果出现任何异常,将通过异常订阅通知。(推荐在更新之前检查当前软件环境) | diff --git a/README_en.md b/README_en.md index d0ffb77..7687904 100644 --- a/README_en.md +++ b/README_en.md @@ -27,7 +27,7 @@ | Black list | yes | Files and file extensions from the blacklist are skipped during the update process. | | OSS | yes | Minimal updates require only the version configuration file of version.json to be placed on the file server. Components are updated and downloaded based on the version information in the configuration file.(Supported windows,MAUI Android) | | 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 | test | 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. | +| 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) | -- Gitee From 5b7bbad3552218f4e67ebaf4d2b25f2f87bce56c Mon Sep 17 00:00:00 2001 From: Juster Zhu Date: Sun, 24 Dec 2023 00:38:13 +0800 Subject: [PATCH 2/3] Update GeneralUpdate.ClientCore.csproj --- src/c#/GeneralUpdate.ClientCore/GeneralUpdate.ClientCore.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/c#/GeneralUpdate.ClientCore/GeneralUpdate.ClientCore.csproj b/src/c#/GeneralUpdate.ClientCore/GeneralUpdate.ClientCore.csproj index 9a5012e..156e66d 100644 --- a/src/c#/GeneralUpdate.ClientCore/GeneralUpdate.ClientCore.csproj +++ b/src/c#/GeneralUpdate.ClientCore/GeneralUpdate.ClientCore.csproj @@ -107,6 +107,7 @@ + -- Gitee From da7ae2ba2976498178886ebcce0c18d4cbef3835 Mon Sep 17 00:00:00 2001 From: Juster Zhu Date: Sun, 24 Dec 2023 22:03:59 +0800 Subject: [PATCH 3/3] refactor: driver backup --- .../GeneralClientBootstrap.cs | 21 +++++++ .../Driver/DriverProcessor.cs | 3 + .../Driver/InstallDriverCommand.cs | 3 + .../Pipelines/Middleware/DriveMiddleware.cs | 57 +++++++++++++++++-- .../Middleware/MiddlewareExtensions.cs | 2 +- 5 files changed, 81 insertions(+), 5 deletions(-) diff --git a/src/c#/GeneralUpdate.ClientCore/GeneralClientBootstrap.cs b/src/c#/GeneralUpdate.ClientCore/GeneralClientBootstrap.cs index b20053c..555e18f 100644 --- a/src/c#/GeneralUpdate.ClientCore/GeneralClientBootstrap.cs +++ b/src/c#/GeneralUpdate.ClientCore/GeneralClientBootstrap.cs @@ -13,6 +13,7 @@ using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; +using System.Security; using System.Threading.Tasks; namespace GeneralUpdate.ClientCore @@ -54,6 +55,7 @@ namespace GeneralUpdate.ClientCore private async Task BaseLaunch() { + ClearEnvironmentVariable(); await ExecuteCustomOptions(); var versionService = new VersionService(); var mainResp = await versionService.ValidationVersion(Packet.MainUpdateUrl); @@ -244,6 +246,25 @@ namespace GeneralUpdate.ClientCore } } + /// + /// The values passed between processes during previous updates are cleared when the client starts. + /// + private void ClearEnvironmentVariable() + { + try + { + Environment.SetEnvironmentVariable("ProcessBase64", null, EnvironmentVariableTarget.Machine); + } + catch (SecurityException ex) + { + Trace.WriteLine($"Error: You do not have sufficient permissions to delete this environment variable.{ex}"); + } + catch (ArgumentException ex) + { + Trace.WriteLine($"Error: The environment variable name is invalid. {ex}"); + } + } + #endregion Private Methods } } \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/Driver/DriverProcessor.cs b/src/c#/GeneralUpdate.Core/Driver/DriverProcessor.cs index 9d02c28..88b2546 100644 --- a/src/c#/GeneralUpdate.Core/Driver/DriverProcessor.cs +++ b/src/c#/GeneralUpdate.Core/Driver/DriverProcessor.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; namespace GeneralUpdate.Core.Driver { @@ -19,6 +20,8 @@ namespace GeneralUpdate.Core.Driver /// public void ProcessCommands() { + if (!_commands.Any()) return; + /* * This section describes the PnPUtil command. * https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/pnputil-command-syntax diff --git a/src/c#/GeneralUpdate.Core/Driver/InstallDriverCommand.cs b/src/c#/GeneralUpdate.Core/Driver/InstallDriverCommand.cs index 9e7a61f..41c3f53 100644 --- a/src/c#/GeneralUpdate.Core/Driver/InstallDriverCommand.cs +++ b/src/c#/GeneralUpdate.Core/Driver/InstallDriverCommand.cs @@ -4,6 +4,9 @@ using System.Text; namespace GeneralUpdate.Core.Driver { + /// + /// Install the new driver, and if the installation fails, the backup is automatically restored. + /// public class InstallDriverCommand : IDriverCommand { private DriverInformation _information; diff --git a/src/c#/GeneralUpdate.Core/Pipelines/Middleware/DriveMiddleware.cs b/src/c#/GeneralUpdate.Core/Pipelines/Middleware/DriveMiddleware.cs index 701f07a..018f02c 100644 --- a/src/c#/GeneralUpdate.Core/Pipelines/Middleware/DriveMiddleware.cs +++ b/src/c#/GeneralUpdate.Core/Pipelines/Middleware/DriveMiddleware.cs @@ -1,4 +1,7 @@ -using System.IO; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; using System.Threading.Tasks; using GeneralUpdate.Core.Driver; using GeneralUpdate.Core.Pipelines.Context; @@ -12,20 +15,66 @@ namespace GeneralUpdate.Core.Pipelines.Middleware { public async Task InvokeAsync(BaseContext context, MiddlewareStack stack) { + var drivers = GetAllDriverDirectories(context.TargetPath); + var information = new DriverInformation.Builder() .SetInstallDirectory(Path.Combine(context.SourcePath,context.Version.ToString())) + //TODO: TargetPath to CachePath .SetOutPutDirectory(Path.Combine(context.TargetPath,context.Version.ToString())) - .SetDriverNames(null) + .SetDriverNames(drivers) .Build(); var processor = new DriverProcessor(); - // Backup driver. processor.AddCommand(new BackupDriverCommand(information)); - // Install the new driver, and if the installation fails, the backup is automatically restored. + processor.AddCommand(new DeleteDriverCommand(information)); processor.AddCommand(new InstallDriverCommand(information)); processor.ProcessCommands(); + var node = stack.Pop(); if (node != null) await node.Next.Invoke(context, stack); } + + /// + /// Identifies all folders containing driver files in the specified directory and returns the directory collection. + /// + /// + /// + private List GetAllDriverDirectories(string path) + { + var driverDirectories = new HashSet(); + try + { + foreach (string filePath in Directory.GetFiles(path)) + { + if (IsDriverFile(filePath)) + { + driverDirectories.Add(filePath); + } + } + + foreach (string directory in Directory.GetDirectories(path)) + { + driverDirectories.UnionWith(GetAllDriverDirectories(directory)); + } + } + catch (UnauthorizedAccessException) + { + Trace.WriteLine("No access directory:" + path); + } + catch (PathTooLongException) + { + Trace.WriteLine("Path overlength:" + path); + } + + return new List(driverDirectories); + } + + /// + /// Match the driver installation boot file. + /// + /// + /// + private bool IsDriverFile(string filePath)=> + string.Equals(Path.GetExtension(filePath), ".inf", StringComparison.OrdinalIgnoreCase); } } \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/Pipelines/Middleware/MiddlewareExtensions.cs b/src/c#/GeneralUpdate.Core/Pipelines/Middleware/MiddlewareExtensions.cs index 6fab560..4ffa3b1 100644 --- a/src/c#/GeneralUpdate.Core/Pipelines/Middleware/MiddlewareExtensions.cs +++ b/src/c#/GeneralUpdate.Core/Pipelines/Middleware/MiddlewareExtensions.cs @@ -32,7 +32,7 @@ namespace GeneralUpdate.Core.Pipelines.Middleware MethodInfo invokeMethod = null; foreach (var method in methods) { - if (string.Equals(method.Name, InvokeAsyncMethodName, StringComparison.Ordinal)) + if (string.Equals(method.Name, InvokeAsyncMethodName, StringComparison.OrdinalIgnoreCase)) { if (method == null) throw new InvalidOperationException(InvokeAsyncMethodName); invokeMethod = method; -- Gitee