/// <summary> /// 修改服务器列表配置数据 /// </summary> /// <param name="index">索引</param> /// <param name="data">服务器列表配置数据</param> public static void Modify(int index, ServerListConfigData data) { if (index >= 0 && index < ServerListConfig.DataList.Count) { ServerListConfig.DataList[index] = data; ServerListConfig.Save(); } }
/// <summary> /// 渠道列表选择改变响应 /// </summary> //protected void channelListBox_SelectedIndexChanged(object sender, EventArgs e) //{ // this.UpdateCurrentServerList(); //} /// <summary> /// 添加按钮点击响应 /// </summary> protected void addButton_Click(object sender, EventArgs e) { ServerListConfigData data = new ServerListConfigData(); this.UpdateData(data); ServerListConfig.Add(data); this.channelListBox.Items.Add(new ListItem(data.Name, data.Name)); this.channelListBox.SelectedIndex = channelListBox.Items.Count - 1; }
/// <summary> /// 修改按钮点击响应 /// </summary> protected void modifyButton_Click(object sender, EventArgs e) { if (this.channelListBox.SelectedIndex < 0) { return; } ServerListConfigData data = ServerListConfig.GetData(this.channelListBox.SelectedIndex); this.UpdateData(data); ServerListConfig.Modify(this.channelListBox.SelectedIndex, data); this.channelListBox.Items[this.channelListBox.SelectedIndex].Text = data.Name; }
/// <summary> /// 更新服务器列表配置数据 /// </summary> /// <param name="data">服务器列表配置数据</param> private void UpdateData(ServerListConfigData data) { data.Name = this.nameTextBox.Text; data.ChannelList.Clear(); string[] lineSet = this.channelTextBox.Text.Replace("\r\n", "\n").Split('\n'); foreach (var line in lineSet) { if (!string.IsNullOrEmpty(line)) { data.ChannelList.Add(line); } } }
/// <summary> /// 载入 /// </summary> public static void Load() { string configBinaryFile = HttpRuntime.AppDomainAppPath + "configs/ServerList.bytes"; if (!File.Exists(configBinaryFile)) { return; } using (FileStream stream = File.OpenRead(configBinaryFile)) { byte[] buffer = new byte[stream.Length]; stream.Read(buffer, 0, buffer.Length); for (int i = 0; i < stream.Length; ++i) { buffer[i] = (byte)(buffer[i] ^ 0x37); } using (BinaryReader reader = new BinaryReader(new MemoryStream(buffer))) { ushort count = reader.ReadUInt16(); for (int i = 0; i < count; ++i) { ServerListConfigData data = new ServerListConfigData(); data.Name = reader.ReadString(); byte channelCount = reader.ReadByte(); for (int j = 0; j < channelCount; ++j) { data.ChannelList.Add(reader.ReadString()); } byte serverCount = reader.ReadByte(); for (int j = 0; j < serverCount; ++j) { data.ServerList.Add(reader.ReadString(), reader.ReadBoolean()); } ServerListConfig.DataList.Add(data); } } } }
/// <summary> /// 更新当前显示的服务器列表 /// </summary> private void UpdateCurrentServerList() { if (this.channelListBox.SelectedIndex >= 0) { ServerListConfigData data = ServerListConfig.DataList[this.channelListBox.SelectedIndex]; this.nameTextBox.Text = data.Name; this.channelTextBox.Text = ""; foreach (var channel in data.ChannelList) { if (!string.IsNullOrEmpty(this.channelTextBox.Text)) { this.channelTextBox.Text += "\r\n"; } this.channelTextBox.Text += channel; } } else { this.nameTextBox.Text = ""; this.channelTextBox.Text = ""; } }
/// <summary> /// 添加服务器列表配置数据 /// </summary> /// <param name="data">服务器列表配置数据</param> public static void Add(ServerListConfigData data) { ServerListConfig.DataList.Add(data); ServerListConfig.Save(); }