示例#1
0
        private static DirectoryAttributes AddDirectoriesRecursive(DirectoryAttributes folder, string current, ref int fCount)
        {
            //current = Path.Combine(current, folder.RelativePath);
            foreach (var subd in Directory.GetDirectories(folder.FullPath))
            {
                try
                {
                    DirectoryAttributes subda = new DirectoryAttributes(new DirectoryInfo(subd));
                    string p = Path.Combine(current, subda.Name);
                    subda.RelativePath = p;
                    folder.SubFolders.Add(subda);

                    foreach (var subf in Directory.GetFiles(subd))
                    {
                        FileAttributes a = new FileAttributes(new FileInfo(subf));
                        fCount++;
                        a.RelativePath = Path.Combine(p, a.FileName);
                        subda.Files.Add(a);
                    }

                    AddDirectoriesRecursive(subda, Path.Combine(current, subda.Name), ref fCount);
                }
                catch (Exception ex)
                {
                    ISLogger.Write("An error occurred while reading directory {0}. {1}", subd, ex.Message);
                }
            }
            return(folder);
        }
示例#2
0
        private static ClipboardVirtualFileData ReadFileDrop(string[] data)
        {
            string[]            files = data;
            DirectoryAttributes root  = new DirectoryAttributes("", new List <FileAttributes>(), new List <DirectoryAttributes>(), "");
            int fCount = 0;

            foreach (var file in files)
            {
                try
                {
                    if (string.IsNullOrWhiteSpace(file))
                    {
                        continue;
                    }

                    System.IO.FileAttributes fa = System.IO.File.GetAttributes(file);
                    if (fa.HasFlag(System.IO.FileAttributes.Directory))
                    {
                        DirectoryAttributes di = new DirectoryAttributes(new DirectoryInfo(file));
                        root.SubFolders.Add(di);

                        foreach (var baseFile in Directory.GetFiles(file))
                        {
                            FileAttributes df = new FileAttributes(new FileInfo(baseFile));
                            df.RelativePath = Path.Combine(di.Name, df.FileName);
                            di.Files.Add(df);
                        }
                    }
                    else
                    {
                        root.Files.Add(new FileAttributes(new FileInfo(file)));
                    }
                }
                catch (Exception ex)
                {
                    ISLogger.Write("An error occurred while reading attributes for {0}. File not copied: {1}", file, ex.Message);
                    ISLogger.Write(ex.StackTrace);
                }
            }

            foreach (var folder in root.SubFolders)
            {
                AddDirectoriesRecursive(folder, folder.Name, ref fCount);
            }

            return(new ClipboardVirtualFileData(root));
        }
示例#3
0
        private static ClipboardVirtualFileData ReadFileDrop(System.Windows.Forms.IDataObject data)
        {
            string[]            files = (string[])data.GetData(DataFormats.FileDrop);
            DirectoryAttributes root  = new DirectoryAttributes("", new List <FileAttributes>(), new List <DirectoryAttributes>(), "");
            int fCount = 0;

            foreach (var file in files)
            {
                try
                {
                    System.IO.FileAttributes fa = System.IO.File.GetAttributes(file);
                    if (fa.HasFlag(System.IO.FileAttributes.Directory))
                    {
                        DirectoryAttributes di = new DirectoryAttributes(new DirectoryInfo(file));
                        root.SubFolders.Add(di);

                        foreach (var baseFile in Directory.GetFiles(file))
                        {
                            FileAttributes df = new FileAttributes(new FileInfo(baseFile));
                            df.RelativePath = Path.Combine(di.Name, df.FileName);
                            di.Files.Add(df);
                        }
                    }
                    else
                    {
                        root.Files.Add(new FileAttributes(new FileInfo(file)));
                    }
                }
                catch (ClipboardTranslationException ex)
                {
                    ISLogger.Write("An error occurred while reading attributes for {0}. File not copied\n{1}", file, ex.Message);
                }
            }

            foreach (var folder in root.SubFolders)
            {
                AddDirectoriesRecursive(folder, folder.Name, ref fCount);
            }

            return(new ClipboardVirtualFileData(root));
        }
示例#4
0
        private static DirectoryAttributes AddDirectoriesRecursive(DirectoryAttributes folder, string current, ref int fCount)
        {
            //current = Path.Combine(current, folder.RelativePath);
            foreach (var subd in Directory.GetDirectories(folder.FullPath))
            {
                try
                {
                    //Todo - this is a cheap fix to stop massive folders with thousands of files being copied
                    //File transfer needs to be changed to allow better support for a large ammount of files
                    if (fCount > Settings.MaxFileTransferFiles)
                    {
                        throw new ClipboardTranslationException("File count limit reached - " + fCount);
                    }

                    DirectoryAttributes subda = new DirectoryAttributes(new DirectoryInfo(subd));
                    string p = Path.Combine(current, subda.Name);
                    subda.RelativePath = p;
                    folder.SubFolders.Add(subda);

                    foreach (var subf in Directory.GetFiles(subd))
                    {
                        FileAttributes a = new FileAttributes(new FileInfo(subf));
                        fCount++;
                        a.RelativePath = Path.Combine(p, a.FileName);
                        subda.Files.Add(a);
                    }

                    AddDirectoriesRecursive(subda, Path.Combine(current, subda.Name), ref fCount);
                }
                catch (UnauthorizedAccessException ex)
                {
                    ISLogger.Write("An error occurred while reading directory {0}.\n{1}", subd, ex.Message);
                }
            }
            return(folder);
        }