protected override void InitDataSection() { // why we cannot have the same byte length? Read(out byte fuMdf); Flags = (ListFlags)fuMdf; Reader.Seek(3, SeekOrigin.Current); Read(out _blockCount); BlockOffsets = new long[BlockCount]; Time = new UnknownArray(BlockOffsets.Length); Angle = new UnknownArray(BlockOffsets.Length); Distance = new UnknownArray(BlockOffsets.Length); if (Flags.HasFlag(ListFlags.EqualLength)) { Read(out EqualLength); } else { Reader.ReadArray(ref BlockOffsets); } if (Flags.HasFlag(ListFlags.TimeValues)) { Reader.ReadArray(ref Time.Storage); } if (Flags.HasFlag(ListFlags.AngleValues)) { Reader.ReadArray(ref Angle.Storage); } if (Flags.HasFlag(ListFlags.DistanceValues)) { Reader.ReadArray(ref Distance.Storage); } }
public bool Readfile(string filename, bool ConvertToLower = false) { if (flags.HasFlag(ListFlags.InMemory)) { return(false); } try { string listfilename = Path.Combine(Plugin.DataPath, filename); string fileContent = File.ReadAllText(listfilename); if (listfilename.EndsWith(".script")) { list = fileContent.Split(lineseparator, StringSplitOptions.RemoveEmptyEntries).ToList(); } else { list = fileContent.Split(anyseparator, StringSplitOptions.RemoveEmptyEntries).ToList(); } if (ConvertToLower) { LowercaseList(); } return(true); } catch { // Ignoring this for now, I expect it to fail } return(false); }
public bool Add(ref string listname, ref string key, ListFlags flags = ListFlags.Unchanged) { try { var list = this.OpenList(listname); list.Add(key); if (!(flags.HasFlag(ListFlags.InMemory) | flags.HasFlag(ListFlags.ReadOnly))) { list.Writefile(listname); } return(true); } catch (Exception ex) { Logger.Debug(ex.ToString()); } return(false); }
public bool Remove(ref string listname, ref string key, ListFlags flags = ListFlags.Unchanged) { try { var list = this.OpenList(listname); list.Removeentry(key); if (!(flags.HasFlag(ListFlags.InMemory) | flags.HasFlag(ListFlags.ReadOnly))) { list.Writefile(listname); } return(false); } catch (Exception ex) { Logger.Debug(ex.ToString()); } // Going to try this form, to reduce code verbosity. return(false); }
public StringListManager ClearOldList(string request, TimeSpan delta, ListFlags flags = ListFlags.Unchanged) { var listfilename = Path.Combine(Plugin.DataPath, request); var UpdatedAge = Utility.GetFileAgeDifference(listfilename); var list = this.OpenList(request, flags); if (File.Exists(listfilename) && UpdatedAge > delta) // BUG: There's probably a better way to handle this { //RequestBot.Instance.QueueChatMessage($"Clearing old session {request}"); list.Clear(); if (!(flags.HasFlag(ListFlags.InMemory) | flags.HasFlag(ListFlags.ReadOnly))) { list.Writefile(request); } } return(list); }
public bool add(ref string listname, ref string key, ListFlags flags = ListFlags.Unchanged) { try { StringListManager list = OpenList(listname); list.Add(key); if (!(flags.HasFlag(ListFlags.InMemory) | flags.HasFlag(ListFlags.ReadOnly))) { list.Writefile(listname); } return(true); } catch (Exception ex) { Plugin.Log(ex.ToString()); } return(false); }
public StringListManager OpenList(string request, ListFlags flags = ListFlags.Unchanged) // All lists are accessed through here, flags determine mode { if (!this.ListCollection.TryGetValue(request, out var list)) { list = new StringListManager(); this.ListCollection.Add(request, list); if (!flags.HasFlag(ListFlags.InMemory)) { list.Readfile(request); // If in memory, we never read from disk } } else { if (flags.HasFlag(ListFlags.Uncached)) { list.Readfile(request); // If Cache is off, ALWAYS re-read file. } } return(list); }