Beispiel #1
0
        private void SaveSettings(int report)
        {
            //if (report == 1)
            //    WriteConsole(ConsoleTypes.SYSTEM, "Saving states to settings.chromatics..");
            var popSettings = new PoptartSettings();
            var enviroment  = new FileInfo(Assembly.GetExecutingAssembly().Location).DirectoryName;
            var path        = enviroment + @"/settings.poptart";

            popSettings = PoptartSettings;

            try
            {
                using (var sw = new StreamWriter(path, false))
                {
                    var x = new XmlSerializer(popSettings.GetType());
                    x.Serialize(sw, popSettings);
                    sw.WriteLine();
                    sw.Close();
                }

                //if (report == 1)
                //    WriteConsole(ConsoleTypes.SYSTEM, "Saved states to settings.chromatics.");
            }
            catch (Exception ex)
            {
                Console.WriteLine(@"Error saving states to settings.poptart. Error: " + ex.Message);
            }
        }
Beispiel #2
0
        private void LoadSettings()
        {
            Console.WriteLine(@"Searching for settings.poptart..");
            var enviroment = new FileInfo(Assembly.GetExecutingAssembly().Location).DirectoryName;
            var path       = enviroment + @"/settings.poptart";

            if (File.Exists(path))
            {
                //Read Device Save
                Console.WriteLine(@"Attempting to load settings.poptart..");
                using (var sr = new StreamReader(path))
                {
                    try
                    {
                        var reader      = new XmlSerializer(PoptartSettings.GetType());
                        var popSettings = (PoptartSettings)reader.Deserialize(sr);
                        sr.Close();

                        PoptartSettings = popSettings;

                        Console.WriteLine(@"settings.poptart loaded.");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(@"Error loading settings.poptart. Error: " + ex.Message);
                    }
                }
            }
            else
            {
                //Create Device Save
                Console.WriteLine(@"settings.poptart not found. Creating one..");
                try
                {
                    using (var sw = new StreamWriter(path))
                    {
                        var x = new XmlSerializer(PoptartSettings.GetType());
                        x.Serialize(sw, PoptartSettings);
                        sw.WriteLine();
                        sw.Close();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(@"Error creating settings.poptart. Error: " + ex.Message);
                }
            }
        }