private static byte[] GetWebShellNewData(string extension) { string apiUrl = AppConfig.RequestUseGithub ? AppConfig.GithubShellNewApi : AppConfig.GiteeShellNewApi; using (UAWebClient client = new UAWebClient()) { XmlDocument doc = client.GetWebJsonToXml(apiUrl); if (doc == null) { return(null); } foreach (XmlNode node in doc.FirstChild.ChildNodes) { XmlNode nameXN = node.SelectSingleNode("name"); string str = Path.GetExtension(nameXN.InnerText); if (string.Equals(str, extension, StringComparison.OrdinalIgnoreCase)) { try { string dirUrl = AppConfig.RequestUseGithub ? AppConfig.GithubShellNewRawDir : AppConfig.GiteeShellNewRawDir; string fileUrl = $"{dirUrl}/{nameXN.InnerText}"; return(client.DownloadData(fileUrl)); } catch { return(null); } } } return(null); } }
public void ShowLanguageDialog() { using (UAWebClient client = new UAWebClient()) { string apiUrl = AppConfig.RequestUseGithub ? AppConfig.GithubLangsApi : AppConfig.GiteeLangsApi; XmlDocument doc = client.GetWebJsonToXml(apiUrl); if (doc == null) { AppMessageBox.Show(AppString.Message.WebDataReadFailed); return; } XmlNodeList list = doc.FirstChild.ChildNodes; string[] langs = new string[list.Count]; for (int i = 0; i < list.Count; i++) { XmlNode nameXN = list.Item(i).SelectSingleNode("name"); langs[i] = Path.GetFileNameWithoutExtension(nameXN.InnerText); } if (langs.Length == 0) { AppMessageBox.Show(AppString.Message.WebDataReadFailed); return; } using (SelectDialog dlg = new SelectDialog()) { dlg.Items = langs; dlg.Title = AppString.Dialog.DownloadLanguages; string lang = CultureInfo.CurrentUICulture.Name; if (dlg.Items.Contains(lang)) { dlg.Selected = lang; } else { dlg.SelectedIndex = 0; } if (dlg.ShowDialog() == DialogResult.OK) { string fileName = $"{dlg.Selected}.ini"; string filePath = $@"{AppConfig.LangsDir}\{fileName}"; string dirUrl = AppConfig.RequestUseGithub ? AppConfig.GithubLangsRawDir : AppConfig.GiteeLangsRawDir; string fileUrl = $"{dirUrl}/{fileName}"; bool flag = client.WebStringToFile(filePath, fileUrl); if (!flag) { if (AppMessageBox.Show(AppString.Message.WebDataReadFailed + "\r\n ● " + fileName + "\r\n" + AppString.Message.OpenWebUrl, MessageBoxButtons.YesNo) == DialogResult.Yes) { ExternalProgram.OpenWebUrl(fileUrl); } } else { this.LoadLanguages(); string language = new IniWriter(filePath).GetValue("General", "Language"); if (language == "") { language = dlg.Selected; } cmbLanguages.Text = language; ChangeLanguage(); } } } } }
/// <summary>更新程序</summary> /// <param name="isManual">是否为手动点击更新</param> private static void UpdateApp(bool isManual) { using (UAWebClient client = new UAWebClient()) { string url = AppConfig.RequestUseGithub ? AppConfig.GithubLatestApi : AppConfig.GiteeLatestApi; XmlDocument doc = client.GetWebJsonToXml(url); if (doc == null) { if (isManual) { if (AppMessageBox.Show(AppString.Message.WebDataReadFailed + "\r\n" + AppString.Message.OpenWebUrl, MessageBoxButtons.OKCancel) != DialogResult.OK) { return; } url = AppConfig.RequestUseGithub ? AppConfig.GithubLatest : AppConfig.GiteeReleases; ExternalProgram.OpenWebUrl(url); } return; } XmlNode root = doc.FirstChild; XmlNode tagNameXN = root.SelectSingleNode("tag_name"); Version webVer = new Version(tagNameXN.InnerText); Version appVer = new Version(Application.ProductVersion); #if DEBUG appVer = new Version(0, 0, 0, 0);//测试用 #endif if (appVer >= webVer) { if (isManual) { AppMessageBox.Show(AppString.Message.VersionIsLatest, MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { XmlNode bodyXN = root.SelectSingleNode("body"); string info = AppString.Message.UpdateInfo.Replace("%v1", appVer.ToString()).Replace("%v2", webVer.ToString()); info += "\r\n\r\n" + MachinedInfo(bodyXN.InnerText); if (MessageBox.Show(info, AppString.General.AppName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { string netVer = Environment.Version > new Version(4, 0) ? "4.0" : "3.5"; XmlNode assetsXN = root.SelectSingleNode("assets"); foreach (XmlNode itemXN in assetsXN.SelectNodes("item")) { XmlNode nameXN = itemXN.SelectSingleNode("name"); if (nameXN != null && nameXN.InnerText.Contains(netVer)) { XmlNode urlXN = itemXN.SelectSingleNode("browser_download_url"); using (DownloadDialog dlg = new DownloadDialog()) { dlg.Url = urlXN?.InnerText; dlg.FilePath = $@"{AppConfig.AppDataDir}\{webVer}.exe"; dlg.Text = AppString.General.AppName; if (dlg.ShowDialog() == DialogResult.OK) { AppMessageBox.Show(AppString.Message.UpdateSucceeded, MessageBoxButtons.OK, MessageBoxIcon.Information); SingleInstance.Restart(null, dlg.FilePath); } } } } } } } }