diff --git a/src/c#/CoreTest/Driver/DriverInfoTests.cs b/src/c#/CoreTest/Driver/DriverInfoTests.cs deleted file mode 100644 index a45e8268..00000000 --- a/src/c#/CoreTest/Driver/DriverInfoTests.cs +++ /dev/null @@ -1,60 +0,0 @@ -using GeneralUpdate.Core.Driver; -using Xunit; - -namespace CoreTest.Driver -{ - /// - /// Contains test cases for the DriverInfo class. - /// Tests driver metadata storage. - /// - public class DriverInfoTests - { - /// - /// Tests that DriverInfo properties can be set and retrieved. - /// - [Fact] - public void Properties_CanBeSetAndRetrieved() - { - // Arrange - var driverInfo = new DriverInfo(); - - // Act - driverInfo.PublishedName = "oem1.inf"; - driverInfo.OriginalName = "mydriver.inf"; - driverInfo.Provider = "Microsoft"; - driverInfo.ClassName = "Display"; - driverInfo.ClassGUID = "{4d36e968-e325-11ce-bfc1-08002be10318}"; - driverInfo.Version = "1.0.0.0"; - driverInfo.Signer = "Microsoft Windows Hardware Compatibility Publisher"; - - // Assert - Assert.Equal("oem1.inf", driverInfo.PublishedName); - Assert.Equal("mydriver.inf", driverInfo.OriginalName); - Assert.Equal("Microsoft", driverInfo.Provider); - Assert.Equal("Display", driverInfo.ClassName); - Assert.Equal("{4d36e968-e325-11ce-bfc1-08002be10318}", driverInfo.ClassGUID); - Assert.Equal("1.0.0.0", driverInfo.Version); - Assert.Equal("Microsoft Windows Hardware Compatibility Publisher", driverInfo.Signer); - } - - /// - /// Tests that DriverInfo can be instantiated with default values. - /// - [Fact] - public void Constructor_CreatesInstanceWithDefaultValues() - { - // Act - var driverInfo = new DriverInfo(); - - // Assert - Assert.NotNull(driverInfo); - Assert.Null(driverInfo.PublishedName); - Assert.Null(driverInfo.OriginalName); - Assert.Null(driverInfo.Provider); - Assert.Null(driverInfo.ClassName); - Assert.Null(driverInfo.ClassGUID); - Assert.Null(driverInfo.Version); - Assert.Null(driverInfo.Signer); - } - } -} diff --git a/src/c#/CoreTest/Driver/DriverInformationTests.cs b/src/c#/CoreTest/Driver/DriverInformationTests.cs deleted file mode 100644 index b5e92fc9..00000000 --- a/src/c#/CoreTest/Driver/DriverInformationTests.cs +++ /dev/null @@ -1,132 +0,0 @@ -using GeneralUpdate.Core.Driver; -using Xunit; - -namespace CoreTest.Driver -{ - /// - /// Contains test cases for the DriverInformation class. - /// Tests driver information builder pattern and validation. - /// - public class DriverInformationTests - { - /// - /// Tests that Builder can create a valid DriverInformation instance. - /// - [Fact] - public void Builder_WithAllRequiredFields_BuildsSuccessfully() - { - // Arrange - var builder = new DriverInformation.Builder(); - var fieldMappings = new Dictionary - { - { "field1", "value1" } - }; - - // Act - var information = builder - .SetDriverFileExtension(".inf") - .SetOutPutDirectory("/test/output") - .SetDriverDirectory("/test/drivers") - .SetFieldMappings(fieldMappings) - .Build(); - - // Assert - Assert.NotNull(information); - Assert.Equal(".inf", information.DriverFileExtension); - Assert.Equal("/test/output", information.OutPutDirectory); - Assert.Equal("/test/drivers", information.DriverDirectory); - Assert.Equal(fieldMappings, information.FieldMappings); - } - - /// - /// Tests that Builder throws ArgumentNullException when OutPutDirectory is not set. - /// - [Fact] - public void Builder_WithoutOutPutDirectory_ThrowsArgumentNullException() - { - // Arrange - var builder = new DriverInformation.Builder(); - - // Act & Assert - Assert.Throws(() => - builder - .SetDriverFileExtension(".inf") - .SetDriverDirectory("/test/drivers") - .Build()); - } - - /// - /// Tests that Builder throws ArgumentNullException when DriverFileExtension is not set. - /// - [Fact] - public void Builder_WithoutDriverFileExtension_ThrowsArgumentNullException() - { - // Arrange - var builder = new DriverInformation.Builder(); - - // Act & Assert - Assert.Throws(() => - builder - .SetOutPutDirectory("/test/output") - .SetDriverDirectory("/test/drivers") - .Build()); - } - - /// - /// Tests that Builder can set and retrieve all properties. - /// - [Fact] - public void Builder_SetAllProperties_ReturnsCorrectValues() - { - // Arrange - var builder = new DriverInformation.Builder(); - var fieldMappings = new Dictionary - { - { "key1", "val1" }, - { "key2", "val2" } - }; - - // Act - var information = builder - .SetDriverFileExtension(".sys") - .SetOutPutDirectory("/output/path") - .SetDriverDirectory("/driver/path") - .SetFieldMappings(fieldMappings) - .Build(); - - // Assert - Assert.Equal(".sys", information.DriverFileExtension); - Assert.Equal("/output/path", information.OutPutDirectory); - Assert.Equal("/driver/path", information.DriverDirectory); - Assert.Equal(2, information.FieldMappings.Count); - } - - /// - /// Tests that Drivers property can be set and retrieved. - /// - [Fact] - public void Drivers_CanBeSetAndRetrieved() - { - // Arrange - var builder = new DriverInformation.Builder(); - var drivers = new List - { - new DriverInfo { OriginalName = "driver1.inf", PublishedName = "oem1.inf" }, - new DriverInfo { OriginalName = "driver2.inf", PublishedName = "oem2.inf" } - }; - - // Act - var information = builder - .SetDriverFileExtension(".inf") - .SetOutPutDirectory("/test/output") - .SetDriverDirectory("/test/drivers") - .Build(); - - information.Drivers = drivers; - - // Assert - Assert.NotNull(information.Drivers); - Assert.Equal(2, information.Drivers.Count()); - } - } -} diff --git a/src/c#/CoreTest/Driver/DriverProcessorTests.cs b/src/c#/CoreTest/Driver/DriverProcessorTests.cs deleted file mode 100644 index 1c60b2fb..00000000 --- a/src/c#/CoreTest/Driver/DriverProcessorTests.cs +++ /dev/null @@ -1,100 +0,0 @@ -using GeneralUpdate.Core.Driver; -using Moq; -using Xunit; - -namespace CoreTest.Driver -{ - /// - /// Contains test cases for the DriverProcessor class. - /// Tests driver command management and execution. - /// - public class DriverProcessorTests - { - /// - /// Tests that processor can be instantiated. - /// - [Fact] - public void Constructor_CreatesInstance() - { - // Act - var processor = new DriverProcessor(); - - // Assert - Assert.NotNull(processor); - } - - /// - /// Tests that commands can be added to the processor. - /// - [Fact] - public void AddCommand_AddsCommandToProcessor() - { - // Arrange - var processor = new DriverProcessor(); - var mockCommand = new Mock(); - - // Act - processor.AddCommand(mockCommand.Object); - - // Assert - if no exception, command was added - } - - /// - /// Tests that ProcessCommands executes all added commands. - /// - [Fact] - public void ProcessCommands_ExecutesAllCommands() - { - // Arrange - var processor = new DriverProcessor(); - var mockCommand1 = new Mock(); - var mockCommand2 = new Mock(); - var mockCommand3 = new Mock(); - - processor.AddCommand(mockCommand1.Object); - processor.AddCommand(mockCommand2.Object); - processor.AddCommand(mockCommand3.Object); - - // Act - processor.ProcessCommands(); - - // Assert - mockCommand1.Verify(c => c.Execute(), Times.Once); - mockCommand2.Verify(c => c.Execute(), Times.Once); - mockCommand3.Verify(c => c.Execute(), Times.Once); - } - - /// - /// Tests that ProcessCommands with no commands does not throw. - /// - [Fact] - public void ProcessCommands_WithNoCommands_DoesNotThrow() - { - // Arrange - var processor = new DriverProcessor(); - - // Act & Assert - should not throw - processor.ProcessCommands(); - Assert.True(true); - } - - /// - /// Tests that ProcessCommands clears commands after execution. - /// - [Fact] - public void ProcessCommands_ClearsCommandsAfterExecution() - { - // Arrange - var processor = new DriverProcessor(); - var mockCommand = new Mock(); - processor.AddCommand(mockCommand.Object); - - // Act - processor.ProcessCommands(); - processor.ProcessCommands(); // Call again - - // Assert - Execute should only be called once (from first ProcessCommands) - mockCommand.Verify(c => c.Execute(), Times.Once); - } - } -} diff --git a/src/c#/CoreTest/Pipeline/DriverMiddlewareTests.cs b/src/c#/CoreTest/Pipeline/DriverMiddlewareTests.cs deleted file mode 100644 index 39467ac7..00000000 --- a/src/c#/CoreTest/Pipeline/DriverMiddlewareTests.cs +++ /dev/null @@ -1,98 +0,0 @@ -using GeneralUpdate.Common.Internal.Pipeline; -using GeneralUpdate.Core.Pipeline; -using Xunit; - -namespace CoreTest.Pipeline -{ - /// - /// Contains test cases for the DriverMiddleware class. - /// Tests driver installation and management functionality. - /// - public class DriverMiddlewareTests - { - /// - /// Tests that DriverMiddleware can be instantiated. - /// - [Fact] - public void Constructor_CreatesInstance() - { - // Act - var middleware = new DriverMiddleware(); - - // Assert - Assert.NotNull(middleware); - } - - /// - /// Tests that InvokeAsync returns early when DriverOutPut is missing. - /// - [Fact] - public async Task InvokeAsync_WithMissingDriverOutPut_ReturnsEarly() - { - // Arrange - var middleware = new DriverMiddleware(); - var context = new PipelineContext(); - - // Act - should return early without throwing - await middleware.InvokeAsync(context); - } - - /// - /// Tests that InvokeAsync returns early when PatchPath is missing. - /// - [Fact] - public async Task InvokeAsync_WithMissingPatchPath_ReturnsEarly() - { - // Arrange - var middleware = new DriverMiddleware(); - var context = new PipelineContext(); - context.Add("DriverOutPut", "/test/output"); - - // Act - should return early without throwing - await middleware.InvokeAsync(context); - } - - /// - /// Tests that InvokeAsync returns early when FieldMappings is missing. - /// - [Fact] - public async Task InvokeAsync_WithMissingFieldMappings_ReturnsEarly() - { - // Arrange - var middleware = new DriverMiddleware(); - var context = new PipelineContext(); - context.Add("DriverOutPut", "/test/output"); - context.Add("PatchPath", "/test/patch"); - - // Act - should return early without throwing - await middleware.InvokeAsync(context); - } - - /// - /// Tests that context can store driver-related values. - /// - [Fact] - public void Context_CanStoreDriverValues() - { - // Arrange - var context = new PipelineContext(); - var outPutPath = "/test/output"; - var patchPath = "/test/patch"; - var fieldMappings = new Dictionary - { - { "field1", "value1" }, - { "field2", "value2" } - }; - - // Act - context.Add("DriverOutPut", outPutPath); - context.Add("PatchPath", patchPath); - context.Add("FieldMappings", fieldMappings); - - // Assert - Assert.Equal(outPutPath, context.Get("DriverOutPut")); - Assert.Equal(patchPath, context.Get("PatchPath")); - Assert.Equal(fieldMappings, context.Get>("FieldMappings")); - } - } -} diff --git a/src/c#/GeneralUpdate.Core/Driver/BackupDriverCommand.cs b/src/c#/GeneralUpdate.Core/Driver/BackupDriverCommand.cs deleted file mode 100644 index 8613b547..00000000 --- a/src/c#/GeneralUpdate.Core/Driver/BackupDriverCommand.cs +++ /dev/null @@ -1,124 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Text; -using GeneralUpdate.Common.FileBasic; - -namespace GeneralUpdate.Core.Driver -{ - /// - /// When the /export-driver command backs up a driver, it backs up the driver package along with all its dependencies, such as associated library files and other related files. - /// - public class BackupDriverCommand(DriverInformation information) : DriverCommand - { - private readonly string _driverExtension = $"*{information.DriverFileExtension}"; - - public override void Execute() - { - var uninstalledDrivers = Directory.GetFiles(information.DriverDirectory, _driverExtension, SearchOption.AllDirectories).ToList(); - var installedDrivers = GetInstalledDrivers(information.FieldMappings); - var tempDrivers = installedDrivers.Where(a => uninstalledDrivers.Any(b => string.Equals(a.OriginalName, Path.GetFileName(b)))).ToList(); - information.Drivers = tempDrivers; - - //Export the backup according to the driver name. - if (Directory.Exists(information.OutPutDirectory)) - { - StorageManager.DeleteDirectory(information.OutPutDirectory); - } - - Directory.CreateDirectory(information.OutPutDirectory); - - /* - * Back up the specified list of drives. - */ - foreach (var driver in tempDrivers) - { - /* - * If no test driver files are available, you can run the following command to export all installed driver files. - * (1) dism /online /export-driver /destination:"D:\packet\cache\" - * (2) pnputil /export-driver * D:\packet\cache - * - * The following code example exports the specified driver to the specified directory. - * pnputil /export-driver oemXX.inf D:\packet\cache - */ - var path = Path.Combine(information.OutPutDirectory, driver.PublishedName); - var command = new StringBuilder("/c pnputil /export-driver ") - .Append(driver.PublishedName) - .Append(' ') - .Append(path) - .ToString(); - - if (!Directory.Exists(path)) - { - Directory.CreateDirectory(path); - } - - CommandExecutor.ExecuteCommand(command); - } - } - - private IEnumerable GetInstalledDrivers(Dictionary fieldMappings) - { - var drivers = new List(); - var process = new Process(); - process.StartInfo.FileName = "pnputil"; - process.StartInfo.Arguments = "/enum-drivers"; - process.StartInfo.RedirectStandardOutput = true; - process.StartInfo.UseShellExecute = false; - process.StartInfo.CreateNoWindow = true; - process.Start(); - - var output = process.StandardOutput.ReadToEnd(); - process.WaitForExit(); - - var lines = output.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); - - DriverInfo currentDriver = null; - foreach (var line in lines) - { - if (line.StartsWith(fieldMappings["PublishedName"])) - { - if (currentDriver != null) - { - drivers.Add(currentDriver); - } - currentDriver = new (); - currentDriver.PublishedName = line.Split(new[] { ':' }, 2)[1].Trim(); - } - else if (line.StartsWith(fieldMappings["OriginalName"]) && currentDriver != null) - { - currentDriver.OriginalName = line.Split(new[] { ':' }, 2)[1].Trim(); - } - else if (line.StartsWith(fieldMappings["Provider"]) && currentDriver != null) - { - currentDriver.Provider = line.Split(new[] { ':' }, 2)[1].Trim(); - } - else if (line.StartsWith(fieldMappings["ClassName"]) && currentDriver != null) - { - currentDriver.ClassName = line.Split(new[] { ':' }, 2)[1].Trim(); - } - else if (line.StartsWith(fieldMappings["ClassGUID"]) && currentDriver != null) - { - currentDriver.ClassGUID = line.Split(new[] { ':' }, 2)[1].Trim(); - } - else if (line.StartsWith(fieldMappings["Version"]) && currentDriver != null) - { - currentDriver.Version = line.Split(new[] { ':' }, 2)[1].Trim(); - } - else if (line.StartsWith(fieldMappings["Signer"]) && currentDriver != null) - { - currentDriver.Signer = line.Split(new[] { ':' }, 2)[1].Trim(); - } - } - - if (currentDriver != null) - { - drivers.Add(currentDriver); - } - - return drivers; - } - } -} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/Driver/CommandExecutor.cs b/src/c#/GeneralUpdate.Core/Driver/CommandExecutor.cs deleted file mode 100644 index d8333c62..00000000 --- a/src/c#/GeneralUpdate.Core/Driver/CommandExecutor.cs +++ /dev/null @@ -1,66 +0,0 @@ -using System; -using System.Diagnostics; -using GeneralUpdate.Common.Shared; - -namespace GeneralUpdate.Core.Driver -{ - /// - /// When the process starts, PnPUtil is used to execute driver processing commands. - /// - public class CommandExecutor - { - private CommandExecutor() - { } - - public static void ExecuteCommand(string command) - { - /* - * - *Problems may occur, including: -Permission issues: PnPUtil requires administrator rights to run. If you try to run it without the proper permissions, the backup or restore may fail. -Driver compatibility: Although the backed up drivers work properly at backup time, if the operating system is upgraded, the backed up drivers may no longer be compatible with the new operating system version. -Hardware problems: If the hardware device fails or the hardware configuration changes, the backup driver may not work properly. - - To minimize these risks, the following measures are recommended: -Before doing anything, create a system restore point so that it can be restored to its previous state if something goes wrong. -Update the driver regularly to ensure that the driver is compatible with the current operating system version. -If possible, use pre-tested drivers that are proven to work. - * - */ - var processStartInfo = new ProcessStartInfo - { - WindowStyle = ProcessWindowStyle.Hidden, - FileName = "cmd.exe", - Arguments = command, - UseShellExecute = false, - RedirectStandardOutput = true, - RedirectStandardError = true, - Verb = "runas" - }; - - var process = new Process(); - try - { - process.StartInfo = processStartInfo; - process.Start(); - process.WaitForExit(); - - var output = process.StandardOutput.ReadToEnd(); - GeneralTracer.Info(output); - - var error = process.StandardError.ReadToEnd(); - if (!string.IsNullOrEmpty(error)) - { - GeneralTracer.Error(error); - } - - if (process.ExitCode != 0) - throw new ApplicationException($"Operation failed code: {process.ExitCode}"); - } - finally - { - process.Dispose(); - } - } - } -} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/Driver/DeleteDriverCommand.cs b/src/c#/GeneralUpdate.Core/Driver/DeleteDriverCommand.cs deleted file mode 100644 index f0fe0e7a..00000000 --- a/src/c#/GeneralUpdate.Core/Driver/DeleteDriverCommand.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Text; - -namespace GeneralUpdate.Core.Driver; - -public class DeleteDriverCommand(DriverInformation information) : DriverCommand -{ - public override void Execute() - { - //Before installing the driver, delete the driver that has been installed on the local system. Otherwise, an exception may occur. - foreach (var driver in information.Drivers) - { - var command = new StringBuilder("/c pnputil /delete-driver ") - .Append(driver.PublishedName) - .ToString(); - CommandExecutor.ExecuteCommand(command); - } - } -} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/Driver/DriverCommand.cs b/src/c#/GeneralUpdate.Core/Driver/DriverCommand.cs deleted file mode 100644 index eac09220..00000000 --- a/src/c#/GeneralUpdate.Core/Driver/DriverCommand.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; -using GeneralUpdate.Common.FileBasic; - -namespace GeneralUpdate.Core.Driver -{ - public abstract class DriverCommand - { - public abstract void Execute(); - - /// - /// Search for driver files. - /// - /// - /// - protected static IEnumerable SearchDrivers(string patchPath, string fileExtension) - { - var files = StorageManager.GetAllFiles(patchPath, BlackListManager.Instance.SkipDirectorys.ToList()); - return files.Where(x => x.FullName.EndsWith(fileExtension)).ToList(); - } - } -} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/Driver/DriverInfo.cs b/src/c#/GeneralUpdate.Core/Driver/DriverInfo.cs deleted file mode 100644 index 539cfb1b..00000000 --- a/src/c#/GeneralUpdate.Core/Driver/DriverInfo.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace GeneralUpdate.Core.Driver; - -public class DriverInfo -{ - public string PublishedName { get; set; } - public string OriginalName { get; set; } - public string Provider { get; set; } - public string ClassName { get; set; } - public string ClassGUID { get; set; } - public string Version { get; set; } - public string Signer { get; set; } -} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/Driver/DriverInformation.cs b/src/c#/GeneralUpdate.Core/Driver/DriverInformation.cs deleted file mode 100644 index e396e2a6..00000000 --- a/src/c#/GeneralUpdate.Core/Driver/DriverInformation.cs +++ /dev/null @@ -1,70 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace GeneralUpdate.Core.Driver -{ - /// - /// Driver information object. - /// - public class DriverInformation - { - public Dictionary FieldMappings { get; private set; } - - public string DriverFileExtension { get; private set; } - - /// - /// All driver backup directories. - /// - public string OutPutDirectory { get; private set; } - - public string DriverDirectory { get; private set; } - - /// - /// A collection of driver files to be backed up. - /// - public IEnumerable Drivers { get; set; } - - private DriverInformation() - { } - - public class Builder - { - private DriverInformation _information = new (); - - public Builder SetDriverFileExtension(string fileExtension) - { - _information.DriverFileExtension = fileExtension; - return this; - } - - public Builder SetOutPutDirectory(string outPutDirectory) - { - _information.OutPutDirectory = outPutDirectory; - return this; - } - - public Builder SetDriverDirectory(string driverDirectory) - { - _information.DriverDirectory = driverDirectory; - return this; - } - - public Builder SetFieldMappings(Dictionary fieldMappings) - { - _information.FieldMappings = fieldMappings; - return this; - } - - public DriverInformation Build() - { - if (string.IsNullOrWhiteSpace(_information.OutPutDirectory) || - string.IsNullOrWhiteSpace(_information.DriverFileExtension)) - { - throw new ArgumentNullException("Cannot create DriverInformation, not all fields are set."); - } - - return _information; - } - } - } -} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/Driver/DriverProcessor.cs b/src/c#/GeneralUpdate.Core/Driver/DriverProcessor.cs deleted file mode 100644 index 3f4b848d..00000000 --- a/src/c#/GeneralUpdate.Core/Driver/DriverProcessor.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.Collections.Generic; -using System.Linq; - -namespace GeneralUpdate.Core.Driver -{ - /// - /// Handle all drive-related. - /// - public class DriverProcessor - { - private readonly List _commands = new (); - - public void AddCommand(DriverCommand command) => _commands.Add(command); - - /// - /// Execute all driver-related commands. - /// - 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 - */ - foreach (var command in _commands) - { - command.Execute(); - } - _commands.Clear(); - } - } -} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/Driver/InstallDriverCommand.cs b/src/c#/GeneralUpdate.Core/Driver/InstallDriverCommand.cs deleted file mode 100644 index cf42b8b3..00000000 --- a/src/c#/GeneralUpdate.Core/Driver/InstallDriverCommand.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; -using System.IO; -using System.Text; - -namespace GeneralUpdate.Core.Driver -{ - /// - /// Install the new driver, and if the installation fails, the backup is automatically restored. - /// - public class InstallDriverCommand(DriverInformation information) : DriverCommand - { - public override void Execute() - { - foreach (var driver in information.Drivers) - { - try - { - /* - * 1.It is best to ensure that the installed file is OEM INF, otherwise PnPUtil may indicate that non-OEM INF cannot perform the current operation. - * - * 2.Before installation, you need to delete the previously installed driver, otherwise PnPUtil will prompt 259 to exit the code. - * (On Windows, an ExitCode value of 259 (STILL_ACTIVE) means that the process is still running) - * If you do not remove the previous installation 259 prompt will give you a misleading impression of what is running. - */ - var path = Path.Combine(information.DriverDirectory, driver.OriginalName); - var command = new StringBuilder("/c pnputil /add-driver ") - .Append(path) - .Append(" /install") - .ToString(); - CommandExecutor.ExecuteCommand(command); - } - catch (Exception ex) - { - //restore all the drivers in the backup directory. - new RestoreDriverCommand(information).Execute(); - throw new ApplicationException($"Failed to execute driver command: {ex.Message}, details: {ex} !"); - } - } - } - } -} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/Driver/RestoreDriverCommand.cs b/src/c#/GeneralUpdate.Core/Driver/RestoreDriverCommand.cs deleted file mode 100644 index a958e6b1..00000000 --- a/src/c#/GeneralUpdate.Core/Driver/RestoreDriverCommand.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; -using System.Linq; -using System.Text; -using GeneralUpdate.Common.FileBasic; - -namespace GeneralUpdate.Core.Driver -{ - public class RestoreDriverCommand(DriverInformation information) - { - public void Execute() - { - try - { - var backupFiles = StorageManager.GetAllFiles(information.OutPutDirectory, BlackListManager.Instance.SkipDirectorys.ToList()); - var fileExtension = information.DriverFileExtension; - var drivers = backupFiles.Where(x => x.FullName.EndsWith(fileExtension)).ToList(); - - foreach (var driver in drivers) - { - try - { - //Install all drivers in the specified directory, and if the installation fails, restore all the drivers in the backup directory. - var command = new StringBuilder("/c pnputil /add-driver ") - .Append(driver.FullName) - .Append(" /install") - .ToString(); - CommandExecutor.ExecuteCommand(command); - } - catch (Exception e) - { - throw new ApplicationException($"Failed to execute install command for {driver.FullName}, error: {e.Message} !"); - } - } - } - catch - { - throw new ApplicationException($"Failed to execute restore command for {information.OutPutDirectory}"); - } - } - } -} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/Pipeline/DriverMiddleware.cs b/src/c#/GeneralUpdate.Core/Pipeline/DriverMiddleware.cs deleted file mode 100644 index c96ce6b0..00000000 --- a/src/c#/GeneralUpdate.Core/Pipeline/DriverMiddleware.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using GeneralUpdate.Common.Internal.Pipeline; -using GeneralUpdate.Core.Driver; - -namespace GeneralUpdate.Core.Pipeline; - -/// -/// Driver update. -/// Use for Windows Vista/Windows 7/Windows 8/Windows 8.1/Windows 10/Windows 11/Windows Server 2008. -/// -public class DriverMiddleware : IMiddleware -{ - private const string FileExtension = ".inf"; - - public Task InvokeAsync(PipelineContext context) - { - return Task.Run(() => - { - var outPutPath = context.Get("DriverOutPut"); - if (string.IsNullOrWhiteSpace(outPutPath)) - return; - - var patchPath = context.Get("PatchPath"); - if (string.IsNullOrWhiteSpace(patchPath)) - return; - - var fieldMappings = context.Get>("FieldMappings"); - if (fieldMappings == null || fieldMappings.Count == 0) - return; - - var information = new DriverInformation.Builder() - .SetDriverFileExtension(FileExtension) - .SetOutPutDirectory(outPutPath) - .SetDriverDirectory(patchPath) - .SetFieldMappings(fieldMappings) - .Build(); - - var processor = new DriverProcessor(); - processor.AddCommand(new BackupDriverCommand(information)); - processor.AddCommand(new DeleteDriverCommand(information)); - processor.AddCommand(new InstallDriverCommand(information)); - processor.ProcessCommands(); - }); - } -} \ No newline at end of file diff --git a/src/c#/GeneralUpdate.Core/Strategys/LinuxStrategy.cs b/src/c#/GeneralUpdate.Core/Strategys/LinuxStrategy.cs index d52b7ca8..9de91fb7 100644 --- a/src/c#/GeneralUpdate.Core/Strategys/LinuxStrategy.cs +++ b/src/c#/GeneralUpdate.Core/Strategys/LinuxStrategy.cs @@ -33,8 +33,7 @@ protected override PipelineBuilder BuildPipeline(PipelineContext context) return new PipelineBuilder(context) .UseMiddlewareIf(_configinfo.PatchEnabled) .UseMiddleware() - .UseMiddleware() - .UseMiddlewareIf(_configinfo.DriveEnabled); + .UseMiddleware(); } public override void Execute() diff --git a/src/c#/GeneralUpdate.Core/Strategys/WindowsStrategy.cs b/src/c#/GeneralUpdate.Core/Strategys/WindowsStrategy.cs index 6c43a61c..78540f05 100644 --- a/src/c#/GeneralUpdate.Core/Strategys/WindowsStrategy.cs +++ b/src/c#/GeneralUpdate.Core/Strategys/WindowsStrategy.cs @@ -35,8 +35,7 @@ protected override PipelineBuilder BuildPipeline(PipelineContext context) return new PipelineBuilder(context) .UseMiddlewareIf(_configinfo.PatchEnabled) .UseMiddleware() - .UseMiddleware() - .UseMiddlewareIf(_configinfo.DriveEnabled); + .UseMiddleware(); } protected override void OnExecuteComplete() diff --git a/src/c#/GeneralUpdate.sln b/src/c#/GeneralUpdate.sln index 622b48ec..00d0daf8 100644 --- a/src/c#/GeneralUpdate.sln +++ b/src/c#/GeneralUpdate.sln @@ -11,26 +11,16 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GeneralUpdate.ClientCore", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GeneralUpdate.Differential", "GeneralUpdate.Differential\GeneralUpdate.Differential.csproj", "{40BDA496-7614-4213-92D0-3B1B187675D3}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{74BE0282-A10D-4A81-A0F0-FAA79A6152B7}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GeneralUpdate.Upgrad", "GeneralUpdate.Upgrad\GeneralUpdate.Upgrad.csproj", "{E1F9FF93-CA63-4A9C-82F0-450F09ED81F9}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GeneralUpdate.Client", "GeneralUpdate.Client\GeneralUpdate.Client.csproj", "{7779FB4A-D121-48CC-B033-C3D36BD5D4FF}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GeneralUpdate.Common", "GeneralUpdate.Common\GeneralUpdate.Common.csproj", "{D14E59CD-404B-467B-9C6D-91EFC5994D37}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GeneralUpdate.Bowl", "GeneralUpdate.Bowl\GeneralUpdate.Bowl.csproj", "{49D0687D-1321-48E9-84C3-936B10532367}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Generalupdate.CatBowl", "Generalupdate.CatBowl\Generalupdate.CatBowl.csproj", "{1BA0EEDF-D75A-49E9-9244-EA32DFA130B3}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GeneralUpdate.Extension", "GeneralUpdate.Extension\GeneralUpdate.Extension.csproj", "{7B8E164F-C2D8-4C5F-8E20-450FB56AEB34}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{245C36B9-612E-4AB0-979A-4D83A0D8117E}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExtensionTest", "ExtensionTest\ExtensionTest.csproj", "{3FA78F9A-A942-4F7E-A30D-70DF42E8A83D}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GeneralUpdate.Ext", "GeneralUpdate.Ext\GeneralUpdate.Ext.csproj", "{27028918-925E-45D4-BD72-199349B6E6AA}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BowlTest", "BowlTest\BowlTest.csproj", "{E407EE3C-D893-459C-84AA-4019537F2903}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClientCoreTest", "ClientCoreTest\ClientCoreTest.csproj", "{3590E969-0958-49ED-91A0-605ACC0B203C}" @@ -87,30 +77,6 @@ Global {40BDA496-7614-4213-92D0-3B1B187675D3}.Release|x64.Build.0 = Release|Any CPU {40BDA496-7614-4213-92D0-3B1B187675D3}.Release|x86.ActiveCfg = Release|Any CPU {40BDA496-7614-4213-92D0-3B1B187675D3}.Release|x86.Build.0 = Release|Any CPU - {E1F9FF93-CA63-4A9C-82F0-450F09ED81F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E1F9FF93-CA63-4A9C-82F0-450F09ED81F9}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E1F9FF93-CA63-4A9C-82F0-450F09ED81F9}.Debug|x64.ActiveCfg = Debug|Any CPU - {E1F9FF93-CA63-4A9C-82F0-450F09ED81F9}.Debug|x64.Build.0 = Debug|Any CPU - {E1F9FF93-CA63-4A9C-82F0-450F09ED81F9}.Debug|x86.ActiveCfg = Debug|Any CPU - {E1F9FF93-CA63-4A9C-82F0-450F09ED81F9}.Debug|x86.Build.0 = Debug|Any CPU - {E1F9FF93-CA63-4A9C-82F0-450F09ED81F9}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E1F9FF93-CA63-4A9C-82F0-450F09ED81F9}.Release|Any CPU.Build.0 = Release|Any CPU - {E1F9FF93-CA63-4A9C-82F0-450F09ED81F9}.Release|x64.ActiveCfg = Release|Any CPU - {E1F9FF93-CA63-4A9C-82F0-450F09ED81F9}.Release|x64.Build.0 = Release|Any CPU - {E1F9FF93-CA63-4A9C-82F0-450F09ED81F9}.Release|x86.ActiveCfg = Release|Any CPU - {E1F9FF93-CA63-4A9C-82F0-450F09ED81F9}.Release|x86.Build.0 = Release|Any CPU - {7779FB4A-D121-48CC-B033-C3D36BD5D4FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {7779FB4A-D121-48CC-B033-C3D36BD5D4FF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7779FB4A-D121-48CC-B033-C3D36BD5D4FF}.Debug|x64.ActiveCfg = Debug|Any CPU - {7779FB4A-D121-48CC-B033-C3D36BD5D4FF}.Debug|x64.Build.0 = Debug|Any CPU - {7779FB4A-D121-48CC-B033-C3D36BD5D4FF}.Debug|x86.ActiveCfg = Debug|Any CPU - {7779FB4A-D121-48CC-B033-C3D36BD5D4FF}.Debug|x86.Build.0 = Debug|Any CPU - {7779FB4A-D121-48CC-B033-C3D36BD5D4FF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7779FB4A-D121-48CC-B033-C3D36BD5D4FF}.Release|Any CPU.Build.0 = Release|Any CPU - {7779FB4A-D121-48CC-B033-C3D36BD5D4FF}.Release|x64.ActiveCfg = Release|Any CPU - {7779FB4A-D121-48CC-B033-C3D36BD5D4FF}.Release|x64.Build.0 = Release|Any CPU - {7779FB4A-D121-48CC-B033-C3D36BD5D4FF}.Release|x86.ActiveCfg = Release|Any CPU - {7779FB4A-D121-48CC-B033-C3D36BD5D4FF}.Release|x86.Build.0 = Release|Any CPU {D14E59CD-404B-467B-9C6D-91EFC5994D37}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {D14E59CD-404B-467B-9C6D-91EFC5994D37}.Debug|Any CPU.Build.0 = Debug|Any CPU {D14E59CD-404B-467B-9C6D-91EFC5994D37}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -135,18 +101,6 @@ Global {49D0687D-1321-48E9-84C3-936B10532367}.Release|x64.Build.0 = Release|Any CPU {49D0687D-1321-48E9-84C3-936B10532367}.Release|x86.ActiveCfg = Release|Any CPU {49D0687D-1321-48E9-84C3-936B10532367}.Release|x86.Build.0 = Release|Any CPU - {1BA0EEDF-D75A-49E9-9244-EA32DFA130B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1BA0EEDF-D75A-49E9-9244-EA32DFA130B3}.Debug|Any CPU.Build.0 = Debug|Any CPU - {1BA0EEDF-D75A-49E9-9244-EA32DFA130B3}.Debug|x64.ActiveCfg = Debug|Any CPU - {1BA0EEDF-D75A-49E9-9244-EA32DFA130B3}.Debug|x64.Build.0 = Debug|Any CPU - {1BA0EEDF-D75A-49E9-9244-EA32DFA130B3}.Debug|x86.ActiveCfg = Debug|Any CPU - {1BA0EEDF-D75A-49E9-9244-EA32DFA130B3}.Debug|x86.Build.0 = Debug|Any CPU - {1BA0EEDF-D75A-49E9-9244-EA32DFA130B3}.Release|Any CPU.ActiveCfg = Release|Any CPU - {1BA0EEDF-D75A-49E9-9244-EA32DFA130B3}.Release|Any CPU.Build.0 = Release|Any CPU - {1BA0EEDF-D75A-49E9-9244-EA32DFA130B3}.Release|x64.ActiveCfg = Release|Any CPU - {1BA0EEDF-D75A-49E9-9244-EA32DFA130B3}.Release|x64.Build.0 = Release|Any CPU - {1BA0EEDF-D75A-49E9-9244-EA32DFA130B3}.Release|x86.ActiveCfg = Release|Any CPU - {1BA0EEDF-D75A-49E9-9244-EA32DFA130B3}.Release|x86.Build.0 = Release|Any CPU {7B8E164F-C2D8-4C5F-8E20-450FB56AEB34}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {7B8E164F-C2D8-4C5F-8E20-450FB56AEB34}.Debug|Any CPU.Build.0 = Debug|Any CPU {7B8E164F-C2D8-4C5F-8E20-450FB56AEB34}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -171,18 +125,6 @@ Global {3FA78F9A-A942-4F7E-A30D-70DF42E8A83D}.Release|x64.Build.0 = Release|Any CPU {3FA78F9A-A942-4F7E-A30D-70DF42E8A83D}.Release|x86.ActiveCfg = Release|Any CPU {3FA78F9A-A942-4F7E-A30D-70DF42E8A83D}.Release|x86.Build.0 = Release|Any CPU - {27028918-925E-45D4-BD72-199349B6E6AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {27028918-925E-45D4-BD72-199349B6E6AA}.Debug|Any CPU.Build.0 = Debug|Any CPU - {27028918-925E-45D4-BD72-199349B6E6AA}.Debug|x64.ActiveCfg = Debug|Any CPU - {27028918-925E-45D4-BD72-199349B6E6AA}.Debug|x64.Build.0 = Debug|Any CPU - {27028918-925E-45D4-BD72-199349B6E6AA}.Debug|x86.ActiveCfg = Debug|Any CPU - {27028918-925E-45D4-BD72-199349B6E6AA}.Debug|x86.Build.0 = Debug|Any CPU - {27028918-925E-45D4-BD72-199349B6E6AA}.Release|Any CPU.ActiveCfg = Release|Any CPU - {27028918-925E-45D4-BD72-199349B6E6AA}.Release|Any CPU.Build.0 = Release|Any CPU - {27028918-925E-45D4-BD72-199349B6E6AA}.Release|x64.ActiveCfg = Release|Any CPU - {27028918-925E-45D4-BD72-199349B6E6AA}.Release|x64.Build.0 = Release|Any CPU - {27028918-925E-45D4-BD72-199349B6E6AA}.Release|x86.ActiveCfg = Release|Any CPU - {27028918-925E-45D4-BD72-199349B6E6AA}.Release|x86.Build.0 = Release|Any CPU {E407EE3C-D893-459C-84AA-4019537F2903}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {E407EE3C-D893-459C-84AA-4019537F2903}.Debug|Any CPU.Build.0 = Debug|Any CPU {E407EE3C-D893-459C-84AA-4019537F2903}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -251,14 +193,10 @@ Global {35BFF228-5EE4-49A6-B721-FB0122E967A0} = {91F059E6-7AD3-4FB7-9604-30A7849C6EFF} {BAEFF926-6B2C-46F1-BB73-AA2AB1355565} = {91F059E6-7AD3-4FB7-9604-30A7849C6EFF} {40BDA496-7614-4213-92D0-3B1B187675D3} = {91F059E6-7AD3-4FB7-9604-30A7849C6EFF} - {E1F9FF93-CA63-4A9C-82F0-450F09ED81F9} = {74BE0282-A10D-4A81-A0F0-FAA79A6152B7} - {7779FB4A-D121-48CC-B033-C3D36BD5D4FF} = {74BE0282-A10D-4A81-A0F0-FAA79A6152B7} {D14E59CD-404B-467B-9C6D-91EFC5994D37} = {91F059E6-7AD3-4FB7-9604-30A7849C6EFF} {49D0687D-1321-48E9-84C3-936B10532367} = {91F059E6-7AD3-4FB7-9604-30A7849C6EFF} - {1BA0EEDF-D75A-49E9-9244-EA32DFA130B3} = {74BE0282-A10D-4A81-A0F0-FAA79A6152B7} {7B8E164F-C2D8-4C5F-8E20-450FB56AEB34} = {91F059E6-7AD3-4FB7-9604-30A7849C6EFF} {3FA78F9A-A942-4F7E-A30D-70DF42E8A83D} = {245C36B9-612E-4AB0-979A-4D83A0D8117E} - {27028918-925E-45D4-BD72-199349B6E6AA} = {74BE0282-A10D-4A81-A0F0-FAA79A6152B7} {E407EE3C-D893-459C-84AA-4019537F2903} = {245C36B9-612E-4AB0-979A-4D83A0D8117E} {3590E969-0958-49ED-91A0-605ACC0B203C} = {245C36B9-612E-4AB0-979A-4D83A0D8117E} {D20E4300-45FA-451F-BCFA-AFBF7B32373A} = {245C36B9-612E-4AB0-979A-4D83A0D8117E}