diff --git a/src/UnifiedUpdatePlatform.Imaging.NET/IImaging.cs b/src/UnifiedUpdatePlatform.Imaging.NET/IImaging.cs new file mode 100644 index 00000000..ea04226a --- /dev/null +++ b/src/UnifiedUpdatePlatform.Imaging.NET/IImaging.cs @@ -0,0 +1,77 @@ +/* + * Copyright (c) Gustave Monce and Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +using Microsoft.Wim; +using System.Collections.Generic; + +namespace UnifiedUpdatePlatform.Imaging.NET +{ + public interface IImaging + { + public delegate void ProgressCallback(string Operation, int ProgressPercentage, bool IsIndeterminate); + + public bool AddFileToImage(string wimFile, int imageIndex, string fileToAdd, string destination, ProgressCallback progressCallback = null); + + public bool UpdateFilesInImage(string wimFile, int imageIndex, IEnumerable<(string fileToAdd, string destination)> fileList, ProgressCallback progressCallback = null); + + public bool DeleteFileFromImage(string wimFile, int imageIndex, string fileToRemove, ProgressCallback progressCallback = null); + + public bool ExportImage(string wimFile, string destinationWimFile, int imageIndex, IEnumerable referenceWIMs = null, WimCompressionType compressionType = WimCompressionType.Lzx, ProgressCallback progressCallback = null, ExportFlags exportFlags = ExportFlags.None); + + public bool ExtractFileFromImage(string wimFile, int imageIndex, string fileToExtract, string destination); + + public bool RenameFileInImage(string wimFile, int imageIndex, string sourceFilePath, string destinationFilePath, ProgressCallback progressCallback = null); + + public bool ApplyImage(string wimFile, int imageIndex, string OutputDirectory, IEnumerable referenceWIMs = null, bool PreserveACL = true, ProgressCallback progressCallback = null); + + public bool CaptureImage( + string wimFile, + string imageName, + string imageDescription, + string imageFlag, + string InputDirectory, + TempManager.TempManager tempManager, + string imageDisplayName = null, + string imageDisplayDescription = null, + WimCompressionType compressionType = WimCompressionType.Lzx, + ProgressCallback progressCallback = null, + int UpdateFrom = -1, + bool PreserveACL = true); + + public bool EnumerateFiles(string wimFile, int imageIndex, string path, out string[] entries); + + public bool MarkImageAsBootable(string wimFile, int imageIndex); + + public bool GetWIMInformation( + string wimFile, + out WIMInformationXML.WIM wimInformationObject); + + public bool GetWIMImageInformation( + string wimFile, + int imageIndex, + out WIMInformationXML.IMAGE image); + + public bool SetWIMImageInformation( + string wimFile, + int imageIndex, + WIMInformationXML.IMAGE image); + } +} \ No newline at end of file diff --git a/src/UnifiedUpdatePlatform.Imaging.NET/WIMImaging.cs b/src/UnifiedUpdatePlatform.Imaging.NET/WimLibImaging.cs similarity index 97% rename from src/UnifiedUpdatePlatform.Imaging.NET/WIMImaging.cs rename to src/UnifiedUpdatePlatform.Imaging.NET/WimLibImaging.cs index e5aa3749..d59ffd30 100644 --- a/src/UnifiedUpdatePlatform.Imaging.NET/WIMImaging.cs +++ b/src/UnifiedUpdatePlatform.Imaging.NET/WimLibImaging.cs @@ -29,23 +29,21 @@ namespace UnifiedUpdatePlatform.Imaging.NET { - public class WimImaging + public class WimLibImaging : IImaging { - public delegate void ProgressCallback(string Operation, int ProgressPercentage, bool IsIndeterminate); - - public WimImaging() + public WimLibImaging() { InitNativeLibrary(); } - public bool AddFileToImage(string wimFile, int imageIndex, string fileToAdd, string destination, ProgressCallback progressCallback = null) + public bool AddFileToImage(string wimFile, int imageIndex, string fileToAdd, string destination, IImaging.ProgressCallback progressCallback = null) { return UpdateFilesInImage(wimFile, imageIndex, new[] { (fileToAdd, destination) }, progressCallback); } - public bool UpdateFilesInImage(string wimFile, int imageIndex, IEnumerable<(string fileToAdd, string destination)> fileList, ProgressCallback progressCallback = null) + public bool UpdateFilesInImage(string wimFile, int imageIndex, IEnumerable<(string fileToAdd, string destination)> fileList, IImaging.ProgressCallback progressCallback = null) { // Early false returns because calling update with no operations sounds unintentional if (fileList == null) @@ -95,12 +93,12 @@ public bool UpdateFilesInImage(string wimFile, int imageIndex, IEnumerable<(stri return ReformatWindowsImageFileXML(wimFile); } - public bool DeleteFileFromImage(string wimFile, int imageIndex, string fileToRemove, ProgressCallback progressCallback = null) + public bool DeleteFileFromImage(string wimFile, int imageIndex, string fileToRemove, IImaging.ProgressCallback progressCallback = null) { return UpdateFilesInImage(wimFile, imageIndex, new[] { ((string)null, fileToRemove) }, progressCallback); } - public bool ExportImage(string wimFile, string destinationWimFile, int imageIndex, IEnumerable referenceWIMs = null, WimCompressionType compressionType = WimCompressionType.Lzx, ProgressCallback progressCallback = null, ExportFlags exportFlags = ExportFlags.None) + public bool ExportImage(string wimFile, string destinationWimFile, int imageIndex, IEnumerable referenceWIMs = null, WimCompressionType compressionType = WimCompressionType.Lzx, IImaging.ProgressCallback progressCallback = null, ExportFlags exportFlags = ExportFlags.None) { string title = $"Exporting {wimFile.Split(Path.DirectorySeparatorChar).Last()} - Index {imageIndex}"; try @@ -168,7 +166,7 @@ public bool ExtractFileFromImage(string wimFile, int imageIndex, string fileToEx return true; } - public bool RenameFileInImage(string wimFile, int imageIndex, string sourceFilePath, string destinationFilePath, ProgressCallback progressCallback = null) + public bool RenameFileInImage(string wimFile, int imageIndex, string sourceFilePath, string destinationFilePath, IImaging.ProgressCallback progressCallback = null) { sourceFilePath = sourceFilePath.Replace(Path.DirectorySeparatorChar, '\\'); destinationFilePath = destinationFilePath.Replace(Path.DirectorySeparatorChar, '\\'); @@ -193,7 +191,7 @@ public bool RenameFileInImage(string wimFile, int imageIndex, string sourceFileP return ReformatWindowsImageFileXML(wimFile); } - public bool ApplyImage(string wimFile, int imageIndex, string OutputDirectory, IEnumerable referenceWIMs = null, bool PreserveACL = true, ProgressCallback progressCallback = null) + public bool ApplyImage(string wimFile, int imageIndex, string OutputDirectory, IEnumerable referenceWIMs = null, bool PreserveACL = true, IImaging.ProgressCallback progressCallback = null) { string title = $"Applying {wimFile.Split(Path.DirectorySeparatorChar).Last()} - Index {imageIndex}"; try @@ -225,7 +223,7 @@ public bool CaptureImage( string imageDisplayName = null, string imageDisplayDescription = null, WimCompressionType compressionType = WimCompressionType.Lzx, - ProgressCallback progressCallback = null, + IImaging.ProgressCallback progressCallback = null, int UpdateFrom = -1, bool PreserveACL = true) { @@ -564,7 +562,7 @@ private static bool ReformatWindowsImageFileXMLUsingWimgApi(string wimFile) return true; } - private ManagedWimLib.ProgressCallback GetCallbackStatus(String title, ProgressCallback progressCallback = null) + private ManagedWimLib.ProgressCallback GetCallbackStatus(String title, IImaging.ProgressCallback progressCallback = null) { CallbackStatus ProgressCallback(ProgressMsg msg, object info, object progctx) { diff --git a/src/UnifiedUpdatePlatform.Media.Creator.NET/Constants.cs b/src/UnifiedUpdatePlatform.Media.Creator.NET/Constants.cs index 8ce1d846..e8729bd6 100644 --- a/src/UnifiedUpdatePlatform.Media.Creator.NET/Constants.cs +++ b/src/UnifiedUpdatePlatform.Media.Creator.NET/Constants.cs @@ -26,7 +26,7 @@ namespace UnifiedUpdatePlatform.Media.Creator.NET { public static class Constants { - internal static readonly WimImaging imagingInterface = new(); + internal static readonly IImaging imagingInterface = new WimLibImaging(); internal static byte[] winpejpg = new byte[] { diff --git a/src/UnifiedUpdatePlatform.Media.Creator.NET/Installer/InstallerLogger.cs b/src/UnifiedUpdatePlatform.Media.Creator.NET/Installer/InstallerLogger.cs index 1a475ccf..a4d3321d 100644 --- a/src/UnifiedUpdatePlatform.Media.Creator.NET/Installer/InstallerLogger.cs +++ b/src/UnifiedUpdatePlatform.Media.Creator.NET/Installer/InstallerLogger.cs @@ -6,7 +6,7 @@ internal static class InstallerLogger { private static readonly Common.Messaging.Common.ProcessPhase Phase = Common.Messaging.Common.ProcessPhase.CreatingWindowsInstaller; - internal static WimImaging.ProgressCallback GetImagingCallback(this ProgressCallback progressCallback) + internal static IImaging.ProgressCallback GetImagingCallback(this ProgressCallback progressCallback) { return (Operation, ProgressPercentage, IsIndeterminate) => progressCallback?.Invoke(Phase, IsIndeterminate, ProgressPercentage, Operation); } diff --git a/src/UnifiedUpdatePlatform.Media.Creator.Planning.NET/ConversionPlanBuilder.cs b/src/UnifiedUpdatePlatform.Media.Creator.Planning.NET/ConversionPlanBuilder.cs index 6bb3a7cd..d12aceab 100644 --- a/src/UnifiedUpdatePlatform.Media.Creator.Planning.NET/ConversionPlanBuilder.cs +++ b/src/UnifiedUpdatePlatform.Media.Creator.Planning.NET/ConversionPlanBuilder.cs @@ -60,7 +60,7 @@ public static class ConversionPlanBuilder { public delegate void ProgressCallback(string SubOperation); - private static readonly WimImaging imagingInterface = new(); + private static readonly IImaging imagingInterface = new WimLibImaging(); private static EditionTarget BuildTarget( PlannedEdition edition,