public static File GenerateFilesystem() { //Generate root directory File root = new File (); //Generate home, boot, and bin File home = new File ("home", true); File boot = new File ("boot", true); File bin = new File ("bin", true); //Generate homefolder content //This is generics home.AddChild (new File ("Documents", true)); //Generate bootfolder content //This is where bootspecifics go, x-server etc File config = new File ("config",false); boot.AddChild (config); //Generate binfolder content //This is where are all commands go //Add home, boot and bin to filesystem root.AddChild (home); root.AddChild (boot); root.AddChild (bin); return root; }
public File ChangeDirectory(File currentDirectory, string targetName) { File temp = null; if(targetName != ".." && targetName[0] != '/') { foreach(File file in currentDirectory.Children) { if(targetName == file.Name) { temp = file; break; } } if(temp == null) { throw new DirectoryException ("Directory doesnt exist"); } else { if(!temp.Dir) { throw new DirectoryException ("Target isnt a directory.."); } } } else if(targetName == "..") { if (!currentDirectory.Root) return currentDirectory.Parent; else throw new DirectoryException ("Already at rootdirectory"); } else if(targetName[0] == '/') { File current = Filesystem; string[] directorys = targetName.Split ('/'); for(int i = 1; i < directorys.Length; i++) { bool found = false; foreach(File file in current.Children) { if(file.Name == directorys[i]) { current = file; found = true; break; } } if(!found) { throw new DirectoryException ("Path " + targetName + " wasnt found..."); } } temp = current; } return temp; }
public void AddChild(File file) { if(this.Dir) { foreach(File child in Children) { if(child.Name == file.Name) { throw new DirectoryException ("Directory already contains file with name " + file.Name); } } file.Parent = this; this.Children.Add (file); } else { throw new DirectoryException ("Cannot add child to non-directory"); } }
public MainClass () { currentComputer = new Computer ("192.168.0.0"); currentComputer.Username = "******"; currentDirectory = currentComputer.Filesystem; }
public void PrintPrompt(File currentDirectory) { Console.Write ("{0}@{1} \n/{2}\n--> ",Username,IP,currentDirectory.Name); }