public void DeleteSelectedFiles(Boolean isRecycling) { var handle = this.Handle; var view = this; var thread = new Thread(() => { var sink = new FOperationProgressSink(view); var fo = new IIFileOperation(sink, handle, isRecycling); foreach (var item in this.SelectedItems) { fo.DeleteItem(item); this.BeginInvoke(new MethodInvoker(() => { this._IIListView.SetItemState(item.ItemIndex, LVIF.LVIF_STATE, LVIS.LVIS_SELECTED, 0); })); } fo.PerformOperations(); if (isRecycling) { this.RaiseRecycleBinUpdated(); } }); thread.SetApartmentState(ApartmentState.STA); thread.Start(); }
public void RenameShellItem(IShellItem item, String newName, Boolean isAddFileExtension, String extension = "") { var handle = this.Handle; var sink = new FOperationProgressSink(this); var fo = new IIFileOperation(sink, handle, false); fo.RenameItem(item, isAddFileExtension ? newName + extension : newName); fo.PerformOperations(); if (fo.GetAnyOperationAborted()) { this._IsCanceledOperation = true; } }
public void PasteAvailableFiles() { var handle = this.Handle; var view = this; var thread = new Thread(() => { var dataObject = F.Clipboard.GetDataObject(); var dropEffect = dataObject.ToDropEffect(); if (dataObject != null && dataObject.GetDataPresent("Shell IDList Array")) { var shellItemArray = dataObject.ToShellItemArray(); var items = shellItemArray.ToArray(); try { var sink = new FOperationProgressSink(view); var controlItem = FileSystemListItem.InitializeWithIShellItem(this.LVHandle, items.First()).Parent; var fo = new IIFileOperation(sink, handle, true, controlItem.Equals(this.CurrentFolder)); if (dropEffect == System.Windows.DragDropEffects.Copy) { fo.CopyItems(shellItemArray, this.CurrentFolder); } else { fo.MoveItems(shellItemArray, this.CurrentFolder); } fo.PerformOperations(); Marshal.ReleaseComObject(shellItemArray); } catch (SecurityException) { throw; } } else if (dataObject != null && dataObject.GetDataPresent("FileDrop")) { var items = ((String[])dataObject.GetData("FileDrop")).Select(s => ShellItem.ToShellParsingName(s).ComInterface).ToArray(); try { var sink = new FOperationProgressSink(view); var controlItem = FileSystemListItem.InitializeWithIShellItem(this.LVHandle, items.First()).Parent; var fo = new IIFileOperation(sink, handle, true, controlItem.Equals(this.CurrentFolder)); foreach (var item in items) { if (dropEffect == System.Windows.DragDropEffects.Copy) fo.CopyItem(item, this.CurrentFolder); else fo.MoveItem(item, this.CurrentFolder, null); } fo.PerformOperations(); } catch (SecurityException) { throw; } } this.LargeImageList.SupressThumbnailGeneration(false); }); thread.SetApartmentState(ApartmentState.STA); thread.Start(); Shell32.SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1); }