public bool SaveDownload(IStatusProvider statusProvider)
 {
     WebDownloader downloader = new WebDownloader();
     downloader.OnDownloadCompleted += new AsyncCompletedEventHandler(this.FinishedDownloader);
     downloader.BeginDownloadFile(this.GetDirectURL(), this.GetLocalPatchFile(), true);
     return true;
 }
Beispiel #2
0
 private void UpdateSupCom()
 {
     VGen0 gen = null;
     VGen0 gen2 = null;
     ThreadStart start = null;
     ThreadStart start2 = null;
     if (GameInformation.SelectedGame.GameID == -1)
     {
         this.SetStatus("", new object[0]);
     }
     else if (GameInformation.SelectedGame.CurrentVersion == "NOCHECK")
     {
         this.SetStatus("This game is not being versioned.", 0x2710, new object[0]);
         Thread.Sleep(0xbb8);
         try
         {
             if (gen == null)
             {
                 gen = delegate {
                     this.btnFeedback.Enabled = true;
                     this.btnHostGame.Enabled = true;
                     this.btnJoinGame.Enabled = true;
                     this.EnableGameSelectButtons();
                     this.miGameGroup.Enabled = true;
                 };
             }
             base.BeginInvoke(gen);
         }
         catch (Exception exception)
         {
             ErrorLog.WriteLine(exception);
         }
     }
     else if (!this.IsSupComPatching && (this.SupComPatchThread == null))
     {
         this.mIsSupComPatching = true;
         if ((base.InvokeRequired && !base.Disposing) && !base.IsDisposed)
         {
             if (gen2 == null)
             {
                 gen2 = delegate {
                     this.miGameGroup.Enabled = false;
                     this.btnHostGame.Enabled = false;
                     this.btnJoinGame.Enabled = false;
                     this.btnRankedGame.Enabled = false;
                     this.btnArrangedTeam.Enabled = false;
                     this.btnPlayNow.Enabled = false;
                     this.DisableGameSelectButtons();
                 };
             }
             base.BeginInvoke(gen2);
         }
         else
         {
             this.miGameGroup.Enabled = false;
             this.btnHostGame.Enabled = false;
             this.btnJoinGame.Enabled = false;
             this.btnRankedGame.Enabled = false;
             this.btnArrangedTeam.Enabled = false;
             this.btnPlayNow.Enabled = false;
             this.DisableGameSelectButtons();
         }
         if (this.IsRemoteVersion)
         {
             if (this.LocalGameVersion != this.ServerGameVersion)
             {
                 if (start == null)
                 {
                     start = delegate {
                         WebDownloader downloader = new WebDownloader();
                         downloader.OnDownloadCompleted += new AsyncCompletedEventHandler(this.SmartPatchComplete);
                         string weburl = GameInformation.SelectedGame.PatcherAppURL;
                         downloader.BeginDownloadFile(weburl, this.GetLocalPatchFile(), true);
                     };
                 }
                 this.SupComPatchThread = new Thread(start);
             }
             else
             {
                 this.SetPatchButtonsCompleted();
                 this.SetStatus("", new object[0]);
             }
         }
         else
         {
             if (start2 == null)
             {
                 start2 = delegate {
                     string str;
                     EventHandler handler = null;
                     OGen0 gen3 = null;
                     OGen0 gen4 = null;
                     VGen0 method = null;
                     VGen0 gen6 = null;
                     bool failed = false;
                     try
                     {
                         this.SetStatus("<LOC>Checking for {0} updates...", new object[] { GameInformation.SelectedGame.GameDescription });
                         if (handler == null)
                         {
                             handler = delegate (object s, EventArgs e) {
                                 this.SupComPatchThread = null;
                             };
                         }
                         base.Disposed += handler;
                         Process[] processesByName = Process.GetProcessesByName("patch");
                         if (processesByName.Length > 0)
                         {
                             this.SetStatus("<LOC>Patching {0}...", new object[] { GameInformation.SelectedGame.GameDescription });
                             processesByName[0].WaitForExit();
                         }
                         if (((GameInformation.SelectedGame.GameLocation == null) || (GameInformation.SelectedGame.GameLocation.Length <= 0)) || !System.IO.File.Exists(GameInformation.SelectedGame.GameLocation))
                         {
                         }
                         if (((gen3 == null) && !((bool) base.Invoke(gen3 = delegate {
                             return this.LocateExe("SupremeCommander", false);
                         }))) || !this.IsSupComVersionEnforced)
                         {
                             return;
                         }
                         int num = 0;
                         bool flag = false;
                         int count = -1;
                         int num3 = 0;
                         int num4 = 0;
                         bool flag2 = this.LocalGameVersion != this.ServerGameVersion;
                         try
                         {
                             if (flag2 && (this.ServerGameVersion.ToUpper() == "MULTI"))
                             {
                                 DataList queryDataSafe = DataAccess.GetQueryDataSafe("Get Multi Version", new object[] { GameInformation.SelectedGame.GameID });
                                 foreach (DataRecord record in queryDataSafe)
                                 {
                                     if (record["build_chksum"] == this.LocalGameVersion)
                                     {
                                         flag2 = false;
                                         this.mServerGameVersion = record["build_chksum"];
                                         goto Label_0E15;
                                     }
                                 }
                             }
                         }
                         catch (Exception exception1)
                         {
                             ErrorLog.WriteLine(exception1);
                         }
                     Label_0E15:
                         while (flag2 || ((count < 0) || (num3 < count)))
                         {
                             try
                             {
                                 if (num4 > 4)
                                 {
                                     this.SetStatus("<LOC>An error orrured while trying to patch, please try again later.", new object[0]);
                                     Thread.Sleep(0xfa0);
                                     return;
                                 }
                                 if (num >= 2)
                                 {
                                     this.SetStatus("<LOC>Download failed, aborting update...", new object[0]);
                                     Thread.Sleep(0x7d0);
                                     failed = true;
                                     return;
                                 }
                                 DataList list2 = DataAccess.GetQueryDataSafe("GetVersionPatchURI", new object[] { this.LocalGameVersion });
                                 count = list2.Count;
                                 if (((list2 == null) || (list2.Count < 1)) || (num3 >= list2.Count))
                                 {
                                     if (!this.IsGameCurrent)
                                     {
                                         this.SetStatus("<LOC>{0} appears to be corrupt and/or modified. Please re-install {0}.", new object[] { GameInformation.SelectedGame.GameDescription });
                                         Thread.Sleep(0xfa0);
                                     }
                                     return;
                                 }
                                 foreach (DataRecord record2 in list2)
                                 {
                                     IOException exception2;
                                     VGen0 curgen = null;
                                     VGen0 curgen2 = null;
                                     string uri;
                                     bool flag3 = false;
                                     bool flag4 = false;
                                     flag3 = (record2.InnerHash.ContainsKey("patch_uri") && (record2["patch_uri"] != null)) && (record2["patch_uri"] != "(null)");
                                     flag4 = (record2.InnerHash.ContainsKey("file_uri") && (record2["file_uri"] != null)) && (record2["file_uri"] != "(null)");
                                     string str2 = null;
                                     if (flag3)
                                     {
                                         uri = record2["patch_uri"];
                                         str = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + @"\" + GameInformation.SelectedGame.GameDescription + @"\";
                                         if (Directory.Exists(str))
                                         {
                                             str = str + "patch.exe";
                                         }
                                         else
                                         {
                                             str = Path.GetDirectoryName(GameInformation.SelectedGame.GameLocation) + @"\patch.exe";
                                         }
                                         if ((record2.InnerHash.ContainsKey("patch_check") && (record2["patch_check"] != null)) && (record2["patch_check"] != "(null)"))
                                         {
                                             str2 = record2["patch_check"];
                                         }
                                     }
                                     else if (flag4)
                                     {
                                         uri = record2["file_uri"];
                                         str = Path.GetDirectoryName(GameInformation.SelectedGame.GameLocation) + @"\" + record2["file_path"];
                                         if ((record2.InnerHash.ContainsKey("file_check") && (record2["file_check"] != null)) && (record2["file_check"] != "(null)"))
                                         {
                                             str2 = record2["file_check"];
                                         }
                                     }
                                     else
                                     {
                                         ErrorLog.WriteLine("Invalid patch record for {0} found.", new object[] { GameInformation.SelectedGame.GameDescription });
                                         num3++;
                                         continue;
                                     }
                                     WebClient dlClient = null;
                                     bool flag5 = false;
                                     bool flag6 = true;
                                     if (System.IO.File.Exists(str) && (str2 != null))
                                     {
                                         if (flag3)
                                         {
                                             flag6 = this.CheckSum(str) != str2;
                                         }
                                         else
                                         {
                                             flag6 = this.CheckSum(str) != str2;
                                         }
                                     }
                                     else if (System.IO.File.Exists(str) && (str2 == null))
                                     {
                                         flag6 = false;
                                     }
                                     else if (!(System.IO.File.Exists(str) || (str2 == null)))
                                     {
                                         flag6 = false;
                                     }
                                     else
                                     {
                                         flag6 = true;
                                         if (flag3)
                                         {
                                             try
                                             {
                                                 System.IO.File.Delete(str);
                                             }
                                             catch (Exception exception5)
                                             {
                                                 ErrorLog.WriteLine(exception5);
                                                 this.SetStatus("<LOC>Invalid patch file exists and cannot be deleted. Please restart program.", new object[0]);
                                                 Thread.Sleep(0xbb8);
                                                 return;
                                             }
                                         }
                                     }
                                     DlgDownloadProgress dlg = null;
                                     if (flag6)
                                     {
                                         int lastResponse = Environment.TickCount;
                                         bool finished = false;
                                         dlClient = new WebClient();
                                         bool downloading = true;
                                         if (curgen == null)
                                         {
                                             curgen = delegate
                                             {
                                                 dlg = new DlgDownloadProgress(uri, dlClient);
                                             };
                                         }
                                         base.Invoke(curgen);
                                         dlClient.DownloadProgressChanged += delegate (object s, System.Net.DownloadProgressChangedEventArgs e) {
                                             if ((e.ProgressPercentage == 100) && (e.BytesReceived == e.TotalBytesToReceive))
                                             {
                                                 finished = true;
                                             }
                                             lastResponse = Environment.TickCount;
                                             this.SetStatus("<LOC>Downloading {1} update: {0}%", new object[] { e.ProgressPercentage, GameInformation.SelectedGame.GameDescription });
                                         };
                                         dlClient.DownloadFileCompleted += delegate (object s, AsyncCompletedEventArgs e) {
                                             finished = true;
                                             downloading = false;
                                             lastResponse = Environment.TickCount;
                                         };
                                         if (flag3)
                                         {
                                             try
                                             {
                                                 if (System.IO.File.Exists(str))
                                                 {
                                                     System.IO.File.Delete(str);
                                                 }
                                             }
                                             catch (IOException exception6)
                                             {
                                                 exception2 = exception6;
                                                 ErrorLog.WriteLine(exception2);
                                             }
                                         }
                                         this.SetStatus("<LOC>Downloading {0} update...", new object[] { GameInformation.SelectedGame.GameDescription });
                                         if (curgen2 == null)
                                         {
                                             curgen2 = delegate
                                             {
                                                 dlg.Show();
                                                 dlg.BringToFront();
                                             };
                                         }
                                         base.BeginInvoke(curgen2);
                                         if (!flag)
                                         {
                                             this.ShowPatchMessage();
                                             flag = true;
                                         }
                                         if (flag3)
                                         {
                                             dlClient.DownloadFileAsync(new Uri(uri), str);
                                         }
                                         else
                                         {
                                             dlClient.DownloadFileAsync(new Uri(uri), str + ".exe");
                                         }
                                         lastResponse = Environment.TickCount;
                                         while (downloading)
                                         {
                                             if (!(finished || ((Environment.TickCount - lastResponse) <= 0x7530)))
                                             {
                                                 flag5 = true;
                                                 if (dlClient != null)
                                                 {
                                                     dlClient.CancelAsync();
                                                     dlClient.Dispose();
                                                     dlClient = null;
                                                 }
                                                 break;
                                             }
                                             Thread.Sleep(100);
                                         }
                                     }
                                     else
                                     {
                                         num3++;
                                         continue;
                                     }
                                     base.BeginInvoke((VGen0)delegate {
                                         if ((((dlg != null) && !dlg.Disposing) && !dlg.IsDisposed) && dlg.Visible)
                                         {
                                             try
                                             {
                                                 dlg.Close();
                                                 dlg = null;
                                             }
                                             catch (Exception exception)
                                             {
                                                 ErrorLog.WriteLine(exception);
                                             }
                                         }
                                     });
                                     if (flag5 && (num >= 2))
                                     {
                                         this.SetStatus("<LOC>Download failed, aborting update...", new object[0]);
                                         Thread.Sleep(0x7d0);
                                         return;
                                     }
                                     if (flag5)
                                     {
                                         this.SetStatus("<LOC>Download timed out, retrying...", new object[0]);
                                         if (dlClient != null)
                                         {
                                             dlClient.CancelAsync();
                                             dlClient.Dispose();
                                             dlClient = null;
                                         }
                                         num++;
                                         if (flag3)
                                         {
                                             try
                                             {
                                                 System.IO.File.Delete(str);
                                             }
                                             catch (Exception exception7)
                                             {
                                                 ErrorLog.WriteLine(exception7);
                                             }
                                         }
                                         Thread.Sleep(0x7d0);
                                     }
                                     else
                                     {
                                         bool flag7 = false;
                                         num = 0;
                                         if (flag3 || flag4)
                                         {
                                             while (!flag7 && (num < 2))
                                             {
                                                 this.SetStatus("<LOC>Patching {0}...", new object[] { GameInformation.SelectedGame.GameDescription });
                                                 bool flag8 = false;
                                                 string[] strArray = new string[] { "SupremeCommander", "SupremeCommanderR", "SupremeCommanderD" };
                                                 for (int j = 0; j < strArray.Length; j++)
                                                 {
                                                     Process[] processArray2 = Process.GetProcessesByName(strArray[j]);
                                                     if (processArray2.Length > 0)
                                                     {
                                                         if (!flag8)
                                                         {
                                                         }
                                                         if ((gen4 != null) || (((DialogResult) base.Invoke(gen4 = delegate {
                                                             return new DlgYesNo(this, GameInformation.SelectedGame.GameDescription, "<LOC>" + GameInformation.SelectedGame.GameDescription + " is currently running and must be closed for patching to continue. OK to close " + GameInformation.SelectedGame.GameDescription + "?").ShowDialog(this);
                                                         })) == DialogResult.Yes))
                                                         {
                                                             flag8 = true;
                                                             foreach (Process process in processArray2)
                                                             {
                                                                 process.Kill();
                                                             }
                                                         }
                                                         else
                                                         {
                                                             this.SetStatus("<LOC>" + GameInformation.SelectedGame.GameDescription + " failed to patch!", new object[0]);
                                                             Thread.Sleep(0x7d0);
                                                             return;
                                                         }
                                                     }
                                                 }
                                                 if (flag4)
                                                 {
                                                     str = str + ".exe";
                                                 }
                                                 ProcessStartInfo startInfo = new ProcessStartInfo(str);
                                                 if (flag3)
                                                 {
                                                     startInfo.WorkingDirectory = new FileInfo(str).DirectoryName;
                                                 }
                                                 Process process2 = Process.Start(startInfo);
                                                 if (method == null)
                                                 {
                                                     method = delegate {
                                                         base.Show();
                                                         base.BringToFront();
                                                     };
                                                 }
                                                 base.Invoke(method);
                                                 process2.WaitForExit();
                                                 GameInformation.CheckMissingPaths();
                                                 int exitCode = process2.ExitCode;
                                                 if (exitCode == 0)
                                                 {
                                                     ErrorLog.WriteLine("Patching of SupCom succeeded via code {0}", new object[] { exitCode });
                                                     try
                                                     {
                                                         if (System.IO.File.Exists(str))
                                                         {
                                                             System.IO.File.Delete(str);
                                                         }
                                                     }
                                                     catch (IOException exception8)
                                                     {
                                                         exception2 = exception8;
                                                         ErrorLog.WriteLine(exception2);
                                                     }
                                                     flag7 = true;
                                                     this.SetStatus("<LOC>" + GameInformation.SelectedGame.GameDescription + " patching complete.", new object[0]);
                                                     Thread.Sleep(0x7d0);
                                                 }
                                                 else
                                                 {
                                                     ErrorLog.WriteLine("Patching of SupCom failed via error code {0}", new object[] { exitCode });
                                                     num++;
                                                     if (num > 1)
                                                     {
                                                         this.SetStatus("<LOC>" + GameInformation.SelectedGame.GameDescription + " failed to patch!", new object[0]);
                                                         try
                                                         {
                                                             if (System.IO.File.Exists(str))
                                                             {
                                                                 System.IO.File.Delete(str);
                                                             }
                                                         }
                                                         catch (IOException exception9)
                                                         {
                                                             exception2 = exception9;
                                                             ErrorLog.WriteLine(exception2);
                                                         }
                                                         Thread.Sleep(0x7d0);
                                                         return;
                                                     }
                                                     this.SetStatus("<LOC>Patch failed, retrying...", new object[0]);
                                                     Thread.Sleep(0x7d0);
                                                 }
                                             }
                                         }
                                         else
                                         {
                                             try
                                             {
                                                 if (System.IO.File.Exists(str))
                                                 {
                                                     System.IO.File.Replace(str + ".dl", str, str + ".back");
                                                 }
                                                 else
                                                 {
                                                     System.IO.File.Move(str + ".dl", str);
                                                 }
                                             }
                                             catch (Exception exception4)
                                             {
                                                 ErrorLog.WriteLine(exception4);
                                                 this.SetStatus("<LOC>Error updating file: {0}, ensure it is not in use or read-only.", new object[] { Path.GetFileName(str) });
                                                 Thread.Sleep(0xfa0);
                                                 if (System.IO.File.Exists(str + ".back"))
                                                 {
                                                     System.IO.File.Move(str + ".back", str);
                                                 }
                                             }
                                             finally
                                             {
                                                 if (System.IO.File.Exists(str + ".dl"))
                                                 {
                                                     System.IO.File.Delete(str + ".dl");
                                                 }
                                                 if (System.IO.File.Exists(str + ".back"))
                                                 {
                                                     System.IO.File.Delete(str + ".back");
                                                 }
                                             }
                                             num3++;
                                             break;
                                         }
                                     }
                                 }
                                 continue;
                             }
                             catch (Exception exception11)
                             {
                                 ErrorLog.WriteLine(exception11);
                                 num++;
                                 this.SetStatus("<LOC>Patch failed, retrying...", new object[0]);
                                 Thread.Sleep(0x7d0);
                             }
                             finally
                             {
                                 num4++;
                             }
                         }
                     }
                     catch (Exception exception12)
                     {
                         ErrorLog.WriteLine(exception12);
                     }
                     finally
                     {
                         this.SupComPatchThread = null;
                         GPG.Logging.EventLog.WriteLine("<LOC>Supreme Commander patching complete.", new object[0]);
                         Thread.Sleep(0x7d0);
                         if ((GameInformation.SelectedGame.GameLocation != null) && (GameInformation.SelectedGame.GameLocation.Length > 0))
                         {
                             str = Path.GetDirectoryName(GameInformation.SelectedGame.GameLocation) + @"\patch.exe";
                             if (System.IO.File.Exists(str))
                             {
                                 try
                                 {
                                     System.IO.File.Delete(str);
                                 }
                                 catch (Exception exception13)
                                 {
                                     ErrorLog.WriteLine(exception13);
                                 }
                             }
                         }
                         if ((base.InvokeRequired && !base.Disposing) && !base.IsDisposed)
                         {
                             try
                             {
                                 if (gen6 == null)
                                 {
                                     gen6 = delegate {
                                         if (!failed)
                                         {
                                             this.btnFeedback.Enabled = true;
                                             this.btnHostGame.Enabled = true;
                                             this.btnJoinGame.Enabled = true;
                                             this.btnRankedGame.Enabled = true;
                                             this.btnArrangedTeam.Enabled = true;
                                             this.btnPlayNow.Enabled = true;
                                             this.btnViewRankings.Enabled = true;
                                             this.EnableGameSelectButtons();
                                             this.miGameGroup.Enabled = true;
                                             this.miRankings.Enabled = true;
                                             this.btnRankedGame.Image = SkinManager.GetImage("nav-ranked_game.png");
                                             this.btnRankedGame.ToolTipText = Loc.Get("<LOC>Play Ranked Game");
                                             this.btnArrangedTeam.Image = SkinManager.GetImage("nav-ranked_team.png");
                                             this.btnArrangedTeam.ToolTipText = Loc.Get("<LOC>Play Arranged Team Game");
                                         }
                                     };
                                 }
                                 base.BeginInvoke(gen6);
                             }
                             catch (Exception exception14)
                             {
                                 ErrorLog.WriteLine(exception14);
                             }
                         }
                         this.mIsSupComPatching = false;
                         this.SetStatus("", new object[0]);
                     }
                 };
             }
             this.SupComPatchThread = new Thread(start2);
         }
         if (this.SupComPatchThread != null)
         {
             this.SupComPatchThread.IsBackground = true;
             this.SupComPatchThread.Start();
         }
     }
 }