Exemplo n.º 1
0
 private void filesView_MouseDoubleClick(object sender, MouseEventArgs e)
 {
     if (!connected)
     {
         return;
     }
     if (filesView.SelectedItems.Count > 0)
     {
         if (filesView.SelectedItems[0].Text == "..")
         {
             filesView.Items.Clear();
             currentPath = currentPath.TrimEnd('/');
             currentPath = currentPath.Substring(0, currentPath.LastIndexOf('/'));
             if (currentPath == "")
             {
                 currentPath = "/";
             }
             p.controlConnection.send(new Model.Commands.GetFileListing(currentPath));
             return;
         }
         Model.Commands.FSListing tag = (Model.Commands.FSListing)filesView.SelectedItems[0].Tag;
         if (tag.isFolder)
         {
             filesView.Items.Clear();
             if (currentPath == "/")
             {
                 currentPath += tag.name;
             }
             else
             {
                 currentPath += "/" + tag.name;
             }
             p.controlConnection.send(new Model.Commands.GetFileListing(currentPath));
         }
         else
         {
             string s;
             if (currentPath == "/")
             {
                 s = "/" + tag.name;
             }
             else
             {
                 s = currentPath + "/" + tag.name;
             }
             p.downloadElement(s, tag);
         }
     }
 }
Exemplo n.º 2
0
 private void downloadToolStripMenuItem_Click(object sender, EventArgs e)
 {
     foreach (ListViewItem i in filesView.SelectedItems)
     {
         Model.Commands.FSListing tag = (Model.Commands.FSListing)i.Tag;
         string s;
         if (currentPath == "/")
         {
             s = "/" + tag.name;
         }
         else
         {
             s = currentPath + "/" + tag.name;
         }
         p.downloadElement(s, tag);
     }
 }
Exemplo n.º 3
0
        public void downloadElement(string s, Model.Commands.FSListing tag)
        {
            bool useUDT = false;

            Model.Transfer t;
            lock (transfers)
            {
                if (!transfers.ContainsKey(s))
                {
                    t              = new Model.Transfer();
                    t.thePeer      = this;
                    transfers[s]   = t;
                    t.originalPath = s;
                    t.path         = s;
                    t.username     = username;
                    t.userId       = id;
                    t.filename     = tag.name;
                    t.download     = true;
                    t.size         = tag.size;
                    t.completed    = 0;
                    if (dataConnection is Model.LoopbackOutgoingConnection)
                    {
                        t.protocol = "Loopback";
                    }
                    else
                    if (dataConnection is Model.ReliableOutgoingConnection)
                    {
                        t.protocol = "TCP";
                    }
                    else
                    {
                        t.protocol = "UDT";
                    }

                    transfers[t.path] = t;
                    lock (Model.Transfer.transfers)
                        Model.Transfer.transfers.Add(t);
                }
                else
                {
                    t = transfers[s];
                }
            }
            System.Threading.Thread t2 = new System.Threading.Thread(delegate()
            {
                long startingByte   = 0;
                string downloadPath = Model.Peer.downloadFilePath(s);
                if (System.IO.File.Exists(downloadPath + ".incomplete"))
                {
                    startingByte   = new System.IO.FileInfo(downloadPath + ".incomplete").Length;
                    t.completed    = (ulong)startingByte;
                    t.startingByte = t.completed;
                }
                if (startingByte >= (long)tag.size) //we already have the file
                {
                    transfers.Remove(t.path);
                    lock (Model.Transfer.transfers)
                        Model.Transfer.transfers.Remove(t);
                    return;
                }
                Model.Commands.Command c;
                if (tag.isFolder)
                {
                    c = new Model.Commands.RequestFolderContents {
                        path = s
                    };
                }
                else
                {
                    c = new Model.Commands.RequestChunks()
                    {
                        allChunks = true, path = s, startingByte = startingByte
                    };
                }
                t.con = dataConnection;
                dataConnection.send(c);
            });
            t2.IsBackground = true;
            t2.Name         = "Download request thread";
            t2.Start();
        }