static void DownloadExtensionIndex(DownloadProgressChangedEventHandler downloadProgressChanged, AsyncCompletedEventHandler downloadFileCompleted)
 {
   DownloadFile dlg = null;
   try
   {
     tempUpdateIndex = Path.GetTempFileName();
     dlg = new DownloadFile();
     if (downloadProgressChanged != null) dlg.Client.DownloadProgressChanged += downloadProgressChanged;
     if (downloadFileCompleted != null) dlg.Client.DownloadFileCompleted += downloadFileCompleted;
     dlg.Client.DownloadFileCompleted += UpdateIndex_DownloadFileCompleted;
     dlg.StartDownload(UpdateIndexUrl, tempUpdateIndex);
   }
   catch (Exception ex)
   {
     MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
   }
   finally
   {
     if (downloadProgressChanged != null) dlg.Client.DownloadProgressChanged -= downloadProgressChanged;
     if (downloadFileCompleted != null) dlg.Client.DownloadFileCompleted -=downloadFileCompleted;
     dlg.Client.DownloadFileCompleted -= UpdateIndex_DownloadFileCompleted;
     File.Delete(tempUpdateIndex);
   }
 }
 public static string GetPackageLocation(PackageClass packageClass, DownloadProgressChangedEventHandler downloadProgressChanged, AsyncCompletedEventHandler downloadFileCompleted)
 {
   string newPackageLoacation = packageClass.GeneralInfo.Location;
   if (!File.Exists(newPackageLoacation))
   {
     newPackageLoacation = packageClass.LocationFolder + packageClass.GeneralInfo.Id + ".mpe2";
     if (!File.Exists(newPackageLoacation))
     {
       if (!string.IsNullOrEmpty(packageClass.GeneralInfo.OnlineLocation))
       {
         DownloadFile dlg = null;
         try
         {
           newPackageLoacation = Path.GetTempFileName();
           dlg = new DownloadFile();
           if (downloadProgressChanged != null) dlg.Client.DownloadProgressChanged += downloadProgressChanged;
           if (downloadFileCompleted != null) dlg.Client.DownloadFileCompleted += downloadFileCompleted;
           dlg.StartDownload(packageClass.GeneralInfo.OnlineLocation, newPackageLoacation);
         }
         catch (Exception ex)
         {
           MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         finally
         {
           if (downloadProgressChanged != null) dlg.Client.DownloadProgressChanged -= downloadProgressChanged;
           if (downloadFileCompleted != null) dlg.Client.DownloadFileCompleted -= downloadFileCompleted;
         }
       }
     }
   }
   return newPackageLoacation;
 }