Skip to content
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

Add AddDriversEx() method to add drivers from a directory #67

Merged
merged 1 commit into from
Aug 6, 2018
Merged
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
17 changes: 17 additions & 0 deletions src/Microsoft.Dism/DismApi.AddDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//
// Licensed under the MIT license.

using System.IO;
using System.Runtime.InteropServices;

namespace Microsoft.Dism
Expand All @@ -23,6 +24,22 @@ public static void AddDriver(DismSession session, string driverPath, bool forceU
DismUtilities.ThrowIfFail(hresult, session);
}

/// <summary>
/// Adds third party drivers (.inf) from the specified directory to an offline Windows® image.
/// </summary>
/// <param name="session">A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the <see cref="OpenOfflineSession(string)"/> method.</param>
/// <param name="driverDirectory">A relative or absolute path to a directory containing driver .inf files.</param>
/// <param name="forceUnsigned">Indicates whether to accept unsigned drivers to an x64-based image. Unsigned drivers will automatically be added to an x86-based image.</param>
/// <param name="recursive"><code>true</code> to search recursively for driver files, otherwise <code>false</code>.</param>
/// <exception cref="DirectoryNotFoundException">The directory specified by the <paramref name="driverDirectory"/> parameter does not exist.</exception>
public static void AddDriversEx(DismSession session, string driverDirectory, bool forceUnsigned, bool recursive)
{
foreach (string driverPath in Directory.EnumerateFiles(driverDirectory, "*.inf", recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly))
{
AddDriver(session, driverPath, forceUnsigned);
}
}

internal static partial class NativeMethods
{
/// <summary>
Expand Down