public static void CheckForUpdates() { string lastKnownVersionToken = Path.Combine(EditorManager.GetDirectory(EditorManager.DirectoryType.UserDataPath), "LastKnownVersion.token"); WebClient webClient = new WebClient(); webClient.DownloadStringCompleted += (sender, eventArgs) => { try { if (eventArgs.Error != null) { return; } string json = eventArgs.Result.Trim(new char[] { ' ', '\t', '\n', '[', ']' }); JavaScriptSerializer serializer = new JavaScriptSerializer(); var anarchyVersionInfo = serializer.Deserialize <AnarchyVersionInfo>(json); Version versionOnServer = new Version(anarchyVersionInfo.currentVersion); Version lastKnownVersion = Assembly.GetEntryAssembly().GetName().Version; if (File.Exists(lastKnownVersionToken)) { Version tmp = new Version(File.ReadAllText(lastKnownVersionToken)); if (tmp > lastKnownVersion) { lastKnownVersion = tmp; } } if (lastKnownVersion < versionOnServer) { UpdateDlg dlg = new UpdateDlg(anarchyVersionInfo); dlg.ShowDialog(); if (dlg.AskLater) { File.WriteAllText(lastKnownVersionToken, versionOnServer.ToString()); } } } catch { } }; try { webClient.DownloadStringAsync(new Uri("http://www.projectanarchy.com/svc/version.json")); } catch { } }
public static void CheckForUpdates() { string lastKnownVersionToken = Path.Combine(EditorManager.GetDirectory(EditorManager.DirectoryType.UserDataPath), "LastKnownVersion.token"); WebClient webClient = new WebClient(); webClient.DownloadStringCompleted += (sender, eventArgs) => { try { if (eventArgs.Error != null) return; string json = eventArgs.Result.Trim(new char[] { ' ', '\t', '\n', '[', ']' }); JavaScriptSerializer serializer = new JavaScriptSerializer(); var anarchyVersionInfo = serializer.Deserialize<AnarchyVersionInfo>(json); Version versionOnServer = new Version(anarchyVersionInfo.currentVersion); Version lastKnownVersion; if (File.Exists(lastKnownVersionToken)) lastKnownVersion = new Version(File.ReadAllText(lastKnownVersionToken)); else lastKnownVersion = Assembly.GetEntryAssembly().GetName().Version; if (lastKnownVersion < versionOnServer) { UpdateDlg dlg = new UpdateDlg(anarchyVersionInfo); dlg.ShowDialog(); if (dlg.AskLater) { File.WriteAllText(lastKnownVersionToken, versionOnServer.ToString()); } } } catch { } }; try { webClient.DownloadStringAsync(new Uri("http://www.projectanarchy.com/svc/version.json")); } catch { } }