Esempio n. 1
0
        public DokanError CreateFile(string fileName, DokanNet.FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, DokanFileInfo info)
        {
            info.DeleteOnClose = (options & FileOptions.DeleteOnClose) != 0;
            //Console.WriteLine("CreateFile: {0}, mode = {1}", fileName, mode);

            if (fileName == "\\")
            {
                return DokanError.ErrorSuccess;
            }

            Directory dir = new Directory(Util.GetPathDirectory(fileName));
            if (!dir.Exists())
            {
                return DokanError.ErrorPathNotFound;
            }

            String name = Util.GetPathFileName(fileName);

            if (name.Length == 0)
            {
                return DokanError.ErrorInvalidName;
            }
            if (name.IndexOfAny(Path.GetInvalidFileNameChars()) > -1)
            {
                return DokanError.ErrorInvalidName;
            }

            // dokan API 要求在目标文件是目录时候,设置 info.IsDirectory = true
            if (dir.Contains(name) && (dir.GetItemInfo(name).attribute & FileAttributes.Directory) != 0)
            {
                info.IsDirectory = true;
                return DokanError.ErrorSuccess;
            }

            try
            {
                File f = new File(fileName, mode);
                f.flagDeleteOnClose = info.DeleteOnClose;
                info.Context = f;
            }
            catch (FileNotFoundException)
            {
                return DokanError.ErrorFileNotFound;
            }
            catch (IOException)
            {
                return DokanError.ErrorAlreadyExists;
            }
            catch (NotImplementedException)
            {
                return DokanError.ErrorAccessDenied;
            }
            catch (Exception)
            {
                return DokanError.ErrorError;
            }

            return DokanError.ErrorSuccess;
        }
Esempio n. 2
0
        public DokanError GetFileInformation(string fileName, out FileInformation fileInfo, DokanFileInfo info)
        {
            //Console.WriteLine("GetFileInformation: {0}, isDirectory = {1}", fileName, info.IsDirectory);

            if (fileName == "\\" || info.IsDirectory)
            {
                Directory dir = new Directory(fileName);
                if (!dir.Exists())
                {
                    //Console.WriteLine("GetFileInformation: PathNotFound");
                    fileInfo = new FileInformation();
                    return DokanError.ErrorPathNotFound;
                }

                String name;
                String path;

                if (fileName == "\\")
                {
                    name = "\\"; path = "\\";
                }
                else
                {
                    name = Util.GetPathFileName(fileName);
                    path = fileName;
                }

                fileInfo = new DirectoryItem(name, path, dir.GetSelfINodeIndex()).GetFileInformation();
                //Console.WriteLine("GetFileInformation: Success");
                return DokanError.ErrorSuccess;
            }

            {
                Directory dir = new Directory(Util.GetPathDirectory(fileName));

                if (!dir.Exists())
                {
                    fileInfo = new FileInformation();
                    return DokanError.ErrorPathNotFound;
                }

                String name = Util.GetPathFileName(fileName);

                if (!dir.Contains(name))
                {
                    fileInfo = new FileInformation();
                    return DokanError.ErrorPathNotFound;
                }

                fileInfo = dir.GetItemInfo(name).GetFileInformation();
                //Console.WriteLine("GetFileInformation: Success");
                return DokanError.ErrorSuccess;
            }
        }