public void DeletePath_Template(string wimFileName, string deletePath) { string srcWim = Path.Combine(TestSetup.SampleDir, wimFileName); string destDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); string destWim = Path.Combine(destDir, wimFileName); try { Directory.CreateDirectory(destDir); File.Copy(srcWim, destWim, true); 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); } using (Wim wim = Wim.OpenWim(destWim, OpenFlags.WRITE_ACCESS)) { wim.RegisterCallback(ProgressCallback); Assert.IsTrue(wim.PathExists(1, deletePath)); wim.DeletePath(1, deletePath, DeleteFlags.RECURSIVE); wim.Overwrite(WriteFlags.DEFAULT, Wim.DefaultThreads); Assert.IsTrue(_checked.All(x => x)); Assert.IsFalse(wim.PathExists(1, deletePath)); } } finally { if (Directory.Exists(destDir)) { Directory.Delete(destDir, true); } } }
public void DeletePathTemplate(string wimFileName, string deletePath) { string srcWim = Path.Combine(TestSetup.SampleDir, wimFileName); string destDir = TestHelper.GetTempDir(); string destWim = Path.Combine(destDir, wimFileName); try { Directory.CreateDirectory(destDir); File.Copy(srcWim, destWim, true); 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); } using (Wim wim = Wim.OpenWim(destWim, OpenFlags.WriteAccess)) { wim.RegisterCallback(ProgressCallback); Assert.IsTrue(wim.PathExists(1, deletePath)); wim.DeletePath(1, deletePath, DeleteFlags.Recursive); wim.Overwrite(WriteFlags.None, Wim.DefaultThreads); Assert.IsTrue(_checked.All(x => x)); Assert.IsFalse(wim.PathExists(1, deletePath)); } } finally { if (Directory.Exists(destDir)) { Directory.Delete(destDir, true); } } }