Beispiel #1
0
        public static void SaveSettings(Calib config, string sFile)
        {
            int pos = sFile.LastIndexOf("\\");
            string sDir = sFile.Substring(0, pos);

            if (!Directory.Exists(sDir))
                Directory.CreateDirectory(sDir);

            if (File.Exists(sFile))
                File.Delete(sFile);

            XmlSerializer xs = new XmlSerializer(typeof(Calib));
            Stream stream = new FileStream(sFile, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.ReadWrite);
            xs.Serialize(stream, config);
            stream.Close();
        }
Beispiel #2
0
 public static void LoadSettings(ref Calib config, string sFile)
 {
     if (!File.Exists(sFile))
         throw new FileNotFoundException(string.Format("位于:{0}的配置文件不存在", sFile));
     Stream stream = new FileStream(sFile, FileMode.Open, FileAccess.Read, FileShare.Read);
     try
     {
         XmlSerializer xs = new XmlSerializer(typeof(Calib));
         config = xs.Deserialize(stream) as Calib;
     }
     catch(Exception ex)
     {
         MessageBox.Show("Falied to load the setting: " + ex.Message);
     }
     stream.Close();
 }