예제 #1
0
        public WimImage(WimFile file, int imageIndex)
        {
            if (file == null)
            {
                throw new ArgumentNullException(nameof(file));
            }

            if (imageIndex > file.ImagesCount)
            {
                throw new ArgumentOutOfRangeException(nameof(imageIndex), "The index does not exist in the specified WIM file.");
            }

            _handle = NativeMethods.WIMLoadImage(file.CheckDisposed(), imageIndex);

            if (!NativeMethods.WIMGetImageInformation(_handle, out var builder, out var bytes))
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }

            // Ensure the length of the returned bytes to avoid garbage characters at the end.
            var count = bytes / sizeof(char);

            if (null != builder)
            {
                // Get rid of the unicode file marker at the beginning of the XML.
                builder.Remove(0, 1);
                builder.EnsureCapacity(count - 1);
                builder.Length = count - 1;

                // This isn't likely to change while we have the image open, so cache it.
                var xml = XDocument.Parse(builder.ToString().Trim());
                _xmlElement = xml.Root;
            }
        }
예제 #2
0
 internal WimFileErrorEventArgs(WimFile file, WIM_MSG message, IntPtr wParam, IntPtr lParam)
     : base(message, wParam, lParam)
 {
     Path         = Marshal.PtrToStringUni(wParam);
     RelativePath = file.GetRelativePath(Path);
     ErrorCode    = lParam.ToInt32();
     if (ErrorCode != 0)
     {
         ErrorMessage = new Win32Exception(ErrorCode).Message;
     }
 }
예제 #3
0
 internal WimFileProcessEventArgs(WimFile file, WIM_MSG message, IntPtr wParam, IntPtr lParam)
     : base(message, wParam, lParam)
 {
     Path         = Marshal.PtrToStringUni(wParam);
     RelativePath = file.GetRelativePath(Path);
 }