示例#1
0
        void watcher_Renamed(object sender, RenamedEventArgs e)
        {
            MPTVSeriesLog.Write("File Watcher: Renamed event: " + e.OldFullPath + " to " + e.FullPath);

            List <PathPair> filesToRemove     = new List <PathPair>();
            List <PathPair> filesToAdd        = new List <PathPair>();
            bool            isDirectoryRename = false;

            if (Directory.Exists(e.FullPath))
            {
                isDirectoryRename = true;

                List <string> folder = new List <string>();
                folder.Add(e.FullPath);
                filesToAdd = Filelister.GetFiles(folder);

                foreach (PathPair pathPair in filesToAdd)
                {
                    filesToRemove.Add(new PathPair(pathPair.m_sMatch_FileName, pathPair.m_sFull_FileName.Replace(e.FullPath, e.OldFullPath)));
                }
            }

            // rename: delete the old, add the new
            lock (m_modifiedFilesList)
            {
                if (isDirectoryRename)
                {
                    foreach (PathPair pathPair in filesToRemove)
                    {
                        removeFromModifiedFilesList(pathPair.m_sFull_FileName, WatcherItemType.Added, false);
                        m_modifiedFilesList.Add(new WatcherItem(pathPair, WatcherItemType.Deleted));
                    }
                    foreach (PathPair pathPair in filesToAdd)
                    {
                        removeFromModifiedFilesList(pathPair.m_sFull_FileName, WatcherItemType.Deleted, false);
                        m_modifiedFilesList.Add(new WatcherItem(pathPair, WatcherItemType.Added));
                    }
                }
                else
                {
                    String sOldExtention = System.IO.Path.GetExtension(e.OldFullPath);
                    if (MediaPortal.Util.Utils.VideoExtensions.IndexOf(sOldExtention) != -1)
                    {
                        removeFromModifiedFilesList(e.OldFullPath, WatcherItemType.Added, false);
                        m_modifiedFilesList.Add(new WatcherItem(sender as FileSystemWatcher, e, true));
                    }
                    String sNewExtention = System.IO.Path.GetExtension(e.FullPath);
                    if (MediaPortal.Util.Utils.VideoExtensions.IndexOf(sNewExtention) != -1)
                    {
                        removeFromModifiedFilesList(e.FullPath, WatcherItemType.Deleted, false);
                        m_modifiedFilesList.Add(new WatcherItem(sender as FileSystemWatcher, e, false));
                    }
                }
            }
        }
示例#2
0
        void DoFileScan(List <String> scannedFolders, ref List <PathPair> previousScan)
        {
            MPTVSeriesLog.Write("File Watcher: Performing File Scan on Import Paths for changes", MPTVSeriesLog.LogLevel.Normal);

            // Check if Fullscreen Video is active as this can cause stuttering/dropped frames
            if (!DBOption.GetOptions(DBOption.cImportScanWhileFullscreenVideo) && Helper.IsFullscreenVideo)
            {
                MPTVSeriesLog.Write("File Watcher: Fullscreen Video has been detected, aborting file scan");
                return;
            }

            List <PathPair> newScan = Filelister.GetFiles(scannedFolders);

            List <PathPair> addedFiles = new List <PathPair>();

            addedFiles.AddRange(newScan);

            foreach (PathPair pair in previousScan)
            {
                addedFiles.RemoveAll(item => item.m_sFull_FileName == pair.m_sFull_FileName);
            }

            List <PathPair> removedFiles = new List <PathPair>();

            removedFiles.AddRange(previousScan);
            foreach (PathPair pair in newScan)
            {
                removedFiles.RemoveAll(item => item.m_sFull_FileName == pair.m_sFull_FileName);
            }

            lock (m_modifiedFilesList)
            {
                foreach (PathPair pair in addedFiles)
                {
                    m_modifiedFilesList.Add(new WatcherItem(pair, WatcherItemType.Added));
                }

                foreach (PathPair pair in removedFiles)
                {
                    m_modifiedFilesList.Add(new WatcherItem(pair, WatcherItemType.Deleted));
                }
            }

            previousScan = newScan;

            MPTVSeriesLog.Write("File Watcher: Finished File Scan on Import Paths", MPTVSeriesLog.LogLevel.Normal);
        }
