public FileNode parent; // odniesienie do węzła nadrzędnego #endregion Fields #region Constructors public FileNode() { this.name = ""; this.isDirectory = false; this.fileLocation = null; this.children = null; this.parent = null; }
public FileNode(string name) { this.name = name; this.isDirectory = true; this.fileLocation = null; this.children = new List<FileNode>(); this.parent = null; }
public FileNode(string name, FileNetworkAddress address) { this.name = name; this.isDirectory = false; this.fileLocation = new ArrayList(); this.fileLocation.Add(address); this.children = null; this.parent = null; }
public FileTree() { root = new FileNode("/"); }
public string mkdir(string path, string name) { FileNode newDirectory = new FileNode(name); FileNode directory; bool exist = false; directory = locateDirectory(path); if (directory == null) return "Path doesn't exist. Can't create directory!"; foreach (FileNode fn in directory.children) if (fn.name == name && fn.isDirectory == true) exist = true; if (exist == true) return "Directory exist. Can't create!"; else { newDirectory.parent = directory; directory.children.Add(newDirectory); return "Directory created."; } }
private void delete() { root = new FileNode("/"); }
public void findDirectory(FileNode directory, string workingDirectory, string name, ArrayList result) { foreach (FileNode fn in directory.children) { Console.WriteLine("AAA {0}, {1}, {2},", fn.name, name, fn.isDirectory); if (fn.name == name && fn.isDirectory == true) { result.Add(workingDirectory + "/" + name); Console.WriteLine("ffff"); } if (fn.isDirectory == true) findDirectory(fn, workingDirectory + "/" + fn.name, name, result); } }
public void findFile(FileNode directory, string workingDirectory, string name, ArrayList result) { foreach (FileNode fn in directory.children) { if (fn.name == name && fn.isDirectory == false) result.Add(workingDirectory + "/" + name); if (fn.isDirectory == true) findFile(fn, workingDirectory + "/" + fn.name, name, result); } }
public string create(string path, string name, string locationIP, string locationPort, string id) { FileNode directory; bool exist = false; directory = locateDirectory(path); if (directory == null) return "Path doesn't exist. Can't create file!"; foreach (FileNode fn in directory.children) if (fn.name == name && fn.isDirectory == false) exist = true; if (exist == true) return "File exist. Can't create!"; else { FileNetworkAddress address = new FileNetworkAddress(id, locationIP, locationPort); FileNode newFile = new FileNode(name, address); newFile.parent = directory; directory.children.Add(newFile); return "File successfully created."; } }
public string cpdir(string sourcePath, string destinationPath) { FileNode file, newFile; FileNode destinationDiretory; bool exist = false; file = locateDirectory(sourcePath); if (file == null) return "Directory doesn't exist. Can't copy!"; destinationDiretory = locateDirectory(destinationPath); if (destinationDiretory == null) return "Destination directory doesn't exist. Can't copy!"; if (file.children.Count > 0) return "Source directory doesn't empty. Can't copy!"; foreach (FileNode fn in destinationDiretory.children) if (fn.name == file.name && fn.isDirectory == true) exist = true; if (exist == true) return "In destination directory exist directory with the same name. Can't copy!"; newFile = new FileNode(file.name); newFile.parent = destinationDiretory; destinationDiretory.children.Add(newFile); return "Directory successfully copied."; }
public string cp(string sourcePath, string destinationPath, FileNetworkAddress address) { FileNode file, newFile; FileNode destinationDiretory; bool exist = false; file = locateFile(sourcePath); if (file == null) return "File doesn't exist. Can't copy!"; destinationDiretory = locateDirectory(destinationPath); if (destinationDiretory == null) return "Destination directory doesn't exist. Can't copy!"; foreach (FileNode fn in destinationDiretory.children) if (fn.name == file.name && fn.isDirectory == false) exist = true; if (exist == true) return "In destination directory exist file with the same name. Can't copy!"; newFile = new FileNode(file.name, address); newFile.parent = destinationDiretory; destinationDiretory.children.Add(newFile); return "File successfully copied."; }