Skip to content

Commit

Permalink
Back up the driver file to be updated
Browse files Browse the repository at this point in the history
  • Loading branch information
JusterZhu committed Nov 17, 2023
1 parent 6d9fe39 commit 543c1ed
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
| 相互升级 | 支持 | 主程序可更新升级程序,升级程序可更新主程序。 |
| 黑名单 | 支持 | 在更新过程中会跳过黑名单中的文件列表和文件扩展名列表。 |
| OSS | 支持 | 极简化更新,是一套独立的更新机制。只需要在文件服务器中放置version.json的版本配置文件。组件会根据配置文件中的版本信息进行更新下载。(支持Windows,MAUI Android) |
| 回滚 | 待测试 | 逐版本更新时会备份每个版本,如果更新失败则逐版本回滚。 |
| 驱动更新 | 待测试 | 逐版本更新时会备份每个版本的驱动文件(.inf),如果更新失败则逐版本回滚。 |



Expand Down
11 changes: 7 additions & 4 deletions src/c#/GeneralUpdate.Core/Driver/BackupDriverCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace GeneralUpdate.Core.Driver
Expand All @@ -18,11 +18,14 @@ public BackupDriverCommand(DriverInformation information)

public void Execute()
{
var command = new StringBuilder("/c dism /online /export-driver /destination:\"")
.Append(_information.OutPutDirectory)
foreach (var driverName in _information.DriverNames)
{
var command = new StringBuilder("/c dism /online /export-driver /destination:\"")
.Append(Path.Combine(_information.OutPutDirectory, driverName))
.Append("\"")
.ToString();
CommandExecutor.ExecuteCommand(command);
CommandExecutor.ExecuteCommand(command);
}
}
}
}
21 changes: 20 additions & 1 deletion src/c#/GeneralUpdate.Core/Driver/DriverInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,21 @@ namespace GeneralUpdate.Core.Driver
/// </summary>
public class DriverInformation
{
/// <summary>
/// Directory for storing the driver to be installed (Update the driver file in the package).
/// </summary>
public string InstallDirectory { get; private set; }

/// <summary>
/// All driver backup directories.
/// </summary>
public string OutPutDirectory { get; private set; }

/// <summary>
/// A collection of driver files to be backed up.
/// </summary>
public List<string> DriverNames { get; private set; }

private DriverInformation(){}

public class Builder
Expand All @@ -30,10 +42,17 @@ public Builder SetOutPutDirectory(string outPutDirectory)
return this;
}

public Builder SetDriverNames(List<string> driverNames)
{
_information.DriverNames = driverNames;
return this;
}

public DriverInformation Build()
{
if (string.IsNullOrWhiteSpace(_information.InstallDirectory) ||
string.IsNullOrWhiteSpace(_information.OutPutDirectory))
string.IsNullOrWhiteSpace(_information.OutPutDirectory) ||
!_information.DriverNames.Any())
{
throw new InvalidOperationException("Cannot create DriverInformation, not all fields are set.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public async Task InvokeAsync(BaseContext context, MiddlewareStack stack)
var information = new DriverInformation.Builder()
.SetInstallDirectory(Path.Combine(context.SourcePath,context.Version.ToString()))
.SetOutPutDirectory(Path.Combine(context.TargetPath,context.Version.ToString()))
.SetDriverNames(null)
.Build();

var processor = new DriverProcessor();
Expand Down

0 comments on commit 543c1ed

Please sign in to comment.