private void Reload() { SoundManager.GetSounds().ForEach(definition => SettingsManager.Cache.Add(SoundModel.fromDefinition(definition))); SettingsManager.Save(); views.Clear(); foreach (Definition definition in SoundManager.GetSounds()) { views.Add(creationDelegate(SoundModel.fromDefinition(definition))); } }
/// <summary> /// Initializes the Settings Manager. /// </summary> public static void Init() { Log.Debug("Starting the SettingsManager"); if (!File.Exists(AppSettings.SoundSettingsFilePath)) { Cache = new List <SoundModel>(); foreach (var definition in SoundManager.Cache.SoundList) { Cache.Add(SoundModel.fromDefinition(definition)); } CreateStandardFile(); } else { try { var readText = File.ReadAllText(AppSettings.SoundSettingsFilePath); if (string.IsNullOrWhiteSpace(readText)) { File.Delete(AppSettings.SoundSettingsFilePath); CreateStandardFile(); } List <JsonSoundModel> jsonModels = JsonConvert.DeserializeObject <List <JsonSoundModel> >(readText); Cache = new List <SoundModel>(); foreach (JsonSoundModel model in jsonModels) { Cache.Add(SoundModel.fromJsonSoundModel(model)); } } catch (Exception exception) { File.Delete(AppSettings.SoundSettingsFilePath); Log.Error("Settings Manager initialization failed!", exception); } } Cache.RemoveAll(item => item.Name == "DummyItem"); if (Settings.Default.EnableSoundHotKeys) { // When the Definitions are read in, the application can start setting up the Keybinds. (Keybinds are stored in the soundSettings.json!) KeybindManager.SetKeybinds(); } }
public SoundModel ToSoundModel() { return(SoundModel.fromDefinition(SoundManager.GetSound(Sound.Name))); }