-
Notifications
You must be signed in to change notification settings - Fork 58
Add driver update functionality via Drivelution integration #145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
28c0321
94a1a82
3d7c496
9807cec
a7ea9f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| #if NET8_0_OR_GREATER | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Diagnostics.CodeAnalysis; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using System.Threading.Tasks; | ||
| using GeneralUpdate.Common.Internal.Pipeline; | ||
| using GeneralUpdate.Common.Shared; | ||
| using GeneralUpdate.Drivelution; | ||
| using GeneralUpdate.Drivelution.Abstractions.Models; | ||
|
|
||
| namespace GeneralUpdate.Core.Pipeline; | ||
|
|
||
| /// <summary> | ||
| /// Middleware for handling driver updates using GeneralUpdate.Drivelution functionality. | ||
| /// </summary> | ||
| public class DrivelutionMiddleware : IMiddleware | ||
| { | ||
| [RequiresUnreferencedCode("Driver update process includes signature validation that may require runtime reflection on some platforms")] | ||
| [RequiresDynamicCode("Driver update process includes signature validation that may require runtime code generation on some platforms")] | ||
| public async Task InvokeAsync(PipelineContext context) | ||
| { | ||
| try | ||
| { | ||
| var driverDirectory = context.Get<string>("DriverDirectory"); | ||
|
|
||
| if (string.IsNullOrWhiteSpace(driverDirectory)) | ||
| { | ||
| GeneralTracer.Info("Driver directory not specified in context, skipping driver update."); | ||
| return; | ||
| } | ||
|
|
||
| if (!Directory.Exists(driverDirectory)) | ||
| { | ||
| GeneralTracer.Info($"Driver directory does not exist: {driverDirectory}, skipping driver update."); | ||
| return; | ||
| } | ||
|
|
||
| GeneralTracer.Info($"Starting driver update from directory: {driverDirectory}"); | ||
|
|
||
| // Get drivers from the specified directory | ||
| var drivers = await GeneralDrivelution.GetDriversFromDirectoryAsync(driverDirectory); | ||
|
|
||
| if (drivers == null || !drivers.Any()) | ||
| { | ||
| GeneralTracer.Info($"No drivers found in directory: {driverDirectory}"); | ||
| return; | ||
| } | ||
|
|
||
| GeneralTracer.Info($"Found {drivers.Count} driver(s) in directory."); | ||
|
|
||
| // Update each driver | ||
| var successCount = 0; | ||
| var failureCount = 0; | ||
| var results = new List<UpdateResult>(); | ||
|
|
||
| foreach (var driver in drivers) | ||
| { | ||
| try | ||
| { | ||
| GeneralTracer.Info($"Updating driver: {driver.Name} (Version: {driver.Version})"); | ||
|
|
||
| var result = await GeneralDrivelution.QuickUpdateAsync(driver); | ||
| results.Add(result); | ||
|
|
||
| if (result.Success) | ||
| { | ||
| successCount++; | ||
| GeneralTracer.Info($"Driver {driver.Name} updated successfully. Status: {result.Status}"); | ||
| } | ||
| else | ||
| { | ||
| failureCount++; | ||
| var errorMessage = result.Error != null | ||
| ? $"{result.Error.Code}: {result.Error.Message}" | ||
| : "Unknown error"; | ||
| GeneralTracer.Warn($"Driver {driver.Name} update failed. Error: {errorMessage}"); | ||
| } | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| failureCount++; | ||
| GeneralTracer.Error($"Exception while updating driver {driver.Name}", ex); | ||
| } | ||
| } | ||
|
|
||
| GeneralTracer.Info($"Driver update completed. Success: {successCount}, Failed: {failureCount}"); | ||
|
|
||
| // Store results in context for potential later use | ||
| context.Add("DriverUpdateResults", results); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| GeneralTracer.Error($"Error in DrivelutionMiddleware while processing directory '{context.Get<string>("DriverDirectory")}'", ex); | ||
| throw; | ||
| } | ||
| } | ||
| } | ||
| #endif | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -21,19 +21,22 @@ protected override PipelineContext CreatePipelineContext(VersionInfo version, st | |||||
| // Driver middleware (Linux-specific) | ||||||
| if (_configinfo.DriveEnabled == true) | ||||||
|
||||||
| if (_configinfo.DriveEnabled == true) | |
| if (_configinfo.DriveEnabled == true && !string.IsNullOrWhiteSpace(_configinfo.DriverDirectory)) |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -23,19 +23,22 @@ protected override PipelineContext CreatePipelineContext(VersionInfo version, st | |||||
| // Driver middleware (Windows-specific) | ||||||
| if (_configinfo.DriveEnabled == true) | ||||||
|
||||||
| if (_configinfo.DriveEnabled == true) | |
| if (_configinfo.DriveEnabled == true && !string.IsNullOrWhiteSpace(_configinfo.DriverDirectory)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The log message is misleading. If
DriveEnabledis true butDriverDirectoryis not set, this suggests a configuration error rather than an intentional skip. Consider changing the log level to Warn and clarifying that this is a configuration issue: 'Driver directory not configured despite driver updates being enabled. Skipping driver update.'