Exemplo n.º 1
0
 /// <summary>
 /// Create a new FileOperation object that will perform all queued operations when disposed.
 /// </summary>
 /// <param name="owner">Owner of the file operations</param>
 public FileOperation(IWin32Window owner)
 {
     _fileOperation = (IFileOperation)Activator.CreateInstance(_fileOperationType);
       _fileOperation.SetOperationFlags(FileOperationFlags.FOF_NOCONFIRMMKDIR);
       if(owner != null)
     _fileOperation.SetOwnerWindow((uint)owner.Handle);
 }
Exemplo n.º 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);
    }
Exemplo n.º 3
0
 /// <summary>
 /// Create a new FileOperation object that will perform all queued operations when disposed.
 /// </summary>
 /// <param name="owner">Owner of the file operations.</param>
 public CopyFilesOperation(IWin32Window owner)
 {
     _fileOperation = (IFileOperation)Activator.CreateInstance(_fileOperationType);
     _fileOperation.SetOperationFlags(FileOperationFlags.FOF_NOCONFIRMMKDIR);
     if (owner != null)
     {
         _fileOperation.SetOwnerWindow((uint)owner.Handle);
     }
     _shellItemFactory = new ShellItemFactory();
 }
Exemplo n.º 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(IWin32Window owner = null)
 {
     op = new IFileOperation();
     if (owner != null)
     {
         op.SetOwnerWindow(owner.Handle);
     }
     sink       = new OpSink(this);
     sinkCookie = op.Advise(sink);
 }
Exemplo n.º 5
0
        private void Execute(IFileOperation operation)
        {
            switch (operation.Mode)
            {
            case Mode.Copy:
                deviceConnector.CopyFiles(operation.Files, operation.TargetPath, operation.BehaviorRegardingDuplicates);
                break;

            case Mode.Move:
                deviceConnector.MoveFiles(operation.Files, operation.TargetPath, operation.BehaviorRegardingDuplicates);
                break;
            }
        }
Exemplo n.º 6
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);
            }
        }
Exemplo n.º 7
0
        private ResourceHandle FinishOperation(IFileOperation operation, FileOperationProgressSink sink)
        {
            operation.PerformOperations();
            //await sink.WhenCompleted();
            var item = sink.CreatedItems.LastOrDefault();

            if (item != null)
            {
                return(new ShellFileHandle(item, this));
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FileOperation"/> class.
        /// </summary>
        /// <param name="callbackSink">
        /// The callback sink.
        /// </param>
        /// <param name="owner">
        /// The owner.
        /// </param>
        public FileOperation(FileOperationProgressSink callbackSink, IWin32Window owner)
        {
            this.callbackSink  = callbackSink;
            this.fileOperation = (IFileOperation)Activator.CreateInstance(FileOperationType);

            this.fileOperation.SetOperationFlags(FileOperationFlags.FOF_NOCONFIRMMKDIR | FileOperationFlags.FOF_SILENT | FileOperationFlags.FOFX_SHOWELEVATIONPROMPT | FileOperationFlags.FOFX_NOCOPYHOOKS | FileOperationFlags.FOFX_REQUIREELEVATION);
            if (this.callbackSink != null)
            {
                this.sinkCookie = this.fileOperation.Advise(this.callbackSink);
            }

            if (owner != null)
            {
                this.fileOperation.SetOwnerWindow((uint)owner.Handle);
            }
        }
        /// <summary>
        ///     進捗通知クラスとオーナーウィンドウを指定して、
        ///     <see cref="FileOperation" />クラスの新しいインスタンスを初期化します。
        /// </summary>
        /// <param name="progress">進捗通知クラス。</param>
        /// <param name="ownerWindow">オーナーウィンドウ。</param>
        public FileOperation(FileOperationProgress progress, Window ownerWindow)
        {
            this.fileOperation = (IFileOperation)Activator.CreateInstance(FileOperationType);

            if (progress != null)
            {
                this.progressSink = new FileOperationProgressSink(progress);
                this.cookie       = this.fileOperation.Advise(this.progressSink);
            }

            if (ownerWindow != null)
            {
                var windowHelper = new WindowInteropHelper(ownerWindow);
                this.fileOperation.SetOwnerWindow(windowHelper.Handle);
            }
        }
Exemplo n.º 10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="callbackSink"></param>
        /// <param name="owner"></param>
        /// <param name="isRecycle"></param>
        public IIFileOperation(FileOperationProgressSink callbackSink, IntPtr owner, Boolean isRecycle)
        {
            this._CallbackSink  = callbackSink;
            this._FileOperation = (IFileOperation)Activator.CreateInstance(_FileOperationType);

            var flags = isRecycle ? FileOperationFlags.FOF_NOCONFIRMMKDIR | FileOperationFlags.FOF_ALLOWUNDO : FileOperationFlags.FOF_NOCONFIRMMKDIR;

            this._FileOperation.SetOperationFlags(flags);

            if (this._CallbackSink != null)
            {
                this._SinkCookie = this._FileOperation.Advise(_CallbackSink);
            }
            if (owner != IntPtr.Zero)
            {
                this._FileOperation.SetOwnerWindow((uint)owner);
            }
        }
Exemplo n.º 11
0
        public static bool Begin(bool undoable = true)
        {
            if (_fileOperation != null)
            {
                throw new InvalidOperationException();
            }

            try
            {
                _fileOperation = Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("3ad05575-8857-4850-9277-11b85bdb8e09"))) as IFileOperation;
                _fileOperation?.SetOperationFlags(
                    (undoable ? OperationFlag.AllowUndo : OperationFlag.None)
                    | OperationFlag.NoUI);
            }
            catch { return(false); }

            return(_fileOperation != null);
        }
