Ejemplo n.º 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");
            }
        }
Ejemplo n.º 2
0
        private void copyFolder(string what, string where, IComponent root)
        {
            DirectoryInfo dir = new DirectoryInfo(what);

            DirectoryInfo[] dirs = dir.GetDirectories();

            DirectoryInfo _dir = Directory.CreateDirectory(where);

            this.id++;
            dir directory = null;

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

            root.AddComponent(directory);

            foreach (DirectoryInfo subdir in dirs)
            {
                string tempPath = Path.Combine(where, subdir.Name);
                copyFolder(subdir.FullName, tempPath, directory);
            }
            FileInfo[] files = dir.GetFiles();
            foreach (FileInfo file in files)
            {
                this.id++;
                string   temppath = Path.Combine(where, file.Name);
                FileInfo temp     = file.CopyTo(temppath, false);

                file dat = new file {
                    path = temp.FullName, name = temp.Name, size = temp.Length, id = this.id, folder = false, root = directory, permitWriting = !temp.IsReadOnly, link = System.IO.File.GetAttributes(temp.FullName).HasFlag(FileAttributes.ReparsePoint)
                };
                directory.AddComponent(dat);
            }
        }
Ejemplo n.º 3
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");
            }
        }
Ejemplo n.º 4
0
        private void loadLeafs(string path, IComponent root)
        {

            string[] files = Directory.GetFiles(path);

            foreach (string file in files)
            {
                this.id++;
                FileInfo fileInfo = new FileInfo(file);

                file dat = new file { path = file, name = fileInfo.Name, size = fileInfo.Length, id = this.id, folder = false, root = root, permitWriting = !fileInfo.IsReadOnly, link = System.IO.File.GetAttributes(file).HasFlag(FileAttributes.ReparsePoint) };
                root.AddComponent(dat);
            }
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        private void loadLeafs(string path, IComponent root)
        {
            string[] files = Directory.GetFiles(path);

            foreach (string file in files)
            {
                this.id++;
                FileInfo fileInfo = new FileInfo(file);

                file dat = new file {
                    path = file, name = fileInfo.Name, size = fileInfo.Length, id = this.id, folder = false, root = root, permitWriting = !fileInfo.IsReadOnly, link = System.IO.File.GetAttributes(file).HasFlag(FileAttributes.ReparsePoint)
                };
                root.AddComponent(dat);
            }
        }
Ejemplo n.º 7
0
        private void loadLeafs(string path, IComponent root)
        {

            string[] folders = Directory.GetFiles(path);

            foreach (string file in folders)
            {
                this.id++;
                FileInfo temp = new FileInfo(file);
                file dat;
                if (System.IO.File.GetAttributes(file).HasFlag(FileAttributes.ReparsePoint))
                {
                    continue;
                }
                else
                {
                    dat = new file { path = file, name = temp.Name, size = temp.Length, id = this.id, folder = false, root = root, permitWriting = !temp.IsReadOnly };
                }
                root.AddComponent(dat);
            }
        }
Ejemplo n.º 8
0
        private void loadLeafs(string path, IComponent root)
        {
            string[] folders = Directory.GetFiles(path);

            foreach (string file in folders)
            {
                this.id++;
                FileInfo temp = new FileInfo(file);
                file     dat;
                if (System.IO.File.GetAttributes(file).HasFlag(FileAttributes.ReparsePoint))
                {
                    continue;
                }
                else
                {
                    dat = new file {
                        path = file, name = temp.Name, size = temp.Length, id = this.id, folder = false, root = root, permitWriting = !temp.IsReadOnly
                    };
                }
                root.AddComponent(dat);
            }
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
0
        public void AddComponentTest()
        {
            IComponent c = new FakeComponent();

            bool result = m_component.AddComponent(c);

            Assert.IsNotNull(c);
            Assert.IsNotNull(c.Parent);
            Assert.AreSame(c.Parent, m_component.Parent);
            Assert.IsTrue(result);
        }
Ejemplo n.º 11
0
 public void AddComponent(IComponent component, object InitialValue)
 {
     component.AddComponent(this, InitialValue);
 }
Ejemplo n.º 12
0
        private void copyFolder(string what, string where, IComponent root)
        {

            DirectoryInfo dir = new DirectoryInfo(what);
            DirectoryInfo[] dirs = dir.GetDirectories();

            DirectoryInfo _dir = Directory.CreateDirectory(where);

            this.id++;
            dir folder = null;
            if (DS_Type == "NTFS")
            {
                folder = new dir { path = _dir.FullName, id = this.id, name = _dir.Name, folder = true, root = root, link = System.IO.File.GetAttributes(_dir.FullName).HasFlag(FileAttributes.ReparsePoint) };
            }
            else if (DS_Type == "exFAT")
            {
                if (!System.IO.File.GetAttributes(_dir.FullName).HasFlag(FileAttributes.ReparsePoint))
                    folder = new dir { path = _dir.FullName, id = this.id, name = new DirectoryInfo(_dir.FullName).Name, folder = true, root = root, link = false };
            }

            root.AddComponent(folder);

            foreach (DirectoryInfo subdir in dirs)
            {
                string temppath = Path.Combine(where, subdir.Name);
                copyFolder(subdir.FullName, temppath, folder);
            }
            FileInfo[] files = dir.GetFiles();
            foreach (FileInfo file in files)
            {
                this.id++;
                string temppath = Path.Combine(where, file.Name);
                FileInfo temp = file.CopyTo(temppath, false);

                file dat = new file { path = temp.FullName, name = temp.Name, size = temp.Length, id = this.id, folder = false, root = folder, permitWriting = !temp.IsReadOnly, link = System.IO.File.GetAttributes(temp.FullName).HasFlag(FileAttributes.ReparsePoint) };
                folder.AddComponent(dat);

            }
        }
Ejemplo n.º 13
0
 public void AddComponent(int entityID, IComponent component, object InitialValue)
 {
     component.AddComponent(GetEntity(entityID), InitialValue);
 }