Пример #1
0
        private void watcher_Changed(object sender, FileSystemEventArgs e)
        {
            if (!VideoTypeManager.IsSupported(Path.GetExtension(e.FullPath)))
            {
                return;
            }

            if (e.FullPath == currentFile)
            {
                // In this case we can't use the normal heuristic of trying to get exclusive access on the file,
                // because the player screen itself already has the file opened.

                // First of all we need to stop the player from playing the file as it's reading frames from disk (no caching).
                dummy.BeginInvoke((Action) delegate { player.StopPlaying(); });

                // We normally receive only two events. One at start and one on close.
                overwriteEventCount++;
                if (overwriteEventCount >= 2)
                {
                    overwriteEventCount = 0;
                    dummy.BeginInvoke((Action) delegate { LoadVideo(e.FullPath); });
                }
            }
            else
            {
                if (FilesystemHelper.CanRead(e.FullPath))
                {
                    dummy.BeginInvoke((Action) delegate { LoadVideo(e.FullPath); });
                }
            }
        }
Пример #2
0
        public static void ImportDirectory(string dir)
        {
            // Import all files from the directory into corresponding entries.
            // Used for debugging and as a conveniency for first time use.

            List <CaptureHistoryEntry> entries = new List <CaptureHistoryEntry>();

            foreach (string file in Directory.GetFiles(dir))
            {
                string extension = Path.GetExtension(file);
                if (!VideoTypeManager.IsSupported(extension))
                {
                    continue;
                }

                CaptureHistoryEntry entry = CreateEntryFromFile(file);
                entries.Add(entry);
            }

            entries.Sort((e1, e2) => e1.Start.CompareTo(e2.Start));
            foreach (CaptureHistoryEntry entry in entries)
            {
                AddEntry(entry);
            }
        }
Пример #3
0
        private void watcher_Changed(object sender, FileSystemEventArgs e)
        {
            if (!VideoTypeManager.IsSupported(Path.GetExtension(e.FullPath)))
            {
                return;
            }

            log.DebugFormat("Replay watcher received an event: {0}, filename: \"{1}\".", e.ChangeType, e.Name);

            if (e.FullPath == currentFile)
            {
                // Special case where the user is overwriting the currently loaded file.
                // In this case we can't use the normal heuristic of trying to get exclusive access on the file,
                // because the player screen itself already has the file opened.

                // First of all we need to stop the player from playing the file as it's reading frames from disk (no caching).
                dummy.BeginInvoke((Action) delegate { player.StopPlaying(); });

                // We normally receive only two events. One at start and one on close.
                overwriteEventCount++;
                if (overwriteEventCount >= 2)
                {
                    log.DebugFormat("Loading overwritten video.");
                    overwriteEventCount = 0;
                    dummy.BeginInvoke((Action) delegate { LoadVideo(e.FullPath); });
                }
                else
                {
                    log.DebugFormat("The file was just created, it is not ready to be loaded yet.");
                }
            }
            else
            {
                if (FilesystemHelper.CanRead(e.FullPath))
                {
                    log.DebugFormat("Loading new video.");
                    dummy.BeginInvoke((Action) delegate { LoadVideo(e.FullPath); });
                }
                else
                {
                    log.DebugFormat("The file is still being written.");
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Look for the most recent supported video file in the folder.
        /// </summary>
        public static string GetMostRecentFile(string path)
        {
            var directory = new DirectoryInfo(path);

            if (directory == null)
            {
                return(null);
            }

            FileInfo latest = directory.GetFiles()
                              .Where(f => VideoTypeManager.IsSupported(f.Extension))
                              .OrderByDescending(f => f.LastWriteTime)
                              .FirstOrDefault();

            if (latest == null)
            {
                return(null);
            }

            return(latest.FullName);
        }
Пример #5
0
        private void UpdateFileList(CShItem folder, ListView listView, bool refreshThumbnails, bool shortcuts)
        {
            // Update a file list with the given folder.
            // Triggers an update of the thumbnails pane if requested.
            if (folder == null)
            {
                return;
            }

            this.Cursor = Cursors.WaitCursor;

            listView.BeginUpdate();
            listView.View = View.Details;
            listView.Items.Clear();
            listView.Columns.Clear();
            listView.Columns.Add("", listView.Width);
            listView.GridLines   = true;
            listView.HeaderStyle = ColumnHeaderStyle.None;

            // Each list element will store the CShItem it's referring to in its Tag property.
            ArrayList fileList = folder.GetFiles();

            List <string> filenames = new List <string>();

            foreach (object item in fileList)
            {
                CShItem shellItem = item as CShItem;
                if (shellItem == null)
                {
                    continue;
                }

                try
                {
                    string path      = shellItem.Path;
                    string extension = Path.GetExtension(path);
                    if (string.IsNullOrEmpty(extension) || !VideoTypeManager.IsSupported(extension))
                    {
                        continue;
                    }

                    filenames.Add(path);
                }
                catch (Exception)
                {
                    // Known case : when we are in OS/X parallels context, the path of existing files are invalid.
                    log.ErrorFormat("An error happened while trying to add a file to the file list : {0}", shellItem.Path);
                }
            }

            filenames.Sort(new AlphanumComparator());

            foreach (string filename in filenames)
            {
                ListViewItem lvi = new ListViewItem(Path.GetFileName(filename));
                lvi.Tag        = filename;
                lvi.ImageIndex = 0;
                listView.Items.Add(lvi);
            }

            listView.EndUpdate();

            UpdateFileWatcher(folder);

            // Even if we don't want to reload the thumbnails, we must ensure that
            // the screen manager backup list is in sync with the actual file list.
            // desync can happen in case of renaming and deleting files.
            // the screenmanager backup list is used at BringBackThumbnail,
            // (i.e. when we close a screen)
            NotificationCenter.RaiseCurrentDirectoryChanged(this, shortcuts, filenames, refreshThumbnails);
            this.Cursor = Cursors.Default;
        }