Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/c#/GeneralUpdate.Common/Shared/Object/BaseConfigInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,11 @@ public abstract class BaseConfigInfo
/// This script is executed after update to ensure proper file permissions.
/// </summary>
public string Script { get; set; }

/// <summary>
/// The directory path containing driver files for driver update functionality.
/// Used when DriveEnabled is true to locate and install driver files during updates.
/// </summary>
public string DriverDirectory { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/// <param name="source">The user-provided configuration object containing initial settings.</param>
/// <param name="target">The internal configuration object to be populated. If null, a new instance is created.</param>
/// <returns>A GlobalConfigInfo object populated with values from the source Configinfo.</returns>
public static GlobalConfigInfo MapToGlobalConfigInfo(Configinfo source, GlobalConfigInfo target = null)

Check warning on line 21 in src/c#/GeneralUpdate.Common/Shared/Object/ConfigurationMapper.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.

Check warning on line 21 in src/c#/GeneralUpdate.Common/Shared/Object/ConfigurationMapper.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.
{
// Create new instance if both source and target are not provided
if (target == null)
Expand All @@ -43,6 +43,7 @@
target.Scheme = source.Scheme;
target.Token = source.Token;
target.Script = source.Script;
target.DriverDirectory = source.DriverDirectory;

// Map GlobalConfigInfo-specific fields
target.UpdateUrl = source.UpdateUrl;
Expand Down Expand Up @@ -92,6 +93,7 @@
scheme: source.Scheme,
token: source.Token,
script: source.Script,
driverDirectory: source.DriverDirectory, // Driver directory for driver updates
blackFileFormats: blackFileFormats, // From BlackListManager
blackFiles: blackFiles, // From BlackListManager
skipDirectories: skipDirectories // From BlackListManager
Expand Down Expand Up @@ -127,6 +129,7 @@
target.Scheme = source.Scheme;
target.Token = source.Token;
target.Script = source.Script;
target.DriverDirectory = source.DriverDirectory;
}
}
}
6 changes: 6 additions & 0 deletions src/c#/GeneralUpdate.Common/Shared/Object/GlobalConfigInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@
/// </summary>
public bool? DriveEnabled { get; set; }

/// <summary>
/// Directory path containing driver files for update.
/// Used when DriveEnabled is true to locate driver files for installation.
/// </summary>
public string DriverDirectory { get; set; }

Check warning on line 107 in src/c#/GeneralUpdate.Common/Shared/Object/GlobalConfigInfo.cs

View workflow job for this annotation

GitHub Actions / build

'GlobalConfigInfo.DriverDirectory' hides inherited member 'BaseConfigInfo.DriverDirectory'. Use the new keyword if hiding was intended.

Check warning on line 107 in src/c#/GeneralUpdate.Common/Shared/Object/GlobalConfigInfo.cs

View workflow job for this annotation

GitHub Actions / build

'GlobalConfigInfo.DriverDirectory' hides inherited member 'BaseConfigInfo.DriverDirectory'. Use the new keyword if hiding was intended.

/// <summary>
/// Indicates whether differential patch update is enabled.
/// Computed from UpdateOption.Patch or defaults to true.
Expand Down
10 changes: 10 additions & 0 deletions src/c#/GeneralUpdate.Common/Shared/Object/ProcessInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public ProcessInfo() { }
/// <param name="scheme">The URL scheme for update requests</param>
/// <param name="token">The authentication token</param>
/// <param name="script">The Linux permission script</param>
/// <param name="driverDirectory">The directory path containing driver files</param>
/// <param name="blackFileFormats">List of file format extensions to skip</param>
/// <param name="blackFiles">List of specific files to skip</param>
/// <param name="skipDirectories">List of directories to skip</param>
Expand All @@ -64,6 +65,7 @@ public ProcessInfo(string appName
, string scheme
, string token
, string script
, string driverDirectory
, List<string> blackFileFormats
, List<string> blackFiles
, List<string> skipDirectories)
Expand Down Expand Up @@ -98,6 +100,7 @@ public ProcessInfo(string appName
Scheme = scheme;
Token = token;
Script = script;
DriverDirectory = driverDirectory;

// Set blacklist parameters
BlackFileFormats = blackFileFormats;
Expand Down Expand Up @@ -229,5 +232,12 @@ public ProcessInfo(string appName
/// </summary>
[JsonPropertyName("Script")]
public string Script { get; set; }

/// <summary>
/// The directory path containing driver files for driver update functionality.
/// Used when DriveEnabled is true to locate and install driver files.
/// </summary>
[JsonPropertyName("DriverDirectory")]
public string DriverDirectory { get; set; }
}
}
5 changes: 4 additions & 1 deletion src/c#/GeneralUpdate.Core/GeneralUpdate.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<RepositoryType>public</RepositoryType>
<PackageTags>upgrade,update</PackageTags>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<TargetFrameworks>netstandard2.0;</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\GeneralUpdate.Common\Compress\CompressProvider.cs" Link="Common\CompressProvider.cs" />
Expand Down Expand Up @@ -90,6 +90,9 @@
<Compile Include="..\GeneralUpdate.Differential\Binary\StrangeCRC.cs" Link="Common\StrangeCRC.cs" />
<Compile Include="..\GeneralUpdate.Differential\DifferentialCore.cs" Link="Common\DifferentialCore.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<ProjectReference Include="..\GeneralUpdate.Drivelution\GeneralUpdate.Drivelution.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Common\" />
</ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion src/c#/GeneralUpdate.Core/GeneralUpdateBootstrap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ private void InitializeFromEnvironment()
Token = processInfo.Token,
DriveEnabled = GetOption(UpdateOption.Drive) ?? false,
PatchEnabled = GetOption(UpdateOption.Patch) ?? true,
Script = processInfo.Script
Script = processInfo.Script,
DriverDirectory = processInfo.DriverDirectory
};
}

