示例#1
0
        private static string GetStatusErrorMessage(DokanStatus status)
        {
            switch (status)
            {
            case DokanStatus.Error:
                return(Resources.ErrorDokan);

            case DokanStatus.DriveLetterError:
                return(Resources.ErrorBadDriveLetter);

            case DokanStatus.DriverInstallError:
                return(Resources.ErrorDriverInstall);

            case DokanStatus.MountError:
                return(Resources.ErrorAssignDriveLetter);

            case DokanStatus.StartError:
                return(Resources.ErrorStart);

            case DokanStatus.MountPointError:
                return(Resources.ErrorMountPointInvalid);

            case DokanStatus.VersionError:
                return(Resources.ErrorVersion);

            default:
                return(Resources.ErrorUnknown);
            }
        }
示例#2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DokanException"/> class with a <see cref="Exception.HResult"/>.
 /// </summary>
 /// <param name="status">
 /// The error status also written to <see cref="Exception.HResult"/>.
 /// </param>
 /// <param name="message">
 /// The error message.
 /// </param>
 internal DokanException(DokanStatus status, string message)
     : base(message)
 {
     ErrorStatus = status;
     HResult     = (int)status;
 }
示例#3
0
        /// <summary>
        /// Mount a new %Dokan Volume.
        /// This function block until the device is unmount.
        /// </summary>
        /// <param name="operations">Instance of <see cref="IDokanOperations"/> that will be called for each request made by the kernel.</param>
        /// <param name="mountPoint">Mount point. Can be <c>M:\\</c> (drive letter) or <c>C:\\mount\\dokan</c> (path in NTFS).</param>
        /// <param name="mountOptions"><see cref="DokanOptions"/> features enable for the mount.</param>
        /// <param name="threadCount">Number of threads to be used internally by %Dokan library. More thread will handle more event at the same time.</param>
        /// <param name="version">Version of the dokan features requested (Version "123" is equal to %Dokan version 1.2.3).</param>
        /// <param name="timeout">Max timeout in ms of each request before dokan give up.</param>
        /// <param name="uncName">UNC name used for network volume.</param>
        /// <param name="allocationUnitSize">Allocation Unit Size of the volume. This will behave on the file size.</param>
        /// <param name="sectorSize">Sector Size of the volume. This will behave on the file size.</param>
        /// <param name="logger"><see cref="ILogger"/> that will log all DokanNet debug informations.</param>
        /// <exception cref="DokanException">If the mount fails.</exception>
        public static void Mount(this IDokanOperations operations, string mountPoint, DokanOptions mountOptions,
                                 int threadCount, int version, TimeSpan timeout, string uncName = null, int allocationUnitSize = 512,
                                 int sectorSize = 512, ILogger logger = null)
        {
            if (logger == null)
            {
#if TRACE
                logger = new ConsoleLogger("[DokanNet] ");
#else
                logger = new NullLogger();
#endif
            }

            var dokanOperationProxy = new DokanOperationProxy(operations, logger);

            var dokanOptions = new DOKAN_OPTIONS
            {
                Version            = (ushort)version,
                MountPoint         = mountPoint,
                UNCName            = string.IsNullOrEmpty(uncName) ? null : uncName,
                ThreadCount        = (ushort)threadCount,
                Options            = (uint)mountOptions,
                Timeout            = (uint)timeout.TotalMilliseconds,
                AllocationUnitSize = (uint)allocationUnitSize,
                SectorSize         = (uint)sectorSize
            };

            var dokanOperations = new DOKAN_OPERATIONS
            {
                ZwCreateFile         = dokanOperationProxy.ZwCreateFileProxy,
                Cleanup              = dokanOperationProxy.CleanupProxy,
                CloseFile            = dokanOperationProxy.CloseFileProxy,
                ReadFile             = dokanOperationProxy.ReadFileProxy,
                WriteFile            = dokanOperationProxy.WriteFileProxy,
                FlushFileBuffers     = dokanOperationProxy.FlushFileBuffersProxy,
                GetFileInformation   = dokanOperationProxy.GetFileInformationProxy,
                FindFiles            = dokanOperationProxy.FindFilesProxy,
                FindFilesWithPattern = dokanOperationProxy.FindFilesWithPatternProxy,
                SetFileAttributes    = dokanOperationProxy.SetFileAttributesProxy,
                SetFileTime          = dokanOperationProxy.SetFileTimeProxy,
                DeleteFile           = dokanOperationProxy.DeleteFileProxy,
                DeleteDirectory      = dokanOperationProxy.DeleteDirectoryProxy,
                MoveFile             = dokanOperationProxy.MoveFileProxy,
                SetEndOfFile         = dokanOperationProxy.SetEndOfFileProxy,
                SetAllocationSize    = dokanOperationProxy.SetAllocationSizeProxy,
                LockFile             = dokanOperationProxy.LockFileProxy,
                UnlockFile           = dokanOperationProxy.UnlockFileProxy,
                GetDiskFreeSpace     = dokanOperationProxy.GetDiskFreeSpaceProxy,
                GetVolumeInformation = dokanOperationProxy.GetVolumeInformationProxy,
                Mounted              = dokanOperationProxy.MountedProxy,
                Unmounted            = dokanOperationProxy.UnmountedProxy,
                GetFileSecurity      = dokanOperationProxy.GetFileSecurityProxy,
                SetFileSecurity      = dokanOperationProxy.SetFileSecurityProxy,
                FindStreams          = dokanOperationProxy.FindStreamsProxy
            };

            DokanStatus status = (DokanStatus)NativeMethods.DokanMain(ref dokanOptions, ref dokanOperations);
            if (status != DokanStatus.Success)
            {
                throw new DokanException(status);
            }
        }
