/// <summary> /// Save setting value /// </summary> /// <param name="settingsType">type of setting</param> /// <param name="value">value you want to save</param> public static void SetSetting(SettingsType settingsType, dynamic value) { if (settingTypes.TryGetValue(settingsType, out SettingsValueType valueType)) { switch (valueType) { case SettingsValueType.FLOAT: if (value is float || value is int) { PlayerPrefs.SetFloat(settingsType.ToString(), (float)value); } // TODO: log error break; case SettingsValueType.INT: if (value is int || value is float) { PlayerPrefs.SetInt(settingsType.ToString(), (int)value); } // TODO: log error break; case SettingsValueType.STRING: if (value is string) { PlayerPrefs.SetString(settingsType.ToString(), (string)value); } // TODO: log error break; } } }
/// <summary> /// Deserializes the next block of data. /// </summary> /// <param name="serializedData">The serialized data.</param> /// <param name="settings">The settings.</param> /// <returns>The deserialization result.</returns> private static DeserializationResult DeserializeBlock(BinaryData serializedData, Settings settings) { if (serializedData == null || serializedData.Left == 0) { return(DeserializationResult.EndOfData); } SettingsType settingsType = serializedData.PeekSettingsType(); Log.DevDebug(typeof(BinarySettings), "DeserializeBlock", applySettings, settingsType); switch (settingsType) { case SettingsType.StandardService: return(DeserializeStandardServiceSettings(serializedData, settings)); case SettingsType.HiddenService: return(DeserializeHiddenServiceSettings(serializedData, settings)); case SettingsType.ServiceRanges: return(DeserializeRangeSettings(serializedData, settings)); case SettingsType.Compatibility: return(DeserializeCompatibilitySettings(serializedData, settings)); default: throw new InvalidOperationException("Unknown settings type: " + settingsType.ToString()); } }
public static String GetSettings(SettingsType type, SectionType section) { return (ConfigurationManager.AppSettings[ String.Format("{0}_{1}", Enum.Parse(typeof(SettingsType), type.ToString()).ToString(), Enum.Parse(typeof(SectionType), section.ToString()).ToString()) ]); }
public void UpdateSettings(SettingsType theType, object theSetting) { //collect them from the Application Resources Collection theSettings = App.Current.Resources["UserPreferences"] as UserSettings; switch (theType) { case SettingsType.AddCustomServer: case SettingsType.RemoveCustomServer: //don't all any duplicates theSettings.CustomServers.RemoveAll(cs => cs.ServerId == ((CustomServer)theSetting).ServerId); if (theType == SettingsType.AddCustomServer) { theSettings.CustomServers.Add(theSetting as CustomServer); } break; case SettingsType.AddServerCredentials: case SettingsType.RemoveServerCredentials: //get a serverdetail object ServerDetails addMe = theSetting as ServerDetails; //don't allow duplicate username for this server theSettings.Servers.RemoveAll(sd => sd.ServerId == addMe.ServerId && sd.Username.Equals(addMe.Username, StringComparison.InvariantCultureIgnoreCase)); if (theType == SettingsType.AddServerCredentials) { theSettings.Servers.Add(addMe); } break; default: //update the setting theSettings.GetType().GetProperty(theType.ToString()).SetValue(theSettings, theSetting, null); break; } App.Current.Resources["UserPreferences"] = theSettings; BinaryFormatter bf = new BinaryFormatter(); LauncherEncryption myEncryption = new LauncherEncryption(); IsolatedStorageFile inFile = IsolatedStorageFile.GetUserStoreForAssembly(); //and save that into the file using (MemoryStream msOut = new MemoryStream()) using (IsolatedStorageFileStream outStream = new IsolatedStorageFileStream("settings.cfg", FileMode.OpenOrCreate, System.IO.FileAccess.Write, inFile)) using (BinaryWriter bwOut = new BinaryWriter(outStream)) { //serialize it bf.Serialize(msOut, theSettings); //encrypt it and write it out bwOut.Write(myEncryption.Encrypt(msOut.ToArray())); } }
/// <summary> /// Get setting value /// </summary> /// <param name="settingsType">type of setting</param> /// <returns>dynamic variable containing setting value</returns> public static dynamic GetSetting(SettingsType settingsType) { if (settingTypes.TryGetValue(settingsType, out SettingsValueType valueType)) { switch (valueType) { case SettingsValueType.FLOAT: return(PlayerPrefs.GetFloat(settingsType.ToString())); case SettingsValueType.INT: return(PlayerPrefs.GetInt(settingsType.ToString())); case SettingsValueType.STRING: return(PlayerPrefs.GetString(settingsType.ToString())); } } return(null); }
public void SetTab(SettingsType settingTab, bool isSelected) { _localizedTabTitle.StringReference.TableEntryReference = settingTab.ToString(); _currentTabType = settingTab; if (isSelected) { SelectTab(); } else { UnselectTab(); } }
public static IUserSettings GetSettings(SettingsType t) { switch (t) { case SettingsType.NETSettings: return(UserSettingsNET.Instance); case SettingsType.JSONSettings: return(UserSettingsJSON.Instance); default: throw new NotImplementedException($"Settings mode for {t.ToString()} is not implemented."); } }
/// <summary> /// Get setting value /// </summary> /// <param name="settingsType">type of setting</param> /// <param name="resultValueType">setting value type</param> /// <returns>dynamic variable containing setting value</returns> public static object GetSetting(SettingsType settingsType, out Type resultValueType) { if (settingTypes.TryGetValue(settingsType, out SettingsValueType valueType)) { switch (valueType) { case SettingsValueType.FLOAT: resultValueType = typeof(float); return(PlayerPrefs.GetFloat(settingsType.ToString())); case SettingsValueType.INT: resultValueType = typeof(int); return(PlayerPrefs.GetInt(settingsType.ToString())); case SettingsValueType.STRING: resultValueType = typeof(string); return(PlayerPrefs.GetString(settingsType.ToString())); } } resultValueType = null; return(null); }
static async Task <T> LoadSettingsAsync <T>(SettingsType type) where T : new() { var dbSettings = await DB.Settings.GetAsync((int)type); if (dbSettings?.Data is null) { var settings = new T(); await DB.Settings.SetAsync((int)type, JsonConvert.SerializeObject(settings, Formatting.Indented)); return(settings); } try { return(JsonConvert.DeserializeObject <T>(dbSettings.Data)); } catch (Exception ex) { RiftBot.Log.Fatal(ex, $"Failed to deserialize {type.ToString()} settings!"); return(default);
/// <summary> /// Returns a settings path updated with current deets /// </summary> /// <param name="weights">if it's a weights file or otherwise just a settings file</param> /// <returns>path to settings</returns> public static string GetSettingsPath(SettingsType type, bool pvp) { return(Logging.ApplicationPath + "\\Settings\\EquipMe\\EquipMe_" + StyxWoW.Me.Name + "_" + EquipMe.GetSpecName() + (pvp && Styx.Logic.Battlegrounds.IsInsideBattleground ? "_PVP" : "") + "_" + type.ToString() + ".xml"); }
public void SaveValue <T>(SettingsType settingsType, T value) { var software = Registry.CurrentUser.OpenSubKey("Software", true); var umbrella = software.CreateSubKey("Umbrella"); switch (settingsType) { case SettingsType.ExePath: umbrella.SetValue(settingsType.ToString().ToLower(), (T)Convert.ChangeType(value, typeof(T))); break; case SettingsType.IsUrlLanguageRemembered: umbrella.SetValue(settingsType.ToString().ToLower(), ValueTypeCaster <T> .From(value), RegistryValueKind.DWord); break; case SettingsType.IsAuthorized: umbrella.SetValue(settingsType.ToString().ToLower(), ValueTypeCaster <T> .From(value), RegistryValueKind.DWord); break; case SettingsType.DotaScriptsAutoUpdate: umbrella.SetValue(settingsType.ToString().ToLower(), ValueTypeCaster <T> .From(value), RegistryValueKind.DWord); break; case SettingsType.DotaCheckCRC: umbrella.SetValue(settingsType.ToString().ToLower(), ValueTypeCaster <T> .From(value), RegistryValueKind.DWord); break; case SettingsType.AntiVac: umbrella.SetValue(settingsType.ToString().ToLower(), ValueTypeCaster <T> .From(value), RegistryValueKind.DWord); break; case SettingsType.DotaLaunchTrigger: umbrella.SetValue(settingsType.ToString().ToLower(), ValueTypeCaster <T> .From(value), RegistryValueKind.DWord); break; case SettingsType.ServerIndex: umbrella.SetValue(settingsType.ToString().ToLower(), ValueTypeCaster <T> .From(value), RegistryValueKind.DWord); break; case SettingsType.DotaLaunchOptions: umbrella.SetValue(settingsType.ToString().ToLower(), (T)Convert.ChangeType(value, typeof(T))); break; case SettingsType.Login: umbrella.SetValue(settingsType.ToString().ToLower(), (T)Convert.ChangeType(value, typeof(T))); break; case SettingsType.Password: umbrella.SetValue(settingsType.ToString().ToLower(), (T)Convert.ChangeType(value, typeof(T))); break; case SettingsType.Language: umbrella.SetValue(settingsType.ToString().ToLower(), (T)Convert.ChangeType(value, typeof(T))); break; case SettingsType.DXVersion: umbrella.SetValue(settingsType.ToString().ToLower(), (T)Convert.ChangeType(value, typeof(T))); break; case SettingsType.UrlLangType: umbrella.SetValue(settingsType.ToString().ToLower(), (T)Convert.ChangeType(value, typeof(T))); break; default: break; } }
public T ReadValue <T>(SettingsType settingsType) where T : IConvertible { try { var software = Registry.CurrentUser.OpenSubKey("Software", true); var umbrella = software.CreateSubKey("Umbrella"); switch (settingsType) { case SettingsType.IsUrlLanguageRemembered: return(ValueTypeCaster <T> .From(umbrella.GetValue(settingsType.ToString().ToLower(), RegistryValueKind.DWord))); case SettingsType.IsAuthorized: return(ValueTypeCaster <T> .From(umbrella.GetValue(settingsType.ToString().ToLower(), RegistryValueKind.DWord))); case SettingsType.DotaScriptsAutoUpdate: return(ValueTypeCaster <T> .From(umbrella.GetValue(settingsType.ToString().ToLower(), RegistryValueKind.DWord))); case SettingsType.DotaCheckCRC: return(ValueTypeCaster <T> .From(umbrella.GetValue(settingsType.ToString().ToLower(), RegistryValueKind.DWord))); case SettingsType.AntiVac: return(ValueTypeCaster <T> .From(umbrella.GetValue(settingsType.ToString().ToLower(), RegistryValueKind.DWord))); case SettingsType.DotaLaunchTrigger: return(ValueTypeCaster <T> .From(umbrella.GetValue(settingsType.ToString().ToLower(), RegistryValueKind.DWord))); case SettingsType.ServerIndex: return(ValueTypeCaster <T> .From(umbrella.GetValue(settingsType.ToString().ToLower(), RegistryValueKind.DWord))); case SettingsType.DotaLaunchOptions: return((T)Convert.ChangeType(umbrella.GetValue(settingsType.ToString().ToLower()), typeof(T))); case SettingsType.Login: return((T)Convert.ChangeType(umbrella.GetValue(settingsType.ToString().ToLower()), typeof(T))); case SettingsType.Password: return((T)Convert.ChangeType(umbrella.GetValue(settingsType.ToString().ToLower()), typeof(T))); case SettingsType.Language: return((T)Convert.ChangeType(umbrella.GetValue(settingsType.ToString().ToLower()), typeof(T))); case SettingsType.DXVersion: return((T)Convert.ChangeType(umbrella.GetValue(settingsType.ToString().ToLower()), typeof(T))); case SettingsType.UrlLangType: return((T)Convert.ChangeType(umbrella.GetValue(settingsType.ToString().ToLower()), typeof(T))); default: return(default(T)); } } catch { return(default(T)); } }
/// <summary> /// Returns a settings path updated with current deets /// </summary> /// <param name="weights">if it's a weights file or otherwise just a settings file</param> /// <returns>path to settings</returns> public static string GetSettingsPath(SettingsType type, bool pvp) { return Logging.ApplicationPath + "\\Settings\\EquipMe\\EquipMe_" + StyxWoW.Me.Name + "_" + EquipMe.GetSpecName() + (pvp && Styx.Logic.Battlegrounds.IsInsideBattleground ? "_PVP" : "") + "_" + type.ToString() + ".xml"; }