private bool _updateAvailableResolver(LauncherVersion ver) { // ReSharper disable once AssignNullToNotNullAttribute var dlgResult = MessageBox.Show(Application.Current.MainWindow, "Download and install it?", $"A new version is available {ver}", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No); return(dlgResult == MessageBoxResult.Yes); }
public async Task <LauncherVersion> GetLauncherVersion() { string url = @"http://10.14.161.44/TechAppLauncherAPI/api/TechAppLauncher/GetLauncherVersion/"; var request = new HttpRequestMessage() { RequestUri = new Uri(url), Method = HttpMethod.Get, }; request.Headers.Accept.Clear(); request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); s_httpClient = new HttpClient(_handler); s_httpClient.DefaultRequestHeaders.Accept.Clear(); s_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); s_httpClient.Timeout = GetTimeOut(5); LauncherVersion launcherVersion = null; try { var response = await s_httpClient.SendAsync(request, HttpCompletionOption.ResponseContentRead); if (response.StatusCode == HttpStatusCode.OK) { var content = await response.Content.ReadAsStringAsync(); if (content != null && !string.IsNullOrEmpty(content)) { launcherVersion = JsonConvert.DeserializeObject <LauncherVersion>(content); } } } catch (Exception ex) { } return(launcherVersion); }
internal bool IsNewerThan(LauncherVersion _other_version) { if (major >= _other_version.major && minor >= _other_version.minor && date >= _other_version.date) { if (major > _other_version.major) { return(true); } else if (minor > _other_version.minor) { return(true); } else if (date > _other_version.date) { return(true); } else if (hotfix > _other_version.hotfix) { return(true); } } return(false); }
private void _DownloadStringCompletedHandler(object sender, DownloadStringCompletedEventArgs e) { _webClient.DownloadStringCompleted -= _DownloadStringCompletedHandler; _CloseWebClient(); if (e.Error == null) { try { var updateInfoObject = JsonConvert.DeserializeObject <UpdateInfoObject>(e.Result); var version = LauncherVersion.Parse(updateInfoObject.Version); var currentVersion = _versionService.GetAssemblyVersion(); if (version.AssemblyVersion <= currentVersion) { return; } var acceptUpdate = UpdateAvailableResolver.Invoke(version); if (!acceptUpdate) { return; } InDownloadStage = true; _BeginDownload(updateInfoObject); } catch (Exception ex) { _RaiseError(ex.Message); } } else { _RaiseError(e.Error.Message); } }
public static void SaveProfile() { string mainDir = SettingsControl.MainDirectory; if (!Directory.Exists(mainDir)) { Directory.CreateDirectory(mainDir); } RootLauncherProfiles rootLauncherProfiles = new RootLauncherProfiles(); LauncherVersion launcherVersion = new LauncherVersion(); AuthenticationDatabase authenticationDatabase = new AuthenticationDatabase(); Profile profile = new Profile(); profile.javaArgs = JavaArguments; profile.javaDir = JavaDirectory; profile.lastVersionId = LastVersionId; profile.name = ProfileName; profile.gameDir = mainDir; rootLauncherProfiles.profiles = new Dictionary <string, Profile>(1); rootLauncherProfiles.profiles.Add(ProfileName, profile); authenticationDatabase.accessToken = AccessToken; authenticationDatabase.displayName = DisplayName; authenticationDatabase.userid = UserId; authenticationDatabase.username = Username; authenticationDatabase.uuid = UUID; rootLauncherProfiles.authenticationDatabase = new Dictionary <string, AuthenticationDatabase>(1); rootLauncherProfiles.authenticationDatabase.Add(SelectedUser, authenticationDatabase); rootLauncherProfiles.launcherVersion = launcherVersion; rootLauncherProfiles.selectedUser = SelectedUser; rootLauncherProfiles.clientToken = ClientToken; if (!string.IsNullOrWhiteSpace(SelectedProfile)) { rootLauncherProfiles.selectedProfile = SelectedProfile; } else { rootLauncherProfiles.selectedProfile = LastVersionId; } launcherVersion.name = Constants.LAUNCHER_VERSION_OFFICIAL; launcherVersion.format = Constants.LAUNCHER_VERSION_FORMAT_OFFICIAL; try { using (FileStream fileStream = new FileStream(mainDir + "\\launcher_profiles.json", FileMode.Create, FileAccess.Write, FileShare.None)) { using (StreamWriter writer = new StreamWriter(fileStream, Encoding.ASCII)) { writer.Write(JsonConvert.SerializeObject(rootLauncherProfiles, Formatting.Indented)); } } } catch (Exception ex) { MessageBox.Show(Messages.ERROR_SAVE_SETTINGS_PROFILE + ex.Message, Messages.CAPTION_COMMON); } }
public static void SetVersion(LauncherVersion versionInstance) { _launcherVersion = versionInstance; }