private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
 {
     if (OnDirectoryChanged != null)
     {
         OnDirectoryChanged.Invoke(e.Node.FullPath);
     }
 }
예제 #2
0
        async UniTask OnChanged(object source, FileSystemEventArgs args, string root)
        {
            await UniTask.SwitchToMainThread();

            //Change
            if (File.Exists(args.FullPath) || Directory.Exists(args.FullPath))
            {
                //Directory change
                if (File.GetAttributes(args.FullPath) == FileAttributes.Directory)
                {
                    OnDirectoryChanged?.Invoke(args.FullPath, root);
                }
                //File change
                else
                {
                    string fileExtension = $"*{Path.GetExtension(args.FullPath)}";
                    for (int i = 0; i < FileExtensions.Length; i++)
                    {
                        if (fileExtension == FileExtensions[i])
                        {
                            OnFileChanged?.Invoke(args.FullPath, root);
                            break;
                        }
                    }
                }
            }
            //Remove
            else
            {
                OnDeleted?.Invoke(args.FullPath, root);
            }
        }
예제 #3
0
        public void ChangeDirectory(DirectoryMove move, string path = null)
        {
            switch (move)
            {
            case DirectoryMove.Back:
                var backDir = CurrentDirectory.Parent;
                ChangeDirectory(backDir);
                break;

            case DirectoryMove.ToRoot:
                var root = Path.GetPathRoot(CurrentDirectoryPath);
                ChangeDirectory(new DirectoryInfo(root));
                break;

            case DirectoryMove.Inner when path is not null:
                var next = Path.Combine(CurrentDirectoryPath, path);
                if (!Path.IsPathFullyQualified(next))
                {
                    throw ExceptionsFactory.PathNotExist(next);
                }
                ChangeDirectory(next);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(move), move, null);
            }

            OnDirectoryChanged?.Invoke();
        }
예제 #4
0
        public static Int64 CountLine(String dir, String fileExt)
        {
            DirectoryChangedEventArgs args = new DirectoryChangedEventArgs();

            args.DirectoryPath = dir;

            Int64 lineCount = 0;

            // 先遍历所有文件
            string[] files;
            try
            {
                files = System.IO.Directory.GetFiles(dir);
            }
            catch (Exception ex)
            {
                args.IsOpenSuccess = false;
                args.ErrMessage    = ex.Message;
                OnDirectoryChanged?.Invoke(args);
                return(0);
            }

            args.IsOpenSuccess = true;
            OnDirectoryChanged?.Invoke(args);

            if (files != null && files.Length > 0)
            {
                foreach (string file in files)
                {
                    if (file.EndsWith(fileExt))
                    {
                        Int32 tmpCount = CountFileLine(file);
                        lineCount += tmpCount;

                        OnFileChanged?.Invoke(file, tmpCount);
                    }
                }
            }

            string[] dirs = System.IO.Directory.GetDirectories(dir);

            if (dirs != null && dir.Length > 0)
            {
                foreach (string d in dirs)
                {
                    lineCount += CountLine(d, fileExt);
                }
            }

            return(lineCount);
        }
예제 #5
0
        public void ChangeDirectory(string path)
        {
            DirectoryInfo newDirectory;

            if (StringPathIsDirectory(path))
            {
                newDirectory = new DirectoryInfo(path);
            }
            else
            {
                Current = new FileInfo(path).ToInfo();
                var directory = Path.GetDirectoryName(path);
                newDirectory = new DirectoryInfo(directory);
            }
            ChangeDirectory(newDirectory);

            OnDirectoryChanged?.Invoke();
        }
예제 #6
0
        void ProcessDirectory(string path, string root)
        {
            OnDirectoryChanged?.Invoke(path, root);

            //Recursive branching
            string[] subFolders = Directory.GetDirectories(path);
            for (int i = 0; i < subFolders.Length; i++)
            {
                ProcessDirectory(subFolders[i], root);
            }

            for (int i = 0; i < FileExtensions.Length; i++)
            {
                string[] files = Directory.GetFiles(path, FileExtensions[i]);
                for (int j = 0; j < files.Length; j++)
                {
                    OnFileChanged?.Invoke(files[j], root);
                }
            }
        }