示例#1
0
 /// <summary>
 /// Notify Dokan that a file or directory has been renamed.
 /// This method supports in-place rename for file/directory within the same parent.
 /// </summary>
 /// <param name="dokanInstance">The dokan mount context created by <see cref="DokanCreateFileSystem"/></param>
 /// <param name="oldPath">Old, absolute path to the file or directory, including the mount-point of the file system.</param>
 /// <param name="newPath">New, absolute path to the file or directory, including the mount-point of the file system.</param>
 /// <param name="isDirectory">Indicates if the path is a directory.</param>
 /// <param name="isInSameDirectory">Indicates if the file or directory have the same parent directory.</param>
 /// <returns>true if notification succeeded.</returns>
 /// <remarks><see cref="DokanOptions.EnableNotificationAPI"/> must be set in the mount options for this to succeed.</remarks>
 public static bool Rename(DokanInstance dokanInstance, string oldPath, string newPath, bool isDirectory, bool isInSameDirectory)
 {
     return(NativeMethods.DokanNotifyRename(dokanInstance.DokanHandle, oldPath,
                                            newPath,
                                            isDirectory,
                                            isInSameDirectory));
 }
示例#2
0
 /// <summary>
 /// Notify Dokan that file or directory extended attributes have changed.
 /// </summary>
 /// <param name="dokanInstance">The dokan mount context created by <see cref="DokanCreateFileSystem"/></param>
 /// <param name="filePath">Absolute path to the file or directory, including the mount-point of the file system.</param>
 /// <returns>true if notification succeeded.</returns>
 /// <remarks><see cref="DokanOptions.EnableNotificationAPI"/> must be set in the mount options for this to succeed.</remarks>
 public static bool XAttrUpdate(DokanInstance dokanInstance, string filePath)
 {
     return(NativeMethods.DokanNotifyXAttrUpdate(dokanInstance.DokanHandle, filePath));
 }
示例#3
0
 /// <summary>
 /// Notify Dokan that a file or directory has been deleted.
 /// </summary>
 /// <param name="dokanInstance">The dokan mount context created by <see cref="DokanCreateFileSystem"/></param>
 /// <param name="filePath">Absolute path to the file or directory, including the mount-point of the file system.</param>
 /// <param name="isDirectory">Indicates if the path is a directory.</param>
 /// <returns>true if notification succeeded.</returns>
 /// <remarks><see cref="DokanOptions.EnableNotificationAPI"/> must be set in the mount options for this to succeed.</remarks>
 public static bool Delete(DokanInstance dokanInstance, string filePath, bool isDirectory)
 {
     return(NativeMethods.DokanNotifyDelete(dokanInstance.DokanHandle, filePath, isDirectory));
 }
示例#4
0
 /// <summary>
 /// Wait until the FileSystem is unmount.
 /// </summary>
 /// <param name="dokanInstance">The dokan mount context created by <see cref="CreateFileSystem"/>.</param>
 /// <param name="milliSeconds">The time-out interval, in milliseconds. If a nonzero value is specified, the function waits until the object is signaled or the interval elapses. If <param name="milliSeconds"> is zero,
 /// the function does not enter a wait state if the object is not signaled; it always returns immediately. If <param name="milliSeconds"> is INFINITE, the function will return only when the object is signaled.</param>
 /// <returns>See <a href="https://docs.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-waitforsingleobject">WaitForSingleObject</a> for a description of return values.</returns>
 public static uint WaitForFileSystemClosed(this DokanInstance dokanInstance, uint milliSeconds)
 {
     return(NativeMethods.DokanWaitForFileSystemClosed(dokanInstance.DokanHandle, milliSeconds));
 }
示例#5
0
 /// <summary>
 /// Check if the FileSystem is still running or not.
 /// </summary>
 /// <param name="dokanInstance">The dokan mount context created by <see cref="CreateFileSystem"/>.</param>
 /// <returns>Whether the FileSystem is still running or not.</returns>
 public static bool IsFileSystemRunning(this DokanInstance dokanInstance)
 {
     return(NativeMethods.DokanIsFileSystemRunning(dokanInstance.DokanHandle));
 }
示例#6
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);
        }