Advertisement
Guest User

Полный код HelloWorldFS

a guest
Apr 12th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.44 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Security.AccessControl;
  5. using System.Text;
  6. using DokanNet;
  7.  
  8. namespace XakepFS
  9. {
  10.     class HelloWorldFSClass : IDokanOperations
  11.     {
  12.         public void Cleanup(string fileName, DokanFileInfo info)
  13.         {
  14.         }
  15.  
  16.         public void CloseFile(string fileName, DokanFileInfo info)
  17.         {
  18.         }
  19.        
  20.         public NtStatus CreateFile(string fileName, DokanNet.FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, DokanFileInfo info)
  21.         {
  22.             return NtStatus.Success;
  23.         }
  24.  
  25.         public NtStatus DeleteDirectory(string fileName, DokanFileInfo info)
  26.         {
  27.             return NtStatus.Success;
  28.         }
  29.  
  30.         public NtStatus DeleteFile(string fileName, DokanFileInfo info)
  31.         {
  32.             return NtStatus.Success;
  33.         }
  34.  
  35.         public NtStatus FindFiles(string fileName, out IList<FileInformation> files, DokanFileInfo info)
  36.         {
  37.             files = new List<FileInformation>();
  38.             FileInformation fi;
  39.             GetFileInformation("\\HelloWorld.txt", out fi, null);
  40.             files.Add(fi);
  41.             return NtStatus.Success;
  42.         }
  43.  
  44.         public NtStatus FindFilesWithPattern(string fileName, string searchPattern, out IList<FileInformation> files, DokanFileInfo info)
  45.         {
  46.             return FindFiles(null, out files, null);
  47.         }
  48.  
  49.         public NtStatus FindStreams(string fileName, out IList<FileInformation> streams, DokanFileInfo info)
  50.         {
  51.             throw new NotImplementedException();
  52.         }
  53.  
  54.         public NtStatus FlushFileBuffers(string fileName, DokanFileInfo info)
  55.         {
  56.             return NtStatus.Success;
  57.         }
  58.  
  59.         public NtStatus GetDiskFreeSpace(out long freeBytesAvailable, out long totalNumberOfBytes, out long totalNumberOfFreeBytes, DokanFileInfo info)
  60.         {
  61.             freeBytesAvailable = 0x4000000;
  62.             totalNumberOfBytes = 0x4000000 * 5;
  63.             totalNumberOfFreeBytes = 0x4000000;
  64.             return NtStatus.Success;
  65.         }
  66.  
  67.         public NtStatus GetFileInformation(string fileName, out FileInformation fileInfo, DokanFileInfo info)
  68.         {
  69.             if (fileName == "\\") //Возвращаем корректную информацию о корневой папке
  70.             {
  71.                 fileInfo = new FileInformation
  72.                 {
  73.                     FileName = "\\",
  74.                     LastAccessTime = DateTime.Now,
  75.                     Attributes = FileAttributes.Directory
  76.                 };
  77.                 return NtStatus.Success;
  78.             }
  79.             if (fileName != "\\HelloWorld.txt")
  80.             {
  81.                 fileInfo = new FileInformation { };
  82.                 return NtStatus.NoSuchFile;
  83.             }
  84.             fileInfo = new FileInformation
  85.             {
  86.                 Attributes = FileAttributes.Normal,
  87.                 CreationTime = DateTime.Now,
  88.                 FileName = "HelloWorld.txt",
  89.                 LastAccessTime = DateTime.Now,
  90.                 LastWriteTime = DateTime.Now,
  91.                 Length = 57 //Длина в байтах строки, которую мы возвращаем через ReadFile
  92.             };
  93.             return NtStatus.Success;
  94.         }
  95.  
  96.         public NtStatus GetFileSecurity(string fileName, out FileSystemSecurity security, AccessControlSections sections, DokanFileInfo info)
  97.         {
  98.             security = null;
  99.             return NtStatus.Error;
  100.         }
  101.  
  102.         public NtStatus GetVolumeInformation(out string volumeLabel, out FileSystemFeatures features, out string fileSystemName, out uint maximumComponentLength, DokanFileInfo info)
  103.         {
  104.             volumeLabel = "Hello world!";
  105.             features = FileSystemFeatures.None;
  106.             fileSystemName = "HelloWorldFS";
  107.             maximumComponentLength = 256;
  108.             return NtStatus.Success;
  109.         }
  110.  
  111.         public NtStatus LockFile(string fileName, long offset, long length, DokanFileInfo info)
  112.         {
  113.             throw new NotImplementedException();
  114.         }
  115.  
  116.         public NtStatus Mounted(DokanFileInfo info)
  117.         {
  118.             return NtStatus.Success;
  119.         }
  120.  
  121.         public NtStatus MoveFile(string oldName, string newName, bool replace, DokanFileInfo info)
  122.         {
  123.             throw new NotImplementedException();
  124.         }
  125.  
  126.         public NtStatus ReadFile(string fileName, byte[] buffer, out int bytesRead, long offset, DokanFileInfo info)
  127.         {
  128.             bytesRead = 0;
  129.             var x = Encoding.ASCII.GetBytes("Hello World from HelloWorldFS!\r\nThis is just a test file.");
  130.             if (info.Context == null) // memory mapped read
  131.             {
  132.                 using (var stream = new MemoryStream(x))
  133.                 {
  134.                     stream.Position = offset;
  135.                     bytesRead = stream.Read(buffer, 0, buffer.Length);
  136.                 }
  137.             }
  138.             return NtStatus.Success;
  139.         }
  140.  
  141.         public NtStatus SetAllocationSize(string fileName, long length, DokanFileInfo info)
  142.         {
  143.             throw new NotImplementedException();
  144.         }
  145.  
  146.         public NtStatus SetEndOfFile(string fileName, long length, DokanFileInfo info)
  147.         {
  148.             throw new NotImplementedException();
  149.         }
  150.  
  151.         public NtStatus SetFileAttributes(string fileName, FileAttributes attributes, DokanFileInfo info)
  152.         {
  153.             throw new NotImplementedException();
  154.         }
  155.  
  156.         public NtStatus SetFileSecurity(string fileName, FileSystemSecurity security, AccessControlSections sections, DokanFileInfo info)
  157.         {
  158.             throw new NotImplementedException();
  159.         }
  160.  
  161.         public NtStatus SetFileTime(string fileName, DateTime? creationTime, DateTime? lastAccessTime, DateTime? lastWriteTime, DokanFileInfo info)
  162.         {
  163.             throw new NotImplementedException();
  164.         }
  165.  
  166.         public NtStatus UnlockFile(string fileName, long offset, long length, DokanFileInfo info)
  167.         {
  168.             throw new NotImplementedException();
  169.         }
  170.  
  171.         public NtStatus Unmounted(DokanFileInfo info)
  172.         {
  173.             return NtStatus.Success;
  174.         }
  175.  
  176.         public NtStatus WriteFile(string fileName, byte[] buffer, out int bytesWritten, long offset, DokanFileInfo info)
  177.         {
  178.             throw new NotImplementedException();
  179.         }
  180.     }
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement