예제 #1
0
        public void ApplyProgress_Template(string fileName)
        {
            string destDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            try
            {
                CallbackTested tested = new CallbackTested(false);

                string wimFile = Path.Combine(TestSetup.BaseDir, "Samples", fileName);
                using (Wim wim = Wim.OpenWim(wimFile, WimLibOpenFlags.DEFAULT, ApplyProgress_Callback, tested))
                {
                    wim.ExtractImage(1, destDir, WimLibExtractFlags.DEFAULT);
                }

                Assert.IsTrue(tested.Value);

                TestHelper.CheckSample01(destDir);
            }
            finally
            {
                if (Directory.Exists(destDir))
                {
                    Directory.Delete(destDir, true);
                }
            }
        }
예제 #2
0
        public CallbackStatus UpdateProgress_Callback(ProgressMsg msg, object info, object progctx)
        {
            CallbackTested tested = progctx as CallbackTested;

            Assert.IsNotNull(tested);

            switch (msg)
            {
            case ProgressMsg.UPDATE_BEGIN_COMMAND:
            case ProgressMsg.UPDATE_END_COMMAND:
            {
                ProgressInfo_Update m = (ProgressInfo_Update)info;

                Assert.IsNotNull(m);
                tested.Set();

                UpdateCommand cmd = m.Command;
                switch (cmd.Op)
                {
                case UpdateOp.ADD:
                {
                    var add = cmd.Add;
                    Console.WriteLine($"ADD [{add.FsSourcePath}] -> [{add.WimTargetPath}]");
                }
                break;

                case UpdateOp.DELETE:
                {
                    var del = cmd.Delete;
                    Console.WriteLine($"DELETE [{del.WimPath}]");
                }
                break;

                case UpdateOp.RENAME:
                {
                    var ren = cmd.Rename;
                    Console.WriteLine($"RENAME [{ren.WimSourcePath}] -> [{ren.WimTargetPath}]");
                }
                break;
                }
            }
            break;

            default:
                break;
            }
            return(CallbackStatus.CONTINUE);
        }
예제 #3
0
        public static CallbackStatus UpdateProgressCallback(ProgressMsg msg, object info, object progctx)
        {
            CallbackTested tested = progctx as CallbackTested;

            Assert.IsNotNull(tested);

            switch (msg)
            {
            case ProgressMsg.UpdateBeginCommand:
            case ProgressMsg.UpdateEndCommand:
            {
                UpdateProgress m = (UpdateProgress)info;
                Assert.IsNotNull(m);

                tested.Set();

                UpdateCommand cmd = m.Command;
                Console.WriteLine($"Commands = {m.CompletedCommands}/{m.TotalCommands}");
                switch (cmd.Op)
                {
                case UpdateOp.Add:
                {
                    AddCommand add = cmd.Add;
                    Console.WriteLine($"ADD [{add.FsSourcePath}] -> [{add.WimTargetPath}]");
                }
                break;

                case UpdateOp.Delete:
                {
                    DeleteCommand del = cmd.Delete;
                    Console.WriteLine($"DELETE [{del.WimPath}]");
                }
                break;

                case UpdateOp.Rename:
                {
                    RenameCommand ren = cmd.Rename;
                    Console.WriteLine($"RENAME [{ren.WimSourcePath}] -> [{ren.WimTargetPath}]");
                }
                break;
                }
            }
            break;
            }

            return(CallbackStatus.Continue);
        }
예제 #4
0
        public WimLibProgressStatus ApplyProgress_Callback(WimLibProgressMsg msg, object info, object progctx)
        {
            CallbackTested tested = progctx as CallbackTested;

            Assert.IsNotNull(tested);

            switch (msg)
            {
            case WimLibProgressMsg.EXTRACT_STREAMS:
            {         // Extract of one file
                WimLibProgressInfoExtract m = (WimLibProgressInfoExtract)info;
                Assert.IsNotNull(m);

                tested.Set();

                Console.WriteLine($"Extract {m.CompletedBytes * 100 / m.TotalBytes}%");
            }
            break;

            default:
                break;
            }
            return(WimLibProgressStatus.CONTINUE);
        }
