Exemple #1
0
        public void GetMountedImageHandleTest_ReadWrite()
        {
            ExecuteAgainstMountedImage((wimHandle, imageHandle) =>
            {
                using (WimHandle actualWimHandle = WimgApi.GetMountedImageHandle(MountPath, false, out WimHandle actualImageHandle))
                {
                    try
                    {
                        actualWimHandle.ShouldNotBeNull();

                        actualImageHandle.ShouldNotBeNull();

                        WimMountInfo wimMountInfo = WimgApi.GetMountedImageInfoFromHandle(actualImageHandle);

                        wimMountInfo.ShouldNotBeNull();

                        wimMountInfo.ImageIndex.ShouldBe(1);
                        wimMountInfo.MountPath.ShouldBe(MountPath, StringCompareShould.IgnoreCase);
                        wimMountInfo.Path.ShouldBe(TestWimPath);
                        wimMountInfo.ReadOnly.ShouldBeTrue();
                        wimMountInfo.State.ShouldBe(WimMountPointState.Mounted);
                    }
                    finally
                    {
                        actualImageHandle.Dispose();
                    }
                }
            });
        }
Exemple #2
0
        public void GetMountedImageInfoFromHandleTest()
        {
            ExecuteAgainstMountedImage((wimHandle, imageHandle) =>
            {
                WimMountInfo wimMountInfo = WimgApi.GetMountedImageInfoFromHandle(imageHandle);

                wimMountInfo.ShouldNotBeNull();

                wimMountInfo.ImageIndex.ShouldBe(1);
                wimMountInfo.MountPath.ShouldBe(MountPath, StringCompareShould.IgnoreCase);
                wimMountInfo.Path.ShouldBe(TestWimPath);
                wimMountInfo.ReadOnly.ShouldBeTrue();
                wimMountInfo.State.ShouldBe(WimMountPointState.Mounted);
            });
        }
Exemple #3
0
        public void MountImageHandleTest_ReadWrite()
        {
            const bool readOnly = false;

            ExecuteAgainstMountedImage(readOnly, (wimHandle, imageHandle) =>
            {
                wimHandle.ShouldNotBeNull();
                wimHandle.IsInvalid.ShouldBeFalse();
                wimHandle.IsClosed.ShouldBeFalse();
                imageHandle.ShouldNotBeNull();
                imageHandle.IsClosed.ShouldBeFalse();
                imageHandle.IsInvalid.ShouldBeFalse();

                WimMountInfo wimMountInfo = WimgApi.GetMountedImageInfoFromHandle(imageHandle);

                wimMountInfo.ReadOnly.ShouldBe(readOnly);
            });
        }
Exemple #4
0
        public void GetMountedImageInfoTest()
        {
            ExecuteAgainstMountedImage((wimHandle, imageHandle) =>
            {
                WimMountInfoCollection wimMountInfos = WimgApi.GetMountedImageInfo();

                wimMountInfos.ShouldNotBeNull();

                wimMountInfos.Count.ShouldBe(1);

                WimMountInfo wimMountInfo = wimMountInfos.FirstOrDefault();

                wimMountInfo.ShouldNotBeNull();

                // ReSharper disable once PossibleNullReferenceException
                wimMountInfo.ImageIndex.ShouldBe(1);
                wimMountInfo.MountPath.ShouldBe(MountPath, StringCompareShould.IgnoreCase);
                wimMountInfo.Path.ShouldBe(TestWimPath);
                wimMountInfo.ReadOnly.ShouldBeTrue();
                wimMountInfo.State.ShouldBe(WimMountPointState.Mounted);
            });
        }
Exemple #5
0
        public static List <LogInfo> WimUnmount(EngineState s, CodeCommand cmd)
        {
            List <LogInfo> logs = new List <LogInfo>(1);

            Debug.Assert(cmd.Info.GetType() == typeof(CodeInfo_WimUnmount));
            CodeInfo_WimUnmount info = cmd.Info as CodeInfo_WimUnmount;

            string mountDir = StringEscaper.Preprocess(s, info.MountDir);

            // Check MountDir
            if (!Directory.Exists(mountDir))
            {
                logs.Add(new LogInfo(LogState.Error, $"Directory [{mountDir}] does not exist"));
                return(logs);
            }

            // Unmount Wim
            // https://msdn.microsoft.com/ko-kr/library/windows/desktop/dd834953.aspx
            WimHandle hWim   = null;
            WimHandle hImage = null;

            try
            {
                hWim = WimgApi.GetMountedImageHandle(mountDir, true, out hImage);

                WimMountInfo wimInfo = WimgApi.GetMountedImageInfoFromHandle(hImage);
                Debug.Assert(wimInfo.MountPath.Equals(mountDir, StringComparison.OrdinalIgnoreCase));

                // Prepare Command Progress Report
                WimgApi.RegisterMessageCallback(hWim, WimgApiCallback);
                s.MainViewModel.BuildCommandProgressTitle = "WimUnmount Progress";
                s.MainViewModel.BuildCommandProgressText  = string.Empty;
                s.MainViewModel.BuildCommandProgressMax   = 100;
                s.MainViewModel.BuildCommandProgressShow  = true;

                try
                { // Unmount
                    WimgApi.UnmountImage(hImage);
                    logs.Add(new LogInfo(LogState.Success, $"Unmounted [{wimInfo.Path}]'s image [{wimInfo.ImageIndex}] from [{mountDir}]"));
                }
                finally
                { // Finalize Command Progress Report
                    s.MainViewModel.BuildCommandProgressShow  = false;
                    s.MainViewModel.BuildCommandProgressTitle = "Progress";
                    s.MainViewModel.BuildCommandProgressText  = string.Empty;
                    s.MainViewModel.BuildCommandProgressValue = 0;
                    WimgApi.UnregisterMessageCallback(hWim, WimgApiCallback);
                }
            }
            catch (Win32Exception e)
            {
                logs.Add(new LogInfo(LogState.Error, $"Unable to unmount [{mountDir}]\r\nError Code [0x{e.ErrorCode:X8}]\r\nNative Error Code [0x{e.NativeErrorCode:X8}]\r\n"));
                return(logs);
            }
            finally
            {
                hWim?.Close();
                hImage?.Close();
            }

            return(logs);
        }
Exemple #6
0
        private void VerifyMountState(WimHandle imageHandle, WimMountPointState expectedMountPointState)
        {
            WimMountInfo mountedImageInfo = WimgApi.GetMountedImageInfoFromHandle(imageHandle);

            (mountedImageInfo.State | expectedMountPointState).ShouldBe(expectedMountPointState);
        }