예제 #1
0
 public void LoadDrives()
 {
     foreach (var drive in new BasicDirectory().DrivesDirectory)
     {
         MyDirectories.Add(GetItem(drive));
     }
 }
예제 #2
0
        public MyDirectories Get()
        {
            MyDirectories d = new MyDirectories();

            d.GetRoot();
            foreach (var dir in d.Children)
            {
                paths.Add(dir.Key, dir.Value[0]);
            }
            cache.Add(d.CurrentDir.GetHashCode(), d);
            return(d);
        }
예제 #3
0
        public MyDirectories Get(int id)
        {
            MyDirectories d = new MyDirectories();

            if (cache.TryGetValue(id, out d))
            {
                return(d);
            }
            else
            {
                d            = new MyDirectories();
                d.CurrentDir = paths[id];

                if (Directory.GetParent(d.CurrentDir) != null)
                {
                    d.ParentDir = (Directory.GetParent(d.CurrentDir).FullName).GetHashCode();
                }
                else
                {
                    string r = "root";
                    d.ParentDir = r.GetHashCode();
                }

                try
                {
                    foreach (var item in Directory.EnumerateDirectories(d.CurrentDir))
                    {
                        d.Children.Add(item.GetHashCode(), new List <string> {
                            item, item.Substring(item.LastIndexOf(@"\") + 1)
                        });
                    }

                    foreach (var item in Directory.EnumerateFiles(d.CurrentDir))
                    {
                        d.Files.Add(item.Substring(item.LastIndexOf(@"\") + 1));
                    }
                }
                catch (IOException) { }
                catch (UnauthorizedAccessException) { }

                d.CountFilesSize(d.CurrentDir);
                d.key = d.CurrentDir.GetHashCode();

                foreach (var dir in d.Children)
                {
                    paths.Add(dir.Key, dir.Value[0]);
                }
                cache.Add(d.CurrentDir.GetHashCode(), d);

                return(d);
            }
        }