예제 #5
0
        public void Update_Template(string fileName, UpdateCommand[] cmds)
        {
            string destDir = TestHelper.GetTempDir();

            try
            {
                CallbackTested tested = new CallbackTested(false);
                Directory.CreateDirectory(destDir);

                string srcWimFile  = Path.Combine(TestSetup.SampleDir, fileName);
                string destWimFile = Path.Combine(destDir, fileName);
                File.Copy(srcWimFile, destWimFile, true);

                using (Wim wim = Wim.OpenWim(destWimFile, OpenFlags.WRITE_ACCESS, UpdateProgress_Callback, tested))
                {
                    wim.UpdateImage(1, cmds, UpdateFlags.SEND_PROGRESS);

                    wim.Overwrite(WriteFlags.DEFAULT, Wim.DefaultThreads);
                }

                List <string> entries = new List <string>();
                CallbackStatus IterateCallback(DirEntry dentry, object userData)
                {
                    entries.Add(dentry.FullPath);
                    return(CallbackStatus.CONTINUE);
                }

                using (Wim wim = Wim.OpenWim(destWimFile, OpenFlags.DEFAULT))
                {
                    wim.IterateDirTree(1, Wim.RootPath, IterateFlags.RECURSIVE, IterateCallback, entries);
                }

                Assert.IsTrue(tested.Value);
                foreach (UpdateCommand cmd in cmds)
                {
                    switch (cmd.Op)
                    {
                    case UpdateOp.ADD:
                    {
                        UpdateCommand.UpdateAdd add = cmd.Add;
                        Assert.IsTrue(entries.Contains(Path.Combine(Wim.RootPath, add.WimTargetPath), StringComparer.Ordinal));
                    }
                    break;

                    case UpdateOp.DELETE:
                    {
                        UpdateCommand.UpdateDelete del = cmd.Delete;
                        Assert.IsFalse(entries.Contains(Path.Combine(Wim.RootPath, del.WimPath), StringComparer.Ordinal));
                    }
                    break;

                    case UpdateOp.RENAME:
                    {
                        UpdateCommand.UpdateRename ren = cmd.Rename;
                        Assert.IsTrue(entries.Contains(Path.Combine(Wim.RootPath, ren.WimTargetPath), StringComparer.Ordinal));
                    }
                    break;
                    }
                }
            }
            finally
            {
                if (Directory.Exists(destDir))
                {
                    Directory.Delete(destDir, true);
                }
            }
        }
예제 #6
0
        public void UpdateTemplate(string fileName, UpdateCommand[] cmds)
        {
            string destDir = TestHelper.GetTempDir();

            try
            {
                CallbackTested tested = new CallbackTested(false);
                Directory.CreateDirectory(destDir);

                string srcWimFile  = Path.Combine(TestSetup.SampleDir, fileName);
                string destWimFile = Path.Combine(destDir, fileName);
                File.Copy(srcWimFile, destWimFile, true);

                using (Wim wim = Wim.OpenWim(destWimFile, OpenFlags.WriteAccess, UpdateProgressCallback, tested))
                {
                    wim.UpdateImage(1, cmds, UpdateFlags.SendProgress);

                    wim.Overwrite(WriteFlags.None, Wim.DefaultThreads);
                }

                List <string> entries = new List <string>();
                int IterateCallback(DirEntry dentry, object userData)
                {
                    entries.Add(dentry.FullPath);
                    return(Wim.IterateCallbackSuccess);
                }

                using (Wim wim = Wim.OpenWim(destWimFile, OpenFlags.None))
                {
                    wim.IterateDirTree(1, Wim.RootPath, IterateDirTreeFlags.Recursive, IterateCallback, entries);
                }

                Assert.IsTrue(tested.Value);
                foreach (UpdateCommand cmd in cmds)
                {
                    switch (cmd.Op)
                    {
                    case UpdateOp.Add:
                    {
                        AddCommand add = cmd.Add;
                        Assert.IsTrue(entries.Contains(Path.Combine(Wim.RootPath, add.WimTargetPath), StringComparer.Ordinal));
                    }
                    break;

                    case UpdateOp.Delete:
                    {
                        DeleteCommand del = cmd.Delete;
                        Assert.IsFalse(entries.Contains(Path.Combine(Wim.RootPath, del.WimPath), StringComparer.Ordinal));
                    }
                    break;

                    case UpdateOp.Rename:
                    {
                        RenameCommand ren = cmd.Rename;
                        Assert.IsTrue(entries.Contains(Path.Combine(Wim.RootPath, ren.WimTargetPath), StringComparer.Ordinal));
                    }
                    break;
                    }
                }
            }
            finally
            {
                if (Directory.Exists(destDir))
                {
                    Directory.Delete(destDir, true);
                }
            }
        }