예제 #1
0
        public static void Join(IEnumerable <string> swms, string outputPath, OpenFlags swmOpenFlags, WriteFlags wimWriteFlags)
        {
            string[]  swmArr = swms.ToArray();
            ErrorCode ret    = NativeMethods.Join(swmArr, (uint)swmArr.Length, outputPath, swmOpenFlags, wimWriteFlags);

            WimLibException.CheckWimLibError(ret);
        }
예제 #2
0
        public void ReferenceResources(IEnumerable <Wim> resourceWims)
        {
            IntPtr[]  wims = resourceWims.Select(x => x._ptr).ToArray();
            ErrorCode ret  = NativeMethods.ReferenceResources(_ptr, wims, (uint)wims.Length, 0);

            WimLibException.CheckWimLibError(ret);
        }
예제 #3
0
        public void IterateLookupTable(IterateLookupTableCallback callback, object userData)
        {
            ManagedIterateLookupTableCallback cb = new ManagedIterateLookupTableCallback(callback, userData);

            ErrorCode ret = NativeMethods.IterateLookupTable(_ptr, 0, cb.NativeFunc, IntPtr.Zero);

            WimLibException.CheckWimLibError(ret);
        }
예제 #4
0
        public static void GlobalInit(string libPath, InitFlags initFlags)
        {
            if (NativeMethods.Loaded)
            {
                throw new InvalidOperationException(NativeMethods.MsgAlreadyInit);
            }
            {
                NativeMethods.UseUtf16    = true;
                NativeMethods.LongBitType = NativeMethods.LongBits.Long32;

                if (libPath == null)
                {
                    throw new ArgumentNullException(nameof(libPath));
                }

                libPath = Path.GetFullPath(libPath);
                if (!File.Exists(libPath))
                {
                    throw new ArgumentException("Specified .dll file does not exist");
                }

                string libDir = Path.GetDirectoryName(libPath);
                if (libDir != null && !libDir.Equals(AppDomain.CurrentDomain.BaseDirectory))
                {
                    NativeMethods.Win32.SetDllDirectory(libDir);
                }

                NativeMethods.hModule = NativeMethods.Win32.LoadLibrary(libPath);
                if (NativeMethods.hModule == IntPtr.Zero)
                {
                    throw new ArgumentException($"Unable to load [{libPath}]", new Win32Exception());
                }

                NativeMethods.Win32.SetDllDirectory(null);
                if (NativeMethods.Win32.GetProcAddress(NativeMethods.hModule, nameof(NativeMethods.Utf16.wimlib_open_wim)) == IntPtr.Zero)
                {
                    GlobalCleanup();
                    throw new ArgumentException($"[{libPath}] is not a valid wimlib-15.dll");
                }
            }


            try
            {
                NativeMethods.LoadFunctions();
                NativeMethods.ErrorFile = Path.GetTempFileName();
                WimLibException.CheckWimLibError(NativeMethods.SetErrorFile(NativeMethods.ErrorFile));
                SetPrintErrors(true);
                ErrorCode ret = NativeMethods.GlobalInit(initFlags);
                WimLibException.CheckWimLibError(ret);
            }
            catch (Exception)
            {
                GlobalCleanup(); throw;
            }
        }
예제 #5
0
        public void UpdateImage(int image, IEnumerable <UpdateCommand> cmds, UpdateFlags updateFlags)
        {
            ErrorCode ret;
            int       bits;

            switch (IntPtr.Size)
            {
            case 4:
                bits = 32;
                break;

            case 8:
                bits = 64;
                break;

            default:
                throw new PlatformNotSupportedException();
            }
            switch (bits)
            {
            case 32:
                UpdateCommand32[] cmds32 = cmds.Select(x => x.ToNativeStruct32()).ToArray();
                try
                {
                    ret = NativeMethods.UpdateImage32(_ptr, image, cmds32, (uint)cmds32.Length, updateFlags);
                }
                finally
                {
                    foreach (UpdateCommand32 cmd32 in cmds32)
                    {
                        cmd32.Free();
                    }
                }
                break;

            case 64:
                UpdateCommand64[] cmds64 = cmds.Select(x => x.ToNativeStruct64()).ToArray();
                try
                {
                    ret = NativeMethods.UpdateImage64(_ptr, image, cmds64, (ulong)cmds64.Length, updateFlags);
                }
                finally
                {
                    foreach (UpdateCommand64 cmd64 in cmds64)
                    {
                        cmd64.Free();
                    }
                }
                break;

            default:
                throw new PlatformNotSupportedException();
            }

            WimLibException.CheckWimLibError(ret);
        }
