Dokan drive
This commit is contained in:
@@ -1,18 +1,19 @@
|
||||
#include "stdafx.h"
|
||||
#include "SiaDokenDrive.h"
|
||||
#include <dokan\dokan.h>
|
||||
#include <dokan\fileinfo.h>
|
||||
|
||||
using namespace Sia::Api;
|
||||
using namespace Sia::Api::Dokan;
|
||||
|
||||
class DokanImpl
|
||||
{
|
||||
private:
|
||||
static std::mutex _dokanMutex;
|
||||
static CSiaApi* _siaApi;
|
||||
static DOKAN_OPERATIONS _dokanOps;
|
||||
|
||||
static bool s_dokenInitialized = false;
|
||||
static CSiaDokenDrive* s_dokenDrive = nullptr;
|
||||
static DOKAN_OPERATIONS s_dokanOps = {0};
|
||||
|
||||
|
||||
static NTSTATUS DOKAN_CALLBACK SiaDrive_ZwCreateFile(
|
||||
private:
|
||||
static NTSTATUS DOKAN_CALLBACK SiaDrive_ZwCreateFile(
|
||||
LPCWSTR FileName,
|
||||
PDOKAN_IO_SECURITY_CONTEXT SecurityContext,
|
||||
ACCESS_MASK DesiredAccess,
|
||||
@@ -21,28 +22,86 @@ static NTSTATUS DOKAN_CALLBACK SiaDrive_ZwCreateFile(
|
||||
ULONG CreateDisposition,
|
||||
ULONG CreateOptions,
|
||||
PDOKAN_FILE_INFO DokanFileInfo)
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
static NTSTATUS DOKAN_CALLBACK SiaDrive_FindFiles(
|
||||
LPCWSTR FileName,
|
||||
PFillFindData FillFindData,
|
||||
PDOKAN_FILE_INFO DokanFileInfo)
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
static void Initialize(CSiaApi* siaApi)
|
||||
{
|
||||
_siaApi = siaApi;
|
||||
_dokanOps.Cleanup = nullptr;
|
||||
_dokanOps.CloseFile = nullptr;
|
||||
_dokanOps.DeleteDirectory = nullptr;
|
||||
_dokanOps.DeleteFileW = nullptr;
|
||||
_dokanOps.FindFiles = SiaDrive_FindFiles;
|
||||
_dokanOps.FindFilesWithPattern = nullptr;
|
||||
_dokanOps.FindStreams = nullptr;
|
||||
_dokanOps.FlushFileBuffers = nullptr;
|
||||
_dokanOps.GetDiskFreeSpaceW = nullptr;
|
||||
_dokanOps.GetFileInformation = nullptr;
|
||||
_dokanOps.GetFileSecurityW = nullptr;
|
||||
_dokanOps.GetVolumeInformationW = nullptr;
|
||||
_dokanOps.LockFile = nullptr;
|
||||
_dokanOps.Mounted = nullptr;
|
||||
_dokanOps.MoveFileW = nullptr;
|
||||
_dokanOps.ReadFile = nullptr;
|
||||
_dokanOps.SetAllocationSize = nullptr;
|
||||
_dokanOps.SetEndOfFile = nullptr;
|
||||
_dokanOps.SetFileAttributesW = nullptr;
|
||||
_dokanOps.SetFileSecurityW = nullptr;
|
||||
_dokanOps.SetFileTime = nullptr;
|
||||
_dokanOps.UnlockFile = nullptr;
|
||||
_dokanOps.Unmounted = nullptr;
|
||||
_dokanOps.WriteFile = nullptr;
|
||||
_dokanOps.ZwCreateFile = SiaDrive_ZwCreateFile;
|
||||
}
|
||||
|
||||
static void Shutdown()
|
||||
{
|
||||
_siaApi = nullptr;
|
||||
ZeroMemory(&_dokanOps, sizeof(_dokanOps));
|
||||
}
|
||||
|
||||
static std::mutex& GetMutex()
|
||||
{
|
||||
return _dokanMutex;
|
||||
}
|
||||
|
||||
static bool IsInitialized()
|
||||
{
|
||||
return _siaApi != nullptr;
|
||||
}
|
||||
};
|
||||
std::mutex DokanImpl::_dokanMutex;
|
||||
CSiaApi* DokanImpl::_siaApi = nullptr;
|
||||
DOKAN_OPERATIONS DokanImpl::_dokanOps = { 0 };
|
||||
|
||||
CSiaDokenDrive::CSiaDokenDrive(CSiaApi& siaApi) :
|
||||
_siaApi(siaApi)
|
||||
{
|
||||
if (s_dokenDrive)
|
||||
std::lock_guard<std::mutex> l(DokanImpl::GetMutex());
|
||||
if (DokanImpl::IsInitialized())
|
||||
{
|
||||
throw SiaDokenDriveException("Sia drive has already been activated");
|
||||
}
|
||||
else
|
||||
{
|
||||
s_dokenDrive = this;
|
||||
s_dokanOps.ZwCreateFile = SiaDrive_ZwCreateFile;
|
||||
DokanImpl::Initialize(&_siaApi);
|
||||
}
|
||||
}
|
||||
|
||||
CSiaDokenDrive::~CSiaDokenDrive()
|
||||
{
|
||||
std::lock_guard<std::mutex> l(DokanImpl::GetMutex());
|
||||
Unmount();
|
||||
s_dokenDrive = nullptr;
|
||||
DokanImpl::Shutdown();
|
||||
}
|
||||
|
||||
void CSiaDokenDrive::Mount(const wchar_t& driveLetter)
|
||||
|
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include <SiaApi.h>
|
||||
#include <mutex>
|
||||
|
||||
NS_BEGIN(Sia)
|
||||
NS_BEGIN(Api)
|
||||
|
Reference in New Issue
Block a user