Skip to content

Commit

Permalink
Imaging: Revert a few late changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gus33000 committed Oct 7, 2023
1 parent ca921e9 commit 1b0fc12
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 15 deletions.
77 changes: 77 additions & 0 deletions src/UnifiedUpdatePlatform.Imaging.NET/IImaging.cs
Original file line number Diff line number Diff line change
@@ -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<string> 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<string> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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<string> referenceWIMs = null, WimCompressionType compressionType = WimCompressionType.Lzx, ProgressCallback progressCallback = null, ExportFlags exportFlags = ExportFlags.None)
public bool ExportImage(string wimFile, string destinationWimFile, int imageIndex, IEnumerable<string> 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
Expand Down Expand Up @@ -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, '\\');
Expand All @@ -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<string> referenceWIMs = null, bool PreserveACL = true, ProgressCallback progressCallback = null)
public bool ApplyImage(string wimFile, int imageIndex, string OutputDirectory, IEnumerable<string> referenceWIMs = null, bool PreserveACL = true, IImaging.ProgressCallback progressCallback = null)
{
string title = $"Applying {wimFile.Split(Path.DirectorySeparatorChar).Last()} - Index {imageIndex}";
try
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/UnifiedUpdatePlatform.Media.Creator.NET/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 1b0fc12

Please sign in to comment.