public bool setChannel(string name, BotChannel channel) { lock (channels) { if (channel == null) { if (channels.ContainsKey(name)) { channels.Remove(name); } } else { if (hasChannel(name)) { channels.Remove(name); } if (hasChannel(channel.index)) { channels.Remove(channelIndexToName(channel.index)); } channels.AddOrReplace(channel.channelName, channel); } writeChannelsToFile(); } return(true); }
public void loadChannelsFromFile() { if (File.Exists(channelsPath) == false) { return; } lock (channels) { BinaryReader reader; try { reader = new BinaryReader(new FileStream(channelsPath, FileMode.Open)); } catch (Exception e) { Logging.error("Cannot open {0} file: {1}", channelsPath, e.Message); return; } try { int version = reader.ReadInt32(); int num_channels = reader.ReadInt32(); for (int i = 0; i < num_channels; i++) { int channel_len = reader.ReadInt32(); byte[] channel_bytes = reader.ReadBytes(channel_len); BotChannel bc = new BotChannel(channel_bytes); channels.AddOrReplace(bc.channelName, bc); } } catch (Exception e) { Logging.error("Cannot read from {0} file: {1}", channelsPath, e.Message); // TODO TODO notify the user or something like that } reader.Close(); } }