public void Cache_To_DlodXfer(List<string> cachestuff,string path)
 {
     CacheHandler ch =new CacheHandler();
     ch.setCache("../../CacheDir");
     //DirectoryInfo di = new DirectoryInfo(path);
     foreach (string file in cachestuff)
     {
         FileInfo f = new FileInfo(ch.getCache() +"\\"+file);
         f.CopyTo(path +"\\" + f.Name.Split('-')[0], true);
     }
 }
        private void PopulateCacheListBox()
        {
            try
            {
                CacheHandler ch =new CacheHandler();
                ch.setCache("../../CacheDir");
                string path=ch.getCache();
                DirectoryInfo di = new DirectoryInfo(path);
                FileInfo[] files = di.GetFiles();

                foreach (FileInfo file in files)
                {
                    Dispatcher.Invoke(new Action<FileInfo>(AddCacheItems), new object[] { file });
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
 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);
     }
 }