コード例 #1
0
        public ManagedWimLibCallback(WimLibCallback callback, object userData)
        {
            _callback = callback ?? throw new ArgumentNullException("callback");
            _userData = userData;

            // Avoid GC by keeping ref here
            NativeFunc = Callback;
        }
コード例 #2
0
ファイル: WimStruct.cs プロジェクト: Taviruni/pebakery
        /// <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);
        }
コード例 #3
0
ファイル: WimStruct.cs プロジェクト: Taviruni/pebakery
        /// <summary>
        /// Register a progress function with a ::WIMStruct.
        /// </summary>
        /// <param name="wim">The ::WIMStruct for which to register the progress function.</param>
        /// <param name="callback">
        /// Pointer to the progress function to register.  If the WIM already has a
        /// progress function registered, it will be replaced with this one.  If @p
        /// NULL, the current progress function (if any) will be unregistered.
        /// </param>
        /// <param name="userData">
        /// The value which will be passed as the third argument to calls to @p
        /// progfunc.
        /// </param>
        public void RegisterCallback(WimLibCallback callback, object userData = null)
        {
            if (callback != null)
            { // RegisterCallback
                ManagedCallback = new ManagedWimLibCallback(callback, userData);
                WimLibNative.RegisterProgressFunction(Ptr, ManagedCallback.NativeFunc, IntPtr.Zero);

                //ManagedCallback = new ManagedWimLibCallback(callback, userData);
                //WimLibNative.RegisterProgressFunction(Ptr, ManagedCallback.DummyCallback, IntPtr.Zero);
            }
            else
            { // Delete callback
                ManagedCallback = null;
                WimLibNative.RegisterProgressFunction(Ptr, null, IntPtr.Zero);
            }
        }