Пример #1
0
        public static void Reset()
        {
            Logging.WriteBannerToLog("Reset");

            Default = new SettingsImpl();

            Logging.WriteLineToLog("Settings reset to default.");
        }
Пример #2
0
        public static void Load()
        {
            Logging.WriteBannerToLog("Load");

            string file = Path.Combine(Environment.GetFolderPath(
                                           Environment.SpecialFolder.ApplicationData),
                                       "crtcpl", "config.xml");

            Logging.WriteLineToLog("Settings file is at: {0}", file);

            if (!File.Exists(file))
            {
                Logging.WriteLineToLog("Settings file does not exist.");
                Reset();
                return;
            }

            XmlSerializer serializer = new XmlSerializer(typeof(SettingsImpl));

            try
            {
                Logging.WriteLineToLog("Deserialize settings XML now...");

                using (FileStream fs = File.OpenRead(file))
                {
                    Default = (SettingsImpl)serializer.Deserialize(fs);
                    fs.Close();
                }
            }
            catch (InvalidOperationException e)
            {
                Logging.WriteLineToLog("Unable to load settings: {0}", e);
                Reset();
            }
            catch (IOException e)
            {
                Logging.WriteLineToLog("Unable to load settings: {0}", e);
                Reset();
            }
            catch (UnauthorizedAccessException e)
            {
                Logging.WriteLineToLog("Unable to load settings: {0}", e);
                Reset();
            }

            Logging.WriteLineToLog("Loaded settings OK!");
        }