Пример #1
0
        public override Int32 CanDelete(
            Object fileNode,
            Object fileDesc0,
            String fileName)
        {
            FileDescriptor fileDesc = (FileDescriptor)fileDesc0;

            if (fileDesc.IsWriteable())
            {
                fileDesc.SetDisposition(false);
                return(STATUS_SUCCESS);
            }
            else
            {
                return(STATUS_ACCESS_DENIED);
            }
        }
Пример #2
0
        public void MakeWriteable(FileDescriptor fileDesc)
        {
            if (!fileDesc.IsWriteable())
            {
                var path = Path.GetDirectoryName(GetWritePath(fileDesc.FileName));
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                path = GetWritePath(fileDesc.FileName);

                File.Copy(GetReadOnlyPath(fileDesc.FileName), path, true);

                fileDesc.WriteStream = new FileStream(
                    path,
                    FileMode.Open,
                    FileAccess.ReadWrite,
                    FileShare.Read | FileShare.Write | FileShare.Delete,
                    4096, 0);
            }
        }
Пример #3
0
        public override Boolean ReadDirectoryEntry(
            Object fileNode,
            Object fileDesc0,
            String pattern,
            String marker,
            ref Object context,
            out String fileName,
            out FileInfo fileInfo)
        {
            FileDescriptor fileDesc = (FileDescriptor)fileDesc0;

            if (null == fileDesc.FileSystemInfos)
            {
                if (null != pattern)
                {
                    pattern = pattern.Replace('<', '*').Replace('>', '?').Replace('"', '.');
                }
                else
                {
                    pattern = "*";
                }

                SortedList list = new SortedList();

                if (fileDesc.IsWriteable())
                {
                    if (null != fileDesc.WriteDirInfo && null != fileDesc.WriteDirInfo.Parent)
                    {
                        list.Add(".", fileDesc.WriteDirInfo);
                        list.Add("..", fileDesc.WriteDirInfo.Parent);
                    }
                }
                else
                {
                    if (null != fileDesc.ReadOnlyDirInfo && null != fileDesc.ReadOnlyDirInfo.Parent)
                    {
                        list.Add(".", fileDesc.ReadOnlyDirInfo);
                        list.Add("..", fileDesc.ReadOnlyDirInfo.Parent);
                    }
                }

                if (fileDesc.WriteDirInfo != null)
                {
                    IEnumerable e = fileDesc.WriteDirInfo.EnumerateFileSystemInfos(pattern);

                    foreach (FileSystemInfo info in e)
                    {
                        list.Add(info.Name, info);
                    }
                }

                if (fileDesc.ReadOnlyDirInfo != null)
                {
                    IEnumerable e = fileDesc.ReadOnlyDirInfo.EnumerateFileSystemInfos(pattern);

                    foreach (FileSystemInfo info in e)
                    {
                        if (!list.ContainsKey(info.Name))
                        {
                            list.Add(info.Name, info);
                        }
                    }
                }

                fileDesc.FileSystemInfos = new DictionaryEntry[list.Count];

                list.CopyTo(fileDesc.FileSystemInfos, 0);
            }
            int index;

            if (null == context)
            {
                index = 0;
                if (null != marker)
                {
                    index = Array.BinarySearch(fileDesc.FileSystemInfos,
                                               new DictionaryEntry(marker, null),
                                               Utils._DirectoryEntryComparer);
                    if (0 <= index)
                    {
                        index++;
                    }
                    else
                    {
                        index = ~index;
                    }
                }
            }
            else
            {
                index = (int)context;
            }
            if (fileDesc.FileSystemInfos.Length > index)
            {
                context  = index + 1;
                fileName = (String)fileDesc.FileSystemInfos[index].Key;
                Utils.GetFileInfoFromFileSystemInfo(
                    (FileSystemInfo)fileDesc.FileSystemInfos[index].Value,
                    out fileInfo);
                return(true);
            }
            else
            {
                fileName = default(String);
                fileInfo = default(FileInfo);
                return(false);
            }
        }