Пример #1
0
        void CopyFiles()
        {
            CurrentStatus = 1;
            _block.WaitOne();
            foreach (var item in SourceItemsCollection.Where(c => c.Item3 == 0))
            {
                OldBytes = 0;
                if (this.OPType == OperationType.Copy)
                {
                    if (item.Item3 == 1)
                    {
                        if (!Directory.Exists(item.Item2))
                        {
                            try
                            {
                                Directory.CreateDirectory(item.Item2);
                            }
                            catch (UnauthorizedAccessException)
                            {
                                WindowsAPI.SendMessage(MessageReceiverHandle, WM_FOERROR, IntPtr.Zero, IntPtr.Zero);
                                Environment.Exit(5);
                            }
                        }
                    }
                    else
                    {
                        try
                        {
                            ProcessItems(item.Item1, item.Item2);
                        }
                        catch (Exception)
                        {
                            WindowsAPI.SendMessage(MessageReceiverHandle, WM_FOERROR, IntPtr.Zero, IntPtr.Zero);
                            Environment.Exit(5);
                        }
                    };
                }

                if (this.OPType == OperationType.Move)
                {
                    if (item.Item3 == 0)
                    {
                        try
                        {
                            ProcessItems(item.Item1, item.Item2);
                        }
                        catch (Exception)
                        {
                            WindowsAPI.SendMessage(MessageReceiverHandle, WM_FOERROR, IntPtr.Zero, IntPtr.Zero);
                            Environment.Exit(5);
                        }
                    }

                    foreach (var dir in this.SourceItemsCollection.Select(c => ShellObject.FromParsingName(c.Item1)).ToArray().Where(c => c.IsFolder))
                    {
                        DeleteFolderRecursive(new DirectoryInfo(dir.ParsingName));
                    }
                    GC.WaitForPendingFinalizers();
                    GC.Collect();
                }

                if (this.OPType == OperationType.Delete)
                {
                    foreach (var entry in this.SourceItemsCollection)
                    {
                        _block.WaitOne();
                        try
                        {
                            if (!Directory.Exists(entry.Item1) || (Path.GetExtension(entry.Item1).ToLowerInvariant() == ".zip"))
                            {
                                var itemInfo = new FileInfo(entry.Item1);
                                if (itemInfo.IsReadOnly)
                                {
                                    File.SetAttributes(entry.Item1, FileAttributes.Normal);
                                }
                                if (this.DeleteToRB)
                                {
                                    Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile(entry.Item1, Microsoft.VisualBasic.FileIO.UIOption.OnlyErrorDialogs, Microsoft.VisualBasic.FileIO.RecycleOption.SendToRecycleBin, Microsoft.VisualBasic.FileIO.UICancelOption.DoNothing);
                                }
                                else
                                {
                                    File.Delete(entry.Item1);
                                }

                                byte[] data = System.Text.Encoding.Unicode.GetBytes(String.Format("{0}|{1}|{2}|{3}", 1, 0, totaltransfered, entry.Item1));
                                WindowsAPI.SendStringMessage(MessageReceiverHandle, data, 0, data.Length);
                            }
                            else
                            {
                                if (this.DeleteToRB)
                                {
                                    RecycleBin.SendSilent(entry.Item1);
                                }
                                else
                                {
                                    DeleteAllFilesFromDir(new DirectoryInfo(entry.Item1));
                                    DeleteFolderRecursive(new DirectoryInfo(entry.Item1));
                                }
                            }
                        }
                        catch (Exception)
                        {
                            WindowsAPI.SendMessage(MessageReceiverHandle, WM_FOERROR, IntPtr.Zero, IntPtr.Zero);
                            Environment.Exit(5);
                        }
                    }
                }
            }
        }