<commit_before>﻿namespace Jekov.Nevix.Desktop.Common
{
    using Jekov.Nevix.Common.ViewModels;
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Windows.Forms;

    public class FileManager
    {
        private static string[] MediaTypes = { ".avi", ".mov", ".mpeg", ".mkv", ".mp3", ".mp4", ".wav" };
        private static string[] SkipDownloadDirs = { "appdata", "windows", "program files", "program files (x86)", "programdata", "all users" };

        public MediaFolderViewModel ConvertToMediaFolderViewModel(DirectoryInfo rootDirectory)
        {
            MediaFolderViewModel subFolder;
            MediaFolderViewModel rootMediaFolder = new MediaFolderViewModel
            {
                Location = rootDirectory.FullName,
                Name = rootDirectory.Name
            };

            foreach (var file in rootDirectory.GetFiles())
            {
                rootMediaFolder.Files.Add(ConvertToMediaFileViewModel(file));
            }

            foreach (var subDir in rootDirectory.GetDirectories())
            {
                subFolder = new MediaFolderViewModel
                {
                    Location = subDir.FullName,
                    Name = subDir.Name
                };

                foreach (var file in subDir.GetFiles())
                {
                    subFolder.Files.Add(ConvertToMediaFileViewModel(file));
                }

                rootMediaFolder.Folders.Add(ConvertToMediaFolderViewModel(subDir));
            }

            return rootMediaFolder;
        }

        private MediaFileViewModel ConvertToMediaFileViewModel(FileInfo file)
        {
            return new MediaFileViewModel
                        {
                            Length = file.Length,
                            Location = file.FullName,
                            Name = file.Name
                        };
        }

        public IEnumerable<DirectoryInfo> GetAllDownloadDirectories(IEnumerable<DriveInfo> drives)
        {
            List<DirectoryInfo> downloadDirs = new List<DirectoryInfo>();
            HashSet<string> visitedDirs = new HashSet<string>();
            Queue<DirectoryInfo> dirs = new Queue<DirectoryInfo>();

            foreach (var drive in drives)
            {
                DirectoryInfo dir = new DirectoryInfo(drive.Name);
                var directories = dir.GetDirectories();
                foreach (var d in directories)
                {
                    if (!SkipDownloadDirs.Contains(d.Name.ToLower()))
                    {
                        dirs.Enqueue(d);
                    }
                }
            }<commit_msg>Added filter for directories collected.<commit_after>﻿namespace Jekov.Nevix.Desktop.Common
{
    using Jekov.Nevix.Common.ViewModels;
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Windows.Forms;

    public class FileManager
    {
        private static HashSet< string> MediaTypes = new HashSet<string> { ".avi", ".mov", ".mpeg", ".mkv", ".mp3", ".mp4", ".wav" };
        private static string[] SkipDownloadDirs = { "appdata", "windows", "program files", "program files (x86)", "programdata", "all users" };

        public MediaFolderViewModel ConvertToMediaFolderViewModel(DirectoryInfo rootDirectory)
        {
            MediaFolderViewModel subFolder;
            MediaFolderViewModel rootMediaFolder = new MediaFolderViewModel
            {
                Location = rootDirectory.FullName,
                Name = rootDirectory.Name
            };

            foreach (var file in rootDirectory.GetFiles())
            {
                if (MediaTypes.Contains(file.Extension.ToLower()))
                {
                    rootMediaFolder.Files.Add(ConvertToMediaFileViewModel(file));
                }
            }

            foreach (var subDir in rootDirectory.GetDirectories())
            {
                if (DirectoryHasMediaInside(subDir))
                {
                    
                }

                subFolder = new MediaFolderViewModel
                {
                    Location = subDir.FullName,
                    Name = subDir.Name
                };

                foreach (var file in subDir.GetFiles())
                {
                    if (MediaTypes.Contains(file.Extension.ToLower()))
                    {
                        subFolder.Files.Add(ConvertToMediaFileViewModel(file));
                    }
                }

                rootMediaFolder.Folders.Add(ConvertToMediaFolderViewModel(subDir));
            }

            return rootMediaFolder;
        }

        private bool DirectoryHasMediaInside(DirectoryInfo subDir)
        {
            if (subDir.GetFiles().Any(f => MediaTypes.Contains(f.Extension.ToLower())))
            {
                return true;
            }

            var subDirs = subDir.GetDirectories();

            if (subDirs.Any())
            {
                foreach (var innerSubDir in subDirs)
                {
                    return DirectoryHasMediaInside(innerSubDir);
                }
            }

            return false;
        }

        private MediaFileViewModel ConvertToMediaFileViewModel(FileInfo file)
        {
            return new MediaFileViewModel
                        {
                            Length = file.Length,
                            Location = file.FullName,
                            Name = file.Name
                        };
        }

        public IEnumerable<DirectoryInfo> GetAllDownloadDirectories(IEnumerable<DriveInfo> drives)
        {
            List<DirectoryInfo> downloadDirs = new List<DirectoryInfo>();
            HashSet<string> visitedDirs = new HashSet<string>();
            Queue<DirectoryInfo> dirs = new Queue<DirectoryInfo>();

            foreach (var drive in drives)
            {
                DirectoryInfo dir = new DirectoryInfo(drive.Name);
                var directories = dir.GetDirectories();
                foreach (var d in directories)
                {
                    if (!SkipDownloadDirs.Contains(d.Name.ToLower()))
                    {
                        dirs.Enqueue(d);
                    }
                }
            }
{'fraction_non_alphanumeric': 0.08389951019118344, 'fraction_numerical': 0.0012640227524095434, 'mean_word_length': 1.4318094506338839, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2143902', 'n_tokens_mistral': 1560, 'n_tokens_neox': 1426, 'n_words': 300}