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()); }
/// <summary> /// Define observe /// </summary> private void ObservableSettings() { // Handle add new // TODO: Add filter var watchNew = WatchedFolders.ObserveAdd(); // Get pmx objects watchNew.Subscribe(x => GetMmdObjects(x.Value)); // Handle watch events //watchNew.Select(x => new FileSystemWatcher(x.Value)) // .Do(x => x.Created += (_, __) => { }) // .Do(x => x.Changed += (_, __) => { }) // .Do(x => x.Deleted += (_, __) => { }) // .Subscribe(x => FileSystemWatchers.Add(x)); // Handle remove var folderRemove = WatchedFolders.ObserveRemove(); folderRemove .SelectMany(x => ObservedMMDObjects.ToList() .Where(f => f.WatchedFolder == x.Value)) .ForEachAsync(x => ObservedMMDObjects.Remove(x)) .Subscribe(); //folderRemove.Select(x => FileSystemWatchers.Where(f => f.Path == x.Value).FirstOrDefault()) // .Do(x => x.Dispose()) // .Subscribe(x => FileSystemWatchers.Remove(x)); Observable.Timer(TimeSpan.FromSeconds(1)) .Subscribe(_ => { GameObject.Find("MMDRenderer").GetComponent <PreviewBuilder.PreviewBuilder>().OnRenderComplete += () => { System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor; ObservedMMDObjects.Clear(); Debug.Log("Reload"); foreach (var watchedFolder in WatchedFolders) { GetMmdObjects(watchedFolder); } System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default; }; }); }