예제 #6
0
        public static void Join(IEnumerable <string> swms, string outputPath, OpenFlags swmOpenFlags, WriteFlags wimWriteFlags,
                                ProgressCallback callback, object userData)
        {
            ManagedProgressCallback mCallback = new ManagedProgressCallback(callback, userData);

            string[]  swmArr = swms.ToArray();
            ErrorCode ret    = NativeMethods.JoinWithProgress(swmArr, (uint)swmArr.Length, outputPath, swmOpenFlags, wimWriteFlags,
                                                              mCallback.NativeFunc, IntPtr.Zero);

            WimLibException.CheckWimLibError(ret);
        }
예제 #7
0
        /// <summary>
        /// Open a WIM file and create a instance of Wim class for it.
        /// </summary>
        /// <param name="wimFile">The path to the WIM file to open.</param>
        /// <param name="openFlags">Bitwise OR of flags prefixed with WIMLIB_OPEN_FLAG.</param>
        /// <returns>
        /// On success, a new instance of Wim class backed by the specified
        ///	on-disk WIM file is returned. This instance must be disposed
        ///	when finished with it.
        ///	</returns>
        ///	<exception cref="WimLibException">wimlib did not return ErrorCode.SUCCESS.</exception>
        public static Wim OpenWim(string wimFile, OpenFlags openFlags)
        {
            if (!NativeMethods.Loaded)
            {
                throw new InvalidOperationException(NativeMethods.MsgInitFirstError);
            }

            ErrorCode ret = NativeMethods.OpenWim(wimFile, openFlags, out IntPtr wimPtr);

            WimLibException.CheckWimLibError(ret);

            return(new Wim(wimPtr));
        }
예제 #8
0
        public static void SetPrintErrors(bool showMessages)
        {
            if (!NativeMethods.Loaded)
            {
                throw new InvalidOperationException(NativeMethods.MsgInitFirstError);
            }

            ErrorCode ret = NativeMethods.SetPrintErrors(showMessages);

            WimLibException.CheckWimLibError(ret);

            NativeMethods.PrintErrorsEnabled = showMessages;
        }
예제 #9
0
        /// <summary>
        /// Same as wimlib_open_wim(), but allows specifying a progress function and\
        /// progress context.  If successful, the progress function will be registered in
        /// the newly open ::WIMStruct, as if by an automatic call to
        /// wimlib_register_progress_function().  In addition, if
        /// ::WIMLIB_OPEN_FLAG_CHECK_INTEGRITY is specified in @p open_flags, then the
        /// progress function will receive ::WIMLIB_PROGRESS_MSG_VERIFY_INTEGRITY
        /// messages while checking the WIM file's integrity.
        /// </summary>
        /// <param name="wimFile">The path to the WIM file to open.</param>
        /// <param name="openFlags">Bitwise OR of flags prefixed with WIMLIB_OPEN_FLAG.</param>
        /// <returns>
        /// On success, a pointer to a new ::WIMStruct backed by the specified
        ///	on-disk WIM file is written to the memory location pointed to by this
        ///	parameter.This ::WIMStruct must be freed using using wimlib_free()
        ///	when finished with it.
        ///	</returns>
        ///	<exception cref="WimLibException">wimlib does not return WIMLIB_ERR_SUCCESS.</exception>
        public static Wim OpenWim(string wimFile, WimLibOpenFlags openFlags, WimLibCallback callback = null, object userData = null)
        {
            WimLibErrorCode ret = WimLibNative.OpenWim(wimFile, openFlags, out IntPtr wimPtr);

            WimLibException.CheckWimLibError(ret);

            Wim wim = new Wim(wimPtr);

            if (callback != null)
            {
                wim.RegisterCallback(callback, userData);
            }

            return(wim);
        }
