Exemplo n.º 1
0
 /// <summary>
 /// Visual representation of a <see cref="TreeEntry"/>.
 /// </summary>
 public FilesystemItem(Crawler crawler, TreeEntry entry) : base()
 {
     this.crawler = crawler;
     Header       = entry;
     if (entry.IsDirectory)
     {
         Items.Add(new FilesystemItem(null, new TreeEntry()
         {
             Name = "Loading..."
         }));
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Download an FTP entry to a local path.
 /// </summary>
 /// <param name="entry">Remote file entry</param>
 /// <param name="outputPath">Full output path and file name</param>
 void ManualDownload(TreeEntry entry, string outputPath)
 {
     if (File.Exists(outputPath) && new FileInfo(outputPath).Length == entry.Size)
     {
         return; // Skip already downloaded files
     }
     downloader = new FileDownload(entry.RequestURI, outputPath, credentials)
     {
         reporter = DownloadProgress
     };
     downloading = entry.Name;
     downloader.Download();
     taskEngine.UpdateStatus(string.Format("Downloaded {0}.", downloading));
 }
Exemplo n.º 3
0
        /// <summary>
        /// Get the contents of a folder in this filesystem.
        /// </summary>
        public override List <TreeEntry> ListFolder(TreeEntry folder = null)
        {
            List <TreeEntry> result = new List <TreeEntry>();

            if (folder != null)
            {
                string path = folder.URI;
                if (!path.EndsWith('\\'))
                {
                    path += '\\';
                }
                string[] folders;
                try {
                    folders = Directory.GetDirectories(path);
                } catch (UnauthorizedAccessException e) {
                    return(new List <TreeEntry>(new TreeEntry[1] {
                        new TreeEntry()
                        {
                            Name = e.Message
                        }
                    }));
                }
                for (int i = 0; i < folders.Length; ++i)
                {
                    result.Add(new TreeEntry()
                    {
                        IsDirectory     = true,
                        Name            = Path.GetFileName(folders[i]),
                        ParentDirectory = path
                    });
                }
            }
            else
            {
                string[] drives = Directory.GetLogicalDrives();
                for (int i = 0; i < drives.Length; ++i)
                {
                    result.Add(new TreeEntry()
                    {
                        IsDirectory     = true,
                        Name            = drives[i],
                        ParentDirectory = string.Empty
                    });
                }
            }
            return(result);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Callback when the user expands an entry, creates entries for all contained files of folders.
        /// </summary>
        protected override void OnExpanded(RoutedEventArgs e)
        {
            TreeEntry treeEntry = (TreeEntry)((TreeViewItem)e.OriginalSource).Header;

            if (!treeEntry.IsDirectory)
            {
                return;
            }
            Items.Clear();
            List <TreeEntry> result = crawler.ListFolder(treeEntry);

            foreach (TreeEntry entry in result)
            {
                Items.Add(new FilesystemItem(crawler, entry));
            }
            base.OnExpanded(e);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Download the selected file when double clicked.
        /// </summary>
        protected override void OnMouseDoubleClick(MouseButtonEventArgs e)
        {
            if (SelectedItem == null)
            {
                return;
            }
            TreeEntry entry = SelectedEntry, targetParent = localFilesystem.SelectedEntry;

            if (targetParent == null)
            {
                MessageBox.Show("Please select the output folder on the local filesystem browser, then retry this download.");
                return;
            }
            if (!entry.IsDirectory)
            {
                cancel = false;
                taskEngine.Run(() => ManualDownload(entry, string.Format("{0}\\{1}", targetParent.URI, downloading = entry.Name)));
            }
            base.OnMouseDoubleClick(e);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Download all files from the server last modified after the given date.
        /// </summary>
        public void DownloadAllAfter(DateTime after)
        {
            TreeEntry output = localFilesystem.SelectedEntry;

            if (output == null)
            {
                MessageBox.Show("Please select the output folder on the local filesystem browser, then retry this download.");
                return;
            }
            cancel = false;
            ManualDownloadRecursive(null, string.Format(output.URI + '\\'), after);
            if (!cancel)
            {
                taskEngine.UpdateProgressBar(1);
                taskEngine.UpdateStatus("Latest files downloaded.");
            }
            else
            {
                taskEngine.UpdateStatus("Process cancelled.");
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// Get the contents of a folder in this filesystem.
 /// </summary>
 public abstract List <TreeEntry> ListFolder(TreeEntry folder = null);