コード例 #1
0
        internal BaseFile GetFile(PlainFolder aParent, FileInfo info)
        {
            BaseFile item;

            lock (ids) {
                item = ids.GetItemByPath(info.FullName) as BaseFile;
            }
            if (item != null && item.InfoDate == info.LastAccessTimeUtc && item.InfoSize == info.Length)
            {
                return(item);
            }

            var ext       = re_sansitizeExt.Replace(info.Extension.ToLower().Substring(1), string.Empty);
            var type      = DlnaMaps.Ext2Dlna[ext];
            var mediaType = DlnaMaps.Ext2Media[ext];

            if (store != null)
            {
                item = store.MaybeGetFile(this, info, type);
                if (item != null)
                {
                    return(item);
                }
            }

            return(BaseFile.GetFile(aParent, info, type, mediaType));
        }
コード例 #2
0
ファイル: FileServer.cs プロジェクト: AlexAkulov/simpleDLNA
        internal BaseFile GetFile(PlainFolder aParent, FileInfo info)
        {
            BaseFile item;

            lock (ids) {
                item = ids.GetItemByPath(info.FullName) as BaseFile;
            }
            if (item != null &&
                item.InfoDate == info.LastAccessTimeUtc &&
                item.InfoSize == info.Length)
            {
                return(item);
            }

            var ext = re_sansitizeExt.Replace(
                info.Extension.ToUpperInvariant().Substring(1),
                string.Empty
                );
            var type      = DlnaMaps.Ext2Dlna[ext];
            var mediaType = DlnaMaps.Ext2Media[ext];

            if (store != null)
            {
                item = store.MaybeGetFile(this, info, type);
                if (item != null)
                {
                    lock (this) {
                        pendingFiles.Add(new WeakReference(item));
                    }
                    return(item);
                }
            }

            lock (this) {
                var rv = BaseFile.GetFile(aParent, info, type, mediaType);
                pendingFiles.Add(new WeakReference(rv));
                return(rv);
            }
        }
コード例 #3
0
        private void OnChanged(object source, FileSystemEventArgs e)
        {
            try {
                watcherRestartCount = 0;
                if (store != null &&
                    icomparer.Equals(e.FullPath, store.StoreFile.FullName))
                {
                    return;
                }
                var ext = string.Empty;
                if (!string.IsNullOrEmpty(e.FullPath))
                {
                    ext = Path.GetExtension(e.FullPath);
                    ext = string.IsNullOrEmpty(ext) ? string.Empty : ext.Substring(1);
                }
                if (!Filter.Filtered(ext))
                {
                    // Check if this is a meta data filter file and there are files in the same folder
                    if (MetaFilter.Filtered(ext) && e.ChangeType != WatcherChangeTypes.Deleted)
                    {
                        var affectedFiles = Directory.GetFiles(Path.GetDirectoryName(e.FullPath)).Where(f => Filter.Filtered(Path.GetExtension(f).Substring(1)));
                        var refreshFiles  = new ConcurrentQueue <WeakReference>();
                        foreach (var file in affectedFiles)
                        {
                            // Add the files to the pending files list
                            var type = DlnaMaps.Ext2Dlna[Path.GetExtension(file).ToUpperInvariant().Substring(1)];
                            if (store != null)
                            {
                                var item = store.MaybeGetFile(this, new FileInfo(file), type);
                                if (item != null)
                                {
                                    refreshFiles.Enqueue(new WeakReference(item));
                                }
                            }
                        }
                        BackgroundCacher.AddFiles(store, refreshFiles);

                        DebugFormat("Found {0} affected files from metadata file {1}", affectedFiles.Count(), e.FullPath);
                    }
                    else
                    {
                        DebugFormat(
                            "Skipping name {0} {1}",
                            e.Name, Path.GetExtension(e.FullPath));
                    }
                    return;
                }
                DebugFormat(
                    "File System changed ({1}): {0}", e.FullPath, e.ChangeType);
                lock (ids) {
                    var master = ids.GetItemById(Identifiers.GENERAL_ROOT) as VirtualFolder;
                    if (master != null)
                    {
                        switch (e.ChangeType)
                        {
                        case WatcherChangeTypes.Changed:
                            if (HandleFileDeleted(e.FullPath, master) && HandleFileAdded(e.FullPath))
                            {
                                ReaddRoot(master);
                                return;
                            }
                            break;

                        case WatcherChangeTypes.Created:
                            if (HandleFileAdded(e.FullPath))
                            {
                                ReaddRoot(master);
                                return;
                            }
                            break;

                        case WatcherChangeTypes.Deleted:
                            if (HandleFileDeleted(e.FullPath, master))
                            {
                                ReaddRoot(master);
                                return;
                            }
                            break;
                        }
                    }
                }
                DelayedRescan(e.ChangeType);
            }
            catch (Exception ex) {
                Error("OnChanged failed", ex);
            }
        }