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 = ""; } 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(); }
//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); } }