Beispiel #1
0
        private static bool DoProcessMovies(ObservableCollection <MovieItem> movies, ThumbGenMainWindow mainWindow, StartActionType actionType)
        {
            bool _aborted = false;

            foreach (MovieItem _item in movies)
            {
                if (FolderToSkip != null)
                {
                    if (string.Compare(FolderToSkip, Path.GetDirectoryName(_item.FilePath), true) != 0)
                    {
                        FolderToSkip          = null;
                        FolderCompleteSkipped = false;
                    }
                    else
                    {
                        if (FolderCompleteSkipped)
                        {
                            continue;
                        }
                    }
                }
                if (!ProcessMovie(_item, actionType))
                {
                    m_ProgressText.Text   = "Aborted by the user.";
                    _item.MovieItemStatus = MovieItemStatus.Unknown;
                    _aborted = true;
                    break;
                }

                //generate the dummy file for HUB (if required)
                FileManager.GenerateDummyFile(_item.FilePath);

                mainWindow.progressListBox.ScrollIntoViewCentered(_item);
                Thread.Sleep(0);
            }

            return(_aborted);
        }
Beispiel #2
0
        public static void ProcessMovies(ObservableCollection <CollectorNode> selectedCollectors,
                                         ThumbGenMainWindow mainWindow, IList <string> rootPaths,
                                         StartActionType actionType)
        {
            CurrentSeriesHelper.Reset();

            FolderToSkip          = null;
            FolderCompleteSkipped = false;

            if (actionType == StartActionType.Unknown)
            {
                return;
            }
            m_OverwriteExisting = Configuration.Options.OverwriteExistingThumbs;
            m_Progress          = mainWindow.progressBar1;
            m_ProgressText      = mainWindow.textBlock1;
            Movies.Clear();
            mainWindow.progressListBox.DataContext = Movies;
            //(mainWindow.FindResource("MoviesCollectionView") as CollectionViewSource).Source = Movies;

            bool _aborted = false;

            m_ProgressText.Text = "Collecting movies...";
            try
            {
                ShowAdorner("Collecting movies...", false);
                Helpers.DoEvents();

                List <FileInfo> _files = null;
                if (rootPaths.Count != 0)
                {
                    mainWindow.Dispatcher.Invoke((Action) delegate
                    {
                        FilesCollector _fc = new FilesCollector();
                        _files             = new List <FileInfo>();
                        // new approach, scan the given folders fully
                        foreach (string _item in rootPaths)
                        {
                            if (Directory.Exists(_item))
                            {
                                // collect all movies
                                List <FileInfo> _tmp = _fc.CollectFiles(_item, true, false).ToList <FileInfo>();

                                if (_tmp.Count != 0)
                                {
                                    _files.AddRange(_tmp);
                                }
                            }
                            else
                            {
                                if (File.Exists(_item))
                                {
                                    _files.Add(new FileInfo(_item));
                                }
                            }
                        }
                    }, DispatcherPriority.Background);
                }
                else
                {
                    return;
                }

                switch (actionType)
                {
                case StartActionType.Process:
                case StartActionType.ProcessAutomatic:
                case StartActionType.ProcessSemiautomatic:
                case StartActionType.ProcessFeelingLucky:
                case StartActionType.GenerateRandomThumbs:
                    foreach (FileInfo _file in _files)
                    {
                        Movies.Add(new MovieItem(_file.FullName));
                        Thread.Sleep(0);
                    }
                    break;

                case StartActionType.FixNetworkShares:
                    MP4Tagger.MP4Manager.ApplyBatchFix(_files);
                    break;

                case StartActionType.UnfixNetworkShares:
                    MP4Tagger.MP4Manager.ApplyBatchUnFix(_files);
                    break;

                case StartActionType.GenerateDummyFile:
                    FileManager.GenerateDummyFiles(_files);
                    break;

                case StartActionType.UpdateMoviesheetsTemplate:
                    foreach (FileInfo _file in _files)
                    {
                        Movies.Add(new MovieItem(_file.FullName));
                        Thread.Sleep(0);
                    }
                    MoviesheetsUpdateManager.ApplyNewTemplate(_files, MoviesheetsUpdateManager.SelectedTemplates);
                    break;

                case StartActionType.CreatePlaylist:
                    foreach (FileInfo _file in _files)
                    {
                        Movies.Add(new MovieItem(_file.FullName));
                        Thread.Sleep(0);
                    }

                    ShowAdorner("Generating playlists... Please wait...", false);
                    using (Playlists.PlaylistManager _manager = new Playlists.PlaylistManager())
                    {
                        _manager.CreatePlaylists(_files, FileManager.Configuration.Options.PlaylistsJobs);
                    }

                    break;
                }
            }
            finally
            {
                HideAdorners();
            }
            if (Movies != null && Movies.Count != 0 &&
                (actionType == StartActionType.Process ||
                 actionType == StartActionType.ProcessAutomatic ||
                 actionType == StartActionType.ProcessSemiautomatic ||
                 actionType == StartActionType.ProcessFeelingLucky ||
                 actionType == StartActionType.GenerateRandomThumbs))
            {
                m_Progress.Minimum = 0;
                m_Progress.Maximum = Movies.Count;
                m_Progress.Value   = 0;

                List <BaseCollector> _collectors = new List <BaseCollector>();
                if (actionType != StartActionType.GenerateRandomThumbs)
                {
                    foreach (CollectorNode _node in selectedCollectors)
                    {
                        if (_node.Collector != null)
                        {
                            // if it is a XMLImportCollectorBase derived collector then call Load
                            XMLImportCollectorBase _xmlCol = _node.Collector as XMLImportCollectorBase;
                            if (_xmlCol != null)
                            {
                                _xmlCol.Load();
                            }

                            // check if online
                            try
                            {
                                IPHostEntry _inetServer = Dns.GetHostEntry(_node.Collector.Host.Replace("http://", String.Empty));
                                // add it if online
                                _collectors.Add(_node.Collector);
                            }
                            catch
                            {
                                MessageBox.Show(String.Format("Unable to connect to {0}.\n\nThe {1} collector will be disabled for this session.", _node.Collector.Host, _node.Collector.CollectorName), "Connection error", MessageBoxButton.OK, MessageBoxImage.Warning);
                                _node.IsSelected = false; // disable the collector
                            }
                        }
                    }
                }
                else
                {
                    //_collectors.Add(new RandomSnapshotsCollector());
                }
                CurrentCollector            = new AllProvidersCollector(_collectors);
                CurrentCollector.MainWindow = mainWindow;

                if (CurrentCollector != null)
                {
                    CurrentCollector.Processing       += new EventHandler(_collector_Processing);
                    CurrentCollector.Processed        += new EventHandler(_collector_Processed);
                    CurrentCollector.ThumbnailCreated += new EventHandler(_collector_ThumbnailCreated);
                }

                _aborted = DoProcessMovies(Movies, mainWindow, actionType);
            }

            CurrentSeriesHelper.Reset();

            m_Progress.Value = 0;

            if (!_aborted && (actionType == StartActionType.ProcessAutomatic || actionType == StartActionType.ProcessFeelingLucky))
            {
                // chkeck if there are "Not found" movies and ask user maybe he wants to reprocess them manually
                var _notFoundMovies = from c in Movies
                                      where c.MovieItemStatus == MovieItemStatus.NotFound || c.MovieItemStatus == MovieItemStatus.Exception
                                      select c;
                if (_notFoundMovies != null && _notFoundMovies.Count() != 0)
                {
                    if (MessageBox.Show(string.Format("Not found: {0} movie(s)\r\n\r\nWould you like to manually process them?", _notFoundMovies.Count()),
                                        "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes) == MessageBoxResult.Yes)
                    {
                        ObservableCollection <MovieItem> _movies = new ObservableCollection <MovieItem>(_notFoundMovies);
                        FileManager.Mode = ProcessingMode.Manual;
                        _aborted         = DoProcessMovies(_movies, mainWindow, StartActionType.Process);
                    }
                }
            }

            if (!_aborted)
            {
                m_ProgressText.Text = "Done.";
            }

            CurrentSeriesHelper.Reset();

            m_Progress.Value = 0;
        }