private void CheckUpdate(CheckUpdateState state) { try { Logging.Debug($"Checking updates... - {state.apiUrl}"); if (string.IsNullOrEmpty(state.currentVersion)) { if (CheckUpdateCompleted != null) { CheckUpdateCompleted.Invoke(this, new CheckUpdateEventArgs() { App = state.app, ApiUrl = state.apiUrl, CurrentVersion = state.currentVersion, UserState = state.userState }); } } else { WebClient http = CreateWebClient(); http.Encoding = Encoding.UTF8; http.DownloadStringCompleted += http_DownloadStringCompleted; http.DownloadStringAsync(new Uri(state.apiUrl), state); } } catch (Exception ex) { Logging.LogUsefulException(ex); } }
private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { CheckUpdateTimer timer = (CheckUpdateTimer)sender; CheckUpdateState state = timer.State; timer.Elapsed -= Timer_Elapsed; timer.Enabled = false; timer.Dispose(); CheckUpdate(state); }
public void CheckUpdateForGUI(int delay = 0, object userState = null) { CheckUpdateState state = new CheckUpdateState { app = App.GUI, apiUrl = GUI_UPDATE_API_URL, currentVersion = GUI_VERSION, userState = userState }; CheckUpdate(state, delay); }
public void CheckUpdateForKCPTun(int delay = 0, object userState = null) { string version = controller.KCPTunnelController.GetKcptunVersionNumber(); CheckUpdateState state = new CheckUpdateState { app = App.KCPTun, apiUrl = KCPTUN_UPDATE_API_URL, currentVersion = version, userState = userState }; CheckUpdate(state, delay); }
private void CheckUpdate(CheckUpdateState state, int delay = 0) { if (delay > 0) { CheckUpdateTimer timer = new CheckUpdateTimer(delay); timer.State = state; timer.AutoReset = false; timer.Elapsed += Timer_Elapsed; timer.Enabled = true; } else { CheckUpdate(state); } }
private void http_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { try { CheckUpdateState state = (CheckUpdateState)e.UserState; string response = e.Result; JArray result = JArray.Parse(response); CheckUpdateEventArgs args = new CheckUpdateEventArgs(); args.App = state.app; args.ApiUrl = state.apiUrl; args.CurrentVersion = state.currentVersion; args.UserState = state.userState; if (result != null) { foreach (JObject release in result) { if ((bool)release["prerelease"]) { continue; } foreach (JObject asset in (JArray)release["assets"]) { Release ass = new Release() { app = state.app }; ass.Parse(asset); if (ass.IsNewVersion(state.currentVersion)) { args.ReleaseList.Add(ass); } } } } if (CheckUpdateCompleted != null) { CheckUpdateCompleted(this, args); } } catch (Exception ex) { Logging.LogUsefulException(ex); } }