-
Notifications
You must be signed in to change notification settings - Fork 238
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
305 changed files
with
56,400 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
# Build Folders (you can keep bin if you'd like, to store dlls and pdbs) | ||
bin | ||
obj | ||
|
||
*.suo | ||
*.user | ||
_ReSharper* | ||
# mstest test results | ||
TestResults |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
using System; | ||
using DokanNet.Native; | ||
|
||
|
||
namespace DokanNet | ||
{ | ||
|
||
public static class Dokan | ||
{ | ||
#region Dokan Driver Options | ||
|
||
private const ushort DOKAN_VERSION = 600; // ver 0.6.0 | ||
/* private const uint DOKAN_OPTION_DEBUG = 1; | ||
private const uint DOKAN_OPTION_STDERR = 2; | ||
private const uint DOKAN_OPTION_ALT_STREAM = 4; | ||
private const uint DOKAN_OPTION_KEEP_ALIVE = 8; | ||
private const uint DOKAN_OPTION_NETWORK = 16; | ||
private const uint DOKAN_OPTION_REMOVABLE = 32;*/ | ||
|
||
#endregion | ||
|
||
#region Dokan Driver Errors | ||
|
||
private const int DOKAN_SUCCESS = 0; | ||
private const int DOKAN_ERROR = -1; | ||
private const int DOKAN_DRIVE_LETTER_ERROR = -2; | ||
private const int DOKAN_DRIVER_INSTALL_ERROR = -3; | ||
private const int DOKAN_START_ERROR = -4; | ||
private const int DOKAN_MOUNT_ERROR = -5; | ||
private const int DOKAN_MOUNT_POINT_ERROR = -6; | ||
|
||
#endregion | ||
public static void Mount(this IDokanOperations operations, string mountPoint) | ||
{ | ||
Mount(operations, mountPoint, DokanOptions.FixedDrive, 0, DOKAN_VERSION); | ||
} | ||
|
||
public static void Mount(this IDokanOperations operations, string mountPoint, DokanOptions mountOptions) | ||
{ | ||
Mount(operations, mountPoint, mountOptions, 0, DOKAN_VERSION); | ||
} | ||
public static void Mount(this IDokanOperations operations, string mountPoint,DokanOptions mountOptions,int threadCount) | ||
{ | ||
Mount(operations,mountPoint,mountOptions,threadCount,DOKAN_VERSION); | ||
} | ||
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 "); | ||
} | ||
} | ||
|
||
|
||
public static bool Unmount(char driveLetter) | ||
{ | ||
return NativeMethods.DokanUnmount(driveLetter) == DOKAN_SUCCESS; | ||
} | ||
|
||
public static bool RemoveMountPoint(string mountPoint) | ||
{ | ||
return NativeMethods.DokanRemoveMountPoint(mountPoint) == DOKAN_SUCCESS; | ||
} | ||
|
||
public static int Version | ||
{ | ||
get { return (int) NativeMethods.DokanVersion(); } | ||
} | ||
|
||
public static int DriverVersion | ||
{ | ||
get { return (int) NativeMethods.DokanDriverVersion(); } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
namespace DokanNet | ||
{ | ||
public enum DokanError | ||
{ | ||
// From WinError.h -> http://msdn.microsoft.com/en-us/library/ms819773.aspx | ||
ErrorFileNotFound = -2, // MessageText: The system cannot find the file specified. | ||
ErrorPathNotFound = -3, // MessageText: The system cannot find the path specified. | ||
ErrorAccessDenied = -5, // MessageText: Access is denied. | ||
ErrorSharingViolation = -32, | ||
ErrorFileExists = -80, | ||
ErrorDiskFull = -112, // There is not enough space on the disk. | ||
ErrorInvalidName = -123, | ||
ErrorDirNotEmpty = -145, // MessageText: The directory is not empty. | ||
|
||
ErrorAlreadyExists = -183, | ||
// MessageText: Cannot create a file when that file already exists. | ||
|
||
ErrorExceptionInService = -1064, | ||
// An exception occurred in the service when handling thecontrol request. | ||
ErrorSuccess = 0, | ||
ErrorError = -1, | ||
ErrorNotImplemented = -120, | ||
|
||
ErrorPrivilegeNotHeld = -1314, | ||
ErrorNotReady = -21, | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
|
||
namespace DokanNet | ||
{ | ||
[Serializable] | ||
public class DokanException : Exception | ||
{ | ||
|
||
internal DokanException(int status, string message) : base(message) | ||
{ | ||
base.HResult = status; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
using System.Security.Principal; | ||
using DokanNet.Native; | ||
|
||
#pragma warning disable 649,169 | ||
namespace DokanNet | ||
{ | ||
[StructLayout(LayoutKind.Sequential, Pack = 4)] | ||
public sealed class DokanFileInfo | ||
{ | ||
|
||
private ulong _context; | ||
private readonly ulong _dokanContext; | ||
private readonly IntPtr _dokanOptions; | ||
private readonly uint _processId; | ||
[MarshalAs(UnmanagedType.U1)] private bool _isDirectory; | ||
[MarshalAs(UnmanagedType.U1)] private bool _deleteOnClose; | ||
[MarshalAs(UnmanagedType.U1)] private bool _pagingIo; | ||
[MarshalAs(UnmanagedType.U1)] private bool _synchronousIo; | ||
[MarshalAs(UnmanagedType.U1)] private bool _nocache; | ||
[MarshalAs(UnmanagedType.U1)] private bool _writeToEndOfFile; | ||
|
||
|
||
public object Context | ||
{ | ||
get { return _context != 0 ? ((GCHandle) ((IntPtr) _context)).Target : null; } | ||
set | ||
{ | ||
if (_context != 0) | ||
{ | ||
((GCHandle) ((IntPtr) _context)).Free(); | ||
_context = 0; | ||
} | ||
if (value != null) | ||
{ | ||
_context = (ulong) (IntPtr) GCHandle.Alloc(value); | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
public int ProcessId | ||
{ | ||
get { return (int) _processId; } | ||
} | ||
|
||
public bool IsDirectory | ||
{ | ||
get { return _isDirectory; } | ||
set { _isDirectory = value; } | ||
} | ||
|
||
public bool DeleteOnClose | ||
{ | ||
get { return _deleteOnClose; } | ||
set { _deleteOnClose = value; } | ||
} | ||
|
||
public bool PagingIo | ||
{ | ||
get { return _pagingIo; } | ||
} | ||
|
||
public bool SynchronousIo | ||
{ | ||
get { return _synchronousIo; } | ||
} | ||
|
||
public bool NoCache | ||
{ | ||
get { return _nocache; } | ||
} | ||
|
||
public bool WriteToEndOfFile | ||
{ | ||
get { return _writeToEndOfFile; } | ||
} | ||
|
||
public WindowsIdentity GetRequestor() | ||
{ | ||
try | ||
{ | ||
return new WindowsIdentity(NativeMethods.DokanOpenRequestorToken(this)); | ||
} | ||
catch | ||
{ | ||
|
||
return null; | ||
} | ||
|
||
} | ||
|
||
public bool TryResetTimeout(int milliseconds) | ||
{ | ||
|
||
return NativeMethods.DokanResetTimeout((uint) milliseconds, this); | ||
} | ||
|
||
|
||
private DokanFileInfo(){} | ||
} | ||
} | ||
#pragma warning restore 649,169 |
Oops, something went wrong.