예제 #1
0
        private void GitIgnoreTab_Selected(object sender, RoutedEventArgs e)
        {
            if (_projects == null)
            {
                return;
            }

            if (GitIgnoreList.Items.Count == 0)
            {
                foreach (var proj in _projects)
                {
                    if (Path.IsPathRooted(proj.Path))
                    {
                        Freeze();

                        var task = Task.Run(() =>
                        {
                            var files     = new List <FilesListItem>();
                            var git_files = GitIgnoreReader
                                            .Find(proj.Path, SearchOption.AllDirectories)
                                            .Select(p => GitIgnoreReader.Load(p));

                            Dispatcher.Invoke(() =>
                            {
                                foreach (var git_file in git_files)
                                {
                                    GitIgnoreList.Items.Add(new FilesListItem(git_file.Path, FilesListItem.Default));

                                    foreach (var rule in git_file.Rules)
                                    {
                                        var item = new FilesListItem($"{rule.Source} -> {rule.Pattern}" + (rule.IsNegative ? " [NEGATIVE]" : ""),
                                                                     rule.IsValid ? FilesListItem.Green : FilesListItem.Red);
                                        GitIgnoreList.Items.Add(item);
                                    }
                                }

                                Freeze(false);
                            });
                        });

                        Closing += (ss, ee) => task.Dispose();
                    }
                }
            }
        }
예제 #2
0
 public bool IsIgnoredForder(string path)
 {
     return(IgnoredFolders?.Any(f => GitIgnoreReader.IsChildedPath(PathIO.Combine(Path, f), path)) ?? false);
 }
예제 #3
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);
        }