protected override void DoWork()
 {
     using (new ThreadExecutionStateLock(true, false))
     {
         using (VirtualSearchFolder folder = new VirtualSearchFolder(this.FContent, null, this.FSearchOptions))
         {
             folder.OnChanged += new EventHandler<VirtualItemChangedEventArgs>(this.SearchFolderChanged);
             folder.Completed += new AsyncCompletedEventHandler(this.SearchFolderCompleted);
             foreach (IVirtualItem item in folder.GetContent())
             {
                 base.CheckSuspendingPending();
                 if (base.CancellationPending)
                 {
                     return;
                 }
                 if (this.OnBeforeSetAttributes != null)
                 {
                     this.OnBeforeSetAttributes(this, new VirtualItemEventArgs(item));
                 }
                 this.SetItemAttributes(item);
                 if (this.OnAfterSetAttributes != null)
                 {
                     this.OnAfterSetAttributes(this, new VirtualItemEventArgs(item));
                 }
                 this.FProcessedCount++;
                 this.OnProgress();
             }
         }
     }
 }
Пример #2
0
 protected override void DoWork()
 {
     try
     {
         using (new ThreadExecutionStateLock(true, false))
         {
             using (VirtualSearchFolder folder = new VirtualSearchFolder(this.FContent, this.FFilter, SearchFolderOptions.SkipUnmatchedSubfolders | SearchFolderOptions.ProcessSubfolders))
             {
                 int num;
                 ProcessItemHandler handler = null;
                 folder.OnChanged += new EventHandler<VirtualItemChangedEventArgs>(this.SearchFolderChanged);
                 folder.Completed += new AsyncCompletedEventHandler(this.SearchFolderCompleted);
                 Dictionary<ISequenceContext, ISequenceProcessor> dictionary = new Dictionary<ISequenceContext, ISequenceProcessor>();
                 Dictionary<IVirtualFolder, IVirtualFolder> FolderMap = new Dictionary<IVirtualFolder, IVirtualFolder>();
                 List<IVirtualFolder> list = new List<IVirtualFolder>();
                 List<IVirtualFolder> list2 = new List<IVirtualFolder>();
                 List<IVirtualItem> SkippedItems = new List<IVirtualItem>();
                 Stack<Tuple<IVirtualFolder, IChangeVirtualItem>> SetTimeFolders = null;
                 if (this.CheckOption(CopyWorkerOptions.CopyFolderTime | CopyWorkerOptions.CopyItemTime))
                 {
                     SetTimeFolders = new Stack<Tuple<IVirtualFolder, IChangeVirtualItem>>();
                 }
                 foreach (IVirtualItem item in folder.GetContent())
                 {
                     if (base.CheckCancellationPending())
                     {
                         return;
                     }
                     bool flag = false;
                     foreach (IVirtualFolder folder2 in list2)
                     {
                         if (folder2.IsChild(item))
                         {
                             flag = true;
                             if (!(item is IVirtualFolder))
                             {
                                 lock (this.FSnapshotLock)
                                 {
                                     this.FSkippedCount++;
                                     if (item.IsPropertyAvailable(3))
                                     {
                                         this.FTotalProcessed.AddProcessedSize(Convert.ToInt64(item[3]));
                                     }
                                 }
                             }
                             break;
                         }
                     }
                     if (flag)
                     {
                         this.RaiseProgress();
                         continue;
                     }
                     IVirtualFolder other = this.FDest;
                     IVirtualFolder folder4 = item as IVirtualFolder;
                     if (folder4 != null)
                     {
                         num = list.Count - 1;
                         while (num >= 0)
                         {
                             if (list[num].IsChild(folder4))
                             {
                                 other = FolderMap[list[num]];
                                 break;
                             }
                             num--;
                         }
                         if (this.CheckOption(CopyWorkerOptions.SkipEmptyFolders))
                         {
                             other = null;
                         }
                         if (other != null)
                         {
                             if (folder4.Equals(other) || folder4.IsChild(other))
                             {
                                 throw new WarningException(string.Format(Resources.sCannotCopyFolderToItself, folder4.FullName));
                             }
                             if (this.CheckOption(CopyWorkerOptions.DeleteSource) && (this.FFilter == null))
                             {
                                 IChangeVirtualItem item2 = folder4 as IChangeVirtualItem;
                                 if ((item2 != null) && item2.CanMoveTo(other))
                                 {
                                     folder.AsyncWaitHandle.WaitOne();
                                     IVirtualFolder folder5 = (IVirtualFolder) this.MoveItem(item2, other);
                                     if (folder5 != null)
                                     {
                                         list2.Add(folder5);
                                         continue;
                                     }
                                 }
                             }
                             other = this.CreateNewFolder(other, folder4);
                             if (other == null)
                             {
                                 list2.Add(folder4);
                                 continue;
                             }
                             IChangeVirtualItem item3 = other as IChangeVirtualItem;
                             if ((item3 != null) && (SetTimeFolders != null))
                             {
                                 SetTimeFolders.Push(Tuple.Create<IVirtualFolder, IChangeVirtualItem>(folder4, item3));
                             }
                         }
                         list.Add(folder4);
                         FolderMap.Add(folder4, other);
                     }
                     else
                     {
                         ISequenceableItem sequenceableItem = item as ISequenceableItem;
                         if ((sequenceableItem == null) && (item is ISequenceable))
                         {
                             sequenceableItem = ((ISequenceable) item).SequenceableItem;
                         }
                         if (sequenceableItem != null)
                         {
                             ISequenceContext sequenceContext = sequenceableItem.SequenceContext;
                             if (sequenceContext != null)
                             {
                                 ISequenceProcessor processor;
                                 if (!dictionary.TryGetValue(sequenceContext, out processor))
                                 {
                                     processor = sequenceContext.CreateProcessor(SequenseProcessorType.Extract);
                                     dictionary.Add(sequenceContext, processor);
                                 }
                                 processor.Add(sequenceableItem, item);
                                 continue;
                             }
                         }
                         if ((item.Parent != null) && FolderMap.ContainsKey(item.Parent))
                         {
                             other = this.GetDestFolder(item.Parent, FolderMap, SetTimeFolders);
                         }
                         if (other != null)
                         {
                             this.CopyItem(item, other, null, SkippedItems);
                             this.RaiseProgress();
                         }
                     }
                 }
                 if (dictionary.Count > 0)
                 {
                     foreach (ISequenceProcessor processor in dictionary.Values)
                     {
                         if (base.CheckCancellationPending())
                         {
                             return;
                         }
                         try
                         {
                             ISetOwnerWindow window = processor as ISetOwnerWindow;
                             if (window != null)
                             {
                                 window.Owner = this.Owner;
                             }
                             if (handler == null)
                             {
                                 handler = delegate (ProcessItemEventArgs e) {
                                     if (!this.CheckCancellationPending())
                                     {
                                         IVirtualItem sourceItem = (IVirtualItem) e.UserState;
                                         IVirtualFolder destFolder = this.FDest;
                                         if (FolderMap.ContainsKey(sourceItem.Parent))
                                         {
                                             destFolder = this.GetDestFolder(sourceItem.Parent, FolderMap, SetTimeFolders);
                                         }
                                         this.CopyItem(sourceItem, destFolder, (IGetStream) e, SkippedItems);
                                         this.RaiseProgress();
                                     }
                                     e.Cancel = this.CancellationPending;
                                 };
                             }
                             processor.Process(handler);
                         }
                         catch (AbortException)
                         {
                             base.CancelAsync();
                         }
                     }
                 }
                 if (SetTimeFolders != null)
                 {
                     while (SetTimeFolders.Count > 0)
                     {
                         if (base.CheckCancellationPending())
                         {
                             return;
                         }
                         Tuple<IVirtualFolder, IChangeVirtualItem> tuple = SetTimeFolders.Pop();
                         this.SetOutFileAttributes(tuple.Item1, tuple.Item2, false, true);
                     }
                 }
                 if (this.CheckOption(CopyWorkerOptions.DeleteSource))
                 {
                     for (num = list.Count - 1; num >= 0; num--)
                     {
                         if (base.CheckCancellationPending())
                         {
                             return;
                         }
                         bool flag2 = this.CheckOption(CopyWorkerOptions.SkipEmptyFolders) && (FolderMap[list[num]] == null);
                         foreach (IVirtualItem item5 in SkippedItems)
                         {
                             if (list[num].IsChild(item5))
                             {
                                 flag2 = true;
                                 break;
                             }
                         }
                         if (!flag2 && !this.DeleteItem(list[num]))
                         {
                             SkippedItems.Add(list[num]);
                         }
                     }
                 }
             }
         }
     }
     finally
     {
         if (base.CancellationPending && (this.SearchError != null))
         {
             throw new ApplicationException(string.Format(Resources.sErrorPopulateCopyItems, this.SearchError.Message), this.SearchError);
         }
     }
 }
 protected override void DoWork()
 {
     using (new ThreadExecutionStateLock(true, false))
     {
         using (VirtualSearchFolder folder = new VirtualSearchFolder(this.FContent, null, SearchFolderOptions.SkipReparsePoints | SearchFolderOptions.ProcessSubfolders))
         {
             IVirtualFolder current;
             folder.OnChanged += new EventHandler<VirtualItemChangedEventArgs>(this.SearchFolderChanged);
             folder.Completed += new AsyncCompletedEventHandler(this.SearchFolderCompleted);
             Dictionary<ISequenceContext, ISequenceProcessor> dictionary = new Dictionary<ISequenceContext, ISequenceProcessor>();
             Stack<IVirtualFolder> stack = new Stack<IVirtualFolder>();
             List<IVirtualFolder> list = new List<IVirtualFolder>();
             List<IVirtualItem> list2 = new List<IVirtualItem>();
             foreach (IVirtualItem item in folder.GetContent())
             {
                 ISequenceableItem sequenceableItem;
                 base.CheckSuspendingPending();
                 if (base.CancellationPending)
                 {
                     return;
                 }
                 bool flag = false;
                 using (List<IVirtualFolder>.Enumerator enumerator2 = list.GetEnumerator())
                 {
                     while (enumerator2.MoveNext())
                     {
                         current = enumerator2.Current;
                         if (current.IsChild(item))
                         {
                             flag = true;
                             goto Label_00DF;
                         }
                     }
                 }
             Label_00DF:
                 sequenceableItem = null;
                 if (flag)
                 {
                     goto Label_01ED;
                 }
                 IVirtualFolder folder3 = item as IVirtualFolder;
                 sequenceableItem = item as ISequenceableItem;
                 if ((sequenceableItem == null) && (item is ISequenceable))
                 {
                     sequenceableItem = ((ISequenceable) item).SequenceableItem;
                 }
                 DialogResult result = this.BeforeDelete(item);
                 if (result != DialogResult.Cancel)
                 {
                     if (result != DialogResult.No)
                     {
                         goto Label_0174;
                     }
                     if (folder3 != null)
                     {
                         list.Add(folder3);
                     }
                     else
                     {
                         list2.Add(item);
                     }
                     flag = true;
                     goto Label_01ED;
                 }
                 base.CancelAsync();
                 return;
             Label_0174:
                 if ((sequenceableItem == null) && (folder3 != null))
                 {
                     IChangeVirtualItem item3 = folder3 as IChangeVirtualItem;
                     if ((this.FSendToBin && (item3 != null)) && item3.CanSendToBin)
                     {
                         this.DeleteItem(item, this.FSendToBin);
                         list.Add(folder3);
                     }
                     else if (!(folder3 is ArchiveFolder))
                     {
                         stack.Push(folder3);
                     }
                     continue;
                 }
             Label_01ED:
                 if (!flag)
                 {
                     if (sequenceableItem != null)
                     {
                         ISequenceContext sequenceContext = sequenceableItem.SequenceContext;
                         if (sequenceContext != null)
                         {
                             ISequenceProcessor processor;
                             if (!dictionary.TryGetValue(sequenceContext, out processor))
                             {
                                 processor = sequenceContext.CreateProcessor(SequenseProcessorType.Delete);
                                 if (processor != null)
                                 {
                                     dictionary.Add(sequenceContext, processor);
                                 }
                             }
                             if (processor != null)
                             {
                                 processor.Add(sequenceableItem, item);
                                 continue;
                             }
                         }
                     }
                     if (!this.DeleteItem(item, this.FSendToBin))
                     {
                         list2.Add(item);
                     }
                 }
                 this.FProcessedItems++;
                 if (!flag)
                 {
                     this.OnProgress();
                 }
             }
             if (dictionary.Count > 0)
             {
                 foreach (ISequenceProcessor processor in dictionary.Values)
                 {
                     base.CheckSuspendingPending();
                     if (base.CancellationPending)
                     {
                         return;
                     }
                     this.ProcessDelete(processor);
                     this.OnProgress();
                 }
             }
             while (stack.Count > 0)
             {
                 base.CheckSuspendingPending();
                 if (base.CancellationPending)
                 {
                     return;
                 }
                 bool flag2 = false;
                 current = stack.Pop();
                 foreach (IVirtualItem item4 in list2)
                 {
                     if (current.IsChild(item4))
                     {
                         flag2 = true;
                         break;
                     }
                 }
                 if (!flag2 && !this.DeleteItem(current, false))
                 {
                     list2.Add(current);
                 }
                 this.FProcessedItems++;
                 if (!flag2)
                 {
                     this.OnProgress();
                 }
             }
         }
     }
 }