/// <summary>
        /// Enables a handler to provide status and error information for all operations.
        /// </summary>
        /// <param name="pfops">An <see cref="IFileOperationProgressSink"/> object to be used for progress status and error notifications.</param>
        /// <returns>A returned token that uniquely identifies this connection. The calling application uses this token later to delete the connection by passing it to <see cref="Unadvise"/>.</returns>
        /// <remarks>Several individual methods have the ability to declare their own progress sinks, which are redundant to the one set here. They are used when you only want to be given progress and error information for a specific operation.</remarks>
        /// <exception cref="ArgumentNullException">Exception thrown when a parameter is null.</exception>
        /// <exception cref="ObjectDisposedException">Exception thrown when this object is disposed.</exception>
        /// <exception cref="Win32Exception">Exception thrown when this method fails because of an error in the Win32 COM API implementation.</exception>
        public uint Advise(FileOperationProgressSink pfops)
        {
            if (pfops == null)
            {
                throw new ArgumentNullException(nameof(pfops));
            }

            if (disposed)
            {
                throw new ObjectDisposedException(nameof(FileOperation));
            }

            HResult hr = fileOperation.Advise(pfops.FileOperationProgressSinkInternal, out uint pdwCookie);

            if (CoreErrorHelper.Succeeded(hr))
            {
                cookies.Add(pdwCookie);

                return(pdwCookie);
            }

            else
            {
                Marshal.ThrowExceptionForHR((int)hr);
            }

            return(0);
        }
Пример #2
0
    public FileOperation(FileOperationProgressSink callbackSink, IWin32Window owner) {
      _callbackSink = callbackSink;
      _fileOperation = (IFileOperation) Activator.CreateInstance(_fileOperationType);

      _fileOperation.SetOperationFlags(FileOperationFlags.FOF_NOCONFIRMMKDIR);
      if (_callbackSink != null) SinkCookie = _fileOperation.Advise(_callbackSink);
      if (owner != null) _fileOperation.SetOwnerWindow((uint) owner.Handle);
    }
Пример #3
0
 /// <summary>Initializes a new instance of the <see cref="ShellFileOperations"/> class.</summary>
 /// <param name="owner">The window that owns the modal dialog. This value can be <see langword="null"/>.</param>
 public ShellFileOperations(IWin32Window owner = null)
 {
     op = new IFileOperation();
     if (owner != null)
     {
         op.SetOwnerWindow(owner.Handle);
     }
     sink       = new OpSink(this);
     sinkCookie = op.Advise(sink);
 }
Пример #4
0
 /// <summary>Initializes a new instance of the <see cref="ShellFileOperations"/> class.</summary>
 /// <param name="owner">The window that owns the modal dialog. This value can be <see langword="null"/>.</param>
 public ShellFileOperations(HWND owner = default)
 {
     op = new IFileOperation();
     if (owner != default)
     {
         op.SetOwnerWindow(owner);
     }
     sink       = new OpSink(this);
     sinkCookie = op.Advise(sink);
 }
Пример #5
0
        public FileOperation(FileOperationProgressSink callbackSink, IWin32Window owner)
        {
            _callbackSink  = callbackSink;
            _fileOperation = (IFileOperation)Activator.CreateInstance(_fileOperationType);

            _fileOperation.SetOperationFlags(FileOperationFlags.FOF_NOCONFIRMMKDIR);
            if (_callbackSink != null)
            {
                SinkCookie = _fileOperation.Advise(_callbackSink);
            }
            if (owner != null)
            {
                _fileOperation.SetOwnerWindow((uint)owner.Handle);
            }
        }
Пример #6
0
        public IIFileOperation(FileOperationProgressSink callbackSink, IntPtr owner, Boolean isRecycle, Boolean isCopyInSameFolder)
        {
            this._CallbackSink       = callbackSink;
            this._IsCopyInSameFolder = isCopyInSameFolder;
            _FileOperation           = (IFileOperation)Activator.CreateInstance(_FileOperationType);

            if (!isRecycle)
            {
                this._FileOperation.SetOperationFlags(FileOperationFlags.FOF_NOCONFIRMMKDIR);
            }

            if (_CallbackSink != null)
            {
                _SinkCookie = _FileOperation.Advise(_CallbackSink);
            }
            if (owner != IntPtr.Zero)
            {
                _FileOperation.SetOwnerWindow((uint)owner);
            }
        }