private async Task <string> GetUpdateString() { try { using (var wc = new AwaredWebClient(UpdateSource, Encoding.UTF8)) { return(await wc.DownloadStringTaskAsync("version.txt")); } } catch (WebException) { return(""); } }
/// <summary> /// 检查更新并存储结果。 /// </summary> /// <param name="force">是否强制更新。</param> public async void CheckUpdate(bool force = false) { await Task.Yield(); try { using (var wc = new AwaredWebClient("", System.Text.Encoding.UTF8)) { wc.Timeout = 5000; var new_meta = await wc.DownloadStringTaskAsync(UpdateSource); var meta_exp = new_meta.Split(new char[] { ';' }, 2); var local_meta = Core.ReadConfig(LocalStorage + ".ver"); if (force) { force = true; } else if (local_meta == "") { force = true; } else if (local_meta.Split(new char[] { ';' }, 2)[0] != meta_exp[0]) { force = true; } if (force) { Core.WriteConfig(LocalStorage + ".ver", new_meta); await wc.DownloadFileTaskAsync(meta_exp[1], Path.Combine(Core.ConfigDirectory, LocalStorage)); Core.Log("[Hotfix] Module successfully updated - " + LocalStorage); } } } catch (Exception ex) { Core.Log(ex); Core.WriteConfig(LocalStorage + ".ver", ""); } }