<commit_before>﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Windows.Input;
using Caliburn.Micro;
using SimpleChecklist.Models;
using SimpleChecklist.Models.Utils;
using Xamarin.Forms;

namespace SimpleChecklist.ViewModels
{
    public class OpenFilePickerViewModel : Screen
    {
        private IDirectory _currentDirectory;

        public OpenFilePickerViewModel()
        {
            FilesList = new ObservableCollection<KeyValuePair<FileType, string>>();
        }

        public Action<string> FileChoosen { get; set; }

        public ICommand FileChoosenCommand => new Command(item =>
        {
            var data = (KeyValuePair<FileType, string>) item;
            switch (data.Key)
            {
                case FileType.Directory:
                    ChangeListedDirectory(data.Value == "..."
                        ? _currentDirectory.GetParent()
                        : _currentDirectory.GetChild(data.Value));
                    break;
                case FileType.File:
                    FileChoosen?.Invoke(Path.Combine(_currentDirectory.Path, data.Value));
                    break;
            }
        });

        public ObservableCollection<KeyValuePair<FileType, string>> FilesList { get; }

        public void ChangeListedDirectory(IDirectory directory)
        {
            if (!directory.Exist)
                return;

            FilesList.Clear();

            _currentDirectory = directory;

            var directories = directory.GetDirectories();

            FilesList.Add(new KeyValuePair<FileType, string>(FileType.Directory, "..."));

            foreach (var dir in directories)
            {
                FilesList.Add(new KeyValuePair<FileType, string>(FileType.Directory, dir.Name));
            }

            var files = directory.GetFiles();

            foreach (var file in files)
            {
                FilesList.Add(new KeyValuePair<FileType, string>(FileType.File, file.Name));
            }
        }
    }
}<commit_msg>Fixed problem with access denied<commit_after>﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Windows.Input;
using Caliburn.Micro;
using SimpleChecklist.Models;
using SimpleChecklist.Models.Utils;
using Xamarin.Forms;

namespace SimpleChecklist.ViewModels
{
    public class OpenFilePickerViewModel : Screen
    {
        private IDirectory _currentDirectory;

        public OpenFilePickerViewModel()
        {
            FilesList = new ObservableCollection<KeyValuePair<FileType, string>>();
        }

        public Action<string> FileChoosen { get; set; }

        public ICommand FileChoosenCommand => new Command(item =>
        {
            var data = (KeyValuePair<FileType, string>) item;
            switch (data.Key)
            {
                case FileType.Directory:
                    ChangeListedDirectory(data.Value == "..."
                        ? _currentDirectory.GetParent()
                        : _currentDirectory.GetChild(data.Value));
                    break;
                case FileType.File:
                    FileChoosen?.Invoke(Path.Combine(_currentDirectory.Path, data.Value));
                    break;
            }
        });

        public ObservableCollection<KeyValuePair<FileType, string>> FilesList { get; }

        public void ChangeListedDirectory(IDirectory directory)
        {
            if (!directory.Exist)
                return;

            try
            {
                var directories = directory.GetDirectories();

                var filesList = new List<KeyValuePair<FileType, string>>
                {
                    new KeyValuePair<FileType, string>(FileType.Directory, "...")
                };

                filesList.AddRange(
                    directories.Select(dir => new KeyValuePair<FileType, string>(FileType.Directory, dir.Name)));

                var files = directory.GetFiles();

                _currentDirectory = directory;

                filesList.AddRange(files.Select(file => new KeyValuePair<FileType, string>(FileType.File, file.Name)));

                FilesList.Clear();

                foreach (var keyValuePair in filesList)
                {
                    FilesList.Add(keyValuePair);
                }
            }
            catch (Exception)
            {
                // ignored
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.08976063829787234, 'fraction_numerical': 0.0, 'mean_word_length': 1.7772307692307692, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5832519', 'n_tokens_mistral': 1139, 'n_tokens_neox': 1041, 'n_words': 220}