Exemple #1
0
        protected override void Populate()
        {
            try
            {
                if (_pages == null)
                {
                    DirectoryEntries files = new DirectoryEntries(this.Path, "*");
                    var pages = new List <BblPage>();
                    using (FastDirectoryEnumerator fde = (FastDirectoryEnumerator)files.GetEnumerator())
                    {
                        while (fde.MoveNext())
                        {
                            _cancelPopulateTask.Token.ThrowIfCancellationRequested();

                            var data = fde.Current;
                            if ((data.dwFileAttributes & FileAttributes.Directory) == FileAttributes.Directory)
                            {
                                continue;
                            }
                            string path = System.IO.Path.Combine(Path, data.cFileName);
                            string ext  = System.IO.Path.GetExtension(path);
                            if (IsImageFileExtension(ext))
                            {
                                BblPage page = new BblPage(this);
                                page.Filename       = data.cFileName;
                                page.Path           = System.IO.Path.Combine(Path, data.cFileName);
                                page.Size           = data.Length;
                                page.CreationTime   = data.CreationTime;
                                page.LastAccessTime = data.LastAccessTime;
                                page.LastWriteTime  = data.LastWriteTime;


                                lock (_lock) { pages.Add(page); }
                            }
                        }
                    }
                    if (pages.Count == 0)
                    {
                        return;
                    }
                    pages.Sort();
                    lock (_lock) { _pages = new ObservableCollection <BblPage>(pages); }
                }
            }
            catch { UnPopulate(); }
        }
Exemple #2
0
 /// 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));
     }
 }
Exemple #3
0
 protected override void Populate()
 {
     try
     {
         _cancelPopulateTask.Token.ThrowIfCancellationRequested();
         if (_pages == null)
         {
             int count;
             var pages = new List <BblPage>();
             using (PdfDocument doc = new PdfDocument(Path))
             {
                 count = doc.PageCount();
             }
             if (count >= 0)
             {
                 for (int i = 0; i < count; i++)
                 {
                     _cancelPopulateTask.Token.ThrowIfCancellationRequested();
                     BblPage p = new BblPage(this);
                     p.Filename       = "page " + (i + 1).ToString();
                     p.Size           = 0;
                     p.LastAccessTime = LastAccessTime;
                     p.LastWriteTime  = LastWriteTime;
                     p.CreationTime   = CreationTime;
                     p.Path           = Path + "::_" + (i + 1).ToString();
                     pages.Add(p);
                 }
             }
             else
             {
                 return;
             }
             lock (_lock) { _pages = new ObservableCollection <BblPage>(pages); }
         }
     }
     catch { UnPopulate(); }
 }
Exemple #4
0
        // 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);
        }