예제 #10
0
        public void ReferenceResourceFiles(IEnumerable <string> resourceWimFiles, RefFlags refFlags, OpenFlags openFlags)
        {
            List <string> resources = new List <string>();

            foreach (string f in resourceWimFiles)
            {
                if (f == null)
                {
                    throw new ArgumentNullException(nameof(resourceWimFiles));
                }

                string dirPath  = Path.GetDirectoryName(f);
                string wildcard = Path.GetFileName(f);
                if (dirPath == null)
                {
                    dirPath = @"\";
                }
                if (dirPath.Length == 0)
                {
                    dirPath = ".";
                }
                if ((refFlags & RefFlags.GLOB_ENABLE) != 0 && wildcard.IndexOfAny(new[] { '*', '?' }) != -1)
                {
                    string removeAsterisk = StringHelper.ReplaceEx(f, "*", string.Empty, StringComparison.Ordinal);
                    var    files          = Directory.EnumerateFiles(dirPath, wildcard, SearchOption.AllDirectories);
                    resources.AddRange(files.Where(x => !x.Equals(removeAsterisk, StringComparison.OrdinalIgnoreCase)));
                }
                else
                {
                    resources.Add(f);
                }
            }

            if (resources.Count == 0 &&
                (refFlags & RefFlags.GLOB_ENABLE) != 0 && (refFlags & RefFlags.GLOB_ERR_ON_NOMATCH) != 0)
            {
                throw new WimLibException(ErrorCode.GLOB_HAD_NO_MATCHES);
            }

            ErrorCode ret = NativeMethods.ReferenceResourceFiles(_ptr, resources.ToArray(), (uint)resources.Count, RefFlags.DEFAULT, openFlags);

            WimLibException.CheckWimLibError(ret);
        }
예제 #11
0
        public void UpdateImage(int image, UpdateCommand cmd, UpdateFlags updateFlags)
        {
            ErrorCode ret;

            switch (IntPtr.Size)
            {
            case 4:
                UpdateCommand32[] cmds32 = new UpdateCommand32[1] {
                    cmd.ToNativeStruct32()
                };
                try
                {
                    ret = NativeMethods.UpdateImage32(_ptr, image, cmds32, 1u, updateFlags);
                }
                finally
                {
                    cmds32[0].Free();
                }
                break;

            case 8:
                UpdateCommand64[] cmds64 = new UpdateCommand64[1] {
                    cmd.ToNativeStruct64()
                };
                try
                {
                    ret = NativeMethods.UpdateImage64(_ptr, image, cmds64, 1u, updateFlags);
                }
                finally
                {
                    cmds64[0].Free();
                }
                break;

            default:
                throw new PlatformNotSupportedException();
            }
            WimLibException.CheckWimLibError(ret);
        }
