Try to create new file, but failing
This commit is contained in:
@@ -147,5 +147,80 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class SIADRIVE_DOKAN_EXPORTABLE DokanCreateFile :
|
||||
public CEvent
|
||||
{
|
||||
public:
|
||||
DokanCreateFile(const SString& filePath, const DWORD& fileAttributesAndFlags, const DWORD& creationDisposition, const ACCESS_MASK& genericDesiredAccess) :
|
||||
_filePath(filePath),
|
||||
_fileAttributesAndFlags(fileAttributesAndFlags),
|
||||
_creationDisposition(creationDisposition),
|
||||
_genericDesiredAccess(genericDesiredAccess)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public:
|
||||
virtual ~DokanCreateFile()
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
const SString _filePath;
|
||||
const DWORD _fileAttributesAndFlags;
|
||||
const DWORD _creationDisposition;
|
||||
const ACCESS_MASK _genericDesiredAccess;
|
||||
|
||||
public:
|
||||
virtual std::shared_ptr<CEvent> Clone() const override
|
||||
{
|
||||
return std::shared_ptr<CEvent>(new DokanCreateFile(_filePath, _fileAttributesAndFlags, _creationDisposition, _genericDesiredAccess));
|
||||
}
|
||||
|
||||
virtual SString GetSingleLineMessage() const override
|
||||
{
|
||||
return L"DokanCreateFile|FILE|" + _filePath +
|
||||
"|ATTR|" + SString::FromUInt32(_fileAttributesAndFlags) +
|
||||
"|DISP|" + SString::FromUInt32(_creationDisposition) +
|
||||
"|MASK|" + SString::FromUInt32(_genericDesiredAccess);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class SIADRIVE_DOKAN_EXPORTABLE DokanFindFiles :
|
||||
public CEvent
|
||||
{
|
||||
public:
|
||||
DokanFindFiles(const SString& cachePath, const SString& rootPath, const SString& siaQuery) :
|
||||
_cachePath(cachePath),
|
||||
_rootPath(rootPath),
|
||||
_siaQuery(siaQuery)
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
virtual ~DokanFindFiles()
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
const SString _cachePath;
|
||||
const SString _rootPath;
|
||||
const SString _siaQuery;
|
||||
|
||||
public:
|
||||
virtual std::shared_ptr<CEvent> Clone() const override
|
||||
{
|
||||
return std::shared_ptr<CEvent>(new DokanFindFiles(_cachePath, _rootPath, _siaQuery));
|
||||
}
|
||||
|
||||
virtual SString GetSingleLineMessage() const override
|
||||
{
|
||||
return L"DokanFindFiles|PATH|" + _cachePath +
|
||||
"|ROOT|" + _rootPath +
|
||||
"|QUERY|" + _siaQuery;
|
||||
}
|
||||
};
|
||||
|
||||
NS_END(3)
|
||||
#endif //_SIADOKANDRIVE_H
|
@@ -5,8 +5,9 @@
|
||||
#include <siacommon.h>
|
||||
#include <siadriveapp.h>
|
||||
#include <include/cef_app.h>
|
||||
#include <filepath.h>
|
||||
#include <eventsystem.h>
|
||||
#include <debugconsumer.h>
|
||||
#include <loggingconsumer.h>
|
||||
|
||||
using namespace Sia;
|
||||
using namespace Sia::Api;
|
||||
@@ -18,6 +19,9 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
|
||||
{
|
||||
UNREFERENCED_PARAMETER(hPrevInstance);
|
||||
UNREFERENCED_PARAMETER(lpCmdLine);
|
||||
CDebugConsumer debugConsumer;
|
||||
CLoggingConsumer loggingConsumer;
|
||||
|
||||
CEventSystem::EventSystem.Start();
|
||||
CefEnableHighDPISupport();
|
||||
|
||||
@@ -31,7 +35,9 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
|
||||
CefSettings settings;
|
||||
settings.no_sandbox = true;
|
||||
settings.remote_debugging_port = 8080;
|
||||
settings.single_process = true;
|
||||
#ifdef _DEBUG
|
||||
settings.single_process = false;
|
||||
#endif
|
||||
CefInitialize(mainArgs, settings, app, nullptr);
|
||||
|
||||
CefRunMessageLoop();
|
||||
|
@@ -1,5 +1,6 @@
|
||||
#include <loggingconsumer.h>
|
||||
#include <eventsystem.h>
|
||||
#include <filepath.h>
|
||||
|
||||
using namespace Sia::Api;
|
||||
|
||||
@@ -15,5 +16,15 @@ CLoggingConsumer::~CLoggingConsumer()
|
||||
|
||||
void CLoggingConsumer::ProcessEvent(const CEvent& eventData)
|
||||
{
|
||||
|
||||
// TODO Implement rolling/max size and timestamp
|
||||
FilePath logPath("logs\\siadrive.log");
|
||||
logPath.MakeAbsolute();
|
||||
FilePath(logPath).RemoveFileName().CreateDirectory();
|
||||
|
||||
FILE* logFile;
|
||||
if (fopen_s(&logFile, SString::ToUtf8(static_cast<SString>(logPath)).c_str(), "a") == 0)
|
||||
{
|
||||
fprintf_s(logFile, SString::ToUtf8(eventData.GetSingleLineMessage() + "\n").c_str());
|
||||
fclose(logFile);
|
||||
}
|
||||
}
|
@@ -173,6 +173,8 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DokanCreateFile(cacheFilePath, fileAttributesAndFlags, creationDisposition, genericDesiredAccess)));
|
||||
|
||||
// Folder (cache operation only)
|
||||
if (DokanFileInfo->IsDirectory)
|
||||
{
|
||||
@@ -404,6 +406,7 @@ private:
|
||||
rootPath = CSiaApi::FormatToSiaPath(rootPath.RemoveFileName());
|
||||
}
|
||||
}
|
||||
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DokanFindFiles(cachePath, rootPath, siaQuery)));
|
||||
|
||||
auto dirList = siaFileTree->QueryDirectories(rootPath);
|
||||
for (auto& dir : dirList)
|
||||
@@ -482,8 +485,8 @@ private:
|
||||
{
|
||||
cachePath.Append(FileName);
|
||||
}
|
||||
|
||||
if (!handle || (handle == INVALID_HANDLE_VALUE))
|
||||
|
||||
if (!handle || (handle == INVALID_HANDLE_VALUE))
|
||||
{
|
||||
handle = ::CreateFile(&cachePath[0], GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, 0, nullptr);
|
||||
if (handle == INVALID_HANDLE_VALUE)
|
||||
@@ -544,7 +547,7 @@ private:
|
||||
_uploadManager.reset(new CUploadManager(CSiaCurl(_siaApi->GetHostConfig()), _siaDriveConfig));
|
||||
StartFileListThread();
|
||||
|
||||
CEventSystem::EventSystem.NotifyEvent(CEventPtr(new DriveMounted(_mountPoint)));
|
||||
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DriveMounted(_mountPoint)));
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -552,7 +555,7 @@ private:
|
||||
{
|
||||
_uploadManager.reset(nullptr);
|
||||
StopFileListThread();
|
||||
CEventSystem::EventSystem.NotifyEvent(CEventPtr(new DriveUnMounted(_mountPoint)));
|
||||
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DriveUnMounted(_mountPoint)));
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -570,7 +573,7 @@ private:
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static NTSTATUS DOKAN_CALLBACK Sia_GetVolumeInformation(
|
||||
static NTSTATUS DOKAN_CALLBACK Sia_GetVolumeInformationW(
|
||||
LPWSTR VolumeNameBuffer, DWORD VolumeNameSize, LPDWORD VolumeSerialNumber,
|
||||
LPDWORD MaximumComponentLength, LPDWORD FileSystemFlags,
|
||||
LPWSTR FileSystemNameBuffer, DWORD FileSystemNameSize,
|
||||
@@ -839,6 +842,114 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
static NTSTATUS DOKAN_CALLBACK Sia_DeleteDirectory(LPCWSTR FileName, PDOKAN_FILE_INFO DokanFileInfo)
|
||||
{
|
||||
FilePath filePath = FilePath(GetCacheLocation(), FileName);
|
||||
NTSTATUS ret = STATUS_SUCCESS;
|
||||
if (DokanFileInfo->DeleteOnClose)
|
||||
{
|
||||
filePath.Append("*");
|
||||
|
||||
WIN32_FIND_DATAW findData;
|
||||
HANDLE findHandle = ::FindFirstFile(&filePath[0], &findData);
|
||||
if (findHandle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
ret = DokanNtStatusFromWin32(error);
|
||||
}
|
||||
else
|
||||
{
|
||||
do
|
||||
{
|
||||
if ((wcscmp(findData.cFileName, L"..") != 0) && (wcscmp(findData.cFileName, L".") != 0))
|
||||
{
|
||||
ret = STATUS_DIRECTORY_NOT_EMPTY;
|
||||
}
|
||||
}
|
||||
while ((ret == STATUS_SUCCESS) && (::FindNextFile(findHandle, &findData) != 0));
|
||||
|
||||
DWORD error = GetLastError();
|
||||
if (error != ERROR_NO_MORE_FILES)
|
||||
{
|
||||
ret = DokanNtStatusFromWin32(error);
|
||||
}
|
||||
|
||||
::FindClose(findHandle);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static NTSTATUS DOKAN_CALLBACK Sia_DeleteFileW(LPCWSTR FileName, PDOKAN_FILE_INFO DokanFileInfo)
|
||||
{
|
||||
// TODO Handle files that aren't cached
|
||||
|
||||
HANDLE handle = reinterpret_cast<HANDLE>(DokanFileInfo->Context);
|
||||
FilePath filePath(GetCacheLocation(), FileName);
|
||||
|
||||
DWORD dwAttrib = ::GetFileAttributes(&filePath[0]);
|
||||
if ((dwAttrib != INVALID_FILE_ATTRIBUTES) && (dwAttrib & FILE_ATTRIBUTE_DIRECTORY))
|
||||
{
|
||||
return STATUS_ACCESS_DENIED;
|
||||
}
|
||||
|
||||
if (handle && (handle != INVALID_HANDLE_VALUE))
|
||||
{
|
||||
FILE_DISPOSITION_INFO fdi;
|
||||
fdi.DeleteFile = DokanFileInfo->DeleteOnClose;
|
||||
if (!::SetFileInformationByHandle(handle, FileDispositionInfo, &fdi, sizeof(FILE_DISPOSITION_INFO)))
|
||||
{
|
||||
return DokanNtStatusFromWin32(GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static NTSTATUS DOKAN_CALLBACK Sia_MoveFileW(LPCWSTR FileName, LPCWSTR NewFileName, BOOL ReplaceIfExisting, PDOKAN_FILE_INFO DokanFileInfo)
|
||||
{
|
||||
// TODO Handle files that aren't cached
|
||||
FilePath filePath(GetCacheLocation(), FileName);
|
||||
FilePath newFilePath(GetCacheLocation(), NewFileName);
|
||||
|
||||
HANDLE handle = reinterpret_cast<HANDLE>(DokanFileInfo->Context);
|
||||
if (!handle || (handle == INVALID_HANDLE_VALUE))
|
||||
{
|
||||
return STATUS_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
size_t len = wcslen(&newFilePath[0]);
|
||||
DWORD bufferSize = static_cast<DWORD>(sizeof(FILE_RENAME_INFO) + (len * sizeof(newFilePath[0])));
|
||||
|
||||
PFILE_RENAME_INFO renameInfo = static_cast<PFILE_RENAME_INFO>(malloc(bufferSize));
|
||||
if (!renameInfo)
|
||||
{
|
||||
return STATUS_BUFFER_OVERFLOW;
|
||||
}
|
||||
::ZeroMemory(renameInfo, bufferSize);
|
||||
|
||||
renameInfo->ReplaceIfExists = ReplaceIfExisting ? TRUE : FALSE; // some warning about converting BOOL to BOOLEAN
|
||||
renameInfo->RootDirectory = nullptr; // hope it is never needed, shouldn't be
|
||||
renameInfo->FileNameLength = static_cast<DWORD>(len) * sizeof(newFilePath[0]); // they want length in bytes
|
||||
|
||||
wcscpy_s(renameInfo->FileName, len + 1, &newFilePath[0]);
|
||||
|
||||
BOOL result = ::SetFileInformationByHandle(handle, FileRenameInfo, renameInfo, bufferSize);
|
||||
free(renameInfo);
|
||||
|
||||
if (result)
|
||||
{
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
return DokanNtStatusFromWin32(error);
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
static void Initialize(CSiaApi* siaApi, CSiaDriveConfig* siaDriveConfig)
|
||||
{
|
||||
@@ -846,8 +957,8 @@ public:
|
||||
_siaDriveConfig = siaDriveConfig;
|
||||
_dokanOps.Cleanup = Sia_Cleanup;
|
||||
_dokanOps.CloseFile = Sia_CloseFile;
|
||||
_dokanOps.DeleteDirectory = nullptr;
|
||||
_dokanOps.DeleteFileW = nullptr;
|
||||
_dokanOps.DeleteDirectory = Sia_DeleteDirectory;
|
||||
_dokanOps.DeleteFileW = Sia_DeleteFileW;
|
||||
_dokanOps.FindFiles = Sia_FindFiles;
|
||||
_dokanOps.FindFilesWithPattern = nullptr;
|
||||
_dokanOps.FindStreams = nullptr;
|
||||
@@ -855,10 +966,10 @@ public:
|
||||
_dokanOps.GetDiskFreeSpaceW = Sia_GetDiskFreeSpaceW;
|
||||
_dokanOps.GetFileInformation = Sia_GetFileInformation;
|
||||
_dokanOps.GetFileSecurityW = nullptr;
|
||||
_dokanOps.GetVolumeInformationW = Sia_GetVolumeInformation;
|
||||
_dokanOps.GetVolumeInformationW = Sia_GetVolumeInformationW;
|
||||
_dokanOps.LockFile = nullptr;
|
||||
_dokanOps.Mounted = Sia_Mounted;
|
||||
_dokanOps.MoveFileW = nullptr;
|
||||
_dokanOps.MoveFileW = Sia_MoveFileW;
|
||||
_dokanOps.ReadFile = Sia_ReadFile;
|
||||
_dokanOps.SetAllocationSize = nullptr;
|
||||
_dokanOps.SetEndOfFile = Sia_SetEndOfFile;
|
||||
@@ -889,7 +1000,7 @@ public:
|
||||
{
|
||||
_dokanOptions.MountPoint = _mountPoint.ToUpper().str().c_str();
|
||||
_mountStatus = DokanMain(&_dokanOptions, &_dokanOps);
|
||||
CEventSystem::EventSystem.NotifyEvent(CEventPtr(new DriveMountEnded(_mountPoint, _mountStatus)));
|
||||
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DriveMountEnded(_mountPoint, _mountStatus)));
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user