示例#3
0
        void workerWatcher_DoWork(object sender, DoWorkEventArgs e)
        {
            System.Threading.Thread.CurrentThread.Priority = ThreadPriority.Lowest;

            // delay the start of file monitoring for a small period
            // this doesnt really need a config setting but can be manually overridden in DB option
            // purpose of the delay is to allow network devices to get ready after fresh boot from windows
            // and resume from standby...benifits UNC shares as Mapped drives are picked up from Device Manager events.
            // also DoFileScan can be expensive, so we dont want to do this on startup while other plugins/background tasks
            // are running as well.
            Thread.Sleep((int)DBOption.GetOptions(DBOption.cDelayImportPathMonitoringValue) * 1000);

            MPTVSeriesLog.Write("File Watcher: Starting File System Watcher Background Task", MPTVSeriesLog.LogLevel.Normal);
            setUpWatches();

            // do the initial scan
            m_PreviousScan          = Filelister.GetFiles(m_ScannedFolders);
            m_PreviousScanRemovable = Filelister.GetFiles(GetDeviceManagerWatchedFolders());

            DateTime timeLastScan = DateTime.Now;

            // then start the watcher loop
            while (!worker.CancellationPending)
            {
                TimeSpan tsUpdate = DateTime.Now - timeLastScan;
                if ((int)tsUpdate.TotalMinutes >= m_nScanLapse)
                {
                    timeLastScan = DateTime.Now;
                    DoFileScan();
                }

                signalModifiedFiles();

                if (refreshWatchers)
                {
                    setUpWatches();
                }

                Thread.Sleep(1000);
            }
        }
示例#4
0
        private void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            System.Threading.Thread.CurrentThread.Priority = System.Threading.ThreadPriority.Lowest;
            List <String> listFolders = new List <string>();

            DBImportPath[] importPathes = DBImportPath.GetAll();
            if (importPathes != null)
            {
                foreach (DBImportPath importPath in importPathes)
                {
                    if (importPath[DBImportPath.cEnabled] != 0)
                    {
                        listFolders.Add(importPath[DBImportPath.cPath]);
                    }
                }
            }
            List <PathPair> files = Filelister.GetFiles(listFolders);

            MPTVSeriesLog.Write("Found " + files.Count.ToString() + " supported video files in your import paths");
            e.Result = Parse(files);
        }
示例#5
0
        void watcher_Changed(object sender, FileSystemEventArgs e)
        {
            MPTVSeriesLog.Write("File Watcher: Changed event: " + e.FullPath);

            List <PathPair> filesChanged      = new List <PathPair>();
            bool            isDirectoryChange = false;

            if (Directory.Exists(e.FullPath))
            {
                isDirectoryChange = true;

                List <string> folder = new List <string>();
                folder.Add(e.FullPath);
                filesChanged = Filelister.GetFiles(folder);
            }

            // a file has changed! created, not created, whatever. Just add it to our list.
            // we only process this list once in a while
            lock (m_modifiedFilesList)
            {
                if (e.ChangeType == WatcherChangeTypes.Deleted)
                {
                    removeFromModifiedFilesList(e.FullPath, WatcherItemType.Added, true);

                    SQLCondition     condition  = new SQLCondition(new DBEpisode(), DBEpisode.cFilename, e.FullPath + "\\%", SQLConditionType.Like);
                    List <DBEpisode> dbepisodes = DBEpisode.Get(condition, false);
                    if (dbepisodes != null && dbepisodes.Count > 0)
                    {
                        foreach (DBEpisode dbepisode in dbepisodes)
                        {
                            m_modifiedFilesList.Add(new WatcherItem(new PathPair(dbepisode[DBEpisode.cFilename].ToString().Substring(e.FullPath.Length).TrimStart('\\'), dbepisode[DBEpisode.cFilename]), WatcherItemType.Deleted));
                        }
                    }
                }

                if (isDirectoryChange)
                {
                    foreach (PathPair pathPair in filesChanged)
                    {
                        removeFromModifiedFilesList(pathPair.m_sFull_FileName, WatcherItemType.Deleted, false);
                        m_modifiedFilesList.Add(new WatcherItem(pathPair, WatcherItemType.Added));
                    }
                }
                else
                {
                    /* duplicates are removed later
                     * foreach (WatcherItem item in m_modifiedFilesList)
                     * {
                     *  if (item.m_sFullPathFileName == e.FullPath)
                     *      return;
                     * }
                     */

                    String sExtention = System.IO.Path.GetExtension(e.FullPath);
                    if (MediaPortal.Util.Utils.VideoExtensions.IndexOf(sExtention) != -1)
                    {
                        if (e.ChangeType == WatcherChangeTypes.Deleted)
                        {
                            removeFromModifiedFilesList(e.FullPath, WatcherItemType.Added, false);
                        }
                        else
                        {
                            removeFromModifiedFilesList(e.FullPath, WatcherItemType.Deleted, false);
                        }

                        m_modifiedFilesList.Add(new WatcherItem(sender as FileSystemWatcher, e));
                    }
                }
            }
        }