Exemplo n.º 12
0
        private static bool CopyItem(IFileOperation pthis, IntPtr sourceItems, IntPtr destinationFolder)
        {
            if (!IsCustomDialog)
            {
                return(false);
            }

            var destinationObject = Marshal.GetObjectForIUnknown(destinationFolder);
            var sourceObject      = Marshal.GetObjectForIUnknown(sourceItems);
            var u                   = SyncContext;
            var shellobj            = ShellObjectFactory.Create((IShellItem)destinationObject);
            var destinationLocation = shellobj.ParsingName;

            shellobj.Dispose();
            u.Post((o) =>
            {
                var sourceItemsCollection =
                    ShellObjectCollection.FromDataObject(
                        (System.Runtime.InteropServices.ComTypes.IDataObject)sourceObject)
                    .Select(c => c.ParsingName)
                    .ToArray();
                var win = System.Windows.Application.Current.MainWindow;

                var tempWindow    = new Shell.FileOperations.FileOperation(sourceItemsCollection, destinationLocation);
                var currentDialog = win.OwnedWindows.OfType <FileOperationDialog>().SingleOrDefault();

                if (currentDialog == null)
                {
                    currentDialog             = new FileOperationDialog();
                    tempWindow.ParentContents = currentDialog;
                    currentDialog.Owner       = win;

                    tempWindow.Visibility = Visibility.Collapsed;
                    currentDialog.Contents.Add(tempWindow);
                }
                else
                {
                    tempWindow.ParentContents = currentDialog;
                    tempWindow.Visibility     = Visibility.Collapsed;
                    currentDialog.Contents.Add(tempWindow);
                }
            }, null);
            return(true);
        }
Exemplo n.º 13
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);
            }
        }
        /// <summary>
        ///     Release all resources used by <see cref="FileOperation" /> class
        ///     and optionally releases managed resources.
        /// </summary>
        /// <param name="disposing">
        ///     <c>true</c> to release both managed and unmanaged resources.
        ///     <c>false</c> to release only unmanaged resources.
        /// </param>
        public void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                if (disposing)
                {
                }

                // Release unmanaged resources.
                if (this.progressSink != null)
                {
                    this.fileOperation.Unadvise(this.cookie);
                    this.progressSink = null;
                }

                Marshal.FinalReleaseComObject(this.fileOperation);
                this.fileOperation = null;

                this.disposed = true;
            }
        }
Exemplo n.º 15
0
 public static void End(bool doTransaction = true)
 {
     if (_fileOperation != null)
     {
         if (doTransaction)
         {
             try
             {
                 _fileOperation.PerformOperations();
             }
             catch (Exception ex)
             {
                 if (!ex.HResult.Equals(unchecked (( int )0x8000FFFF)))
                 {
                     throw;
                 }
             }
         }
         Marshal.ReleaseComObject(_fileOperation);
         _fileOperation = null;
     }
 }
Exemplo n.º 16
0
 public FileOperationViewmodel(IFileOperation fileOperation)
 {
     FileOperation = fileOperation;
     FileOperation.PropertyChanged += OnFileOperationPropertyChanged;
     CommandAbort      = new UiCommand(o => FileOperation.Abort(), o => FileOperation.OperationStatus == FileOperationStatus.Waiting || FileOperation.OperationStatus == FileOperationStatus.InProgress);
     CommandShowOutput = new UiCommand(
         o =>
     {
         var view = new Views.OperationOutputView
         {
             DataContext           = this,
             Owner                 = System.Windows.Application.Current.MainWindow,
             WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner,
             ShowInTaskbar         = false,
         };
         view.ShowDialog();
     }
         );
     CommandShowWarning = new UiCommand(o =>
                                        System.Windows.MessageBox.Show(OperationWarning, resources._caption_Warning,
                                                                       System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Exclamation)
                                        );
 }
