Beispiel #1
0
        public void AddPath(string path)
        {
            var chunks = SplitUrl(path);
            string filename = null;
            if (path[path.Length - 1] != '\\')
            {
                filename = chunks[chunks.Length - 1];
                chunks = chunks.Take(chunks.Length - 1).ToArray();
            }

            var currentDirectory = Root;
            foreach (var chunk in chunks)
            {
                var nextDirectory = currentDirectory.Directories.Where(d => d.Name == chunk).SingleOrDefault();
                if (nextDirectory == null)
                {
                    nextDirectory = new FixedDirectoryInfo()
                    {
                        Name = chunk,
                        Path = currentDirectory.Path + "\\" + chunk
                    };
                    currentDirectory.Directories.Add(nextDirectory);
                }
                currentDirectory = nextDirectory;
            }

            if (filename == null)
                return;

            var currentFile = currentDirectory.Files.Where(f => f.Name == filename).SingleOrDefault();
            if (currentFile != null)
                return;

            currentDirectory.Files.Add(new FixedFileInfo()
            {
                Name = filename,
                Extension = Path.GetExtension(path),
                Path = path
            });
        }
Beispiel #2
0
 public FixedFileSystem()
 {
     Root = new FixedDirectoryInfo() { Name = "\\", Path = "\\" };
 }