Ejemplo n.º 1
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="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, ILogger logger = null)
 {
     Mount(operations, mountPoint, mountOptions, threadCount, version, timeout, uncName, 512, 512, logger);
 }
Ejemplo n.º 2
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="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, ILogger logger = null)
 {
     Mount(operations, mountPoint, mountOptions, threadCount, version, TimeSpan.FromSeconds(20), string.Empty,
           512, 512, logger);
 }
Ejemplo n.º 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
            };

            var status = NativeMethods.DokanMain(ref dokanOptions, ref dokanOperations);

            switch (status)
            {
            case DOKAN_SUCCESS:
                break;

            case DOKAN_ERROR:
                throw new DokanException(status, Resources.ErrorDokan);

            case DOKAN_DRIVE_LETTER_ERROR:
                throw new DokanException(status, Resources.ErrorBadDriveLetter);

            case DOKAN_DRIVER_INSTALL_ERROR:
                throw new DokanException(status, Resources.ErrorDriverInstall);

            case DOKAN_MOUNT_ERROR:
                throw new DokanException(status, Resources.ErrorAssignDriveLetter);

            case DOKAN_START_ERROR:
                throw new DokanException(status, Resources.ErrorStart);

            case DOKAN_MOUNT_POINT_ERROR:
                throw new DokanException(status, Resources.ErrorMountPointInvalid);

            case DOKAN_VERSION_ERROR:
                throw new DokanException(status, Resources.ErrorVersion);

            default:
                throw new DokanException(status, Resources.ErrorUnknown);
            }
        }
Ejemplo n.º 4
0
 public Proxy(DokanOptions options, IDokanOperations operations)
 {
     this.operations = operations;
     this.options    = options;
 }
Ejemplo n.º 5
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="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, ILogger logger = null)
 {
     Mount(operations, mountPoint, mountOptions, threadCount, DOKAN_VERSION, logger);
 }
Ejemplo n.º 6
0
 public static void Mount(this IDokanOperations operations, string mountPoint, DokanOptions mountOptions, int threadCount, int version)
 {
     Mount(operations, mountPoint, mountOptions, threadCount, version, TimeSpan.FromSeconds(20));
 }
Ejemplo n.º 7
0
        public static void Mount(this IDokanOperations operations, string mountPoint, DokanOptions mountOptions, int threadCount, int version)
        {
            var dokanOperationProxy = new DokanOperationProxy(operations);

            var dokanOptions = new DOKAN_OPTIONS
            {
                Version     = (ushort)version,
                MountPoint  = mountPoint,
                ThreadCount = (ushort)threadCount,
                Options     = (uint)mountOptions,
            };

            /*    dokanOptions.Options |= options.RemovableDrive ? DOKAN_OPTION_REMOVABLE : 0;
             *  dokanOptions.Options |= options.DebugMode ? DOKAN_OPTION_DEBUG : 0;
             *  dokanOptions.Options |= options.UseStandardError ? DOKAN_OPTION_STDERR : 0;
             *  dokanOptions.Options |= options.UseAlternativeStreams ? DOKAN_OPTION_ALT_STREAM : 0;
             *  dokanOptions.Options |= options.UseKeepAlive ? DOKAN_OPTION_KEEP_ALIVE : 0;
             *  dokanOptions.Options |= options.NetworkDrive ? DOKAN_OPTION_NETWORK : 0;*/

            var dokanOperations = new DOKAN_OPERATIONS
            {
                CreateFile           = dokanOperationProxy.CreateFileProxy,
                OpenDirectory        = dokanOperationProxy.OpenDirectoryProxy,
                CreateDirectory      = dokanOperationProxy.CreateDirectoryProxy,
                Cleanup              = dokanOperationProxy.CleanupProxy,
                CloseFile            = dokanOperationProxy.CloseFileProxy,
                ReadFile             = dokanOperationProxy.ReadFileProxy,
                WriteFile            = dokanOperationProxy.WriteFileProxy,
                FlushFileBuffers     = dokanOperationProxy.FlushFileBuffersProxy,
                GetFileInformation   = dokanOperationProxy.GetFileInformationProxy,
                FindFiles            = dokanOperationProxy.FindFilesProxy,
                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,
                Unmount              = dokanOperationProxy.UnmountProxy,
                GetFileSecurity      = dokanOperationProxy.GetFileSecurityProxy,
                SetFileSecurity      = dokanOperationProxy.SetFileSecurityProxy,
            };

            int status = NativeMethods.DokanMain(ref dokanOptions, ref dokanOperations);

            switch (status)
            {
            case DOKAN_ERROR:
                throw new DokanException(status, "Dokan error");

            case DOKAN_DRIVE_LETTER_ERROR:
                throw new DokanException(status, "Bad drive letter");

            case DOKAN_DRIVER_INSTALL_ERROR:
                throw new DokanException(status, "Can't install driver");

            case DOKAN_MOUNT_ERROR:
                throw new DokanException(status, "Can't assign a drive letter or mount point");

            case DOKAN_START_ERROR:
                throw new DokanException(status, "Something's wrong with Dokan driver");

            case DOKAN_MOUNT_POINT_ERROR:
                throw new DokanException(status, "Mount point is invalid ");
            }
        }
