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(); } } }
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 }); }
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); } }