Esempio n. 1
0
 private void DownloadPatch(object url)
 {
     ThreadQueue.QueueUserWorkItem(delegate (object p) {
         VGen1 method = null;
         bool isCurrent = false;
         string text = "";
         try
         {
             DataList queryData = DataAccess.GetQueryData("GetGPGNetVersion", new object[0]);
             if (queryData.Count == 1)
             {
                 string str2 = queryData[0][0];
                 if (Assembly.GetExecutingAssembly().GetName().Version.ToString() == str2)
                 {
                     isCurrent = true;
                     this.IsLatestVer = true;
                 }
                 else
                 {
                     DataList list2;
                     string[] strArray = Assembly.GetExecutingAssembly().GetName().Version.ToString().Split(new char[] { '.' });
                     string[] strArray2 = str2.Split(new char[] { '.' });
                     if (((Convert.ToInt32(strArray[0]) > Convert.ToInt32(strArray2[0])) || (Convert.ToInt32(strArray[1]) > Convert.ToInt32(strArray2[1]))) || (Convert.ToInt32(strArray[2]) > Convert.ToInt32(strArray2[2])))
                     {
                         this.IsLatestVer = true;
                         isCurrent = true;
                         list2 = DataAccess.GetQueryData("DowngradeGPGNetPatchURL", new object[] { Assembly.GetExecutingAssembly().GetName().Version.ToString() });
                         if (list2.Count == 1)
                         {
                             DlgMessage.ShowDialog(this, "Warning", "You are being forced to downgrade your version of GPGnet.  This version of GPGnet is not compatible with this server.");
                             text = list2[0][0];
                             isCurrent = false;
                             this.IsLatestVer = false;
                         }
                         else
                         {
                             DlgMessage.Show(this, "Warning", "You are using a pre-release version " + Assembly.GetExecutingAssembly().GetName().Version.ToString() + "  of GPGnet.  This server is expecting version " + str2 + " of GPGnet.  GPGnet may behave unexpectedly.");
                         }
                     }
                     else
                     {
                         list2 = DataAccess.GetQueryData("GetGPGNetPatchURL", new object[] { Assembly.GetExecutingAssembly().GetName().Version.ToString() });
                         if (list2.Count == 1)
                         {
                             text = list2[0][0];
                         }
                     }
                 }
             }
         }
         catch (Exception exception1)
         {
             GPG.Logging.EventLog.WriteLine("GPGnet patching failed.", new object[0]);
             ErrorLog.WriteLine(exception1);
         }
         if (!isCurrent)
         {
             WebClient client = new WebClient();
             int num = Convert.ToInt32(Application.ProductVersion.Split(new char[] { '.' })[2]) + 1;
             string str3 = Application.StartupPath + @"\patch.exe";
             if (text != "")
             {
                 GPG.Logging.EventLog.WriteLine("Patch information", new object[0]);
                 GPG.Logging.EventLog.WriteLine(str3, new object[0]);
                 GPG.Logging.EventLog.WriteLine(text, new object[0]);
                 try
                 {
                     bool flag2 = true;
                     isCurrent = false;
                     flag2 = false;
                     if (method == null)
                     {
                         method = delegate (object objclient) {
                             try
                             {
                                 DlgDownloadProgress progress = new DlgDownloadProgress(Loc.Get("<LOC>GPGnet: Supreme Commander Patch"), objclient as WebClient);
                                 progress.DownloadCancelled += new EventHandler(this.progress_OnCancelDownload);
                                 progress.Show();
                                 this.msQuickButtons.Enabled = false;
                                 this.msMainMenu.Enabled = false;
                                 this.mWelcomePage.CanNavigate = false;
                             }
                             catch (Exception exception)
                             {
                                 isCurrent = true;
                                 ErrorLog.WriteLine(exception);
                             }
                         };
                     }
                     base.Invoke(method, new object[] { client });
                     this.mPatchFileName = str3;
                     client.DownloadFileCompleted += new AsyncCompletedEventHandler(this.client_DownloadFileCompleted);
                     client.DownloadFileAsync(new Uri(text), str3);
                 }
                 catch (Exception exception2)
                 {
                     ErrorLog.WriteLine(exception2);
                     isCurrent = true;
                 }
             }
             else
             {
                 isCurrent = true;
             }
         }
         if (isCurrent)
         {
             this.IsGPGNetPatching = false;
             this.UpdateSupCom();
         }
     }, new object[] { url });
 }
Esempio n. 2
0
 private static void Download(ReplayInfo replay, string location)
 {
     VGen0 method = null;
     WaitCallback callBack = null;
     try
     {
         WebClient client;
         if (Program.MainForm.InvokeRequired)
         {
             if (method == null)
             {
                 method = delegate {
                     Download(replay, location);
                 };
             }
             Program.MainForm.BeginInvoke(method);
         }
         else
         {
             string uriString = ConfigSettings.GetString("BaseReplayURL", "http://gpgnet.gaspowered.com/replays/") + location;
             client = new WebClient();
             string replaysDirectory = Program.Settings.SupcomPrefs.Replays.ReplaysDirectory;
             if (!Directory.Exists(replaysDirectory))
             {
                 Directory.CreateDirectory(replaysDirectory);
             }
             replaysDirectory = replaysDirectory.TrimEnd(new char[] { '\\' }) + @"\" + location.Replace("/", ".");
             if (System.IO.File.Exists(replaysDirectory))
             {
                 ReceieveReplay(replaysDirectory);
             }
             else
             {
                 if (callBack == null)
                 {
                     callBack = delegate (object s) {
                         if (replay != null)
                         {
                             replay.Downloads++;
                         }
                         DataAccess.ExecuteQuery("IncrementReplayDownload", new object[] { location });
                     };
                 }
                 ThreadQueue.QueueUserWorkItem(callBack, new object[0]);
                 DlgDownloadProgress dlg = new DlgDownloadProgress(location, client);
                 dlg.DownloadCancelled += delegate (object s, EventArgs e) {
                     dlg.Client.CancelAsync();
                     client.DownloadFileCompleted -= new AsyncCompletedEventHandler(ReplayInfo.client_DownloadFileCompleted);
                 };
                 dlg.Show();
                 client.DownloadFileCompleted += new AsyncCompletedEventHandler(ReplayInfo.client_DownloadFileCompleted);
                 Guid userToken = Guid.NewGuid();
                 ActiveDownloads[userToken] = replaysDirectory;
                 client.DownloadFileAsync(new Uri(uriString), replaysDirectory + ".gzip", userToken);
             }
         }
     }
     catch (Exception exception)
     {
         ErrorLog.WriteLine(exception);
     }
 }