private void SaveToFile(AnimationSettingsValue <T> update) { var lines = GetFileLines(); var values = GetValues(lines); var updated = false; foreach (var value in values) { if (value.Type == update.Type && value.Matcher == update.Matcher) { lines[value.LineIndex.Value] = update.ToString(); updated = true; break; } } lock (_locker) { if (updated) { File.WriteAllLines(FilePath, lines); } else if (update.Value != null) { File.AppendAllText(FilePath, Environment.NewLine + update.ToString()); } } }
public void Delete(string path, string name) { var delete = new AnimationSettingsValue <T>(path, name, null); if (delete.Type == MatcherType.Key) { KeyFlags.Remove(delete.Matcher); } if (delete.Type == MatcherType.Path) { PathFlags.Remove(delete.Matcher); } SaveToFile(delete); }
public void Save(string path, string name, T settings) { var update = new AnimationSettingsValue <T>(path, name, settings); if (update.Type == MatcherType.Key) { KeyFlags[update.Matcher] = update.Value; } if (update.Type == MatcherType.Path) { PathFlags[update.Matcher] = update.Value; } SaveToFile(update); }
private List <AnimationSettingsValue <T> > GetValues(string[] lines) { var values = new List <AnimationSettingsValue <T> >(); for (var i = 0; i < lines.Length; i++) { var value = AnimationSettingsValue <T> .Parse(lines[i]); if (value != null) { value.LineIndex = i; values.Add(value); } } return(values); }