public bool CaptureImage(string wimFile, string imageName, string imageDescription, string InputDirectory, CompressionType compressionType = CompressionType.LZX, AddFlags addFlags = AddFlags.DEFAULT, ProgressCallback progressCallback = null) { string title = $"Creating {wimFile.Split('\\').Last()}"; try { CallbackStatus ProgressCallback(ProgressMsg msg, object info, object progctx) { switch (msg) { case ProgressMsg.SCAN_BEGIN: { ProgressInfo_Scan m = (ProgressInfo_Scan)info; progressCallback?.Invoke($"Scanning files ({m.NumBytesScanned} bytes scanned, Current directory: {m.CurPath})", 0, true); } break; case ProgressMsg.SCAN_END: { ProgressInfo_Scan m = (ProgressInfo_Scan)info; progressCallback?.Invoke($"Scanning files ({m.NumBytesScanned} bytes scanned, Current directory: {m.CurPath})", 0, true); } break; case ProgressMsg.WRITE_METADATA_BEGIN: break; case ProgressMsg.WRITE_STREAMS: { ProgressInfo_WriteStreams m = (ProgressInfo_WriteStreams)info; progressCallback?.Invoke(title, (int)Math.Round((double)m.CompletedBytes / m.TotalBytes * 100), false); } break; case ProgressMsg.WRITE_METADATA_END: break; } return(CallbackStatus.CONTINUE); } using (Wim wim = Wim.CreateNewWim((ManagedWimLib.CompressionType)compressionType)) { wim.RegisterCallback(ProgressCallback); wim.AddImage(InputDirectory, imageName, null, (ManagedWimLib.AddFlags)addFlags); if (!string.IsNullOrEmpty(imageDescription)) { wim.SetImageDescription(1, imageDescription); } wim.Write(wimFile, Wim.AllImages, WriteFlags.DEFAULT, Wim.DefaultThreads); } } catch { return(false); } return(true); }
public void AddEmptyImage_Template(CompressionType compType, string wimFileName, AddFlags addFlags = AddFlags.DEFAULT) { string destDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); try { Directory.CreateDirectory(destDir); bool[] _checked = new bool[2]; for (int i = 0; i < _checked.Length; i++) { _checked[i] = false; } CallbackStatus ProgressCallback(ProgressMsg msg, object info, object progctx) { switch (msg) { case ProgressMsg.WRITE_METADATA_BEGIN: Assert.IsNull(info); _checked[0] = true; break; case ProgressMsg.WRITE_METADATA_END: Assert.IsNull(info); _checked[1] = true; break; } return(CallbackStatus.CONTINUE); } // Capture Wim string wimFile = Path.Combine(destDir, wimFileName); using (Wim wim = Wim.CreateNewWim(compType)) { wim.RegisterCallback(ProgressCallback); wim.AddEmptyImage("UnitTest"); wim.Write(wimFile, Wim.AllImages, WriteFlags.DEFAULT, Wim.DefaultThreads); WimInfo wi = wim.GetWimInfo(); Assert.IsTrue(wi.ImageCount == 1); } for (int i = 0; i < _checked.Length; i++) { Assert.IsTrue(_checked[i]); } } finally { if (Directory.Exists(destDir)) { Directory.Delete(destDir, true); } } }
public void AddEmptyImageTemplate(CompressionType compType, string wimFileName) { string destDir = TestHelper.GetTempDir(); try { bool[] _checked = new bool[2]; for (int i = 0; i < _checked.Length; i++) { _checked[i] = false; } CallbackStatus ProgressCallback(ProgressMsg msg, object info, object progctx) { switch (msg) { case ProgressMsg.WriteMetadataBegin: Assert.IsNull(info); _checked[0] = true; break; case ProgressMsg.WriteMetadataEnd: Assert.IsNull(info); _checked[1] = true; break; } return(CallbackStatus.Continue); } // Capture Wim string wimFile = Path.Combine(destDir, wimFileName); using (Wim wim = Wim.CreateNewWim(compType)) { wim.RegisterCallback(ProgressCallback); wim.AddEmptyImage("UnitTest"); wim.Write(wimFile, Wim.AllImages, WriteFlags.None, Wim.DefaultThreads); WimInfo wi = wim.GetWimInfo(); Assert.IsTrue(wi.ImageCount == 1); } for (int i = 0; i < _checked.Length; i++) { Assert.IsTrue(_checked[i]); } } finally { if (Directory.Exists(destDir)) { Directory.Delete(destDir, true); } } }
public bool ExportImage(string wimFile, int imageIndex, string outputWIMFile, CompressionType compressionType = CompressionType.LZX, ExportFlags exportFlags = ExportFlags.DEFAULT, ProgressCallback progressCallback = null) { string title = $"Exporting {wimFile.Split('\\').Last()} - Index {imageIndex}"; try { CallbackStatus ProgressCallback(ProgressMsg msg, object info, object progctx) { switch (msg) { case ProgressMsg.WRITE_STREAMS: { ProgressInfo_WriteStreams m = (ProgressInfo_WriteStreams)info; progressCallback?.Invoke(title, (int)Math.Round((double)m.CompletedBytes / m.TotalBytes * 100), false); } break; case ProgressMsg.WRITE_METADATA_BEGIN: break; case ProgressMsg.WRITE_METADATA_END: break; } return(CallbackStatus.CONTINUE); } using (Wim srcWim = Wim.OpenWim(wimFile, OpenFlags.DEFAULT)) { string imageName = srcWim.GetImageName(imageIndex); using (Wim destWim = Wim.CreateNewWim((ManagedWimLib.CompressionType)compressionType)) { destWim.RegisterCallback(ProgressCallback); srcWim.ExportImage(imageIndex, destWim, imageName, null, (ManagedWimLib.ExportFlags)exportFlags); destWim.Write(outputWIMFile, Wim.AllImages, WriteFlags.DEFAULT, Wim.DefaultThreads); } } } catch { return(false); } return(true); }
private void Export_image(string loc1, string loc2, int index, int compression) { if (Tools_location.Conversion.convert_path_type == "Folder") { } if (Tools_location.Conversion.convert_path_type == "ISO") { } else { Wim.GlobalInit("libwim-15.dll"); Wim x = Wim.OpenWim(loc1, 0); if (Tools_location.Conversion.to_convert_part_type == "SWM") { ulong partSize = (ulong)(Tools_location.Conversion.swm_partition_type * 1024); x.Split(Tools_location.Conversion.to_convert_path, partSize, WriteFlags.DEFAULT); } switch (compression) { case 0: y = Wim.CreateNewWim(CompressionType.NONE); break; case 1: y = Wim.CreateNewWim(CompressionType.XPRESS); break; case 2: y = Wim.CreateNewWim(CompressionType.LZMS); break; case 3: y = Wim.CreateNewWim(CompressionType.LZX); break; default: y = Wim.CreateNewWim(CompressionType.NONE); break; } x.ExportImage(index, y, null, null, ExportFlags.DEFAULT); y.Write(loc2, Wim.AllImages, WriteFlags.DEFAULT, Wim.DefaultThreads); } }
public void ExportImage_Template(string wimFileName, int imageIndex, string destImageName) { string srcWimPath = Path.Combine(TestSetup.SampleDir, wimFileName); string destDir = TestHelper.GetTempDir(); string destWimPath = Path.Combine(destDir, wimFileName); try { Directory.CreateDirectory(destDir); bool[] _checked = new bool[3]; for (int i = 0; i < _checked.Length; i++) { _checked[i] = false; } CallbackStatus ProgressCallback(ProgressMsg msg, object info, object progctx) { switch (msg) { case ProgressMsg.WRITE_STREAMS: { ProgressInfo_WriteStreams m = (ProgressInfo_WriteStreams)info; Assert.IsNotNull(m); Assert.AreEqual(m.CompressionType, CompressionType.LZMS); _checked[0] = true; } break; case ProgressMsg.WRITE_METADATA_BEGIN: Assert.IsNull(info); _checked[1] = true; break; case ProgressMsg.WRITE_METADATA_END: Assert.IsNull(info); _checked[2] = true; break; } return(CallbackStatus.CONTINUE); } using (Wim srcWim = Wim.OpenWim(srcWimPath, OpenFlags.DEFAULT)) { WimInfo swi = srcWim.GetWimInfo(); Assert.IsTrue(swi.ImageCount == 3); string imageName = srcWim.GetImageName(imageIndex); Assert.IsTrue(imageName.Equals(destImageName, StringComparison.Ordinal)); using (Wim destWim = Wim.CreateNewWim(CompressionType.LZMS)) { destWim.RegisterCallback(ProgressCallback); srcWim.ExportImage(imageIndex, destWim, destImageName, null, ExportFlags.GIFT); destWim.Write(destWimPath, Wim.AllImages, WriteFlags.DEFAULT, Wim.DefaultThreads); } for (int i = 0; i < _checked.Length; i++) { _checked[i] = false; } } using (Wim destWim = Wim.OpenWim(destWimPath, OpenFlags.DEFAULT)) { WimInfo dwi = destWim.GetWimInfo(); Assert.IsTrue(dwi.ImageCount == 1); string imageName = destWim.GetImageName(1); Assert.IsTrue(imageName.Equals(destImageName, StringComparison.Ordinal)); } long srcSize = new FileInfo(srcWimPath).Length; long destSize = new FileInfo(destWimPath).Length; Assert.IsTrue(destSize < srcSize); } finally { if (Directory.Exists(destDir)) { Directory.Delete(destDir, true); } } }
public void SetOutputChunkSizeTemplate(string wimFileName, CompressionType compType, uint chunkSize, bool success) { string destDir = TestHelper.GetTempDir(); try { Directory.CreateDirectory(destDir); bool[] _checked = new bool[5]; for (int i = 0; i < _checked.Length; i++) { _checked[i] = false; } CallbackStatus ProgressCallback(ProgressMsg msg, object info, object progctx) { switch (msg) { case ProgressMsg.ScanBegin: { ScanProgress m = (ScanProgress)info; Assert.IsNotNull(info); _checked[0] = true; } break; case ProgressMsg.ScanEnd: { ScanProgress m = (ScanProgress)info; Assert.IsNotNull(info); _checked[1] = true; } break; case ProgressMsg.WriteMetadataBegin: Assert.IsNull(info); _checked[2] = true; break; case ProgressMsg.WriteStreams: { WriteStreamsProgress m = (WriteStreamsProgress)info; Assert.IsNotNull(m); _checked[3] = true; } break; case ProgressMsg.WriteMetadataEnd: Assert.IsNull(info); _checked[4] = true; break; } return(CallbackStatus.Continue); } // Capture Wim string srcDir = Path.Combine(TestSetup.SampleDir, "Src01"); string wimFile = Path.Combine(destDir, wimFileName); using (Wim wim = Wim.CreateNewWim(compType)) { wim.RegisterCallback(ProgressCallback); try { wim.SetOutputChunkSize(chunkSize); } catch (WimLibException) { if (success) { Assert.Fail(); } else { return; } } wim.AddImage(srcDir, "UnitTest", null, AddFlags.None); wim.Write(wimFile, Wim.AllImages, WriteFlags.None, Wim.DefaultThreads); WimInfo wi = wim.GetWimInfo(); Assert.IsTrue(wi.ImageCount == 1); } TestHelper.CheckWimPath(SampleSet.Src01, wimFile); } finally { if (Directory.Exists(destDir)) { Directory.Delete(destDir, true); } } }
public void AddImageMultiSource_Template(CompressionType compType, string wimFileName, AddFlags addFlags = AddFlags.DEFAULT) { string destDir = TestHelper.GetTempDir(); try { bool[] _checked = new bool[5]; for (int i = 0; i < _checked.Length; i++) { _checked[i] = false; } CallbackStatus ProgressCallback(ProgressMsg msg, object info, object progctx) { switch (msg) { case ProgressMsg.SCAN_BEGIN: { ProgressInfo_Scan m = (ProgressInfo_Scan)info; Assert.IsNotNull(m); _checked[0] = true; } break; case ProgressMsg.SCAN_END: { ProgressInfo_Scan m = (ProgressInfo_Scan)info; Assert.IsNotNull(m); _checked[1] = true; } break; case ProgressMsg.WRITE_METADATA_BEGIN: Assert.IsNull(info); _checked[2] = true; break; case ProgressMsg.WRITE_STREAMS: { ProgressInfo_WriteStreams m = (ProgressInfo_WriteStreams)info; Assert.IsNotNull(m); _checked[3] = true; } break; case ProgressMsg.WRITE_METADATA_END: Assert.IsNull(info); _checked[4] = true; break; } return(CallbackStatus.CONTINUE); } string srcDir1 = Path.Combine(TestSetup.SampleDir, "Src01"); string srcDir3 = Path.Combine(TestSetup.SampleDir, "Src03"); string wimFile = Path.Combine(destDir, wimFileName); using (Wim wim = Wim.CreateNewWim(compType)) { wim.RegisterCallback(ProgressCallback); CaptureSource[] srcs = new CaptureSource[] { new CaptureSource(srcDir1, @"\A"), new CaptureSource(srcDir3, @"\Z"), }; wim.AddImageMultiSource(srcs, "UnitTest", null, addFlags); wim.Write(wimFile, Wim.AllImages, WriteFlags.DEFAULT, Wim.DefaultThreads); WimInfo wi = wim.GetWimInfo(); Assert.IsTrue(wi.ImageCount == 1); Assert.IsTrue(wim.DirExists(1, "A")); Assert.IsTrue(wim.DirExists(1, "Z")); } for (int i = 0; i < _checked.Length; i++) { Assert.IsTrue(_checked[i]); } } finally { if (Directory.Exists(destDir)) { Directory.Delete(destDir, true); } } }
public bool CaptureImage( string wimFile, string imageName, string imageDescription, string imageFlag, string InputDirectory, string imageDisplayName = null, string imageDisplayDescription = null, WimCompressionType compressionType = WimCompressionType.Lzx, IImaging.ProgressCallback progressCallback = null, int UpdateFrom = -1, bool PreserveACL = true) { string title = $"Creating {imageName} ({wimFile.Split('\\').Last()})"; try { CallbackStatus ProgressCallback(ProgressMsg msg, object info, object progctx) { switch (msg) { case ProgressMsg.ScanBegin: { ScanProgress m = (ScanProgress)info; progressCallback?.Invoke($"Scanning files ({m.NumBytesScanned} bytes scanned, {m.NumDirsScanned} Directories, {m.NumNonDirsScanned} Files, Current directory: {m.CurPath})", 0, true); } break; case ProgressMsg.ScanDEntry: { ScanProgress m = (ScanProgress)info; progressCallback?.Invoke($"Scanning files ({m.NumBytesScanned} bytes scanned, {m.NumDirsScanned} Directories, {m.NumNonDirsScanned} Files, Current directory: {m.CurPath})", 0, true); } break; case ProgressMsg.ScanEnd: { ScanProgress m = (ScanProgress)info; progressCallback?.Invoke($"Scanning files ({m.NumBytesScanned} bytes scanned, {m.NumDirsScanned} Directories, {m.NumNonDirsScanned} Files, Current directory: {m.CurPath})", 0, true); } break; case ProgressMsg.WriteMetadataBegin: break; case ProgressMsg.WriteStreams: { WriteStreamsProgress m = (WriteStreamsProgress)info; progressCallback?.Invoke(title, (int)Math.Round((double)m.CompletedBytes / m.TotalBytes * 100), false); } break; case ProgressMsg.WriteMetadataEnd: break; } return(CallbackStatus.Continue); } if (File.Exists(wimFile)) { using (Wim wim = Wim.OpenWim(wimFile, OpenFlags.WriteAccess)) { wim.RegisterCallback(ProgressCallback); wim.AddImage(InputDirectory, imageName, null, PreserveACL ? AddFlags.StrictAcls : AddFlags.NoAcls); if (!string.IsNullOrEmpty(imageDescription)) { wim.SetImageDescription((int)wim.GetWimInfo().ImageCount, imageDescription); } if (!string.IsNullOrEmpty(imageDisplayName)) { wim.SetImageProperty((int)wim.GetWimInfo().ImageCount, "DISPLAYNAME", imageDisplayName); } if (!string.IsNullOrEmpty(imageDisplayDescription)) { wim.SetImageProperty((int)wim.GetWimInfo().ImageCount, "DISPLAYDESCRIPTION", imageDisplayDescription); } if (!string.IsNullOrEmpty(imageFlag)) { wim.SetImageFlags((int)wim.GetWimInfo().ImageCount, imageFlag); } if (UpdateFrom != -1) { wim.ReferenceTemplateImage((int)wim.GetWimInfo().ImageCount, UpdateFrom); } wim.Overwrite(WriteFlags.None, Wim.DefaultThreads); } } else { var compression = CompressionType.None; switch (compressionType) { case WimCompressionType.Lzms: { compression = CompressionType.LZMS; break; } case WimCompressionType.Lzx: { compression = CompressionType.LZX; break; } case WimCompressionType.None: { compression = CompressionType.None; break; } case WimCompressionType.Xpress: { compression = CompressionType.XPRESS; break; } } using (Wim wim = Wim.CreateNewWim(compression)) { wim.RegisterCallback(ProgressCallback); string config = @"[ExclusionList] \$ntfs.log \hiberfil.sys \pagefile.sys \swapfile.sys \System Volume Information"; var configpath = Path.GetTempFileName(); File.Delete(configpath); File.WriteAllText(configpath, config); wim.AddImage(InputDirectory, imageName, configpath, PreserveACL ? AddFlags.StrictAcls : AddFlags.NoAcls); if (!string.IsNullOrEmpty(imageDescription)) { wim.SetImageDescription((int)wim.GetWimInfo().ImageCount, imageDescription); } if (!string.IsNullOrEmpty(imageDisplayName)) { wim.SetImageProperty((int)wim.GetWimInfo().ImageCount, "DISPLAYNAME", imageDisplayName); } if (!string.IsNullOrEmpty(imageDisplayDescription)) { wim.SetImageProperty((int)wim.GetWimInfo().ImageCount, "DISPLAYDESCRIPTION", imageDisplayDescription); } if (!string.IsNullOrEmpty(imageFlag)) { wim.SetImageFlags((int)wim.GetWimInfo().ImageCount, imageFlag); } wim.Write(wimFile, Wim.AllImages, WriteFlags.None, Wim.DefaultThreads); File.Delete(configpath); } } } catch (Exception ex) { return(false); } return(ReseatWIMXml(wimFile)); }
public bool ExportImage(string wimFile, string destinationWimFile, int imageIndex, IEnumerable <string> referenceWIMs = null, WimCompressionType compressionType = WimCompressionType.Lzx, IImaging.ProgressCallback progressCallback = null) { string title = $"Exporting {wimFile.Split('\\').Last()} - Index {imageIndex}"; try { CallbackStatus ProgressCallback(ProgressMsg msg, object info, object progctx) { switch (msg) { case ProgressMsg.WriteStreams: { WriteStreamsProgress m = (WriteStreamsProgress)info; progressCallback?.Invoke(title, (int)Math.Round((double)m.CompletedBytes / m.TotalBytes * 100), false); } break; case ProgressMsg.WriteMetadataBegin: break; case ProgressMsg.WriteMetadataEnd: break; } return(CallbackStatus.Continue); } using (Wim srcWim = Wim.OpenWim(wimFile, OpenFlags.None)) { string imageName = srcWim.GetImageName(imageIndex); string imageDescription = srcWim.GetImageDescription(imageIndex); var compression = CompressionType.None; switch (compressionType) { case WimCompressionType.Lzms: { compression = CompressionType.LZMS; break; } case WimCompressionType.Lzx: { compression = CompressionType.LZX; break; } case WimCompressionType.None: { compression = CompressionType.None; break; } case WimCompressionType.Xpress: { compression = CompressionType.XPRESS; break; } } if (referenceWIMs != null && referenceWIMs.Count() > 0) { srcWim.ReferenceResourceFiles(referenceWIMs, RefFlags.None, OpenFlags.None); } if (File.Exists(destinationWimFile)) { using (Wim destWim = Wim.OpenWim(destinationWimFile, OpenFlags.WriteAccess)) { destWim.RegisterCallback(ProgressCallback); if (destWim.IsImageNameInUse(imageName)) { srcWim.ExportImage(imageIndex, destWim, imageName + " " + DateTime.UtcNow.ToString(), imageDescription, ExportFlags.None); } else { srcWim.ExportImage(imageIndex, destWim, imageName, imageDescription, ExportFlags.None); } destWim.Overwrite(WriteFlags.None, Wim.DefaultThreads); } } else { using (Wim destWim = Wim.CreateNewWim(compression)) { destWim.RegisterCallback(ProgressCallback); srcWim.ExportImage(imageIndex, destWim, imageName, imageDescription, ExportFlags.None); destWim.Write(destinationWimFile, Wim.AllImages, compression == CompressionType.LZMS ? WriteFlags.Solid : WriteFlags.None, Wim.DefaultThreads); } } } } catch (Exception ex) { return(false); } return(ReseatWIMXml(destinationWimFile)); }
public void AddImage_Template(string wimFileName, CompressionType compType, AddFlags addFlags = AddFlags.DEFAULT) { string srcDir = Path.Combine(TestSetup.SampleDir, "Src01"); string destDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); string wimFile = Path.Combine(destDir, wimFileName); try { Directory.CreateDirectory(destDir); bool[] _checked = new bool[5]; for (int i = 0; i < _checked.Length; i++) { _checked[i] = false; } CallbackStatus ProgressCallback(ProgressMsg msg, object info, object progctx) { switch (msg) { case ProgressMsg.SCAN_BEGIN: { ProgressInfo_Scan m = (ProgressInfo_Scan)info; Assert.IsNotNull(info); _checked[0] = true; } break; case ProgressMsg.SCAN_END: { ProgressInfo_Scan m = (ProgressInfo_Scan)info; Assert.IsNotNull(info); _checked[1] = true; } break; case ProgressMsg.WRITE_METADATA_BEGIN: Assert.IsNull(info); _checked[2] = true; break; case ProgressMsg.WRITE_STREAMS: { ProgressInfo_WriteStreams m = (ProgressInfo_WriteStreams)info; Assert.IsNotNull(m); _checked[3] = true; } break; case ProgressMsg.WRITE_METADATA_END: Assert.IsNull(info); _checked[4] = true; break; } return(CallbackStatus.CONTINUE); } using (Wim wim = Wim.CreateNewWim(compType)) { wim.RegisterCallback(ProgressCallback); wim.AddImage(srcDir, "UnitTest", null, addFlags); wim.Write(wimFile, Wim.AllImages, WriteFlags.DEFAULT, Wim.DefaultThreads); WimInfo wi = wim.GetWimInfo(); Assert.IsTrue(wi.ImageCount == 1); } Assert.IsTrue(_checked.All(x => x)); TestHelper.CheckWimPath(SampleSet.Src01, wimFile); } finally { if (Directory.Exists(destDir)) { Directory.Delete(destDir, true); } } }
public void Split_Template(string testSet, ulong partSize) { string srcDir = Path.Combine(TestSetup.SampleDir, testSet); string destDir = TestHelper.GetTempDir(); string wimFile = Path.Combine(destDir, "LZX.wim"); string splitWimFile = Path.Combine(destDir, "Split.swm"); string splitWildcard = Path.Combine(destDir, "Split*.swm"); try { Directory.CreateDirectory(destDir); bool[] _checked = new bool[2]; for (int i = 0; i < _checked.Length; i++) { _checked[i] = false; } CallbackStatus ProgressCallback(ProgressMsg msg, object info, object progctx) { switch (msg) { case ProgressMsg.SPLIT_BEGIN_PART: { ProgressInfo_Split m = (ProgressInfo_Split)info; Assert.IsNotNull(m); _checked[0] = true; } break; case ProgressMsg.SPLIT_END_PART: { ProgressInfo_Split m = (ProgressInfo_Split)info; Assert.IsNotNull(m); _checked[1] = true; } break; } return(CallbackStatus.CONTINUE); } using (Wim wim = Wim.CreateNewWim(CompressionType.LZX)) { wim.AddImage(srcDir, "UnitTest", null, AddFlags.NO_ACLS); wim.Write(wimFile, Wim.AllImages, WriteFlags.DEFAULT, Wim.DefaultThreads); } TestHelper.CheckWimPath(SampleSet.Src03, wimFile); using (Wim wim = Wim.OpenWim(wimFile, OpenFlags.DEFAULT, ProgressCallback)) { wim.Split(splitWimFile, partSize, WriteFlags.DEFAULT); } Assert.IsTrue(_checked.All(x => x)); List <Tuple <string, bool> > entries = new List <Tuple <string, bool> >(); CallbackStatus IterateCallback(DirEntry dentry, object userData) { string path = dentry.FullPath; bool isDir = (dentry.Attributes & FileAttribute.DIRECTORY) != 0; entries.Add(new Tuple <string, bool>(path, isDir)); return(CallbackStatus.CONTINUE); } using (Wim wim = Wim.OpenWim(splitWimFile, OpenFlags.DEFAULT)) { wim.ReferenceResourceFile(splitWildcard, RefFlags.GLOB_ENABLE | RefFlags.GLOB_ERR_ON_NOMATCH, OpenFlags.DEFAULT); WimInfo wi = wim.GetWimInfo(); Assert.IsTrue(wi.ImageCount == 1); wim.IterateDirTree(1, Wim.RootPath, IterateFlags.RECURSIVE, IterateCallback); } TestHelper.CheckPathList(SampleSet.Src03, entries); } finally { if (Directory.Exists(destDir)) { Directory.Delete(destDir, true); } } }
public void SetOutputPackCompressionType_Template(string wimFileName, CompressionType compType) { string destDir = TestHelper.GetTempDir(); try { Directory.CreateDirectory(destDir); bool[] _checked = new bool[5]; for (int i = 0; i < _checked.Length; i++) { _checked[i] = false; } CallbackStatus ProgressCallback(ProgressMsg msg, object info, object progctx) { switch (msg) { case ProgressMsg.SCAN_BEGIN: { ProgressInfo_Scan m = (ProgressInfo_Scan)info; Assert.IsNotNull(m); _checked[0] = true; } break; case ProgressMsg.SCAN_END: { ProgressInfo_Scan m = (ProgressInfo_Scan)info; Assert.IsNotNull(m); _checked[1] = true; } break; case ProgressMsg.WRITE_METADATA_BEGIN: Assert.IsNull(info); _checked[2] = true; break; case ProgressMsg.WRITE_STREAMS: { ProgressInfo_WriteStreams m = (ProgressInfo_WriteStreams)info; Assert.IsNotNull(m); _checked[3] = true; } break; case ProgressMsg.WRITE_METADATA_END: Assert.IsNull(info); _checked[4] = true; break; } return(CallbackStatus.CONTINUE); } // Capture Wim string srcDir = Path.Combine(TestSetup.SampleDir, "Src01"); string wimFile = Path.Combine(destDir, wimFileName); using (Wim wim = Wim.CreateNewWim(CompressionType.NONE)) { wim.RegisterCallback(ProgressCallback); wim.SetOutputCompressionType(compType); wim.SetOutputPackCompressionType(compType); wim.AddImage(srcDir, "UnitTest", null, AddFlags.DEFAULT); wim.Write(wimFile, Wim.AllImages, WriteFlags.SOLID, Wim.DefaultThreads); } using (Wim wim = Wim.OpenWim(wimFile, OpenFlags.DEFAULT)) { WimInfo wi = wim.GetWimInfo(); Assert.AreEqual(wi.ImageCount, 1u); Assert.AreEqual(wi.CompressionType, compType); } TestHelper.CheckWimPath(SampleSet.Src01, wimFile); } finally { if (Directory.Exists(destDir)) { Directory.Delete(destDir, true); } } }
public void SplitTemplate(string testSet, ulong partSize) { string srcDir = Path.Combine(TestSetup.SampleDir, testSet); string destDir = TestHelper.GetTempDir(); string wimFile = Path.Combine(destDir, "LZX.wim"); string splitWimFile = Path.Combine(destDir, "Split.swm"); string splitWildcard = Path.Combine(destDir, "Split*.swm"); try { Directory.CreateDirectory(destDir); bool[] _checked = new bool[2]; for (int i = 0; i < _checked.Length; i++) { _checked[i] = false; } CallbackStatus ProgressCallback(ProgressMsg msg, object info, object progctx) { switch (msg) { case ProgressMsg.SplitBeginPart: { SplitProgress m = (SplitProgress)info; Assert.IsNotNull(m); _checked[0] = true; } break; case ProgressMsg.SplitEndPart: { SplitProgress m = (SplitProgress)info; Assert.IsNotNull(m); _checked[1] = true; } break; } return(CallbackStatus.Continue); } using (Wim wim = Wim.CreateNewWim(CompressionType.LZX)) { wim.AddImage(srcDir, "UnitTest", null, AddFlags.NoAcls); wim.Write(wimFile, Wim.AllImages, WriteFlags.None, Wim.DefaultThreads); } TestHelper.CheckWimPath(SampleSet.Src03, wimFile); using (Wim wim = Wim.OpenWim(wimFile, OpenFlags.None, ProgressCallback)) { wim.Split(splitWimFile, partSize, WriteFlags.None); } Assert.IsTrue(_checked.All(x => x)); List <Tuple <string, bool> > entries = new List <Tuple <string, bool> >(); int IterateCallback(DirEntry dentry, object userData) { string path = dentry.FullPath; bool isDir = (dentry.Attributes & FileAttributes.Directory) != 0; entries.Add(new Tuple <string, bool>(path, isDir)); return(Wim.IterateCallbackSuccess); } using (Wim wim = Wim.OpenWim(splitWimFile, OpenFlags.None)) { wim.ReferenceResourceFile(splitWildcard, RefFlags.GlobEnable | RefFlags.GlobErrOnNoMatch, OpenFlags.None); WimInfo wi = wim.GetWimInfo(); Assert.IsTrue(wi.ImageCount == 1); wim.IterateDirTree(1, Wim.RootPath, IterateDirTreeFlags.Recursive, IterateCallback); } TestHelper.CheckPathList(SampleSet.Src03, entries); } finally { if (Directory.Exists(destDir)) { Directory.Delete(destDir, true); } } }