public bool setGroup(string name, BotGroup group) { lock (groups) { if (group == null) { if (groups.ContainsKey(name)) { groups.Remove(name); } } else { if (hasGroup(name)) { groups.Remove(name); } if (hasGroup(group.index)) { groups.Remove(groupIndexToName(group.index)); } groups.AddOrReplace(group.groupName, group); } writeGroupsToFile(); } return(true); }
public void loadGroupsFromFile() { if (File.Exists(groupsPath) == false) { return; } lock (groups) { BinaryReader reader; try { reader = new BinaryReader(new FileStream(groupsPath, FileMode.Open)); } catch (Exception e) { Logging.error("Cannot open {0} file: {1}", groupsPath, e.Message); return; } try { int version = reader.ReadInt32(); int num_groups = reader.ReadInt32(); for (int i = 0; i < num_groups; i++) { int group_len = reader.ReadInt32(); byte[] group_bytes = reader.ReadBytes(group_len); BotGroup bc = new BotGroup(group_bytes); groups.AddOrReplace(bc.groupName, bc); } } catch (Exception e) { Logging.error("Cannot read from {0} file: {1}", groupsPath, e.Message); // TODO TODO notify the user or something like that } reader.Close(); } }