Beispiel #1
0
        /// <summary>
        /// Gets information about a mounted image.
        /// </summary>
        /// <param name="mountPath">The full file path of the directory to which the .wim file has been mounted.</param>
        /// <returns>A <see cref="WimMountInfo" /> object containing information about the mounted image.</returns>
        public static WimMountInfo GetMountInfo(string mountPath)
        {
            // Stores the handle to the image
            //
            WimHandle imageHandle = null;

            try
            {
                // Get a mounted image handle
                //
                // ReSharper disable once UnusedVariable
                using (WimHandle wimHandle = WimgApi.GetMountedImageHandle(mountPath, true, out imageHandle))
                {
                    // Return the mounted image info from the handle
                    //
                    return(WimgApi.GetMountedImageInfoFromHandle(imageHandle));
                }
            }
            finally
            {
                // Clean up
                //
                imageHandle?.Dispose();
            }
        }
Beispiel #2
0
        /// <summary>
        /// Loads a volume image from a Windows® image (.wim) file.
        /// </summary>
        /// <param name="wimHandle">A <see cref="WimHandle"/> of a .wim file returned by the <see cref="CreateFile"/> method.</param>
        /// <param name="index">The one-based index of the image to load. An image file may store multiple images.</param>
        /// <returns>A <see cref="WimHandle"/> representing the volume image.</returns>
        /// <exception cref="ArgumentNullException">wimHandle is null.</exception>
        /// <exception cref="IndexOutOfRangeException">index is less than 1
        /// -or-
        /// index is greater than the number of images in the Windows® imaging file.</exception>
        /// <exception cref="Win32Exception">The Windows® Imaging API reported a failure.</exception>
        /// <remarks>You must call the <see cref="SetTemporaryPath"/> method before calling the <see cref="LoadImage"/> method so the image metadata can be extracted and processed from the temporary location.</remarks>
        public static WimHandle LoadImage(WimHandle wimHandle, int index)
        {
            // See if wimHandle is null
            if (wimHandle == null)
            {
                throw new ArgumentNullException(nameof(wimHandle));
            }

            // See if the specified index is valid
            if (index < 1 || index > WimgApi.GetImageCount(wimHandle))
            {
                throw new IndexOutOfRangeException($"There is no image at index {index}.");
            }

            // Call the native function
            WimHandle imageHandle = WimgApi.NativeMethods.WIMLoadImage(wimHandle, (DWORD)index);

            if (imageHandle == null || imageHandle.IsInvalid)
            {
                // Throw a Win32Exception based on the last error code
                throw new Win32Exception();
            }

            // Return the image handle
            return(imageHandle);
        }
Beispiel #3
0
        protected override bool ReleaseHandle()
        {
            // Verify the handle is still valid
            //
            if (!IsInvalid)
            {
                // Close the handle
                //
                return(WimgApi.CloseHandle(handle));
            }

            // Default to return true
            //
            return(true);
        }
Beispiel #4
0
        /// <summary>
        /// Marks the image with the given image index as bootable.
        /// </summary>
        /// <param name="wimHandle">A <see cref="WimHandle"/> of a Windows® image (.wim) file returned by the <see cref="CreateFile"/> method.</param>
        /// <param name="imageIndex">The one-based index of the image to load. An image file can store multiple images.</param>
        /// <exception cref="ArgumentNullException">wimHandle is null.</exception>
        /// <exception cref="IndexOutOfRangeException">index is less than 1 or greater than the number of images in the Windows® image file.</exception>
        /// <exception cref="Win32Exception">The Windows® Imaging API reported a failure.</exception>
        /// <remarks>If imageIndex is zero, then none of the images in the .wim file are marked for boot. At any time, only one image in a .wim file can be set to be bootable.</remarks>
        public static void SetBootImage(WimHandle wimHandle, int imageIndex)
        {
            // See if wimHandle is null
            if (wimHandle == null)
            {
                throw new ArgumentNullException(nameof(wimHandle));
            }

            // See if the specified index is valid
            if (imageIndex < 1 || imageIndex > WimgApi.GetImageCount(wimHandle))
            {
                throw new IndexOutOfRangeException($"There is no image at index {imageIndex}.");
            }

            // Call the native function
            if (!WimgApi.NativeMethods.WIMSetBootImage(wimHandle, (DWORD)imageIndex))
            {
                // Throw a Win32Exception based on the last error code
                throw new Win32Exception();
            }
        }
Beispiel #5
0
 protected override bool ReleaseHandle()
 {
     return !IsInvalid && WimgApi.CloseHandle(handle);
 }
Beispiel #6
0
 /// <summary>
 /// Mounts an image in a Windows® image (.wim) file to the specified directory and does not allow for edits.
 /// </summary>
 /// <param name="mountPath">The full file path of the directory to which the .wim file has to be mounted.</param>
 /// <param name="imagePath">The full file name of the .wim file that has to be mounted.</param>
 /// <param name="imageIndex">An index of the image in the .wim file that has to be mounted.</param>
 /// <exception cref="ArgumentNullException">mountPath or imagePath is null.</exception>
 /// <exception cref="DirectoryNotFoundException">mountPath does not exist.</exception>
 /// <exception cref="FileNotFoundException">imagePath does not exist.</exception>
 /// <exception cref="IndexOutOfRangeException">index is less than 1.</exception>
 /// <exception cref="Win32Exception">The Windows® Imaging API reported a failure.</exception>
 public static void MountImage(string mountPath, string imagePath, int imageIndex)
 {
     // Call an overload
     WimgApi.MountImage(mountPath, imagePath, imageIndex, tempPath: null);
 }
Beispiel #7
0
 /// <summary>
 /// Copies an existing file to a new file.
 /// </summary>
 /// <param name="sourceFile">The name of an existing .wim file.</param>
 /// <param name="destinationFile">The name of the new file.</param>
 /// <param name="options">Specifies how the file is to be copied.</param>
 /// <exception cref="ArgumentNullException">sourceFile or destinationFile is null.</exception>
 /// <exception cref="Win32Exception">The Windows® Imaging API reported a failure.</exception>
 public static void CopyFile(string sourceFile, string destinationFile, WimCopyFileOptions options)
 {
     // Call an override
     WimgApi.CopyFile(sourceFile, destinationFile, options, null, null);
 }
 /// <summary>
 /// Registers a function to be called with imaging-specific data for only the specified WIM file.
 /// </summary>
 /// <param name="wimHandle">An optional <see cref="WimHandle"/> of a .wim file returned by <see cref="CreateFile"/>.</param>
 /// <param name="messageCallback">An application-defined callback function.</param>
 /// <returns>The zero-based index of the callback.</returns>
 /// <exception cref="ArgumentNullException">messageCallback is null.</exception>
 /// <exception cref="Win32Exception">The Windows® Imaging API reported a failure.</exception>
 public static int RegisterMessageCallback(WimHandle wimHandle, WimMessageCallback messageCallback)
 {
     // Call an overload
     return(WimgApi.RegisterMessageCallback(wimHandle, messageCallback, null));
 }