Exemplo n.º 17
0
        public void Run()
        {
            try
            {
                IDevice device = SelectDevice();

                deviceConnector.UseDevice(device);

                IDirectory rootDirectory;
                using (IBusyIndicator busyIndicator = interactor.SetBusy())
                {
                    rootDirectory = deviceConnector.ReadMetadataOfAllFiles();
                }

                IFileOperation operation = interactor.CreateFileOperation(rootDirectory);

                using (IBusyIndicator busyIndicator = interactor.SetBusy())
                {
                    Execute(operation);
                }

                interactor.NotifySuccess(operation);
            }
            catch (NoDeviceConnectedException)
            {
                interactor.NotifyNoDeviceConnected();
            }
            catch (NoDeviceSelectedException)
            {
                interactor.NotifyNoDeviceSelected();
            }
            catch (ExecutionFailedException ex)
            {
                interactor.NotifyFileOperationFailed(ex.Message);
            }
        }
Exemplo n.º 18
0
 public DataTriangleConverter(IFileOperation fileOperation, IInputParser inputParser, IOutputFormatter outputFormatter)
 {
     _myOutputFormatter = outputFormatter;
     _myfileOperation   = fileOperation;
     _myInputParser     = inputParser;
 }
Exemplo n.º 19
0
 public FileOperation()
 {
     fileOperation = (IFileOperation)Activator.CreateInstance(fileOperationType);
     fileOperation.SetOperationFlags(FileOperationFlags.FOF_NOCONFIRMMKDIR);
     fileOperation.SetOwnerWindow(SafeNativeMethods.GetActiveWindowHandle());
 }
Exemplo n.º 20
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FileOperation"/> class.
        /// </summary>
        /// <param name="callbackSink">
        /// The callback sink.
        /// </param>
        /// <param name="owner">
        /// The owner.
        /// </param>
        public FileOperation(FileOperationProgressSink callbackSink, IWin32Window owner)
        {
            this.callbackSink = callbackSink;
            this.fileOperation = (IFileOperation)Activator.CreateInstance(FileOperationType);

            this.fileOperation.SetOperationFlags(FileOperationFlags.FOF_NOCONFIRMMKDIR | FileOperationFlags.FOF_SILENT | FileOperationFlags.FOFX_SHOWELEVATIONPROMPT | FileOperationFlags.FOFX_NOCOPYHOOKS | FileOperationFlags.FOFX_REQUIREELEVATION);
            if (this.callbackSink != null)
            {
                this.sinkCookie = this.fileOperation.Advise(this.callbackSink);
            }

            if (owner != null)
            {
                this.fileOperation.SetOwnerWindow((uint)owner.Handle);
            }
        }
Exemplo n.º 21
0
 public BookOperation(IFileOperation fileOperation)
 {
     this.fileOperation = fileOperation;
 }
Exemplo n.º 22
0
 public FileOperation()
 {
     fileOperation = (IFileOperation)Activator.CreateInstance(typeof(CFileOperations));
     fileOperation.SetOperationFlags(FILEOP_FLAGS.FOF_NOCONFIRMMKDIR);
     fileOperation.SetOwnerWindow(SafeNativeMethods.GetActiveWindowHandle());
 }
Exemplo n.º 23
0
 public FileDomainService(IFileOperation fileOperation, IRepository <File> repository)
 {
     this._fileOperation = fileOperation;
     this._repository    = repository;
 }
Exemplo n.º 24
0
 public LoginOperation(IEncryptService encryptService, IFileOperation fileOperation)
 {
     this.encryptService = encryptService;
     this.fileOperation  = fileOperation;
 }
Exemplo n.º 25
0
 public Calculator(IFileOperation fileOperation)
 {
     _fileOperation = fileOperation;
 }
Exemplo n.º 26
0
 public ProxyFileOperation(IFileOperation operation, string layer = "my_layer")
 {
     Operation           = operation;
     SimpleFileOperation = new FileOperation();
     Layer = layer ?? Guid.NewGuid().ToString();
 }
Exemplo n.º 27
0
        /// <summary>
        /// Operation for changing files
        /// </summary>
        /// <returns>Status of normal ending working with file</returns>
        protected bool FileChange()
        {
            IFileOperation file = storage;

            while (true)
            {
                // Get request
                if (!Provider.GetRequest(out RequestData userData))
                {
                    continue;
                }

                if (!CheckSessionID(userData.SessionId))
                {
                    return(false);
                }

                switch ((FileOperation)userData.Operation)
                {
                case FileOperation.Read:
                    SendResponse(file.ReadFile());
                    break;

                case FileOperation.Write:
                    SendResponse(file.WriteToFile(userData.Property));
                    break;

                case FileOperation.Edit:
                    #region Edit
                    var edit = file.ReadFile();
                    SendResponse(edit);

                    if (edit.Code == 0)
                    {
                        // Get confirm request
                        while (!Provider.GetRequest(out userData))
                        {
                        }
                        if (!CheckSessionID(userData.SessionId))
                        {
                            return(false);
                        }

                        // Commit changes
                        if (userData.Operation == 3)
                        {
                            SendResponse(storage.ChangeFile(userData.Property));
                        }
                        else
                        {
                            SendResponse(new ResponseData(0, "Canceled"));
                        }
                    }
                    #endregion
                    break;

                case FileOperation.Exit:
                    SendResponse(file.CloseFile());
                    return(true);

                default:
                    Provider.SendResponse(new ResponseData(SessionID, StatusCode.BadRequest, "Invalid operation"));
                    Logger.LogAll("Invalid operation");
                    break;
                }
            }
        }
