public static void saveSettings() { Settings4file st = new Settings4file(); st.imgDir = Settings.imgDir; st.openFolderButtonVisible = Settings.openFolderButtonVisible; st.useDB = Settings.useFeDB; if (Settings.useFeDB) { st.DBSrvIP = Settings.DBSrvIP; st.DBSrvPort = Settings.DBSrvPort; st.DBconnectID = Settings.DBconnectID; st.DBconnectPw = PasswordEncoder.Encrypt(Settings.DBconnectPw); } else { st.DBSrvIP = ""; st.DBSrvPort = ""; st.DBconnectID = ""; st.DBconnectPw = ""; } st.usePlugin = Settings.usePlugin; st.ptInfoPlugin = Settings.ptInfoPlugin; XmlSerializer xserializer = new XmlSerializer(typeof(Settings4file)); //Open file System.IO.FileStream fs1 = new System.IO.FileStream(Settings.settingFile_location, System.IO.FileMode.Create); xserializer.Serialize(fs1, st); fs1.Close(); #region Save to plugins.ini if (Settings.usePlugin && !String.IsNullOrWhiteSpace(Settings.ptInfoPlugin)) { string text = "Patient information=" + Settings.ptInfoPlugin + "\r\n"; StreamWriter sw = new StreamWriter(Application.StartupPath + @"\plugins.ini", false); sw.Write(text); sw.Close(); } #endregion }
public static void saveSettings() { Settings4file st = new Settings4file(); st.DBSrvIP = Settings.DBSrvIP; st.DBSrvPort = Settings.DBSrvPort; st.DBconnectID = Settings.DBconnectID; st.DBconnectPw = PasswordEncoder.Encrypt(Settings.DBconnectPw); //<バイナリファイルに書き込む> //BinaryFormatterオブジェクトを作成 BinaryFormatter bf1 = new BinaryFormatter(); //ファイルを開く System.IO.FileStream fs1 = new System.IO.FileStream(Settings.settingFile_location, System.IO.FileMode.Create); //シリアル化し、バイナリファイルに保存する bf1.Serialize(fs1, st); //閉じる fs1.Close(); }
//Read from file public static void readSettings() { if (System.IO.File.Exists(Settings.settingFile_location)) { Settings4file st = new Settings4file(); XmlSerializer xserializer = new XmlSerializer(typeof(Settings4file)); System.IO.FileStream fs2 = new System.IO.FileStream(Settings.settingFile_location, System.IO.FileMode.Open); try { st = (Settings4file)xserializer.Deserialize(fs2); fs2.Close(); } catch (InvalidOperationException) { DialogResult ret; ret = MessageBox.Show(Properties.Resources.SettingFileBroken, "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error); fs2.Close(); if (ret == DialogResult.Yes) { file_control.delFile(Settings.settingFile_location); } } Settings.imgDir = st.imgDir; Settings.openFolderButtonVisible = st.openFolderButtonVisible; Settings.useFeDB = st.useDB; Settings.usePlugin = st.usePlugin; Settings.DBSrvIP = st.DBSrvIP; Settings.DBSrvPort = st.DBSrvPort; Settings.DBconnectID = st.DBconnectID; Settings.DBconnectPw = PasswordEncoder.Decrypt(st.DBconnectPw); } }
public static void readSettings() { if (System.IO.File.Exists(Settings.settingFile_location)) { Settings4file st = new Settings4file(); //<バイナリファイルから読み込む> //BinaryFormatterオブジェクトの作成 BinaryFormatter bf2 = new BinaryFormatter(); //ファイルを開く System.IO.FileStream fs2 = new System.IO.FileStream(Settings.settingFile_location, System.IO.FileMode.Open); //バイナリファイルから読み込み、逆シリアル化する try { st = (Settings4file)bf2.Deserialize(fs2); fs2.Close(); } catch (InvalidOperationException) { DialogResult ret; ret = MessageBox.Show(Properties.Resources.SettingFileBroken, "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error); fs2.Close(); if (ret == DialogResult.Yes) { file_control.delFile(Settings.settingFile_location); } } Settings.DBSrvIP = st.DBSrvIP; Settings.DBSrvPort = st.DBSrvPort; Settings.DBconnectID = st.DBconnectID; Settings.DBconnectPw = PasswordEncoder.Decrypt(st.DBconnectPw); } }