Example #1
0
 public bool IsIgnoredForder(string path)
 {
     return(IgnoredFolders?.Any(f => GitIgnoreReader.IsChildedPath(PathIO.Combine(Path, f), path)) ?? false);
 }
Example #2
0
        public List <FileItem> GetFiles(HashSet <string> extensions, HashSet <string> blackList, GetFilesUpdate onProgress = null)
        {
            var location = Path;
            var list     = new List <FileItem>();

            if (Directory.Exists(location))
            {
                var allowedDirs = GetAllowedFolders();
                //
                var gitIgnores = GitIgnoreReader.Find(location, SearchOption.AllDirectories).Select(p => GitIgnoreReader.Load(p));
                var queue      = new Queue <KeyValuePair <string, IEnumerable <GitIgnoreReader> > >();

                var dirsCount = 0;

                GetFiles(location);

                void GetFiles(string dir)
                {
                    var relevantGitFiles = gitIgnores.Where(f => GitIgnoreReader.IsChildedPath(f.BaseDir, dir));

                    var isAllowedDir =
                        allowedDirs.Count > 0 ? allowedDirs.Any(p => GitIgnoreReader.IsChildedPath(p, dir)) : true;

                    var subs = Directory.EnumerateDirectories(dir)
                               .Where(p => !IsIgnoredForder(p))
                               .Select(s => s.Replace('\\', '/'));

                    var files = Directory.EnumerateFiles(dir)
                                .Where(s => isAllowedDir)
                                .Where(s => extensions.Contains(PathIO.GetExtension(s)))
                                .Where(s => blackList.All(end => !s.EndsWith(end)))
                                .Select(s => s.Replace('\\', '/'));

                    dirsCount += subs.Count();

                    onProgress?.Invoke(queue.Count, dirsCount, dir);

                    foreach (var file in files)
                    {
                        queue.Enqueue(new KeyValuePair <string, IEnumerable <GitIgnoreReader> >(file, relevantGitFiles));
                    }

                    foreach (var sub in subs.Select(s => s + '/'))
                    {
                        var isMatch = relevantGitFiles.All(r => r.IsMatch(sub));

                        if (isMatch)
                        {
                            GetFiles(sub);
                        }
                    }
                }

                while (queue.Count > 0)
                {
                    var pair    = queue.Dequeue();
                    var isMatch = pair.Value.All(r => r.IsMatch(pair.Key));
                    list.Add(new FileItem(pair.Key, isMatch));

                    onProgress?.Invoke(queue.Count, 0, pair.Key);
                }
            }

            return(list);
        }