Exemplo n.º 1
0
 public int GetFileInformation(string filename, FileInformation fileinfo, DokanFileInfo info)
 {
     lock (_syncObj)
     {
         FileHandle handle = (FileHandle)info.Context;
         if (handle == null)
         {
             return(-DokanNet.ERROR_FILE_NOT_FOUND);
         }
         VirtualFileSystemResource resource = handle.Resource;
         VirtualFile file = resource as VirtualFile;
         IFileSystemResourceAccessor resourceAccessor = resource.ResourceAccessor;
         VirtualBaseDirectory        directory        = resource as VirtualBaseDirectory;
         fileinfo.FileName       = filename;
         fileinfo.CreationTime   = resource.CreationTime;
         fileinfo.LastAccessTime = CorrectTimeValue(resourceAccessor == null ? resource.CreationTime : resourceAccessor.LastChanged);
         fileinfo.LastWriteTime  = CorrectTimeValue(resource.CreationTime);
         if (file != null)
         {
             fileinfo.Attributes = FILE_ATTRIBUTES;
             fileinfo.Length     = resourceAccessor == null ? 0 : resourceAccessor.Size;
             return(DokanNet.DOKAN_SUCCESS);
         }
         if (directory != null)
         {
             fileinfo.Attributes = DIRECTORY_ATTRIBUTES;
             fileinfo.Length     = 0;
             return(DokanNet.DOKAN_SUCCESS);
         }
         return(-DokanNet.ERROR_FILE_NOT_FOUND);
     }
 }
Exemplo n.º 2
0
 public int FindFiles(string filename, ArrayList files, DokanFileInfo info)
 {
     lock (_syncObj)
     {
         FileHandle           handle    = (FileHandle)info.Context;
         VirtualBaseDirectory directory = handle == null ? null : handle.Resource as VirtualBaseDirectory;
         if (directory == null)
         {
             return(-DokanNet.ERROR_PATH_NOT_FOUND);
         }
         foreach (KeyValuePair <string, VirtualFileSystemResource> entry in directory.ChildResources)
         {
             VirtualFileSystemResource   resource         = entry.Value;
             IFileSystemResourceAccessor resourceAccessor = resource.ResourceAccessor;
             bool            isFile = resource is VirtualFile;
             FileInformation fi     = new FileInformation
             {
                 Attributes     = isFile ? FILE_ATTRIBUTES : DIRECTORY_ATTRIBUTES,
                 CreationTime   = resource.CreationTime,
                 LastAccessTime = CorrectTimeValue(resourceAccessor == null ? resource.CreationTime : resourceAccessor.LastChanged),
                 LastWriteTime  = CorrectTimeValue(directory.CreationTime),
                 Length         = resourceAccessor == null || !isFile ? 0 : resourceAccessor.Size,
                 FileName       = entry.Key
             };
             files.Add(fi);
         }
         return(DokanNet.DOKAN_SUCCESS);
     }
 }
Exemplo n.º 3
0
        public NtStatus FindFiles(string filename, out IList <FileInformation> files, DokanFileInfo info)
        {
            files = new List <FileInformation>();
            lock (_syncObj)
            {
                FileHandle           handle    = info.Context as FileHandle;
                VirtualBaseDirectory directory = handle == null ? null : handle.Resource as VirtualBaseDirectory;
                if (directory == null)
                {
                    files = null;
                    return(DokanResult.FileNotFound);
                }

                foreach (KeyValuePair <string, VirtualFileSystemResource> entry in directory.ChildResources)
                {
                    VirtualFileSystemResource   resource         = entry.Value;
                    IFileSystemResourceAccessor resourceAccessor = resource.ResourceAccessor;
                    bool            isFile = resource is VirtualFile;
                    FileInformation fi     = new FileInformation
                    {
                        Attributes     = isFile ? FILE_ATTRIBUTES : DIRECTORY_ATTRIBUTES,
                        CreationTime   = resource.CreationTime,
                        LastAccessTime = CorrectTimeValue(resourceAccessor == null ? resource.CreationTime : resourceAccessor.LastChanged),
                        LastWriteTime  = CorrectTimeValue(directory.CreationTime),
                        Length         = resourceAccessor == null || !isFile ? 0 : resourceAccessor.Size,
                        FileName       = entry.Key
                    };
                    files.Add(fi);
                }
                return(DokanResult.Success);
            }
        }
