internal static void checkForUpdate(object sender, EventArgs e) { try { var client = new WebClientWithTimeout(); Uri StringToUri = new Uri("http://launcher.soapboxrace.world/checkUpdate.php?version=" + Application.ProductVersion); client.CancelAsync(); client.DownloadStringAsync(StringToUri); client.DownloadStringCompleted += (sender2, e2) => { try { CheckVersion json = JsonConvert.DeserializeObject <CheckVersion>(e2.Result); if (json.update.info == true) { IniFile SettingFile = new IniFile("Settings.ini"); if (SettingFile.Read("IgnoreUpdateVersion") != json.github_build) { new UpdatePopup(json.github_build).Show(); } /*DialogResult reply = MessageBox.Show("An update is available. Do you wanna download it?\nYour version: " + Application.ProductVersion + "\nUpdated version: " + json.github_build, "GameLauncher", MessageBoxButtons.YesNo, MessageBoxIcon.Information); * if(reply == DialogResult.Yes) { * Process.Start(@"GL_Update.exe", Process.GetCurrentProcess().Id.ToString()); * }*/ } else { try { if (((Form)sender).Name == "mainScreen") { } } catch { MessageBox.Show("Your launcher is up-to-date"); } } } catch { try { if (((Form)sender).Name == "mainScreen") { } } catch { MessageBox.Show("Failed to check for update"); } } }; } catch { MessageBox.Show("Failed to check for update"); } }
internal static void checkForUpdate(object sender, EventArgs e) { try { var client = new WebClientWithTimeout(); Uri StringToUri = new Uri("http://nfsw.metonator.ct8.pl/checkUpdate.php?version=" + Application.ProductVersion); client.CancelAsync(); client.DownloadStringAsync(StringToUri); client.DownloadStringCompleted += (sender2, e2) => { try { CheckVersion json = JsonConvert.DeserializeObject <CheckVersion>(e2.Result); if (json.update.info == true) { DialogResult reply = MessageBox.Show("An update is available. Do you wanna download it?\nYour version: " + Application.ProductVersion + "\nUpdated version: " + json.github_build, "GameLauncher", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (reply == DialogResult.Yes) { WebClientWithTimeout myWebClient = new WebClientWithTimeout(); myWebClient.DownloadFile(json.update.download, "tempname.zip"); //Time to unzip it Process.Start(@"GameLauncherUpdater.exe", Process.GetCurrentProcess().Id.ToString()); } } else { try { if (((Form)sender).Name == "mainScreen") { } } catch { MessageBox.Show("Your launcher is up-to-date"); } } } catch { try { if (((Form)sender).Name == "mainScreen") { } } catch { MessageBox.Show("Failed to check for update"); } } }; } catch { MessageBox.Show("Failed to check for update"); } }
private XmlDocument GetIndexFile(string url, bool useCache) { XmlDocument result; try { if (useCache && Downloader.mIndexCached != null) { result = Downloader.mIndexCached; } else { try { WebClientWithTimeout webClient = new WebClientWithTimeout(); webClient.DownloadDataCompleted += new DownloadDataCompletedEventHandler(this.Downloader_DownloadFileCompleted); string tempFileName = Path.GetTempFileName(); webClient.DownloadFileAsync(new Uri(url), tempFileName); while (webClient.IsBusy) { if (Downloader.mStopFlag) { webClient.CancelAsync(); result = null; return(result); } Thread.Sleep(100); } XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(tempFileName); Downloader.mIndexCached = xmlDocument; result = xmlDocument; } catch { result = null; } } } catch (Exception ex) { MessageBox.Show("GetIndexFile Exception: " + ex.ToString()); result = null; } return(result); }
internal static void checkForUpdate(object sender, EventArgs e) { try { var client = new WebClientWithTimeout(); Uri StringToUri = new Uri("http://launcher.soapboxrace.world/checkUpdate.php?version=" + Application.ProductVersion); client.CancelAsync(); client.DownloadStringAsync(StringToUri); client.DownloadStringCompleted += (sender2, e2) => { try { CheckVersion json = JsonConvert.DeserializeObject <CheckVersion>(e2.Result); if (json.update.info == true) { IniFile SettingFile = new IniFile("Settings.ini"); if (SettingFile.Read("IgnoreUpdateVersion") != json.github_build) { TaskDialog dia = new TaskDialog(); dia.Caption = "Update"; dia.InstructionText = "An update is available!"; dia.DetailsExpanded = true; dia.Icon = TaskDialogStandardIcon.Information; dia.DetailsCollapsedLabel = "Show Changelog"; dia.Text = "An update is available. Do you want to download it?\nYour version: " + Application.ProductVersion + "\nUpdated version: " + json.github_build; dia.DetailsExpandedText = new WebClientWithTimeout().DownloadString("https://launcher.soapboxrace.world/changelog/text.php"); dia.ExpansionMode = TaskDialogExpandedDetailsLocation.ExpandFooter; TaskDialogCommandLink update = new TaskDialogCommandLink("update", "Yes", "Launcher will be updated to " + json.github_build + "."); TaskDialogCommandLink cancel = new TaskDialogCommandLink("cancel", "No", "Launcher will ask for update on next launch."); TaskDialogCommandLink skipupdate = new TaskDialogCommandLink("skipupdate", "Ignore", "This update will be skipped. A new prompt will apear as soon as a newer update is available."); update.UseElevationIcon = true; skipupdate.Click += (sender3, e3) => { SettingFile.Write("IgnoreUpdateVersion", json.github_build); dia.Close(); }; cancel.Click += (sender3, e3) => { dia.Close(); }; update.Click += (sender3, e3) => { if (File.Exists("GL_Update.exe")) { Process.Start(@"GL_Update.exe", Process.GetCurrentProcess().Id.ToString()); } else { Process.Start(@"https://github.com/SoapboxRaceWorld/GameLauncher_NFSW/releases/latest"); } dia.Close(); }; dia.Controls.Add(update); dia.Controls.Add(cancel); dia.Controls.Add(skipupdate); dia.Show(); //new UpdatePopup(json.github_build).Show(); } } else { try { if (((Form)sender).Name == "mainScreen") { } } catch { MessageBox.Show("Your launcher is up-to-date"); } } } catch { try { if (((Form)sender).Name == "mainScreen") { } } catch { MessageBox.Show("Failed to check for update!"); } } }; } catch { MessageBox.Show("Failed to check for update!"); } }