コード例 #1
0
 private static void AddDatabaseImageEntry(GalleryDatabase galleryDatabase, MediaFile mediaFile, bool reScan, string fileName)
 {
     if (reScan || !galleryDatabase.EntryExists(fileName, mediaFile.DatabasePath))
     {
         galleryDatabase.UpdateEntry(fileName, mediaFile.DatabasePath, mediaFile);
     }
 }
コード例 #2
0
        private static void AddDatabaseImageEntry(GalleryDatabase galleryDatabase, MediaFile mediaFile, bool reScan)
        {
            //string path = Path.Combine(mediaFile.Source.ID, mediaFile.RelativePath);

            if (mediaFile is VideoFile)
            {
                AddDatabaseImageEntry(galleryDatabase, mediaFile, reScan, mediaFile.PreviewName);
            }

            AddDatabaseImageEntry(galleryDatabase, mediaFile, reScan, mediaFile.ThumbnailName);
        }
コード例 #3
0
 public static void ScanFolders(GalleryDatabase galleryDatabase, GallerySource source, bool reScan)
 {
     try
     {
         ClearWorkingDirectory();
         int folderCount = 0, fileCount = 0;
         ScanSubFolder(galleryDatabase, source, source.RootFolder, reScan, ref folderCount, ref fileCount, 0);
     }
     finally
     {
         ClearWorkingDirectory();
     }
 }
コード例 #4
0
        private static bool ScanSubFolder(GalleryDatabase galleryDatabase, GallerySource source, MediaFolder folder,
                                          bool reScan, ref int folderCount, ref int fileCount, int depth)
        {
            try
            {
                folderCount++;
                RaiseStatusUpdatedEvent("Scanning folder #" + folderCount + " at depth " + depth + ", found " + fileCount + " files...");
                GetFolders(source, folder);
                GetFiles(galleryDatabase, source, folder, reScan);

                if (folder.SubFolders.Count == 0 && folder.Files.Count == 0)
                {
                    return(false);
                }

                RaiseMediaFolderAddedEvent(folder);
                depth++;
                fileCount += folder.Files.Count;
                List <MediaFolder> emptyFolders = new List <MediaFolder>();
                foreach (MediaFolder subFolder in folder.SubFolders)
                {
                    if (!ScanSubFolder(galleryDatabase, source, subFolder, reScan, ref folderCount, ref fileCount, depth))
                    {
                        emptyFolders.Add(subFolder);
                    }
                }
                foreach (MediaFolder emptyFolder in emptyFolders)
                {
                    folder.SubFolders.Remove(emptyFolder);
                }

                if (folder.SubFolders.Count == 0 && folder.Files.Count == 0)
                {
                    RaiseMediaFolderRemovedEvent(folder);
                    return(false);
                }
            }
            catch { }
            return(true);
        }
コード例 #5
0
        private static void GetFiles(GalleryDatabase galleryDatabase, GallerySource source, MediaFolder parentFolder, bool reScan)
        {
            List <string> files = Directory.GetFiles(Path.Combine(source.RootedPath, parentFolder.RelativePathName)).ToList();

            files.Sort();
            foreach (string file in files)
            {
                try
                {
                    string   extension    = Path.GetExtension(file).ToLower();
                    string   fileName     = Path.GetFileName(file);
                    string   relativePath = RemoveAbsolutePath(Path.GetDirectoryName(file), source.RootedPath);
                    FileInfo fileInfo     = new FileInfo(file);
                    if (MediaFile.IMAGE_FILE_EXTENSIONS.Contains(extension))
                    {
                        if (!files.Any(filePath => (Path.GetFileName(filePath) == Path.GetFileNameWithoutExtension(file))))
                        {
                            ImageFile imageFile = new ImageFile(fileName, relativePath, parentFolder, source)
                            {
                                FileSize = fileInfo.Length
                            };
                            try
                            {
                                imageFile.Size = ImageFileHelper.GetDimensions(file);
                            }
                            catch {}
                            int existingIndex = parentFolder.Files.FindIndex(mediaFile => mediaFile.Name == fileName);
                            if (existingIndex != -1)
                            {
                                parentFolder.Files.RemoveAt(existingIndex);
                            }
                            parentFolder.Files.Add(imageFile);
                            AddDatabaseImageEntry(galleryDatabase, imageFile, reScan);
                        }
                    }
                    else if (MediaFile.VIDEO_FILE_EXTENSIONS.Contains(extension))
                    {
                        VideoFile videoFile = new VideoFile(fileName, relativePath, parentFolder, source)
                        {
                            FileSize = fileInfo.Length
                        };
                        try
                        {
                            TagLib.File tagFile = TagLib.File.Create(file);
                            videoFile.Duration = tagFile.Properties.Duration;
                            videoFile.Size     = new Size(tagFile.Properties.VideoWidth, tagFile.Properties.VideoHeight);
                            foreach (TagLib.ICodec codec in tagFile.Properties.Codecs)
                            {
                                MediaCodec mediaCodec = new MediaCodec(MediaCodec.TranslateCodecType(codec.MediaTypes), codec.Description);
                                if (source.Gallery.Codecs.Contains(mediaCodec))
                                {
                                    mediaCodec = source.Gallery.Codecs.First(x => x.Equals(mediaCodec));
                                }
                                else
                                {
                                    source.Gallery.Codecs.Add(mediaCodec);
                                }
                                videoFile.Codecs.Add(mediaCodec);
                            }
                        }
                        catch {}
                        int existingIndex = parentFolder.Files.FindIndex(mediaFile => mediaFile.Name == fileName);
                        if (existingIndex != -1)
                        {
                            parentFolder.Files.RemoveAt(existingIndex);
                        }
                        parentFolder.Files.Add(videoFile);
                        AddDatabaseImageEntry(galleryDatabase, videoFile, reScan);
                    }
                }
                catch {}
            }
        }