Example #1
0
 public VFSItem(VFSFolder vfolder, string path, bool isFolder, long length)
 {
     Folder    = vfolder;
     Path      = path;
     Directory = isFolder;
     Name      = System.IO.Path.GetFileName(path);
     Length    = length;
 }
Example #2
0
        public Stream OpenWrite(string path)
        {
            VFSFolder folder = LocateFolder(ref path);

            if (folder == null)
            {
                return(null);
            }
            return(folder.OpenWrite(path));
        }
Example #3
0
        public VFSItem[] ListDirectories(string path)
        {
            VFSFolder folder = LocateFolder(ref path);

            if (folder == null)
            {
                return(null);
            }
            return(folder.ListDirectories(path));
        }
Example #4
0
 public void AddVirtualFolder(string path, VFSFolder folder)
 {
     if (string.IsNullOrWhiteSpace(path))
     {
         path = "/";
     }
     else
     {
         path = path.Trim().ToLower();
         if (path[0] != '/')
         {
             path = '/' + path;
         }
     }
     vf[path] = folder;
 }
Example #5
0
        public VFSItem GetItem(string path)
        {
            while (path != "/" && path.EndsWith("/"))
            {
                path = path.Substring(0, path.Length - 1);
            }
            if (path.Length == 0)
            {
                path = "/";
            }
            VFSFolder folder = LocateFolder(ref path);

            if (folder == null)
            {
                return(null);
            }
            return(folder.GetItem(path));
        }
Example #6
0
        private VFSFolder LocateFolder(ref string path)
        {
            VFSFolder candidate             = null;
            string    candidatePath         = null;
            string    candidateRelativePath = null;

            foreach (string k in vf.Keys)
            {
                if (candidate == null ||
                    (path.StartsWith(k) && k.Length > candidatePath.Length))
                {
                    candidate             = vf[k];
                    candidatePath         = k;
                    candidateRelativePath = path.Substring(k.Length);
                }
            }
            path = candidateRelativePath;
            return(candidate);
        }