Skip to content

Commit 2485009

Browse files
committed
add GeneralUpdate.Drivelution
1 parent f1f8bf9 commit 2485009

30 files changed

+3941
-0
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
namespace GeneralUpdate.Drivelution.Abstractions.Configuration;
2+
3+
/// <summary>
4+
/// 驱动更新配置选项
5+
/// Driver update configuration options
6+
/// </summary>
7+
public class DriverUpdateOptions
8+
{
9+
/// <summary>
10+
/// 默认备份路径
11+
/// Default backup path
12+
/// </summary>
13+
public string DefaultBackupPath { get; set; } = "./DriverBackups";
14+
15+
/// <summary>
16+
/// 日志级别(Debug/Info/Warn/Error/Fatal)
17+
/// Log level (Debug/Info/Warn/Error/Fatal)
18+
/// </summary>
19+
public string LogLevel { get; set; } = "Info";
20+
21+
/// <summary>
22+
/// 日志文件路径
23+
/// Log file path
24+
/// </summary>
25+
public string LogFilePath { get; set; } = "./Logs/driver-update-.log";
26+
27+
/// <summary>
28+
/// 是否启用控制台日志
29+
/// Enable console logging
30+
/// </summary>
31+
public bool EnableConsoleLogging { get; set; } = true;
32+
33+
/// <summary>
34+
/// 是否启用文件日志
35+
/// Enable file logging
36+
/// </summary>
37+
public bool EnableFileLogging { get; set; } = true;
38+
39+
/// <summary>
40+
/// 默认重试次数
41+
/// Default retry count
42+
/// </summary>
43+
public int DefaultRetryCount { get; set; } = 3;
44+
45+
/// <summary>
46+
/// 默认重试间隔(秒)
47+
/// Default retry interval (seconds)
48+
/// </summary>
49+
public int DefaultRetryIntervalSeconds { get; set; } = 5;
50+
51+
/// <summary>
52+
/// 默认超时时间(秒)
53+
/// Default timeout (seconds)
54+
/// </summary>
55+
public int DefaultTimeoutSeconds { get; set; } = 300;
56+
57+
/// <summary>
58+
/// 是否在调试模式下跳过签名验证
59+
/// Skip signature validation in debug mode
60+
/// </summary>
61+
public bool DebugModeSkipSignature { get; set; } = false;
62+
63+
/// <summary>
64+
/// 是否在调试模式下跳过哈希验证
65+
/// Skip hash validation in debug mode
66+
/// </summary>
67+
public bool DebugModeSkipHash { get; set; } = false;
68+
69+
/// <summary>
70+
/// 权限校验失败时是否强制终止
71+
/// Force terminate on permission check failure
72+
/// </summary>
73+
public bool ForceTerminateOnPermissionFailure { get; set; } = true;
74+
75+
/// <summary>
76+
/// 是否自动清理旧备份(保留最近N个)
77+
/// Auto cleanup old backups (keep recent N)
78+
/// </summary>
79+
public bool AutoCleanupBackups { get; set; } = true;
80+
81+
/// <summary>
82+
/// 保留的备份数量
83+
/// Number of backups to keep
84+
/// </summary>
85+
public int BackupsToKeep { get; set; } = 5;
86+
87+
/// <summary>
88+
/// 信任的证书指纹列表(用于签名验证)
89+
/// Trusted certificate thumbprints (for signature validation)
90+
/// </summary>
91+
public List<string> TrustedCertificateThumbprints { get; set; } = new();
92+
93+
/// <summary>
94+
/// 信任的GPG公钥列表(Linux用)
95+
/// Trusted GPG public keys (for Linux)
96+
/// </summary>
97+
public List<string> TrustedGpgKeys { get; set; } = new();
98+
}
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
namespace GeneralUpdate.Drivelution.Abstractions.Exceptions;
2+
3+
/// <summary>
4+
/// 驱动更新基础异常
5+
/// Base exception for driver update
6+
/// </summary>
7+
public class DriverUpdateException : Exception
8+
{
9+
public string ErrorCode { get; set; }
10+
public bool CanRetry { get; set; }
11+
12+
public DriverUpdateException(string message, string errorCode = "DU_UNKNOWN", bool canRetry = false)
13+
: base(message)
14+
{
15+
ErrorCode = errorCode;
16+
CanRetry = canRetry;
17+
}
18+
19+
public DriverUpdateException(string message, Exception innerException, string errorCode = "DU_UNKNOWN", bool canRetry = false)
20+
: base(message, innerException)
21+
{
22+
ErrorCode = errorCode;
23+
CanRetry = canRetry;
24+
}
25+
}
26+
27+
/// <summary>
28+
/// 权限异常
29+
/// Permission exception
30+
/// </summary>
31+
public class DriverPermissionException : DriverUpdateException
32+
{
33+
public DriverPermissionException(string message)
34+
: base(message, "DU_PERMISSION_DENIED", false)
35+
{
36+
}
37+
38+
public DriverPermissionException(string message, Exception innerException)
39+
: base(message, innerException, "DU_PERMISSION_DENIED", false)
40+
{
41+
}
42+
}
43+
44+
/// <summary>
45+
/// 校验失败异常
46+
/// Validation failed exception
47+
/// </summary>
48+
public class DriverValidationException : DriverUpdateException
49+
{
50+
public string ValidationType { get; set; }
51+
52+
public DriverValidationException(string message, string validationType)
53+
: base(message, "DU_VALIDATION_FAILED", false)
54+
{
55+
ValidationType = validationType;
56+
}
57+
58+
public DriverValidationException(string message, string validationType, Exception innerException)
59+
: base(message, innerException, "DU_VALIDATION_FAILED", false)
60+
{
61+
ValidationType = validationType;
62+
}
63+
}
64+
65+
/// <summary>
66+
/// 安装失败异常
67+
/// Installation failed exception
68+
/// </summary>
69+
public class DriverInstallationException : DriverUpdateException
70+
{
71+
public DriverInstallationException(string message, bool canRetry = true)
72+
: base(message, "DU_INSTALLATION_FAILED", canRetry)
73+
{
74+
}
75+
76+
public DriverInstallationException(string message, Exception innerException, bool canRetry = true)
77+
: base(message, innerException, "DU_INSTALLATION_FAILED", canRetry)
78+
{
79+
}
80+
}
81+
82+
/// <summary>
83+
/// 备份失败异常
84+
/// Backup failed exception
85+
/// </summary>
86+
public class DriverBackupException : DriverUpdateException
87+
{
88+
public DriverBackupException(string message)
89+
: base(message, "DU_BACKUP_FAILED", true)
90+
{
91+
}
92+
93+
public DriverBackupException(string message, Exception innerException)
94+
: base(message, innerException, "DU_BACKUP_FAILED", true)
95+
{
96+
}
97+
}
98+
99+
/// <summary>
100+
/// 回滚失败异常
101+
/// Rollback failed exception
102+
/// </summary>
103+
public class DriverRollbackException : DriverUpdateException
104+
{
105+
public DriverRollbackException(string message)
106+
: base(message, "DU_ROLLBACK_FAILED", false)
107+
{
108+
}
109+
110+
public DriverRollbackException(string message, Exception innerException)
111+
: base(message, innerException, "DU_ROLLBACK_FAILED", false)
112+
{
113+
}
114+
}
115+
116+
/// <summary>
117+
/// 兼容性异常
118+
/// Compatibility exception
119+
/// </summary>
120+
public class DriverCompatibilityException : DriverUpdateException
121+
{
122+
public DriverCompatibilityException(string message)
123+
: base(message, "DU_COMPATIBILITY_FAILED", false)
124+
{
125+
}
126+
127+
public DriverCompatibilityException(string message, Exception innerException)
128+
: base(message, innerException, "DU_COMPATIBILITY_FAILED", false)
129+
{
130+
}
131+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
namespace GeneralUpdate.Drivelution.Abstractions;
2+
3+
/// <summary>
4+
/// 驱动备份接口
5+
/// Driver backup interface
6+
/// </summary>
7+
public interface IDriverBackup
8+
{
9+
/// <summary>
10+
/// 异步备份驱动
11+
/// Backs up driver asynchronously
12+
/// </summary>
13+
/// <param name="sourcePath">源路径 / Source path</param>
14+
/// <param name="backupPath">备份路径 / Backup path</param>
15+
/// <param name="cancellationToken">取消令牌 / Cancellation token</param>
16+
/// <returns>备份结果 / Backup result</returns>
17+
Task<bool> BackupAsync(string sourcePath, string backupPath, CancellationToken cancellationToken = default);
18+
19+
/// <summary>
20+
/// 异步恢复驱动
21+
/// Restores driver asynchronously
22+
/// </summary>
23+
/// <param name="backupPath">备份路径 / Backup path</param>
24+
/// <param name="targetPath">目标路径 / Target path</param>
25+
/// <param name="cancellationToken">取消令牌 / Cancellation token</param>
26+
/// <returns>恢复结果 / Restore result</returns>
27+
Task<bool> RestoreAsync(string backupPath, string targetPath, CancellationToken cancellationToken = default);
28+
29+
/// <summary>
30+
/// 异步删除备份
31+
/// Deletes backup asynchronously
32+
/// </summary>
33+
/// <param name="backupPath">备份路径 / Backup path</param>
34+
/// <param name="cancellationToken">取消令牌 / Cancellation token</param>
35+
/// <returns>删除结果 / Delete result</returns>
36+
Task<bool> DeleteBackupAsync(string backupPath, CancellationToken cancellationToken = default);
37+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
using GeneralUpdate.Drivelution.Abstractions.Models;
3+
4+
namespace GeneralUpdate.Drivelution.Abstractions;
5+
6+
/// <summary>
7+
/// 驱动验证器接口
8+
/// Driver validator interface
9+
/// </summary>
10+
public interface IDriverValidator
11+
{
12+
/// <summary>
13+
/// 异步验证驱动文件完整性(哈希校验)
14+
/// Validates driver file integrity (hash validation) asynchronously
15+
/// </summary>
16+
/// <param name="filePath">文件路径 / File path</param>
17+
/// <param name="expectedHash">期望的哈希值 / Expected hash</param>
18+
/// <param name="hashAlgorithm">哈希算法 / Hash algorithm (SHA256, MD5)</param>
19+
/// <param name="cancellationToken">取消令牌 / Cancellation token</param>
20+
/// <returns>验证是否通过 / Validation result</returns>
21+
Task<bool> ValidateIntegrityAsync(string filePath, string expectedHash, string hashAlgorithm = "SHA256", CancellationToken cancellationToken = default);
22+
23+
/// <summary>
24+
/// 异步验证驱动数字签名
25+
/// Validates driver digital signature asynchronously
26+
/// </summary>
27+
/// <param name="filePath">文件路径 / File path</param>
28+
/// <param name="trustedPublishers">信任的发布者列表 / Trusted publishers list</param>
29+
/// <param name="cancellationToken">取消令牌 / Cancellation token</param>
30+
/// <returns>验证是否通过 / Validation result</returns>
31+
/// <remarks>
32+
/// Note: On Windows, this may require reflection for X509Certificate validation.
33+
/// Platform-specific implementations should add appropriate AOT compatibility attributes.
34+
/// </remarks>
35+
[RequiresUnreferencedCode("Signature validation may require runtime reflection on some platforms")]
36+
[RequiresDynamicCode("Signature validation may require runtime code generation on some platforms")]
37+
Task<bool> ValidateSignatureAsync(string filePath, IEnumerable<string> trustedPublishers, CancellationToken cancellationToken = default);
38+
39+
/// <summary>
40+
/// 异步验证驱动兼容性
41+
/// Validates driver compatibility asynchronously
42+
/// </summary>
43+
/// <param name="driverInfo">驱动信息 / Driver information</param>
44+
/// <param name="cancellationToken">取消令牌 / Cancellation token</param>
45+
/// <returns>验证是否通过 / Validation result</returns>
46+
Task<bool> ValidateCompatibilityAsync(DriverInfo driverInfo, CancellationToken cancellationToken = default);
47+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
using GeneralUpdate.Drivelution.Abstractions.Models;
3+
4+
namespace GeneralUpdate.Drivelution.Abstractions;
5+
6+
/// <summary>
7+
/// 驱动更新器核心接口
8+
/// Core interface for driver updater
9+
/// </summary>
10+
public interface IGeneralDrivelution
11+
{
12+
/// <summary>
13+
/// 异步更新驱动
14+
/// Updates driver asynchronously
15+
/// </summary>
16+
/// <param name="driverInfo">驱动信息 / Driver information</param>
17+
/// <param name="strategy">更新策略 / Update strategy</param>
18+
/// <param name="cancellationToken">取消令牌 / Cancellation token</param>
19+
/// <returns>更新结果 / Update result</returns>
20+
/// <remarks>
21+
/// Note: Update process may include signature validation that requires reflection on some platforms.
22+
/// </remarks>
23+
[RequiresUnreferencedCode("Update process may include signature validation that requires runtime reflection on some platforms")]
24+
[RequiresDynamicCode("Update process may include signature validation that requires runtime code generation on some platforms")]
25+
Task<UpdateResult> UpdateAsync(DriverInfo driverInfo, UpdateStrategy strategy, CancellationToken cancellationToken = default);
26+
27+
/// <summary>
28+
/// 异步验证驱动
29+
/// Validates driver asynchronously
30+
/// </summary>
31+
/// <param name="driverInfo">驱动信息 / Driver information</param>
32+
/// <param name="cancellationToken">取消令牌 / Cancellation token</param>
33+
/// <returns>验证是否通过 / Validation result</returns>
34+
/// <remarks>
35+
/// Note: Includes signature validation that may require reflection on some platforms.
36+
/// </remarks>
37+
[RequiresUnreferencedCode("Validation includes signature validation that may require runtime reflection on some platforms")]
38+
[RequiresDynamicCode("Validation includes signature validation that may require runtime code generation on some platforms")]
39+
Task<bool> ValidateAsync(DriverInfo driverInfo, CancellationToken cancellationToken = default);
40+
41+
/// <summary>
42+
/// 异步备份驱动
43+
/// Backs up driver asynchronously
44+
/// </summary>
45+
/// <param name="driverInfo">驱动信息 / Driver information</param>
46+
/// <param name="backupPath">备份路径 / Backup path</param>
47+
/// <param name="cancellationToken">取消令牌 / Cancellation token</param>
48+
/// <returns>备份结果 / Backup result</returns>
49+
Task<bool> BackupAsync(DriverInfo driverInfo, string backupPath, CancellationToken cancellationToken = default);
50+
51+
/// <summary>
52+
/// 异步回滚驱动
53+
/// Rolls back driver asynchronously
54+
/// </summary>
55+
/// <param name="backupPath">备份路径 / Backup path</param>
56+
/// <param name="cancellationToken">取消令牌 / Cancellation token</param>
57+
/// <returns>回滚结果 / Rollback result</returns>
58+
Task<bool> RollbackAsync(string backupPath, CancellationToken cancellationToken = default);
59+
}

0 commit comments

Comments
 (0)