示例#1
0
        // create a directory
        public override Dir_Jrod CreateDir(string fileName)
        {
            if (fileName.Contains("/") || fileName.Contains("\\"))
            {
                return(null);
            }

            // check their arent any files or dirs with the same name
            foreach (StdFSDir x in dirs)
            {
                if (x.Name == fileName)
                {
                    return(null);
                }
            }

            foreach (StdFSFile x in files)
            {
                if (x.Name == fileName)
                {
                    return(null);
                }
            }

            StdFSDir dir = new StdFSDir(fileName, this);
            string   m   = dir.GetPath();

            // m = m + "/" + dir.name;
            dirs.Add(dir);
            string cd = Directory.GetCurrentDirectory();

            Directory.CreateDirectory(m);
            return(dir);
        }
示例#2
0
        // this is used in the start function
        private void recursiveAdd(String path, StdFSDir start, List <string> dir_, List <string> files_)
        {
            // add all of the files to the directory
            foreach (string x in files_)
            {
                start.files.Add(new StdFSFile(x, start));
            }
            // if there arent anymore dirs we exit.
            if (dir_.Count == 0)
            {
                return;
            }
            // add all of the
            foreach (string x in dir_)
            {
                start.dirs.Add(new StdFSDir(x, start));
            }


            StringBuilder newpath = new StringBuilder();


            // This is where we recursively call the function, we hand it each new dir path we extracted and look for
            // dirs and files in those paths.
            foreach (StdFSDir x in start.dirs)
            {
                newpath.Append(path + "/" + x.Name);

                List <string> direc = new List <string>();
                foreach (string y in Directory.EnumerateDirectories(newpath.ToString()))
                {
                    string[] list = y.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                    // break the path up  so we can get the last name aka the name of the dir
                    direc.Add(list[list.Length - 1]);
                }

                List <string> files = new List <string>();
                foreach (string y in Directory.EnumerateFiles(newpath.ToString()))
                {
                    string[] list = y.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                    // break the path up  so we can get the last name aka the name of the dir
                    files.Add(list[list.Length - 1]);
                }


                recursiveAdd(newpath.ToString(), x, direc, files);
                newpath.Clear();
            }

            // recursiveAdd( newpath.ToString(), x,Directory.EnumerateDirectories(rootDir),Directory.EnumerateFiles(rootDir));
        }
示例#3
0
        // set up our file system recusively look down the file system and log all of them with or fs
        public static StandardFileSystem Create(string rootDir)
        {
            /// need to see how much protection for malcious code.
            string[] dirs = rootDir.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);


            if (!Directory.Exists(rootDir))
            {
                return(null);
            }


            //set the root


            // this is the new filesystem we are creaating and returning
            StdFSDir           root_dir = new StdFSDir(dirs[dirs.Length - 1], null);
            StandardFileSystem creation = new StandardFileSystem(root_dir, rootDir);

            // now we creation the filesystem structure internally with STDFSDIR AND STDFSFILE
            List <string> direc = new List <string>();

            foreach (string x in Directory.EnumerateDirectories(rootDir))
            {
                string[] list = x.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                direc.Add(list[list.Length - 1]);
            }

            List <string> files = new List <string>();

            foreach (string x in Directory.EnumerateFiles(rootDir))
            {
                string[] list = x.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                // break the path up  so we can get the last name aka the name of the dir
                files.Add(list[list.Length - 1]);
            }

            creation.recursiveAdd(rootDir, root_dir, direc, files);


            return(creation);
        }
示例#4
0
 // this sets the root dir
 public StandardFileSystem(StdFSDir new_root, string rootDir)
 {
     root = new_root;
     Directory.SetCurrentDirectory(rootDir);
 }