Exemplo n.º 4
0
        public NtStatus GetFileInformation(string filename, out FileInformation fileinfo, DokanFileInfo info)
        {
            lock (_syncObj)
            {
                fileinfo = new FileInformation();
                FileHandle handle = info.Context as FileHandle;
                if (handle == null)
                {
                    return(DokanResult.FileNotFound);
                }

                VirtualFileSystemResource resource = handle.Resource;
                VirtualFile file = resource as VirtualFile;
                IFileSystemResourceAccessor resourceAccessor = resource.ResourceAccessor;
                VirtualBaseDirectory        directory        = resource as VirtualBaseDirectory;
                fileinfo.FileName       = filename;
                fileinfo.CreationTime   = resource.CreationTime;
                fileinfo.LastAccessTime = CorrectTimeValue(resourceAccessor == null ? resource.CreationTime : resourceAccessor.LastChanged);
                fileinfo.LastWriteTime  = CorrectTimeValue(resource.CreationTime);
                if (file != null)
                {
                    fileinfo.Attributes = FILE_ATTRIBUTES;
                    fileinfo.Length     = resourceAccessor == null ? 0 : resourceAccessor.Size;
                    return(DokanResult.Success);
                }
                if (directory != null)
                {
                    fileinfo.Attributes = DIRECTORY_ATTRIBUTES;
                    fileinfo.Length     = 0;
                    return(DokanResult.Success);
                }
                return(DokanResult.FileNotFound);
            }
        }
Exemplo n.º 5
0
 public int OpenDirectory(string filename, DokanFileInfo info)
 {
     lock (_syncObj)
     {
         VirtualFileSystemResource resource = ParseFileName(filename);
         if (resource == null || !(resource is VirtualBaseDirectory))
         {
             return(-DokanNet.ERROR_PATH_NOT_FOUND);
         }
         FileHandle handle = new FileHandle(resource);
         info.Context = handle;
         resource.AddFileHandle(handle);
         return(DokanNet.DOKAN_SUCCESS);
     }
 }
Exemplo n.º 6
0
 public int CreateFile(string filename, FileAccess access, FileShare share, FileMode mode, FileOptions options, DokanFileInfo info)
 {
     lock (_syncObj)
     {
         VirtualFileSystemResource resource = ParseFileName(filename);
         if (resource == null)
         {
             return(-DokanNet.ERROR_FILE_NOT_FOUND);
         }
         FileHandle handle = new FileHandle(resource);
         info.Context = handle;
         resource.AddFileHandle(handle);
         if (resource is VirtualBaseDirectory)
         {
             info.IsDirectory = true; // Necessary for the Dokan driver to set this, see docs
         }
         return(DokanNet.DOKAN_SUCCESS);
     }
 }
Exemplo n.º 7
0
 public NtStatus CreateFile(string filename, FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, DokanFileInfo info)
 {
     lock (_syncObj)
     {
         VirtualFileSystemResource resource = ParseFileName(filename);
         if (resource == null)
         {
             return(DokanResult.Error);
         }
         FileHandle handle = new FileHandle(resource);
         info.Context = handle;
         resource.AddFileHandle(handle);
         if (resource is VirtualBaseDirectory)
         {
             info.IsDirectory = true;
         }
         return(DokanResult.Success);
     }
 }
Exemplo n.º 8
0
        protected VirtualFileSystemResource ParseFileName(string fileName)
        {
            if (fileName == "\\")
            {
                return(_root);
            }
            if (!fileName.StartsWith("\\"))
            {
                return(null);
            }
            string[] pathSegments = fileName.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
            VirtualFileSystemResource resource = _root;

            lock (_syncObj)
                foreach (string pathSegment in pathSegments)
                {
                    VirtualBaseDirectory directory = resource as VirtualBaseDirectory;
                    if (directory == null || !directory.ChildResources.TryGetValue(pathSegment, out resource))
                    {
                        return(null);
                    }
                }
            return(resource);
        }
Exemplo n.º 9
0
 public FileHandle(VirtualFileSystemResource resource)
 {
     _resource = resource;
 }
Exemplo n.º 10
0
 public FileHandle(VirtualFileSystemResource resource)
 {
   _resource = resource;
 }
Exemplo n.º 11
0
 public void AddResource(string name, VirtualFileSystemResource resource)
 {
     _children.Add(name, resource);
 }
Exemplo n.º 12
0
 public void AddResource(string name, VirtualFileSystemResource resource)
 {
   _children.Add(name, resource);
 }