Exemplo n.º 28
0
 private void NotifyOperation(EventHandler <FileOperationEventArgs> handler, IFileOperation operation)
 {
     handler?.Invoke(this, new FileOperationEventArgs(operation));
 }
Exemplo n.º 29
0
        static void FileSystemExample()
        {
            /*
             * Let's assume some path and file:
             */
            var path = "C:/Temp/FSTest";
            var file = "test.txt";

            if (Directory.Exists(path))
            {
                Directory.Delete(path, true);
                Directory.CreateDirectory(path);
            }

            /*
             * Let's check that FileOperation works properly
             */
            Console.WriteLine("Firstly we check the FileOperation class");
            FS = new FileOperation();

            Console.WriteLine("\tIs File Removed: {0}", FS.IsRemoved(path, file));
            FS.Create(path, file);
            FS.Append(path, file, new List <string>()
            {
                "Top-Level: Foo", "Top-Level: Bar"
            });
            Console.WriteLine("\tContents of FileOperation FS file:");
            foreach (var line in FS.Read(path, file))
            {
                Console.WriteLine("\t\t{0}", line);
            }
            Console.WriteLine("Press enter to continue:");
            Console.ReadLine();

            /*
             * Now let's check the Proxy on the layer some_layer
             */

            Console.WriteLine("Now let's check the Proxy on the layer some_layer");
            FSProxy = new ProxyFileOperation(new FileOperation(), "some_layer");
            FSProxy.Create(path, file);
            FSProxy.Append(path, file, new List <string>()
            {
                "SOME_LAYER - Yup"
            });
            Console.WriteLine("\tContents of ProxyOperation FS file (some_layer):");
            foreach (var line in FSProxy.Read(path, file))
            {
                Console.WriteLine("\t\t{0}", line);
            }
            Console.WriteLine("Press enter to continue:");
            Console.ReadLine();

            /*
             * Now let's check the Proxy on the layer layer
             */
            Console.WriteLine("Now let's check the Proxy on the layer mindfcuk");
            FSProxy = new ProxyFileOperation(new FileOperation(), "mindfcuk");
            FSProxy.Create(path, file);
            FSProxy.Append(path, file, new List <string>()
            {
                "mindfcuk - ORly?"
            });
            Console.WriteLine("\tContents of ProxyOperation FS file (mindfcuk):");
            foreach (var line in FSProxy.Read(path, file))
            {
                Console.WriteLine("\t\t{0}", line);
            }
            Console.WriteLine("Should we delete the file (1) or not (0)");
            var input = Console.ReadLine();

            if ("1".Equals(input))
            {
                FSProxy.Delete(path, file);
            }

            Console.WriteLine("And now let's delete the contents of file. Is it removed: {0}", FSProxy.IsRemoved(path, file));

            Console.WriteLine("Press enter to continue:");
            Console.ReadLine();

            /*
             * Absurd level
             */
            Console.WriteLine("Absurd level: Proxy of Proxy:");
            FSProxy = new ProxyFileOperation(new ProxyFileOperation(new FileOperation(), "mindfcuk"), "inception");
            FSProxy.Append(path, file, new List <string>()
            {
                "Inception - How is it possible", "Inception - Seriously?"
            });
            Console.WriteLine("\tContents of ProxyProxy FS file (inception)");
            foreach (var line in FSProxy.Read(path, file))
            {
                Console.WriteLine("\t\t{0}", line);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="FileOperation"/> class.
        /// </summary>
        public FileOperation()
        {
            fileOperation = (IFileOperation)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid(NativeAPI.Guids.Shell.FileOperation)));

            Cookies = new System.Collections.ObjectModel.ReadOnlyCollection <uint>(cookies);
        }
Exemplo n.º 31
0
 public void Queue(IFileOperation operation)
 {
     Invoke(parameters: operation);
 }
Exemplo n.º 32
0
 public void Queue(IFileOperation operation, bool toTop)
 {
     Invoke(parameters: new object[] { operation, toTop });
 }
Exemplo n.º 33
0
 public FileOperationEventArgs(IFileOperation operation)
 {
     Operation = operation;
 }