/// this runs on a FileSystemWatcher thread /// Inserts a new page, preserving sort order. public override BblLibraryNode AddChildFile(FileInfoEx info) { if (IsImageFileExtension(info.Extension)) { if (_demoted) { _demoted = false; Root.OnBookOperation(new BookOperationData(this, BookOperations.Add, null)); } else if (IsPopulated) { BblPage p = new BblPage(this); p.SetInfo(info); string name = info.Name; Application.Current.Dispatcher.BeginInvokeIfRequired( DispatcherPriority.Normal, new Action(() => { lock (_lock) { int idx = 0; for (; idx < _pages.Count; idx++) { if (Utils.SafeNativeMethods.StrCmpLogicalW(_pages[idx].Filename, name) >= 0) { break; } } _pages.Insert(idx, p); } } )); } //string pop = (IsPopulated) ? "Pop ||" : "NoPop ||"; //string exist = (info.Exists) ? "exists" : "no exist"; //string s = info.Name + " processed! ||" + pop + exist; //Console.WriteLine(s); return(this); } else { return(base.AddChildFile(info)); } }
// This runs on FileSystemWatcher thread public bool OnPageFileRenamed(FileInfoEx oldPath, FileInfoEx newPath) { ImageViewingParams ivp = new ImageViewingParams(); ivp.Reset(); BblPage oldPage = null; BblPage newPage = null; if (IsPopulated) { oldPage = _pages.Where(x => x.Path == oldPath.FullName).FirstOrDefault(); ivp = oldPage.Ivp; newPage = new BblPage(this); newPage.SetInfo(newPath); Application.Current.Dispatcher.BeginInvokeIfRequired( DispatcherPriority.Normal, new Action(() => { lock (_lock) { _pages.Remove(oldPage); int idx = 0; for (; idx < _pages.Count; idx++) { if (Utils.SafeNativeMethods.StrCmpLogicalW(_pages[idx].Filename, newPath.Name) >= 0) { break; } } _pages.Insert(idx, newPage); } })); } if ((ivp != null && ivp.isDirty) || (_ivps != null && _ivps.TryGetValue(oldPath.Name, out ivp))) { ivp.filename = newPath.Name; if (newPage != null) { lock (newPage._lock) newPage.Ivp = ivp; } if (_ivps != null) { _ivps.Remove(oldPath.Name); if (!_ivps.ContainsKey(newPath.Name)) { try { _ivps.Add(newPath.Name, ivp); } catch (System.ArgumentException e) { if ((UInt32)e.HResult != 0x80070057) { Console.WriteLine(e.Message); } } catch (Exception x) { Console.WriteLine(x.Message); } } } } return(false); }