Esempio n. 1
0
        private void _recursive_resolve(Aga.Controls.Tree.TreeNode node, List <string> dirs)
        {
            DirectoryKey dk = node.Tag as DirectoryKey;

            if (dk != null)
            {
                dirs.Add(dk.Name);
                _recursive_resolve(node.Parent, dirs);
            }
        }
Esempio n. 2
0
 private void ApplyPriority_DirectoryTree(DirectoryKey dk, int p)
 {
     foreach (object ob in dk.Values)
     {
         if (ob is FileInfo)
         {
             (ob as FileInfo).ChangePriority(p);
         }
         else if (ob is DirectoryKey)
         {
             this.ApplyPriority_DirectoryTree(ob as DirectoryKey, p);
         }
     }
 }
Esempio n. 3
0
        public void TorrentCommands_OpenFile(object sender, ExecutedRoutedEventArgs e)
        {
            Aga.Controls.Tree.TreeNode item = files_tree.SelectedItem as Aga.Controls.Tree.TreeNode;

            if (item != null)
            {
                FileInfo fi = item.Tag as FileInfo;
                if (fi != null)
                {
                    System.IO.FileInfo fifo = new System.IO.FileInfo(fi.FullPath);

                    if (fifo.Exists)
                    {
                        string[] dangerous_file_types = { ".exe", ".scr", ".pif", ".js", ".com", ".bat", ".cmd", ".vbs", ".hta" };

                        if (dangerous_file_types.Contains(fifo.Extension.ToLower()))
                        {
                            if (MessageBox.Show(string.Format(@"Opening files downloaded from the Internet may result in harm to your computer or your data."
                                                              + " Are you sure that you want to open {0}?", fifo.Name),
                                                "Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
                            {
                                Process.Start(fifo.FullName);
                            }
                        }
                        else
                        {
                            Process.Start(fifo.FullName);
                        }
                    }
                    else
                    {
                        MessageBox.Show("File doesn't exist", "Error");
                    }
                }
                else
                {
                    DirectoryKey dk = item.Tag as DirectoryKey;
                    if (dk != null)
                    {
                        string partial_path = this.GetDirectoryKeyRelativePath(item);
                        string full_path    = System.IO.Path.Combine(dk.OwnerTorrent.SavePath, partial_path);
                        System.IO.Directory.CreateDirectory(full_path);
                        Process.Start("explorer.exe", string.Format("\"{0}\"", full_path));
                    }
                }
            }
        }
Esempio n. 4
0
        public void TorrentCommands_OpenFileLocation(object sender, RoutedEventArgs e)
        {
            Aga.Controls.Tree.TreeNode item = files_tree.SelectedItem as Aga.Controls.Tree.TreeNode;

            if (item != null)
            {
                FileInfo fi = item.Tag as FileInfo;
                if (fi != null)
                {
                    if (System.IO.File.Exists(fi.FullPath))
                    {
                        Process.Start("explorer.exe", string.Format("/select, \"{0}\"", fi.FullPath));
                    }
                    else
                    {
                        string directory = System.IO.Path.GetDirectoryName(fi.FullPath);
                        System.IO.Directory.CreateDirectory(directory);
                        Process.Start("explorer.exe", string.Format("\"{0}\"", directory));
                    }
                    return;
                }

                //we must have hit a directory then
                //if it's a directory residing inside the torrent folder (root folder), we simply
                //open the torrent save dir
                DirectoryKey dk = item.Tag as DirectoryKey;
                if (dk != null)
                {
                    if (item.Parent != null && item.Parent.Tag != null)
                    {
                        //it's a subdirectory
                        string partial_path = GetDirectoryKeyRelativePath(item.Parent);
                        string full_path    = System.IO.Path.Combine(dk.OwnerTorrent.SavePath, partial_path);
                        System.IO.Directory.CreateDirectory(full_path);
                        Process.Start("explorer.exe", string.Format("/select, \"{0}\"", full_path));
                    }
                    else
                    {
                        //it's a root dir
                        System.IO.Directory.CreateDirectory(dk.OwnerTorrent.SavePath);
                        Process.Start("explorer.exe", string.Format("/select, \"{0}\"", dk.OwnerTorrent.SavePath));
                    }
                }
            }
        }
Esempio n. 5
0
        private void PopulateFileList()
        {
            if (this.FilesTree == null)
            {
                DirectoryKey base_dir = new DirectoryKey("/", this);

                for (int i = 0, j = this.Info.NumFiles; i < j; i++)
                {
                    using (FileEntry file = this.Info.FileAt(i))
                    {
                        DirectoryKey.ProcessFile(file.Path, base_dir, this, file, i);
                    }
                }

                this.FilesTree = base_dir;
                UpdateList("FilesTree");
                this.files_progresses = new long[this.FileInfoList.Count];
            }
        }
Esempio n. 6
0
        /// <summary>
        /// No use outside of TorrentInfo.PopulateFileList()
        /// </summary>
        /// <param name="branch"></param>
        /// <param name="trunk"></param>
        public static void ProcessFile(string branch, DirectoryKey trunk, TorrentInfo owner, Ragnar.FileEntry f, int index)
        {
            string[] parts = branch.Split('\\');
            if (parts.Length == 1)
            {
                //((FileList)trunk[DirectoryKey.FILE_MARKER]).Add(new FileInfo(owner, f));
                trunk.Add(f.Path, new FileInfo(owner, f, index));
            }
            else
            {
                string node  = parts[0];
                string other = branch.Substring(node.Length + 1);

                if (!trunk.ContainsKey(node))
                {
                    trunk[node] = new DirectoryKey(node, owner);
                }
                ProcessFile(other, (DirectoryKey)trunk[node], owner, f, index);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// No use outside of TorrentInfo.PopulateFileList()
        /// </summary>
        /// <param name="branch"></param>
        /// <param name="trunk"></param>
        public static void ProcessFile(string branch, DirectoryKey trunk, TorrentInfo owner, Ragnar.FileEntry f, int index)
        {
            string[] parts = branch.Split('\\');
            if (parts.Length == 1)
            {
                //((FileList)trunk[DirectoryKey.FILE_MARKER]).Add(new FileInfo(owner, f));
                trunk.Add(f.Path, new FileInfo(owner, f, index));
            }
            else
            {
                string node = parts[0];
                string other = branch.Substring(node.Length + 1);

                if (!trunk.ContainsKey(node))
                {
                    trunk[node] = new DirectoryKey(node, owner);
                }
                ProcessFile(other, (DirectoryKey)trunk[node], owner, f, index);
            }
        }
Esempio n. 8
0
        private void TorrentCommands_ChangeFilePriority(object sender, ExecutedRoutedEventArgs e)
        {
            if (files_tree.SelectedItems.Count > 0)
            {
                int priority = Convert.ToInt32(e.Parameter);

                foreach (Aga.Controls.Tree.TreeNode item in files_tree.SelectedItems)
                {
                    if (item.Tag is FileInfo)
                    {
                        FileInfo fi = item.Tag as FileInfo;
                        fi.ChangePriority(priority);
                    }
                    else if (item.Tag is DirectoryKey)
                    {
                        DirectoryKey dk = item.Tag as DirectoryKey;
                        ApplyPriority_DirectoryTree(dk, priority);
                    }
                }
            }
        }