/// <summary> /// Loads the specific entry. /// </summary> /// <param name="name"> /// The name of the entry. /// </param> /// <returns> /// The <see cref="Dictionary{TKey,TValue}" /> collection of the entry contents. /// </returns> public static Dictionary<string, byte[]> Load(string name) { try { var fileName = Path.Combine(MenuSettings.MenuConfigPath, name + ".bin"); if (File.Exists(fileName)) { return Utils.Deserialize<Dictionary<string, byte[]>>(File.ReadAllBytes(fileName)); } } catch (Exception e) { Console.WriteLine(e); } return null; }
/// <summary> /// Sets the value. /// </summary> /// <typeparam name="T"> /// The value type. /// </typeparam> /// <param name="newValue"> /// The new value. /// </param> /// <returns> /// The item instance. /// </returns> public MenuItem SetValue <T>(T newValue) { this.ValueType = MenuValueType.None; if (newValue.GetType().ToString().Contains("Boolean")) { this.ValueType = MenuValueType.Boolean; } else if (newValue.GetType().ToString().Contains("Slider")) { this.ValueType = MenuValueType.Slider; } else if (newValue.GetType().ToString().Contains("KeyBind")) { this.ValueType = MenuValueType.KeyBind; } else if (newValue.GetType().ToString().Contains("Int")) { this.ValueType = MenuValueType.Integer; } else if (newValue.GetType().ToString().Contains("Circle")) { this.ValueType = MenuValueType.Circle; } else if (newValue.GetType().ToString().Contains("StringList")) { this.ValueType = MenuValueType.StringList; } else if (newValue.GetType().ToString().Contains("Color")) { this.ValueType = MenuValueType.Color; } else { Console.WriteLine(@"CommonLibMenu: Data type not supported"); } var readBytes = SavedSettings.GetSavedData(this.SaveFileName, this.SaveKey); var v = newValue; try { if (!this.ValueSet && readBytes != null) { switch (this.ValueType) { case MenuValueType.KeyBind: var savedKeyValue = (KeyBind)(object)Utils.Deserialize <T>(readBytes); if (savedKeyValue.Type == KeyBindType.Press) { savedKeyValue.Active = false; } newValue = (T)(object)savedKeyValue; break; case MenuValueType.Circle: var savedCircleValue = (Circle)(object)Utils.Deserialize <T>(readBytes); var newCircleValue = (Circle)(object)newValue; savedCircleValue.Radius = newCircleValue.Radius; newValue = (T)(object)savedCircleValue; break; case MenuValueType.Slider: var savedSliderValue = (Slider)(object)Utils.Deserialize <T>(readBytes); var newSliderValue = (Slider)(object)newValue; if (savedSliderValue.MinValue == newSliderValue.MinValue && savedSliderValue.MaxValue == newSliderValue.MaxValue) { newValue = (T)(object)savedSliderValue; } break; case MenuValueType.StringList: var savedListValue = (StringList)(object)Utils.Deserialize <T>(readBytes); var newListValue = (StringList)(object)newValue; if (savedListValue.SList.SequenceEqual(newListValue.SList)) { newValue = (T)(object)savedListValue; } break; default: newValue = Utils.Deserialize <T>(readBytes); break; } } } catch (Exception e) { newValue = v; Console.WriteLine(e); } OnValueChangeEventArgs valueChangedEvent = null; if (this.ValueSet) { var handler = this.ValueChanged; if (handler != null) { valueChangedEvent = new OnValueChangeEventArgs(this.value, newValue); handler(this, valueChangedEvent); } } if (valueChangedEvent != null) { if (valueChangedEvent.Process) { this.value = newValue; } } else { this.value = newValue; } this.ValueSet = true; this.serialized = Utils.Serialize(this.value); return(this); }