Example #1
0
        public IEnumerable <Artist> BeginScan(ScanSettings settings)
        {
            fileSelector.Init(settings);

            var dir   = new Dir(settings.ScanPath);
            var stack = new Stack <Dir>();

            stack.Push(dir);

            if (settings.BeforeScan != null)
            {
                int totalFiles = fileSystem.CountFilesRecursively(dir, fileSelector);
                settings.BeforeScan(totalFiles);
            }

            while (stack.Count > 0 && !settings.Stop)
            {
                if (settings.Pause)
                {
                    Thread.Sleep(500);
                    continue;
                }

                var currentDir     = stack.Pop();
                var subDirectories = fileSystem.GetSubDirectories(currentDir);
                foreach (var subDir in subDirectories)
                {
                    stack.Push(subDir);
                }

                if (settings.BeginDirectoryScan != null)
                {
                    settings.BeginDirectoryScan(currentDir.FullName);
                }

                var files = fileSystem.GetFiles(currentDir, fileSelector);
                foreach (var f in files)
                {
                    try
                    {
                        var tags = scanner.GetTags(f.FullName);

                        if (tags.Count() > 0)
                        {
                            if (settings.BeginFileScan != null)
                            {
                                settings.BeginFileScan(f.FullName);
                            }

                            tagsAccumulator.AccumulateTags(tags);
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Write(ex);
                    }
                }
            }

            return(tagsAccumulator.GetAccumulatedResult());
        }