private void button1_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if(listBox1.SelectedIndex>=0)
         {
             CacheHandler ch = new CacheHandler();
             ch.setCache("../../CacheDir");
             string packagedata=listBox1.SelectedItem.ToString();
             string [] package=packagedata.Split('-');
             string []fname=package[package.Length-2].Split('\t');
             string filename = fname[fname.Length - 1];
             string ver=package[package.Length-1];
             string xmlname = filename + ".xml-" + ver;
             string dpath;
             filename += "-" + ver;
             string[] result = client.CreateDownloadList(xmlname, filename);
             List<string> duplicate = new List<string>();
             duplicate.AddRange(result);
             string[] res = ch.ScanCache(result);
             if (res != null)
             {
                 result = res;
             }
             FileTransfer ft = new FileTransfer();
             System.Windows.Forms.FolderBrowserDialog fd = new System.Windows.Forms.FolderBrowserDialog();
             if (fd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                 dpath = fd.SelectedPath;
             else
                 dpath = ".";
             for (int i = 0; i < result.Length; i++)
             {
                 ft.DownloadPackages(result[i], ch.getCache(), client);
             }
             ft.Cache_To_DlodXfer(duplicate, dpath);
             listBox4.Items.Clear();
             PopulateCacheListBox();
             MessageBox.Show("Downloaded Files Successfully");
             listBox1.SelectedIndex = -1;
             DownloadResults(duplicate, res);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string packagedata=listBox1.SelectedItem.ToString();
                string [] package=packagedata.Split('-');
                string []fname=package[package.Length-2].Split('\t');
                string filename = fname[fname.Length - 1];
                string ver=package[package.Length-1];
                string xmlname = filename + ".xml-" + ver;
                string dpath;
                filename += "-" + ver;
                string[] result = client.CreateDownloadList(xmlname, filename);
                FileTransfer ft = new FileTransfer();
                System.Windows.Forms.FolderBrowserDialog fd = new System.Windows.Forms.FolderBrowserDialog();
                if (fd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    dpath = fd.SelectedPath;
                else
                    dpath = ".";
                for (int i = 0; i < result.Length; i++)
                {
                    ft.DownloadPackages(result[i],dpath,client);
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }