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)); } } }
private void ValidateSettings(ProtectedSettings settings) { if (settings.Proxy == null) { settings.Proxy = new ProxySetting(); } ProxySetting proxy = settings.Proxy; if (Uri.CheckHostName(proxy.Host) == UriHostNameType.Unknown) { proxy.Host = string.Empty; } if (proxy.Port < 0 || proxy.Port > 65535) { proxy.Port = 8080; } if (settings.Profiles != null) { TwitterNameValidation twitterValidator = new TwitterNameValidation(); GuildNameValidationRule guildNameValidator = new GuildNameValidationRule(); foreach (var profile in settings.Profiles) { if (profile.News == null) { profile.News = new NewsData(); } if (profile.Login == null) { profile.Login = new LoginData(); } if (profile.Rotation == null) { profile.Rotation = new RotationData(); } if (profile.GameModel == null) { profile.GameModel = new GameModel(); } if (!twitterValidator.Validate(profile.News.TwitterUser, null).IsValid) { profile.News.TwitterUser = Utils.GetDefaultTwitter(); } if (profile.Rotation.Guild != null) { if (!guildNameValidator.Validate(profile.Rotation.Guild, null).IsValid) { profile.Rotation.Guild = string.Empty; } } } } }
private void ApplyProxySettings(ProtectedSettings settings) { ProxyManager pManager = App.Kernel.Get<ProxyManager>(); if (settings.Proxy == null) { settings.Proxy = new ProxySetting(); } pManager.Initialize(settings.Proxy); }
private void ApplyAppTheme(ProtectedSettings ProtectedSettings) { Tuple<AppTheme, Accent> currentTheme = ThemeManager.DetectAppStyle(Application.Current); if (currentTheme == null) { return; } AppTheme appTheme = null; Accent themeAccent = null; if (ProtectedSettings.AppTheme != null) { appTheme = ThemeManager.GetAppTheme(ProtectedSettings.AppTheme); } if (appTheme == null) { appTheme = currentTheme.Item1; } if (ProtectedSettings.ThemeAccent != null) { themeAccent = ThemeManager.GetAccent(ProtectedSettings.ThemeAccent); } if (themeAccent == null) { themeAccent = currentTheme.Item2; } ProtectedSettings.AppTheme = appTheme.Name; ProtectedSettings.ThemeAccent = themeAccent.Name; ThemeManager.ChangeAppStyle(Application.Current, themeAccent, appTheme); }
private static ProtectedSettings DeSerializeSettings(string filepath) { ProtectedSettings settings = new ProtectedSettings(); if (File.Exists(filepath)) { XmlSerializer reader = new XmlSerializer(typeof(ProtectedSettings)); using (var file = new StreamReader(filepath)) { settings = (ProtectedSettings)reader.Deserialize(file); } } return settings; }
public void Save() { ProtectedSettings toSave = new ProtectedSettings(Settings); toSave.Proxy = new ProxySetting(App.Kernel.Get<ProxyManager>().Settings); IProfileManager ProfileManager = App.Kernel.Get<IProfileManager>(); if (ProfileManager.DefaultProfile != null) { toSave.DefaultProfile = ProfileManager.DefaultProfile.Id; } if (ProfileManager.Profiles != null) { LoginManager loginManager = App.Kernel.Get<LoginManager>(); foreach (Profile profile in ProfileManager.Profiles) { ProtectedProfile protectedProfile = new ProtectedProfile(profile); LoginData login = loginManager.GetCredentials(profile); if (login != null) { protectedProfile.Login = new LoginData(login); } toSave.Profiles.Add(protectedProfile); } } new FileIOPermission(FileIOPermissionAccess.Write, SettingsFile).Assert(); XmlSerializer writer = new XmlSerializer(typeof(ProtectedSettings)); using (var file = new StreamWriter(SettingsFile)) { writer.Serialize(file, toSave); } }
public void Initialize() { AppPath = System.IO.Path.GetDirectoryName(System.AppDomain.CurrentDomain.BaseDirectory); AppDataPath = InitFolder(System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData), Path.Combine("GoldRenard", "AdvancedLauncher")); LanguagesPath = InitFolder(AppPath, LOCALE_DIR); Resources3rdPath = InitFolder(AppDataPath, RESOURCE_DIR); ResourcesPath = InitFolder(AppPath, RESOURCE_DIR); PluginsPath = InitFolder(AppPath, PLUGINS_DIR); AppDomain.CurrentDomain.SetData("DataDirectory", AppDataPath); // Initialize ProtectedSettings entity ProtectedSettings ProtectedSettings = null; if (File.Exists(SettingsFile)) { try { ProtectedSettings = DeSerializeSettings(SettingsFile); } catch (Exception) { // fall down and recreate settings file } } bool createSettingsFile = ProtectedSettings == null; if (createSettingsFile) { ProtectedSettings = new ProtectedSettings(); } ValidateSettings(ProtectedSettings); ApplyAppTheme(ProtectedSettings); ApplyProxySettings(ProtectedSettings); InitializeSafeSettings(ProtectedSettings); LanguageManager LM = LanguageManager as LanguageManager; if (LM != null) { Settings.LanguageFile = LM.Initialize(InitFolder(AppPath, LOCALE_DIR), _Settings.LanguageFile); } if (createSettingsFile) { Save(); } }