示例#1
0
 private void InitializeTransfer()
 {
     EnableListen = new Boolean();
     EnableListen = true;
     GlobalTransfer = new Transfer();
     GlobalThread = new Thread(new ThreadStart(GlobalTransfer.ListenForPeers));
     GlobalThread.Start();
 }
示例#2
0
        protected void btnDownload_Click(object sender, System.EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            string remoteFile = null;
            string server = null;
            string remotePath = null;
            string fullRemotePath = null;

            for( int i = 0; i < this.lstResults.ListItems.Count; i++)
            {
                if(this.lstResults.ListItems[i].Selected == true )
                {
                    remotePath = this.lstResults.ListItems[i].SubItems[0];
                    remoteFile =  this.lstResults.ListItems[i].Text;
                    fullRemotePath = remotePath + "\\" + remoteFile;
                    server = this.lstResults.ListItems[i].SubItems[3];
                }
            }

            if(server == null)
            {
                MessageBox.Show("Please select a file to be downloaded","ShareBaby", MessageBox.IconExclamation);
                Cursor = Cursors.Default;
                return;
            }

            if(server != this.GlobalIPAddress)
            {
                try
                {
                    OptionsLoader ol = new OptionsLoader();
                    string path = ol.Path;

                    string localFile = path + "\\" + remoteFile; // Name the two files the same, change the paths
                    Transfer trans = new Transfer();
                    trans.DownloadToClient(server, fullRemotePath, localFile);
                    MessageBox.Show("Successfully transferred " + localFile, "Download Complete", MessageBox.IconInformation);
                }
                catch(Exception exc)
                {
                    MessageBox.Show(exc.ToString(), "Error Tranferring File", MessageBox.IconError);
                }
            }
            else
            {
                MessageBox.Show("This is a local file and does not need to be downloaded","ShareBaby", MessageBox.IconExclamation);
            }
            Cursor = Cursors.Default;
        }