Beispiel #1
0
        private void ScanFiles()
        {
            _movieList.Clear();
            MovieView.VirtualListSize = 0;
            MovieView.Update();

            var directory = _config.PathEntries.MovieAbsolutePath();

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }

            var dpTodo = new Queue <string>();
            var fpTodo = new List <string>();

            dpTodo.Enqueue(directory);
            var ordinals = new Dictionary <string, int>();

            while (dpTodo.Count > 0)
            {
                string dp = dpTodo.Dequeue();

                // enqueue subdirectories if appropriate
                if (_config.PlayMovieIncludeSubDir)
                {
                    foreach (var subDir in Directory.GetDirectories(dp))
                    {
                        dpTodo.Enqueue(subDir);
                    }
                }

                // add movies
                foreach (var extension in MovieService.MovieExtensions)
                {
                    fpTodo.AddRange(Directory.GetFiles(dp, $"*.{extension}"));
                }
            }

            // in parallel, scan each movie
            Parallel.For(0, fpTodo.Count, i =>
            {
                var file = fpTodo[i];
                lock (ordinals)
                {
                    ordinals[file] = i;
                }

                AddMovieToList(file, force: false);
            });

            // sort by the ordinal key to maintain relatively stable results when rescanning
            _movieList.Sort((a, b) => ordinals[a.Filename].CompareTo(ordinals[b.Filename]));

            RefreshMovieList();
        }
Beispiel #2
0
        private void ScanFiles()
        {
            _movieList.Clear();
            MovieView.ItemCount = 0;
            MovieView.Update();

            var directory = PathManager.MakeAbsolutePath(Global.Config.PathEntries.MoviesPathFragment, null);

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }

            var dpTodo = new Queue <string>();
            var fpTodo = new List <string>();

            dpTodo.Enqueue(directory);
            Dictionary <string, int> ordinals = new Dictionary <string, int>();

            while (dpTodo.Count > 0)
            {
                string dp = dpTodo.Dequeue();

                // enqueue subdirectories if appropriate
                if (Global.Config.PlayMovie_IncludeSubdir)
                {
                    foreach (var subdir in Directory.GetDirectories(dp))
                    {
                        dpTodo.Enqueue(subdir);
                    }
                }

                // add movies
                fpTodo.AddRange(Directory.GetFiles(dp, "*." + MovieService.DefaultExtension));
                fpTodo.AddRange(Directory.GetFiles(dp, "*." + TasMovie.Extension));
            }

            // in parallel, scan each movie
            Parallel.For(0, fpTodo.Count, i =>
            {
                var file = fpTodo[i];
                lock (ordinals)
                {
                    ordinals[file] = i;
                }

                AddMovieToList(file, force: false);
            });

            // sort by the ordinal key to maintain relatively stable results when rescanning
            _movieList.Sort((a, b) => ordinals[a.Filename].CompareTo(ordinals[b.Filename]));

            RefreshMovieList();
        }