public static async Task <bool> UpgradeHlae() { try { LatestRelease release = await GetLastReleaseObject(); if (release?.Assets != null && release.Assets.Count > 0) { string archivePath = AppSettings.GetLocalAppDataPath() + Path.DirectorySeparatorChar + "hlae.zip"; string downloadUrl = release.Assets[0].BrowserDownloadUrl; string version = release.TagName.Remove(0, 1); bool downloaded = await Download(downloadUrl, archivePath); if (downloaded) { bool extracted = await ExtractArchive(archivePath); if (extracted) { // create a file containing the version installed to check update later File.WriteAllText(GetHlaeVersionFilePath(), version); return(true); } } } } catch (Exception e) { Logger.Instance.Log(e); return(false); } return(false); }
/// <summary> /// 为用户界面组装一条更新信息 /// </summary> private StringBuilder BuildUpdateTipInfo(LatestRelease release) { var infoBuilder = new StringBuilder(); if (release == null) { return(infoBuilder); } try { infoBuilder.AppendLine($"项目:{release.Name}"); infoBuilder.AppendLine($"版本:{release.TagName}"); infoBuilder.AppendLine($"日期:{release.PublishedAt}"); } catch (Exception e) { OnUpdateStatusChanged(new UpdateStatusChangedEventArgs(UpdateStatus.Error, $"获取更新信息错误。\r\n{e.Message}")); } infoBuilder.AppendLine("更新记录:").AppendLine($"{release.Body}"); if (release.Assets != null) { infoBuilder.AppendLine("------"); foreach (var item in release.Assets) { var size = item.Size / 1024; infoBuilder.AppendLine($"File:{item.Name} ({item.DownloadCount}) Size:{size}Kb"); } } return(infoBuilder); }
#pragma warning restore 649 public static LatestRelease CreateFromJSON(string json) { LatestRelease latestRelease = JsonUtility.FromJson <LatestRelease>(json); latestRelease.version = new Version(latestRelease.tag_name); latestRelease.publishedDateTime = DateTime.Parse(latestRelease.published_at); string changelog = latestRelease.body; latestRelease.body = null; changelog = Regex.Replace(changelog, @"(?<!(\r\n){2}) \*.*\*{2}(.*)\*{2}", "\n<size=13>$2</size>"); changelog = Regex.Replace(changelog, @"(\r\n){2} \*.*\*{2}(.*)\*{2}", "\n\n<size=13>$2</size>"); changelog = new Regex(@"(#+)\s?(.*)\b").Replace( changelog, match => string.Format( "<size={0}>{1}</size>", 30 - match.Groups[1].Value.Length * 6, match.Groups[2].Value ) ); changelog = changelog.Replace(" *", "*"); // Each char gets turned into two triangles and the mesh vertices limit is 2^16. // Let's use another 100 to be on the safe side. const int textLengthLimit = 65536 / 4 - 100; latestRelease.changelogPages = new List <string>((int)Mathf.Ceil(changelog.Length / (float)textLengthLimit)); while (true) { if (changelog.Length > textLengthLimit) { int startIndex = Math.Min(changelog.Length, textLengthLimit); int lastIndexOf = changelog.LastIndexOf("\n", startIndex, StringComparison.Ordinal); if (lastIndexOf == -1) { lastIndexOf = startIndex; } latestRelease.changelogPages.Add(changelog.Substring(0, lastIndexOf)); changelog = changelog.Substring(lastIndexOf).TrimStart('\n', '\r'); } else { latestRelease.changelogPages.Add(changelog); break; } } return(latestRelease); }
#pragma warning restore 649 public static LatestRelease CreateFromJSON(string json) { LatestRelease latestRelease = JsonUtility.FromJson <LatestRelease>(json); latestRelease.version = new Version(latestRelease.tag_name); latestRelease.publishedDateTime = DateTime.Parse(latestRelease.published_at); latestRelease.body = latestRelease.body.Trim(); latestRelease.body = Regex.Replace(latestRelease.body, @"(.*\*{2}.*\*{2}\n)", "\n$1"); return(latestRelease); }
public static async Task <bool> IsUpdateAvailable() { try { LatestRelease release = await GetLastReleaseObject(); string version = release.TagName.Remove(0, 1); return(new Version(version) > new Version(GetHlaeVersion())); } catch (Exception e) { Logger.Instance.Log(e); return(false); } }
private bool CheckLatestRelease() { var newVer = LatestRelease.CheckNewVersion("RyuaNerin", "FFChatBot"); if (newVer != null) { this.Invoke(new Func <string, DialogResult>(MessageBox.Show), "새 버전이 업데이트 되었습니다."); Process.Start(new ProcessStartInfo { UseShellExecute = true, FileName = string.Format("\"{0}\"", newVer) }).Dispose(); return(false); } return(true); }
/// <summary> /// 从指定的github账户获取指定的项目的最后更新信息 /// </summary> /// <param name="owner">指定的github账户</param> /// <param name="projectName">指定的项目</param> /// <param name="latestRelease">最后更新信息</param> /// <param name="errorMessage">如果更新失败的异常信息</param> /// <returns>获取是否成功</returns> public static bool TryGetLatestRelease(string owner, string projectName, out LatestRelease latestRelease, out string errorMessage) { latestRelease = null; errorMessage = string.Empty; try { var rand = Guid.NewGuid().ToString("N").Substring(0, 4); var userAgent = $"nknife-app-updater-{rand}"; var msg = string.Empty; //交换信息。 var isRunsNormally = true; //程序是否正常运行,没有发生异常。 Task.Factory.StartNew(async() => { try { var client = new GitHubClient(new ProductHeaderValue(userAgent)); var releases = await client.Repository.Release.GetAll(owner, projectName); _latestRelease = LatestRelease.Mapped(releases[0]); } catch (Exception e) { isRunsNormally = false; msg = $"{e.Message}\r\n------\r\n{e.InnerException}"; } finally { _visited = true; } }); while (!_visited) { Thread.Sleep(10); } latestRelease = _latestRelease; errorMessage = msg; return(isRunsNormally); } catch (Exception e) { errorMessage = e.Message; return(false); } }
/// <summary> /// Checks for a new version of the application and prompts the user to update if a new version is available /// </summary> /// <returns></returns> public async Task CheckForUpdatesAsync() { _log.Debug("Checking for updates"); OnCheckingForUpdates?.Invoke(this, new()); string json = await _http.GetStringAsync(URL); _latestRelease = JsonSerializer.Deserialize <LatestRelease>(json); var latestVersion = new Version(_latestRelease.tag_name.Replace("v", "")); var compare = Common.Constants.Version.AsDotNetVersion().CompareTo(latestVersion); if (compare < 0) { OnUpdateAvailable?.Invoke(this, new(latestVersion)); } else { OnUpToDate?.Invoke(this, new()); } }
private static async Task <string> GetNewReleaseDownloadUrl() { using (var httpClient = new HttpClient()) { try { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; httpClient.DefaultRequestHeaders.Add("User-Agent", "csgo-demos-manager"); string url = "https://api.github.com/repos/akiver/csgo-demos-manager/releases/latest"; HttpResponseMessage response = await httpClient.GetAsync(url); string json = await response.Content.ReadAsStringAsync(); LatestRelease release = await Task.Factory.StartNew(() => JsonConvert.DeserializeObject <LatestRelease>(json)); string version = release.TagName; if (version.StartsWith("v")) { version = version.Substring(1, version.Length - 1); } Version lastVersion = new Version(version); var resultCompare = AppSettings.APP_VERSION.CompareTo(lastVersion); if (resultCompare < 0 && release.Assets.Count > 0) { string releaseUrl = release.Assets[0].BrowserDownloadUrl; return(releaseUrl); } return(null); } catch (Exception e) { Logger.Instance.Log(e); return(null); } } }
private static void CheckForUpdate() { changelogScrollPosition = Vector3.zero; changelogWidth = 0; changelogPageIndex = 0; if (isManualCheck) { ShowWindow(); } else { if (versionChecked) { EditorApplication.update -= CheckForUpdate; return; } if (EditorPrefs.HasKey(lastCheckKey)) { string lastCheckTicksString = EditorPrefs.GetString(lastCheckKey); DateTime lastCheckDateTime = new DateTime(Convert.ToInt64(lastCheckTicksString)); if (lastCheckDateTime.AddHours(checkUpdateHours) >= DateTime.UtcNow) { versionChecked = true; return; } } } versionResource = versionResource == null ? new WWW(remoteURL) : versionResource; if (!versionResource.isDone) { return; } EditorApplication.update -= CheckForUpdate; if (string.IsNullOrEmpty(versionResource.error)) { latestRelease = LatestRelease.CreateFromJSON(versionResource.text); } versionResource.Dispose(); versionResource = null; versionChecked = true; EditorPrefs.SetString(lastCheckKey, DateTime.UtcNow.Ticks.ToString()); // Clean up the existing hidePromptKeys (except the one for the current version) new[] { VRTK_Defines.CurrentVersion } .Concat(VRTK_Defines.PreviousVersions) .Where(version => latestRelease == null || version != latestRelease.version) .Select(version => string.Format(hidePromptKeyFormat, version)) .Where(EditorPrefs.HasKey) .ToList() .ForEach(EditorPrefs.DeleteKey); if (!isManualCheck && latestRelease != null && (VRTK_Defines.CurrentVersion >= latestRelease.version || EditorPrefs.HasKey(string.Format(hidePromptKeyFormat, latestRelease.version)))) { return; } ShowWindow(); isManualCheck = false; }