Пример #1
0
        // <summary>
        // Scans directory and populates virtual tree; called recursively
        // </summary>
        private void PopulateDirectoryBranch(bool is_top, string path, FolderInventoryNode root)
        {
            DirectoryInfo  di = new DirectoryInfo(path);
            FileAttributes fa = File.GetAttributes(path);

            if ((fa & FileAttributes.ReparsePoint) > 0)
            {
                root.Result      = DirOpenResult.E_HARDLINK;
                root.TotalWeight = 0;
                LogFolder(_LocRM.GetString("LOG_HardLink") + ": " + path);
                return;
            }
            IEnumerable <String> dirs = null;

            try
            {
                dirs = di.EnumerateDirectories().Select(t => t.Name);
                root.InitializeDirInfo(path);
            }
            catch (UnauthorizedAccessException e)
            {
                root.Result      = DirOpenResult.E_ACCESSDENIED;
                root.TotalWeight = 0;
                LogFolder(_LocRM.GetString("LOG_AccessDenied") + ": " + path);
            }
            int i = 0;

            if (dirs != null)
            {
                foreach (string dir in dirs)
                {
                    if (CancellationPending)
                    {
                        break;
                    }
                    i++;
                    if (UpdateDirectoryLabelHandler != null)
                    {
                        UpdateDirectoryLabelHandler(path);
                    }
                    FolderInventoryNode item = new FolderInventoryNode(root);
                    Application.DoEvents();
                    item.Name = dir;
                    string full_path = path + "\\" + dir;
                    root.Items.Add(item);
                    try
                    {
                        PopulateDirectoryBranch(false, full_path, item);
                    }
                    catch (PathTooLongException e)
                    {
                        root.Result      = DirOpenResult.E_OTHER;
                        root.TotalWeight = 0;
                        LogFolder(_LocRM.GetString("LOG_PathTooLong") + ": " + path);
                    }
                    if (is_top)
                    {
                        if (ReportProgressHandler != null)
                        {
                            ReportProgressHandler(i * 100 / dirs.Count());
                        }
                    }
                    root.SubWeight += item.TotalWeight;
                }
                root.TotalWeight = root.OwnWeight + root.SubWeight;
            }
        }
Пример #2
0
        // <summary>
        // Scans directory and populates virtual tree; called recursively
        // </summary>
        private void PopulateDirectoryBranch(bool is_top, string path, FolderInventoryNode root)
        {
            DirectoryInfo di = new DirectoryInfo(path);
            FileAttributes fa = File.GetAttributes(path);
            if ((fa & FileAttributes.ReparsePoint) > 0)
            {
                root.Result = DirOpenResult.E_HARDLINK;
                root.TotalWeight = 0;
                LogFolder(_LocRM.GetString("LOG_HardLink") + ": " + path);
                return;
            }
            IEnumerable<String> dirs = null;
            try
            {
                dirs = di.EnumerateDirectories().Select(t => t.Name);
                root.InitializeDirInfo(path);
            }
            catch (UnauthorizedAccessException e)
            {
                root.Result = DirOpenResult.E_ACCESSDENIED;
                root.TotalWeight = 0;
                LogFolder(_LocRM.GetString("LOG_AccessDenied") + ": " + path);
               }
            int i = 0;
            if (dirs != null)
            {
                foreach (string dir in dirs)
                {

                    if (CancellationPending) { break; }
                    i++;
                    if (UpdateDirectoryLabelHandler != null)
                    {
                        UpdateDirectoryLabelHandler(path);
                    }
                    FolderInventoryNode item = new FolderInventoryNode(root);
                    Application.DoEvents();
                    item.Name = dir;
                    string full_path = path + "\\" + dir;
                    root.Items.Add(item);
                    PopulateDirectoryBranch(false, full_path, item);
                    if (is_top)
                    {

                        if (ReportProgressHandler != null)
                        {
                            ReportProgressHandler(i * 100 / dirs.Count());
                        }
                    }
                    root.SubWeight += item.TotalWeight;
                }
                root.TotalWeight = root.OwnWeight + root.SubWeight;
            }
        }