示例#1
0
        private void loadComposites(string path, IComponent root)
        {
            try
            {
                string[] files = Directory.GetFiles(path, ".");
            }
            catch
            {
                Console.WriteLine("Folder doesn't exist!");
                return;
            }

            try
            {
                string[] folders = Directory.GetDirectories(path);
                foreach (string folderPath in folders)
                {
                    this.id++;
                    dir folder = null;

                    folder = new dir { path = folderPath, id = this.id, name = new DirectoryInfo(folderPath).Name, folder = true, root = root, link = System.IO.File.GetAttributes(folderPath).HasFlag(FileAttributes.ReparsePoint) };

                    root.AddComponent(folder);
                    loadComposites(folderPath, folder);
                }
                loadLeafs(path, root);
                root.CalculateSize();
            }
            catch
            {
                Console.WriteLine("Error");
            }
        }
示例#2
0
        private void loadComposites(string path, IComponent root)
        {
            try
            {
                string[] files = Directory.GetFiles(path, ".");
            }
            catch
            {
                Console.WriteLine("Folder doesn't exist!");
                return;
            }

            try
            {
                string[] folders = Directory.GetDirectories(path);
                foreach (string folderPath in folders)
                {
                    this.id++;
                    dir folder = null;

                    folder = new dir {
                        path = folderPath, id = this.id, name = new DirectoryInfo(folderPath).Name, folder = true, root = root, link = System.IO.File.GetAttributes(folderPath).HasFlag(FileAttributes.ReparsePoint)
                    };

                    root.AddComponent(folder);
                    loadComposites(folderPath, folder);
                }
                loadLeafs(path, root);
                root.CalculateSize();
            }
            catch
            {
                Console.WriteLine("Error");
            }
        }
示例#3
0
        public bool CopyComponent(int what, int where)
        {
            IComponent _what  = main.FindComponent(what);
            IComponent _where = main.FindComponent(where);

            if (_what == null || _where == null)
            {
                Console.WriteLine("Can't find an object!");
                return(false);
            }
            if (_where.folder)
            {
                if (_where.FindComponentInFolder(_what.name) == null)
                {
                    IComponent temp;
                    this.id++;
                    if (_what.folder)
                    {
                        DirectoryInfo dir = Directory.CreateDirectory(_where.path + '\\' + _what.name);
                        CopyDirectory(_what.path, dir.FullName, _where);
                    }
                    else
                    {
                        string destination = System.IO.Path.Combine(_where.path, _what.name);
                        System.IO.File.Copy(_what.path, destination, true);

                        FileInfo fileInfo = new FileInfo(destination);

                        temp = new file {
                            id = this.id, name = _what.name, root = _where, path = destination, size = _what.size, permitWriting = !fileInfo.IsReadOnly
                        };
                        _where.AddComponent(temp);
                    }

                    _where.CalculateSize();

                    return(true);
                }
                else
                {
                    Console.WriteLine("Error, check the name.");
                }
            }
            else
            {
                Console.WriteLine("Error, can't copy the object.");
            }
            return(false);
        }
示例#4
0
        public bool CreateComponent(int where, string name, bool isDirectory)
        {
            IComponent _where = main.FindComponent(where);

            if (!_where.folder)
            {
                Console.WriteLine("Destination has to be a directory!");
                return(false);
            }
            else
            {
                this.id++;
                IComponent root = null;
                if (isDirectory)
                {
                    root = new dir {
                        path = _where.path + '\\' + name, id = this.id, name = name, folder = true, root = _where, link = false
                    };
                }
                else
                {
                    root = new file {
                        path = _where.path + '\\' + name, id = this.id, name = name, folder = false, root = _where, link = false, permitWriting = true
                    };
                }
                if (root == null)
                {
                    return(false);
                }
                else
                {
                    _where.AddComponent(root);
                    _where.CalculateSize();
                }
            }
            return(true);
        }