public void Save(Options opt) { if (!File.Exists(_filename)) File.Create(_filename); try { MemoryStream memory = new MemoryStream(); BinaryFormatter binary = new BinaryFormatter(); binary.Serialize(memory, opt); memory.Position = 0; using (FileStream fStream = new FileStream(_filename, FileMode.Create)) using (GZipStream gStream = new GZipStream(fStream, CompressionMode.Compress)) memory.CopyTo(gStream); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.Message); } }
private void SaveSettings() { Options opt = new Options(); opt.SaveSettings = false; opt.SaveChat = false; if (cb_settingsSave.Checked) { opt.Host = tb_host.Text; opt.Port = tb_port.Text; opt.User = tb_user.Text; opt.Password = cb_settingsSavePW.Checked ? tb_pw.Text : ""; opt.SaveSettings = true; opt.SavePW = cb_settingsSavePW.Checked; opt.ReadSpeedIndex = (byte)cb_settingsReadSpeed.SelectedIndex; } if (cb_settingsSaveChat.Checked) // chat includes AutoResponse { opt.Nick = _b.ChatProcessor.Nick; opt.SaveChat = true; opt.EnableAutoResp = cb_chat_arEnable.Checked; opt.AutoResponseList = _b.AutoResponse.AutoResponseList; } _loadSaveHandler.Save(opt); }
public bool Load(out Options opt) { opt = new Options(); if (!File.Exists(_filename)) return false; try { MemoryStream memory = new MemoryStream(); using (FileStream fStream = new FileStream(_filename, FileMode.Open)) using (GZipStream gStream = new GZipStream(fStream, CompressionMode.Decompress)) gStream.CopyTo(memory); memory.Position = 0; BinaryFormatter binary = new BinaryFormatter(); opt = (Options)binary.Deserialize(memory); // tmp fix to avoid answering to old msgs (which were saved by the server) //opt.EnableAutoResp = false; return true; } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.Message); return false; } }