Example #1
0
 private Dictionary <string, string> GetFileDescription(FileInfo fi, Models.File file)
 {
     return(_pluginManager.GetDescriptions(
                fi.FullName,
                (file == null) || (file.ModifiedDateUtc != fi.LastWriteTimeUtc),
                file?.Data));
 }
Example #2
0
 public Models.File GetFile(FileInfo fi, Models.File file)
 {
     return(new Models.File()
     {
         Name = fi.Name,
         FileSize = fi.Length,
         CreatedDateUtc = fi.CreationTimeUtc,
         ModifiedDateUtc = fi.LastWriteTimeUtc,
         Data = GetFileDescription(fi, file)
     });
 }
        private void FileChanged(object sender, FileSystemEventArgs e)
        {
            DirectoryInfo parent = new DirectoryInfo(Path.GetDirectoryName(e.FullPath));

            if (IsItemInFilteredFolder(parent))
            {
                return;
            }

            DriveModel drive = Drives[parent.Root.Name];

            lock (drive) {
                switch (e.ChangeType)
                {
                case WatcherChangeTypes.Created:
                case WatcherChangeTypes.Changed:
                    // There may be folder changed events coming in with LastWrite filter
                    IfParentFolderExists(parent, drive, folder => {
                        FileInfo fi = new FileInfo(e.FullPath);
                        if (fi.Exists)
                        {
                            WatFile file = folder.Files.SingleOrDefault(f => f.NameEquals(fi.Name));
                            if (file != null)
                            {
                                folder.Files.Remove(file);
                            }
                            if (fi.ShouldScan())
                            {
                                folder.Files.Add(App.Scanner.GetFile(fi, file));
                                folder.Files.Sort();
                            }
                            RaiseChange(drive);
                        }
                    });
                    break;

                case WatcherChangeTypes.Deleted:
                    IfParentFolderExists(parent, drive, folder => {
                        int removed = folder.Files.RemoveAll(f => f.NameEquals(Path.GetFileName(e.Name)));
                        if (removed > 0)
                        {
                            RaiseChange(drive);
                        }
                    });
                    break;

                case WatcherChangeTypes.Renamed:
                    IfParentFolderExists(parent, drive, folder => {
                        RenamedEventArgs rea = (RenamedEventArgs)e;
                        WatFile oldFile      = folder.Files.SingleOrDefault(f => f.NameEquals(Path.GetFileName(rea.OldName)));
                        FileInfo fi          = new FileInfo(e.FullPath);
                        if (oldFile != null)
                        {
                            folder.Files.Remove(oldFile);
                        }
                        if (fi.ShouldScan())
                        {
                            folder.Files.Add(App.Scanner.GetFile(fi, oldFile));
                            folder.Files.Sort();
                        }
                        RaiseChange(drive);
                    });
                    break;
                }
            }
        }