Expand Down
100 changes: 100 additions & 0 deletions src/c#/GeneralUpdate.Core/Pipeline/DrivelutionMiddleware.cs
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.");
Copy link

Copilot AI Feb 11, 2026

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 DriveEnabled is true but DriverDirectory is 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.'

Suggested change
GeneralTracer.Info("Driver directory not specified in context, skipping driver update.");
GeneralTracer.Warn("Driver directory not configured in context. This may indicate a configuration issue. Skipping driver update.");

Copilot uses AI. Check for mistakes.
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
9 changes: 6 additions & 3 deletions src/c#/GeneralUpdate.Core/Strategys/LinuxStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,22 @@ protected override PipelineContext CreatePipelineContext(VersionInfo version, st
// Driver middleware (Linux-specific)
if (_configinfo.DriveEnabled == true)
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DriverDirectory value is added to context without validation. Since DrivelutionMiddleware checks for null/empty values, consider either validating here before adding to context, or documenting that validation happens in the middleware. This would make the data flow more explicit and avoid adding potentially invalid values to the context.

Suggested change
if (_configinfo.DriveEnabled == true)
if (_configinfo.DriveEnabled == true && !string.IsNullOrWhiteSpace(_configinfo.DriverDirectory))

Copilot uses AI. Check for mistakes.
{
context.Add("DriverOutPut", StorageManager.GetTempDirectory("DriverOutPut"));
context.Add("FieldMappings", _configinfo.FieldMappings);
context.Add("DriverDirectory", _configinfo.DriverDirectory);
}

return context;
}

protected override PipelineBuilder BuildPipeline(PipelineContext context)
{
return new PipelineBuilder(context)
var builder = new PipelineBuilder(context)
.UseMiddlewareIf<PatchMiddleware>(_configinfo.PatchEnabled)
.UseMiddleware<CompressMiddleware>()
.UseMiddleware<HashMiddleware>();
#if NET8_0_OR_GREATER
builder.UseMiddlewareIf<DrivelutionMiddleware>(_configinfo.DriveEnabled == true);
#endif
return builder;
}

public override void Execute()
Expand Down
9 changes: 6 additions & 3 deletions src/c#/GeneralUpdate.Core/Strategys/WindowsStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,22 @@ protected override PipelineContext CreatePipelineContext(VersionInfo version, st
// Driver middleware (Windows-specific)
if (_configinfo.DriveEnabled == true)
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DriverDirectory value is added to context without validation. Since DrivelutionMiddleware checks for null/empty values, consider either validating here before adding to context, or documenting that validation happens in the middleware. This would make the data flow more explicit and avoid adding potentially invalid values to the context.

Suggested change
if (_configinfo.DriveEnabled == true)
if (_configinfo.DriveEnabled == true && !string.IsNullOrWhiteSpace(_configinfo.DriverDirectory))

Copilot uses AI. Check for mistakes.
{
context.Add("DriverOutPut", StorageManager.GetTempDirectory("DriverOutPut"));
context.Add("FieldMappings", _configinfo.FieldMappings);
context.Add("DriverDirectory", _configinfo.DriverDirectory);
}

return context;
}

protected override PipelineBuilder BuildPipeline(PipelineContext context)
{
return new PipelineBuilder(context)
var builder = new PipelineBuilder(context)
.UseMiddlewareIf<PatchMiddleware>(_configinfo.PatchEnabled)
.UseMiddleware<CompressMiddleware>()
.UseMiddleware<HashMiddleware>();
#if NET8_0_OR_GREATER
builder.UseMiddlewareIf<DrivelutionMiddleware>(_configinfo.DriveEnabled == true);
#endif
return builder;
}

protected override void OnExecuteComplete()
Expand Down
Loading