示例#4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DokanException"/> class with a <see cref="Exception.HResult"/>.
 /// </summary>
 /// <param name="status">
 /// The error status also written to <see cref="Exception.HResult"/>.
 /// </param>
 internal DokanException(DokanStatus status)
     : this(status, GetStatusErrorMessage(status))
 {
 }
示例#5
0
        /// <summary>
        /// Mount a new %Dokan Volume.
        /// It is mandatory to have called <see cref="DokanInit"/> previously to use this API.
        /// This function returns directly on device mount or on failure.
        /// <see cref="WaitForFileSystemClosed"/> can be used to wait until the device is unmount.
        /// </summary>
        /// <param name="operations">Instance of <see cref="IDokanOperations"/> that will be called for each request made by the kernel.</param>
        /// <param name="mountPoint">Mount point. Can be <c>M:\\</c> (drive letter) or <c>C:\\mount\\dokan</c> (path in NTFS).</param>
        /// <param name="mountOptions"><see cref="DokanOptions"/> features enable for the mount.</param>
        /// <param name="singleThread">Number of threads to be used internally by %Dokan library. More thread will handle more event at the same time.</param>
        /// <param name="version">Version of the dokan features requested (Version "123" is equal to %Dokan version 1.2.3).</param>
        /// <param name="timeout">Max timeout in ms of each request before dokan give up.</param>
        /// <param name="uncName">UNC name used for network volume.</param>
        /// <param name="allocationUnitSize">Allocation Unit Size of the volume. This will behave on the file size.</param>
        /// <param name="sectorSize">Sector Size of the volume. This will behave on the file size.</param>
        /// <param name="logger"><see cref="ILogger"/> that will log all DokanNet debug informations.</param>
        /// <exception cref="DokanException">If the mount fails.</exception>
        /// <returns>Dokan mount instance context that can be used for related instance calls like <see cref="IsFileSystemRunning"/></returns>
        public static DokanInstance CreateFileSystem(this IDokanOperations operations, string mountPoint, DokanOptions mountOptions,
                                                     bool singleThread, int version, TimeSpan timeout, string uncName = null, int allocationUnitSize = 512,
                                                     int sectorSize = 512, ILogger logger = null)
        {
            if (logger == null)
            {
#if TRACE
                logger = new ConsoleLogger("[DokanNet] ");
#else
                logger = new NullLogger();
#endif
            }

            DokanInstance instance = new DokanInstance();

            var dokanOperationProxy = new DokanOperationProxy(operations, logger);

            var dokanOptions = new DOKAN_OPTIONS
            {
                Version                        = (ushort)version,
                MountPoint                     = mountPoint,
                UNCName                        = string.IsNullOrEmpty(uncName) ? null : uncName,
                SingleThread                   = singleThread,
                Options                        = (uint)mountOptions,
                Timeout                        = (uint)timeout.TotalMilliseconds,
                AllocationUnitSize             = (uint)allocationUnitSize,
                SectorSize                     = (uint)sectorSize,
                VolumeSecurityDescriptorLength = 0
            };

            instance.DokanOptions = new NativeStructWrapper <DOKAN_OPTIONS>(dokanOptions);

            var dokanOperations = new DOKAN_OPERATIONS
            {
                ZwCreateFile         = dokanOperationProxy.ZwCreateFileProxy,
                Cleanup              = dokanOperationProxy.CleanupProxy,
                CloseFile            = dokanOperationProxy.CloseFileProxy,
                ReadFile             = dokanOperationProxy.ReadFileProxy,
                WriteFile            = dokanOperationProxy.WriteFileProxy,
                FlushFileBuffers     = dokanOperationProxy.FlushFileBuffersProxy,
                GetFileInformation   = dokanOperationProxy.GetFileInformationProxy,
                FindFiles            = dokanOperationProxy.FindFilesProxy,
                FindFilesWithPattern = dokanOperationProxy.FindFilesWithPatternProxy,
                SetFileAttributes    = dokanOperationProxy.SetFileAttributesProxy,
                SetFileTime          = dokanOperationProxy.SetFileTimeProxy,
                DeleteFile           = dokanOperationProxy.DeleteFileProxy,
                DeleteDirectory      = dokanOperationProxy.DeleteDirectoryProxy,
                MoveFile             = dokanOperationProxy.MoveFileProxy,
                SetEndOfFile         = dokanOperationProxy.SetEndOfFileProxy,
                SetAllocationSize    = dokanOperationProxy.SetAllocationSizeProxy,
                LockFile             = dokanOperationProxy.LockFileProxy,
                UnlockFile           = dokanOperationProxy.UnlockFileProxy,
                GetDiskFreeSpace     = dokanOperationProxy.GetDiskFreeSpaceProxy,
                GetVolumeInformation = dokanOperationProxy.GetVolumeInformationProxy,
                Mounted              = dokanOperationProxy.MountedProxy,
                Unmounted            = dokanOperationProxy.UnmountedProxy,
                GetFileSecurity      = dokanOperationProxy.GetFileSecurityProxy,
                SetFileSecurity      = dokanOperationProxy.SetFileSecurityProxy,
                FindStreams          = dokanOperationProxy.FindStreamsProxy
            };

            instance.DokanOperations = new NativeStructWrapper <DOKAN_OPERATIONS>(dokanOperations);

            DokanStatus status = NativeMethods.DokanCreateFileSystem(instance.DokanOptions, instance.DokanOperations, out instance.DokanHandle);
            if (status != DokanStatus.Success)
            {
                throw new DokanException(status);
            }

            return(instance);
        }