public void SaveOptions(string path) { try { OptionsSerializer os = new OptionsSerializer(); bool restart = false; foreach (OptionsControlBase page in mPages) { os.SOptions.Add(page.ControlledOption); if ((page.ControlledOption is EnvironmentOption)) { restart = true; } } os.SaveState(path); if (restart) { if (MessageBox.Show(this, "Environment has been changed. Restart Application?", "Environment setting", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.OK) { Environment.SetEnvironmentVariable("SPOCLIENT", ""); Application.Exit(); Process.Start(".\\PKStudioLauncher.exe"); } } } catch (Exception ex) { MessageBox.Show(Strings.ERROR_CANT_SAVE_OPTIONS + ": " + ex.Message, Strings.Error + "!", MessageBoxButtons.OK, MessageBoxIcon.Error); //throw; } }
static public OptionsSerializer BackState(string path) { BinaryFormatter bf = new BinaryFormatter(); OptionsSerializer os = null; using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read)) { os = bf.Deserialize(fs) as OptionsSerializer; } return(os); }
public void LoadOptions(string path) { try { OptionsSerializer os = OptionsSerializer.BackState(path); for (int i = 0; i < mPages.Count; i++) { for (int j = 0; j < os.SOptions.Count; j++) { if (mPages[i].ControlledOption.GetType() == os.SOptions[j].GetType()) { //mPages[i].Option = os.SOptions[j]; mPages[i].SetOption(os.SOptions[j]); } } } } catch (Exception) { //MessageBox.Show(Strings.ERROR_CANT_LOAD_OPTIONS, Strings.Error + "!", MessageBoxButtons.OK, MessageBoxIcon.Error); throw; } }
public void SaveOptions(string path) { try { OptionsSerializer os = new OptionsSerializer(); bool restart = false; foreach (OptionsControlBase page in mPages) { os.SOptions.Add(page.ControlledOption); if ((page.ControlledOption is EnvironmentOption)) { restart = true; } } os.SaveState(path); if (restart) { if (MessageBox.Show(this, "Environment has been changed. Restart Application?", "Environment setting", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.OK) { Environment.SetEnvironmentVariable("SPOCLIENT",""); Application.Exit(); Process.Start(".\\PKStudioLauncher.exe"); } } } catch (Exception ex) { MessageBox.Show(Strings.ERROR_CANT_SAVE_OPTIONS + ": " + ex.Message, Strings.Error + "!", MessageBoxButtons.OK, MessageBoxIcon.Error); //throw; } }