Beispiel #1
0
 public static bool Equals(RawSettings a, RawSettings b)
 {
     return(
         Enumerable.SequenceEqual(a.AdNames, b.AdNames) &&
         Enumerable.SequenceEqual(a.AdKeywords, b.AdKeywords) &&
         Enumerable.SequenceEqual(a.SongNames, b.SongNames) &&
         a.OutputFormat == b.OutputFormat &&
         a.OutputFolder == b.OutputFolder &&
         a.TempFolder == b.TempFolder &&
         a.SongRefreshInterval == b.SongRefreshInterval
         );
 }
Beispiel #2
0
 /// <summary>
 /// Note: Creates a new XElement on-demand - it is not cached (so is safe to mutate).
 /// </summary>
 public static XElement ToXml(RawSettings s)
 {
     return(new XElement(
                "settings",
                new XElement("adNames", s.AdNames.Select(x => new XElement("name", x))),
                new XElement("adKeywords", s.AdKeywords.Select(x => new XElement("keyword", x))),
                new XElement("songNames", s.SongNames.Select(x => new XElement("name", x))),
                new XElement("outputFormat", s.OutputFormat.ToString()),
                new XElement("outputFolder", s.OutputFolder),
                new XElement("tempFolder", s.TempFolder),
                new XElement("songRefreshInterval", s.SongRefreshInterval)
                ));
 }
Beispiel #3
0
        public static RawSettings Load(string settingsFolder, Logger logger)
        {
            logger.Log("Loading settings from folder '" + settingsFolder + "'.");

            if (settingsFolder == null)
            {
                throw new ArgumentNullException(nameof(settingsFolder));
            }

            var settingsFilePath    = Path.Combine(settingsFolder, SettingsFileName);
            var oldSettingsFilePath = Path.Combine(settingsFolder, OldSettingsFileName);

            if (!File.Exists(settingsFilePath))
            {
                if (!File.Exists(oldSettingsFilePath))
                {
                    return(LoadDefaultSettings());
                }
                File.Move(oldSettingsFilePath, settingsFilePath);
            }

            using (var fs = File.OpenRead(settingsFilePath))
            {
                var res = RawSettings.FromXml(
                    XDocument.Load(fs).Root
                    );
                logger.Log("Sucessfully loaded saved settings.");
                return(res);
            }

            RawSettings LoadDefaultSettings()
            {
                logger.Log("No saved settings found; reverting to default settings.");

                var defaultSettings = RawSettings.Default;

                RawSettings.ToXml(defaultSettings).Save(settingsFilePath);

                logger.Log("Retrieved and saved default settings.");

                return(defaultSettings);
            }
        }