예제 #12
0
        /// <summary>
        /// Same as OpenWim(), but allows specifying a progress function and progress context.
        /// </summary>
        /// <remarks>
        /// If successful, the progress function will be registered in the newly open WimStruct,
        /// as if by an automatic call to Wim.RegisterCallback().
        ///
        /// In addition, if OpenFlags.CHECK_INTEGRITY is specified in openFlags,
        /// then the callback function will receive ProgressMsg.VERIFY_INTEGRITY messages while checking the WIM file's integrity.
        /// </remarks>
        /// <param name="wimFile">The path to the WIM file to open.</param>
        /// <param name="openFlags">Bitwise OR of flags prefixed with WIMLIB_OPEN_FLAG.</param>
        /// <param name="callback">Callback function to receive progress report</param>
        /// <param name="userData">Data to be passed to callback function</param>
        /// <returns>
        /// On success, a new instance of Wim class backed by the specified on-disk WIM file is returned.
        ///	This instance must be disposed when finished with it.
        ///	</returns>
        ///	<exception cref="WimLibException">wimlib did not return ErrorCode.SUCCESS.</exception>
        public static Wim OpenWim(string wimFile, OpenFlags openFlags, ProgressCallback callback, object userData = null)
        {
            if (!NativeMethods.Loaded)
            {
                throw new InvalidOperationException(NativeMethods.MsgInitFirstError);
            }

            if (callback == null)
            {
                throw new ArgumentNullException(nameof(callback));
            }

            ManagedProgressCallback mCallback = new ManagedProgressCallback(callback, userData);

            ErrorCode ret = NativeMethods.OpenWimWithProgress(wimFile, openFlags, out IntPtr wimPtr, mCallback.NativeFunc, IntPtr.Zero);

            WimLibException.CheckWimLibError(ret);

            return(new Wim(wimPtr)
            {
                _managedCallback = mCallback
            });
        }
예제 #13
0
 public void VerifyWim()
 {
     WimLibException.CheckWimLibError(NativeMethods.VerifyWim(_ptr, 0));
 }
예제 #14
0
 public void Split(string swmName, ulong partSize, WriteFlags writeFlags)
 {
     WimLibException.CheckWimLibError(NativeMethods.Split(_ptr, swmName, partSize, writeFlags));
 }
예제 #15
0
 public void SetOutputPackCompressionType(CompressionType compType)
 {
     WimLibException.CheckWimLibError(NativeMethods.SetOutputPackCompressionType(_ptr, compType));
 }
예제 #16
0
        public void IterateDirTree(int image, string path, IterateFlags iterateFlags, IterateDirTreeCallback callback, object userData = null)
        {
            ManagedIterateDirTreeCallback cb = new ManagedIterateDirTreeCallback(callback, userData);

            WimLibException.CheckWimLibError(NativeMethods.IterateDirTree(_ptr, image, path, iterateFlags, cb.NativeFunc, IntPtr.Zero));
        }
예제 #17
0
        /// <summary>
        /// Extract an image, or all images, from a ::WIMStruct.
        ///
        /// The exact behavior of how wimlib extracts files from a WIM image is
        /// controllable by the @p extract_flags parameter, but there also are
        /// differences depending on the platform (UNIX-like vs Windows).  See the
        /// documentation for <b>wimapply</b> for more information, including about the
        /// NTFS-3G extraction mode.
        /// </summary>
        /// <param name="wim">
        /// The WIM from which to extract the image(s), specified as a pointer to the
        /// ::WIMStruct for a standalone WIM file, a delta WIM file, or part 1 of a
        /// split WIM.  In the case of a WIM file that is not standalone, this
        /// ::WIMStruct must have had any needed external resources previously
        /// referenced using wimlib_reference_resources() or
        /// wimlib_reference_resource_files().
        /// </param>
        /// <param name="image">
        /// The 1-based index of the image to extract, or ::WIMLIB_ALL_IMAGES to
        /// extract all images.  Note: ::WIMLIB_ALL_IMAGES is unsupported in NTFS-3G
        /// extraction mode.
        /// </param>
        /// <param name="target">
        /// A null-terminated string which names the location to which the image(s)
        /// will be extracted.  By default, this is interpreted as a path to a
        /// directory.  Alternatively, if ::WIMLIB_EXTRACT_FLAG_NTFS is specified in
        /// @p extract_flags, then this is interpreted as a path to an unmounted
        /// NTFS volume.
        /// </param>
        /// <param name="extract_flags">
        /// Bitwise OR of flags prefixed with WIMLIB_EXTRACT_FLAG.
        /// </param>
        /// <returns>
        /// return 0 on success; a ::wimlib_error_code value on failure.
        /// </returns>
        public void ExtractImage(int image, string target, WimLibExtractFlags extractFlags)
        {
            WimLibErrorCode ret = WimLibNative.ExtractImage(Ptr, image, target, extractFlags);

            WimLibException.CheckWimLibError(ret);
        }
