-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
266 lines (208 loc) · 7.74 KB
/
Program.cs
File metadata and controls
266 lines (208 loc) · 7.74 KB
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Dokan;
using System.IO;
using System.Collections;
using System.Threading;
using System.Diagnostics;
namespace TorrentFS
{
class Program
{
class TFS : DokanOperations
{
static void LogMe()
{
var frames = new StackTrace(1).GetFrames();
Console.WriteLine("Entering: " + frames[0].GetMethod().Name);
}
public int CreateFile(string filename, FileAccess access, FileShare share, FileMode mode, FileOptions options, DokanFileInfo info)
{
return 0;
}
public int OpenDirectory(string filename, DokanFileInfo info)
{
return 0;
}
public int CreateDirectory(string filename, DokanFileInfo info)
{
return -1;
}
public int Cleanup(string filename, DokanFileInfo info)
{
return 0;
}
public int CloseFile(string filename, DokanFileInfo info)
{
return 0;
}
public int ReadFile(string filename, byte[] buffer, ref uint readBytes, long offset, DokanFileInfo info)
{
return -1;
}
public int WriteFile(string filename, byte[] buffer, ref uint writtenBytes, long offset, DokanFileInfo info)
{
return -1;
}
public int FlushFileBuffers(string filename, DokanFileInfo info)
{
return -1;
}
public int GetFileInformation(string filename, FileInformation fileinfo, DokanFileInfo info)
{
return -1;
}
public int FindFiles(string filename, ArrayList files, DokanFileInfo info)
{
return 0;
}
public int SetFileAttributes(string filename, FileAttributes attr, DokanFileInfo info)
{
return -1;
}
public int SetFileTime(string filename, DateTime ctime, DateTime atime, DateTime mtime, DokanFileInfo info)
{
return -1;
}
public int DeleteFile(string filename, DokanFileInfo info)
{
return -1;
}
public int DeleteDirectory(string filename, DokanFileInfo info)
{
return -1;
}
public int MoveFile(string filename, string newname, bool replace, DokanFileInfo info)
{
return -1;
}
public int SetEndOfFile(string filename, long length, DokanFileInfo info)
{
return -1;
}
public int SetAllocationSize(string filename, long length, DokanFileInfo info)
{
return -1;
}
public int LockFile(string filename, long offset, long length, DokanFileInfo info)
{
return 0;
}
public int UnlockFile(string filename, long offset, long length, DokanFileInfo info)
{
return 0;
}
public int GetDiskFreeSpace(ref ulong freeBytesAvailable, ref ulong totalBytes, ref ulong totalFreeBytes, DokanFileInfo info)
{
LogMe();
freeBytesAvailable = 0;
totalBytes = 1024;
totalFreeBytes = 0;
return 0;
}
public int Unmount(DokanFileInfo info)
{
return 0;
}
}
static void PrintStatus(int status)
{
switch (status)
{
case DokanNet.DOKAN_DRIVE_LETTER_ERROR:
Console.WriteLine("Drvie letter error");
break;
case DokanNet.DOKAN_DRIVER_INSTALL_ERROR:
Console.WriteLine("Driver install error");
break;
case DokanNet.DOKAN_MOUNT_ERROR:
Console.WriteLine("Mount error");
break;
case DokanNet.DOKAN_START_ERROR:
Console.WriteLine("Start error");
break;
case DokanNet.DOKAN_ERROR:
Console.WriteLine("Unknown error");
break;
case DokanNet.DOKAN_SUCCESS:
Console.WriteLine("Success");
break;
default:
Console.WriteLine("Unknown status: {0}", status);
break;
}
}
public class DokanException : Exception
{
public int DokanErrorCode { get; private set; }
public DokanException(string message, int errorcode)
: base(message)
{
this.DokanErrorCode = errorcode;
}
}
static void CheckStatus(int status)
{
switch (status)
{
case DokanNet.DOKAN_DRIVE_LETTER_ERROR:
throw new DokanException("Drvie letter error", status);
case DokanNet.DOKAN_DRIVER_INSTALL_ERROR:
throw new DokanException("Driver install error", status);
case DokanNet.DOKAN_MOUNT_ERROR:
throw new DokanException("DMount error", status);
case DokanNet.DOKAN_START_ERROR:
throw new DokanException("Start error", status);
case DokanNet.DOKAN_ERROR:
throw new DokanException("Unknown errorr", status);
case DokanNet.DOKAN_SUCCESS:
Console.WriteLine("Success");
break;
default:
Console.WriteLine("Unknown status: {0}", status);
break;
}
}
public class ThreadableDisposableDokan : IDisposable
{
public DokanOperations Operations { get; private set; }
public DokanOptions Options { get; private set; }
private int StartStatus = DokanNet.DOKAN_SUCCESS;
private bool disposed = false;
public ThreadableDisposableDokan(DokanOptions options, DokanOperations operations)
{
this.Operations = operations;
this.Options = options;
var thread = new Thread(() =>
{
CheckStatus(this.StartStatus = DokanNet.DokanMain(this.Options, this.Operations));
});
thread.Start();
Thread.Sleep(1000);
}
public void Dispose()
{
if (!disposed)
{
disposed = true;
if (this.StartStatus == DokanNet.DOKAN_SUCCESS)
{
DokanNet.DokanRemoveMountPoint(this.Options.MountPoint);
}
}
}
}
static void Main(string[] args)
{
using (new ThreadableDisposableDokan(new DokanOptions()
{
MountPoint = "t:\\",
DebugMode = true,
UseStdErr = false,
VolumeLabel = "TorrentFS"
}, new TFS())) { }
}
}
}