113 lines
2.5 KiB
C++
113 lines
2.5 KiB
C++
#include "stdafx.h"
|
|
#include "SiaDokenDrive.h"
|
|
#include <dokan\dokan.h>
|
|
|
|
using namespace Sia::Api;
|
|
using namespace Sia::Api::Dokan;
|
|
|
|
class DokanImpl
|
|
{
|
|
private:
|
|
static std::mutex _dokanMutex;
|
|
static CSiaApi* _siaApi;
|
|
static DOKAN_OPERATIONS _dokanOps;
|
|
|
|
private:
|
|
static NTSTATUS DOKAN_CALLBACK SiaDrive_ZwCreateFile(
|
|
LPCWSTR FileName,
|
|
PDOKAN_IO_SECURITY_CONTEXT SecurityContext,
|
|
ACCESS_MASK DesiredAccess,
|
|
ULONG FileAttributes,
|
|
ULONG ShareAccess,
|
|
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)
|
|
{
|
|
std::lock_guard<std::mutex> l(DokanImpl::GetMutex());
|
|
if (DokanImpl::IsInitialized())
|
|
{
|
|
throw SiaDokenDriveException("Sia drive has already been activated");
|
|
}
|
|
else
|
|
{
|
|
DokanImpl::Initialize(&_siaApi);
|
|
}
|
|
}
|
|
|
|
CSiaDokenDrive::~CSiaDokenDrive()
|
|
{
|
|
std::lock_guard<std::mutex> l(DokanImpl::GetMutex());
|
|
Unmount();
|
|
DokanImpl::Shutdown();
|
|
}
|
|
|
|
void CSiaDokenDrive::Mount(const wchar_t& driveLetter)
|
|
{
|
|
}
|
|
|
|
void CSiaDokenDrive::Unmount()
|
|
{
|
|
} |