예제 #18
0
 public void Write(string path, int image, WriteFlags writeFlags, uint numThreads)
 {
     WimLibException.CheckWimLibError(NativeMethods.Write(_ptr, path, image, writeFlags, numThreads));
 }
예제 #19
0
 public void AddImageMultiSource(IEnumerable <CaptureSource> sources, string name, string configFile, AddFlags addFlags)
 {
     CaptureSource[] srcArr = sources.ToArray();
     WimLibException.CheckWimLibError(NativeMethods.AddImageMultiSource(_ptr, srcArr, new IntPtr(srcArr.Length), name, configFile, addFlags));
 }
예제 #20
0
        public void ExportImage(int srcImage, Wim destWim, string destName, string destDescription, ExportFlags exportFlags)
        {
            ErrorCode ret = NativeMethods.ExportImage(_ptr, srcImage, destWim._ptr, destName, destDescription, exportFlags);

            WimLibException.CheckWimLibError(ret);
        }
예제 #21
0
 public void ExtractImage(int image, string target, ExtractFlags extractFlags)
 {
     WimLibException.CheckWimLibError(NativeMethods.ExtractImage(_ptr, image, target, extractFlags));
 }
예제 #22
0
 public void ExtractPath(int image, string target, string path, ExtractFlags extractFlags)
 {
     WimLibException.CheckWimLibError(NativeMethods.ExtractPaths(_ptr, image, target, new string[1] {
         path
     }, new IntPtr(1), extractFlags));
 }
예제 #23
0
 public void ExtractPaths(int image, string target, IEnumerable <string> paths, ExtractFlags extractFlags)
 {
     string[] pathArr = paths.ToArray();
     WimLibException.CheckWimLibError(NativeMethods.ExtractPaths(_ptr, image, target, pathArr, new IntPtr(pathArr.Length), extractFlags));
 }
예제 #24
0
 public void DeleteImage(int image)
 {
     WimLibException.CheckWimLibError(NativeMethods.DeleteImage(_ptr, image));
 }
예제 #25
0
 public void AddTree(int image, string fsSourcePath, string wimTargetPath, AddFlags addFlags)
 {
     WimLibException.CheckWimLibError(NativeMethods.AddTree(_ptr, image, fsSourcePath, wimTargetPath, addFlags));
 }
예제 #26
0
 public void DeletePath(int image, string path, DeleteFlags deleteFlags)
 {
     WimLibException.CheckWimLibError(NativeMethods.DeletePath(_ptr, image, path, deleteFlags));
 }
예제 #27
0
 public void Overwrite(WriteFlags writeFlags, uint numThreads)
 {
     WimLibException.CheckWimLibError(NativeMethods.Overwrite(_ptr, writeFlags, numThreads));
 }
예제 #28
0
        public void ReferenceTemplateImage(int newImage, Wim template, int templateImage)
        {
            ErrorCode ret = NativeMethods.ReferenceTemplateImage(_ptr, newImage, template._ptr, templateImage, 0);

            WimLibException.CheckWimLibError(ret);
        }
예제 #29
0
 public void SetOutputPackChunkSize(uint chunkSize)
 {
     WimLibException.CheckWimLibError(NativeMethods.SetOutputPackChunkSize(_ptr, chunkSize));
 }
예제 #30
0
 public void ExtractPathList(int image, string target, string pathListFile, ExtractFlags extractFlags)
 {
     WimLibException.CheckWimLibError(NativeMethods.ExtractPathList(_ptr, image, target, pathListFile, extractFlags));
 }