public ConfigurationFlag(string key, ConfigurationFlagTypes type, string defaultValue, string description, int rangeMin = 0, int rangeMax = 0, IList<IConfigurationFlagSelectValue> selectValues = null) { this.Key = key; this.Type = type; this.DefaultValue = defaultValue; this.Description = description; this.RangeMin = rangeMin; this.RangeMax = rangeMax; this.SelectValues = selectValues; }
public dynamic this[IGameInfo gameInfo, string key, ConfigurationFlagTypes type] { get { return this.GetValue(gameInfo, key, type); } set { this.SetValue(gameInfo, key, value, type); } }
public void SetDefaultValue(string key, object value, ConfigurationFlagTypes type) { this.SetValue(key, value, type, "default"); }
public dynamic GetValue(IGameInfo gameInfo, string key, ConfigurationFlagTypes type) { return this.GetValue(key, type, gameInfo.UUID, this.GetDefaultValue(key, type)); }
public dynamic GetDefaultValue(string key, ConfigurationFlagTypes type) { return this.GetValue(key, type, "default", this.emulatorBridge.ConfigurationFlags[key].DefaultValue); }
private void SetValue(string key, object value, ConfigurationFlagTypes type, string prefix) { SQLiteConnection flagDb = this.GetConnection(); flagDb.Open(); using (var sqliteCommand = new SQLiteCommand(@"INSERT OR REPLACE INTO flags VALUES( @flagKey, @flagValue)", flagDb)) { sqliteCommand.Parameters.AddWithValue("@flagKey", $"{prefix}-{key}"); sqliteCommand.Parameters.AddWithValue("@flagValue", value.ToString()); sqliteCommand.ExecuteNonQuery(); } flagDb.Close(); }
private dynamic GetValue(string key, ConfigurationFlagTypes type, string prefix, object fallback) { SQLiteConnection dbConnection = this.GetConnection(); dbConnection.Open(); string value = string.Empty; using (var sqlCommand = new SQLiteCommand(@"SELECT `flagValue` FROM `flags` WHERE `flagKey` == @searchQuery" , dbConnection)) { sqlCommand.Parameters.AddWithValue("@searchQuery", $"{prefix}-{key}"); try { value = (string)sqlCommand.ExecuteScalar(); } catch (AccessViolationException) { System.Threading.Thread.Sleep(500); //le concurrency hack :( value = (string)sqlCommand.ExecuteScalar(); } } dbConnection.Close(); value = value ?? fallback.ToString(); switch (type) { case ConfigurationFlagTypes.SELECT_FLAG: return int.Parse(value); case ConfigurationFlagTypes.INTEGER_FLAG: return int.Parse(value); case ConfigurationFlagTypes.BOOLEAN_FLAG: return bool.Parse(value); default: return value; } }
public void SetValue(IGameInfo gameInfo, string key, object value, ConfigurationFlagTypes type) { this.SetValue(key, value, type, gameInfo.UUID); }