/// <summary> /// Initializes a new <see cref="Profile"/> based on another /// </summary> /// <param name="p">Source <see cref="Profile"/></param> public Profile(Profile p) { this.Id = p.Id; this.Guid = p.Guid; this.Name = p.Name; this.ImagePath = p.ImagePath; this.LaunchMode = p.LaunchMode; this.UpdateEngineEnabled = p.UpdateEngineEnabled; this.KBLCServiceEnabled = p.KBLCServiceEnabled; this.Rotation = new RotationData(p.Rotation); this.News = new NewsData(p.News); this.GameModel = new GameModel(p.GameModel); }
public void Login(Profile profile) { if (profile == null) { throw new ArgumentException("profile argument cannot be null"); } LoginData credentials = GetCredentials(profile); if (credentials != null) { if (ConfigurationManager.GetConfiguration(profile.GameModel).IsLastSessionAvailable && !string.IsNullOrEmpty(credentials.LastSessionArgs)) { ShowLastSessionDialog(profile); return; } if (PerformLogin(credentials)) { return; } } ShowLoginDialog(LanguageManager.Model.LoginLogIn, string.Empty, credentials.User); }
public LoginData GetCredentials(Profile profile) { LoginData data = null; if (CredentialsCollection.TryGetValue(profile, out data)) { return data; } return null; }
public bool UpdateLastSessionArgs(Profile profile, string args) { LoginData data = GetCredentials(profile); if (data != null) { data.LastSessionArgs = args; } return data != null; }
public bool UpdateCredentials(Profile profile, LoginData data) { return CredentialsCollection.AddOrUpdate(profile, data, (key, oldValue) => data).Equals(data); }
private async void ShowLastSessionDialog(Profile profile) { MainWindow MainWindow = App.Kernel.Get<MainWindow>(); MessageDialogResult result = await MainWindow.ShowMessageAsync(LanguageManager.Model.UseLastSession, string.Empty, MessageDialogStyle.AffirmativeAndNegative, new MetroDialogSettings() { AffirmativeButtonText = LanguageManager.Model.Yes, NegativeButtonText = LanguageManager.Model.No, ColorScheme = MetroDialogColorScheme.Accented }); LoginData credentials = GetCredentials(profile); if (credentials != null) { if (result == MessageDialogResult.Affirmative) { if (LoginCompleted != null) { LoginCompleted(this, new LoginCompleteEventArgs(LoginCode.SUCCESS, credentials.LastSessionArgs, credentials.User)); } return; } else if (PerformLogin(credentials)) { return; } } ShowLoginDialog(LanguageManager.Model.LoginLogIn, String.Empty, credentials.User); }
private void ApplyChanges(ICollection<Profile> profiles, int defaultProfileId) { if (profiles == null) { throw new ArgumentException("profiles argument cannot be null"); } this.Profiles.Clear(); //Add clones of instances foreach (Profile p in profiles) { Profile newProfile = new Profile(p); IConfiguration config = ConfigurationManager.GetConfiguration(p.GameModel); if (config == null) { newProfile.GameModel.Type = ConfigurationManager.First().GameType; } Profiles.Add(newProfile); } DefaultProfile = Profiles.FirstOrDefault(i => i.Id == defaultProfileId); if (DefaultProfile == null) { DefaultProfile = Profiles.First(); } if (_CurrentProfile != null) { _CurrentProfile = Profiles.FirstOrDefault(i => i.Id == _CurrentProfile.Id); } if (_CurrentProfile == null) { _CurrentProfile = DefaultProfile; } if (_CurrentProfile == null) { _CurrentProfile = Profiles.First(); } OnCollectionChanged(); OnCurrentChanged(); }
public void Start() { lock (lockObject) { if (IsLoaded) { return; } PendingProfiles.Clear(); foreach (Profile p in EnvironmentManager.Settings.Profiles) { PendingProfiles.Add(new Profile(p)); } if (PendingProfiles.Count == 0) { CreateProfile(); } if (EnvironmentManager.Settings.DefaultProfile != null) { PendingDefaultProfile = new Profile(EnvironmentManager.Settings.DefaultProfile); } else { PendingDefaultProfile = PendingProfiles.First(); } ApplyChanges(); if (EnvironmentManager.Settings.Profiles.Count == 0) { EnvironmentManager.Save(); } IsLoaded = true; } }
public void RevertChanges() { PendingDefaultProfile = new Profile(DefaultProfile); PendingProfiles.Clear(); foreach (Profile profile in Profiles) { PendingProfiles.Add(new Profile(profile)); } }
public bool RemoveProfile(Profile profile) { if (profile == null) { throw new ArgumentException("profile argument cannot be null"); } bool result = false; if (PendingProfiles.Count > 1) { bool IsDefault = profile.Id == PendingDefaultProfile.Id; result = PendingProfiles.Remove(profile); if (result) { OnCollectionChanged(); if (IsDefault) { PendingDefaultProfile = PendingProfiles.First(); } } } return result; }
public Profile CreateProfile() { var pNew = new Profile() { Name = "NewProfile", Id = PendingProfiles.Count > 0 ? PendingProfiles.Max(p => p.Id) + 1 : 1 }; IConfiguration config = ConfigurationManager.FirstOrDefault(); if (config != null) { pNew.GameModel.Type = config.GameType; ConfigurationManager CM = ConfigurationManager as ConfigurationManager; // we should not provide this api as public pNew.GameModel.GamePath = CM.GetGamePathFromRegistry(config); pNew.GameModel.LauncherPath = CM.GetLauncherPathFromRegistry(config); if (config.IsWebAvailable) { Server serv = config.ServersProvider.ServerList.FirstOrDefault(); if (serv != null) { pNew.Rotation.ServerId = serv.Identifier; } } } pNew.News.TwitterUser = Utils.GetDefaultTwitter(); pNew.LaunchMode = App.Kernel.Get<LauncherManager>().Default.Mnemonic; PendingProfiles.Add(pNew); OnCollectionChanged(); return pNew; }
public ProtectedProfile(Profile profile) { this.Id = profile.Id; this.Name = profile.Name; this.ImagePath = profile.ImagePath; this.LaunchMode = profile.LaunchMode; this.UpdateEngineEnabled = profile.UpdateEngineEnabled; this.KBLCServiceEnabled = profile.KBLCServiceEnabled; this.Rotation = new RotationData(profile.Rotation); this.News = new NewsData(profile.News); this.GameModel = new GameModel(profile.GameModel); }
private void InitializeSafeSettings(ProtectedSettings settings) { _Settings = new Settings(); _Settings.AppTheme = settings.AppTheme; _Settings.LanguageFile = settings.Language; _Settings.ThemeAccent = settings.ThemeAccent; _Settings.CheckForUpdates = settings.CheckForUpdates; _Settings.Profiles = new List<Profile>(); LoginManager loginManager = App.Kernel.Get<LoginManager>(); if (settings.Profiles != null) { foreach (ProtectedProfile protectedProfile in settings.Profiles) { Profile safeProfile = new Profile(); safeProfile.Id = protectedProfile.Id; safeProfile.Name = protectedProfile.Name; safeProfile.ImagePath = protectedProfile.ImagePath; safeProfile.KBLCServiceEnabled = protectedProfile.KBLCServiceEnabled; safeProfile.UpdateEngineEnabled = protectedProfile.UpdateEngineEnabled; safeProfile.LaunchMode = protectedProfile.LaunchMode; safeProfile.GameModel = new GameModel(protectedProfile.GameModel); safeProfile.News = new NewsData(protectedProfile.News); safeProfile.Rotation = new RotationData(protectedProfile.Rotation); _Settings.Profiles.Add(safeProfile); if (safeProfile.Id == settings.DefaultProfile) { _Settings.DefaultProfile = safeProfile; } loginManager.UpdateCredentials(safeProfile, new LoginData(protectedProfile.Login)); } } }