-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathDokan.cs
140 lines (114 loc) · 6.59 KB
/
Dokan.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
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(); }
}
}
}