Ejemplo n.º 8
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="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, ILogger logger = null)
 {
     return(CreateFileSystem(operations, mountPoint, mountOptions, singleThread, version, timeout, uncName, 512, 512, logger));
 }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
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="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, ILogger logger = null)
 {
     return(CreateFileSystem(operations, mountPoint, mountOptions, singleThread, DOKAN_VERSION, logger));
 }
Ejemplo n.º 11
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="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, ILogger logger = null)
 {
     return(CreateFileSystem(operations, mountPoint, mountOptions, singleThread, version, TimeSpan.FromSeconds(20), string.Empty,
                             512, 512, logger));
 }
Ejemplo n.º 12
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="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,
                                              ILogger logger = null)
 {
     return(CreateFileSystem(operations, mountPoint, mountOptions, false, logger));
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Mount a new %Dokan Volume.
 /// This function block until the device is unmount.
 /// It is mandatory to have called <see cref="DokanInit"/> previously to use this API.
 /// </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">Only use a single thread to process events. This is highly not recommended as can easily create a bottleneck.</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="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,
                          bool singleThread, int version, TimeSpan timeout, ILogger logger = null)
 {
     Mount(operations, mountPoint, mountOptions, singleThread, version, timeout, string.Empty, 512, 512, logger);
 }
Ejemplo n.º 14
0
        public static void Mount(this IDokanOperations operations, string mountPoint, DokanOptions mountOptions, int threadCount, int version, TimeSpan timeout)
        {
            var dokanOperationProxy = new DokanOperationProxy(operations);

            var dokanOptions = new DOKAN_OPTIONS
            {
                Version     = (ushort)version,
                MountPoint  = mountPoint,
                ThreadCount = (ushort)threadCount,
                Options     = (uint)mountOptions,
                Timeout     = (uint)timeout.Milliseconds
            };

            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,
                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,
                Unmount              = dokanOperationProxy.UnmountProxy,
                GetFileSecurity      = dokanOperationProxy.GetFileSecurityProxy,
                SetFileSecurity      = dokanOperationProxy.SetFileSecurityProxy,
                FindStreams          = dokanOperationProxy.FindStreamsProxy
            };

            int status = NativeMethods.DokanMain(ref dokanOptions, ref dokanOperations);

            switch (status)
            {
            case DOKAN_ERROR:
                throw new DokanException(status, "Dokan error");

            case DOKAN_DRIVE_LETTER_ERROR:
                throw new DokanException(status, "Bad drive letter");

            case DOKAN_DRIVER_INSTALL_ERROR:
                throw new DokanException(status, "Can't install the Dokan driver");

            case DOKAN_MOUNT_ERROR:
                throw new DokanException(status, "Can't assign a drive letter or mount point");

            case DOKAN_START_ERROR:
                throw new DokanException(status, "Something's wrong with the Dokan driver");

            case DOKAN_MOUNT_POINT_ERROR:
                throw new DokanException(status, "Mount point is invalid ");
            }
        }
Ejemplo n.º 15
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);
            }
        }
Ejemplo n.º 16
0
 public static void Mount(this IDokanOperations operations, string mountPoint, DokanOptions mountOptions, int threadCount)
 {
     Mount(operations, mountPoint, mountOptions, threadCount, DOKAN_VERSION);
 }
Ejemplo n.º 17
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="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,
                          ILogger logger = null)
 {
     Mount(operations, mountPoint, mountOptions, 0, logger);
 }
Ejemplo n.º 18
0
 public static void Mount(this IDokanOperations operations, string mountPoint, DokanOptions mountOptions)
 {
     Mount(operations, mountPoint, mountOptions, 0);
 }