private void SetupSettings() { // Load at first time AppSettings = AppSettingsXML.LoadAppSettingsXml(); if (AppSettings.WatchedFolders.Length > 0) { foreach (var s in AppSettings.WatchedFolders) { WatchedFolders.Add(s); } } if (AppSettings.SpecifiedMmdObject.Length > 0) { foreach (var s in AppSettings.SpecifiedMmdObject) { SpecifiedMmdObjects.Add(new MMDObject( s, s.Remove(s.LastIndexOf("\\")), string.Empty) ); } } // Subscribe to event // Ignore the first time save WatchedFolders.ObserveCountChanged() .Do(_ => AppSettings.WatchedFolders = WatchedFolders.ToArray()) .Subscribe(_ => AppSettings.SaveToXml()); SpecifiedMmdObjects.ObserveCountChanged() .Do(_ => AppSettings.SpecifiedMmdObject = SpecifiedMmdObjects.Select(m => m.FilePath).ToArray()) .Subscribe(_ => AppSettings.SaveToXml()); }
public static AppSettingsXML LoadAppSettingsXml() { var path = $"{Application.temporaryCachePath}/AppSettings.xml"; if (File.Exists(path)) { var serializer = new XmlSerializer(typeof(AppSettingsXML)); var reader = new StreamReader(path); var res = serializer.Deserialize(reader) as AppSettingsXML; reader.Close(); return(res); } else { var xml = new AppSettingsXML { WatchedFolders = new string[] { }, SpecifiedMmdObject = new string[] { } }; xml.SaveToXml(); return(xml); } }