Mo changes
This commit is contained in:
@@ -49,18 +49,20 @@ private:
|
||||
static bool AddFileToCache(const SString& siaPath, const SString& cacheLocation)
|
||||
{
|
||||
bool ret = false;
|
||||
SString tempPath;
|
||||
tempPath.Resize(MAX_PATH + 1);
|
||||
if (::GetTempPath(MAX_PATH + 1, &tempPath[0]))
|
||||
FilePath tempFilePath = FilePath::GetTempDirectory();
|
||||
tempFilePath.Append(GenerateSha256(siaPath) + ".siatmp");
|
||||
|
||||
// TODO Check cache size is large enough to hold new file
|
||||
ret = ApiSuccess(_siaApi->GetRenter()->DownloadFile(siaPath, tempFilePath));
|
||||
if (ret)
|
||||
{
|
||||
// Check cache size is large enough to hold new file
|
||||
ret = ApiSuccess(_siaApi->GetRenter()->DownloadFile(siaPath, tempPath));
|
||||
if (ret)
|
||||
{
|
||||
FilePath src(tempPath, L"");
|
||||
FilePath dest(GetCacheLocation(), siaPath);
|
||||
ret = src.MoveFile(dest);
|
||||
}
|
||||
FilePath src(tempFilePath);
|
||||
FilePath dest(GetCacheLocation(), siaPath);
|
||||
ret = src.MoveFile(dest);
|
||||
if (!ret)
|
||||
{
|
||||
src.DeleteFile();
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -68,6 +70,7 @@ private:
|
||||
|
||||
static void QueueUploadIfChanged(const ULONG64& id, const std::uint64_t& size)
|
||||
{
|
||||
return;
|
||||
if (!_openFileMap[id].ReadOnly)
|
||||
{
|
||||
if (size > 0)
|
||||
@@ -175,7 +178,7 @@ private:
|
||||
{
|
||||
if (creationDisposition == CREATE_NEW)
|
||||
{
|
||||
if (!::CreateDirectory(&cacheFilePath[0], &securityAttrib))
|
||||
if (!cacheFilePath.CreateDirectory())
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
ret = DokanNtStatusFromWin32(error);
|
||||
@@ -183,10 +186,9 @@ private:
|
||||
}
|
||||
else if (creationDisposition == OPEN_ALWAYS)
|
||||
{
|
||||
if (!::CreateDirectory(&cacheFilePath[0], &securityAttrib))
|
||||
if (cacheFilePath.CreateDirectory())
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
|
||||
if (error != ERROR_ALREADY_EXISTS)
|
||||
{
|
||||
ret = DokanNtStatusFromWin32(error);
|
||||
@@ -355,17 +357,6 @@ private:
|
||||
ofi.ReadOnly = false;
|
||||
std::lock_guard<std::mutex> l(_dokanMutex);
|
||||
_openFileMap.insert({ DokanFileInfo->Context, ofi });
|
||||
|
||||
/*if (creationDisposition == OPEN_ALWAYS ||
|
||||
creationDisposition == CREATE_ALWAYS) {
|
||||
error = GetLastError();
|
||||
if (error == ERROR_ALREADY_EXISTS) {
|
||||
DbgPrint(L"\tOpen an already existing file\n");
|
||||
// Open succeed but we need to inform the driver
|
||||
// that the file open and not created by returning STATUS_OBJECT_NAME_COLLISION
|
||||
return STATUS_OBJECT_NAME_COLLISION;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -549,6 +540,7 @@ private:
|
||||
|
||||
static NTSTATUS DOKAN_CALLBACK Sia_Mounted(PDOKAN_FILE_INFO DokanFileInfo)
|
||||
{
|
||||
// May spend a little wait time here while files are cleaned-up and re-added to queue
|
||||
_uploadManager.reset(new CUploadManager(CSiaCurl(_siaApi->GetHostConfig()), _siaDriveConfig));
|
||||
StartFileListThread();
|
||||
return STATUS_SUCCESS;
|
||||
@@ -791,8 +783,10 @@ private:
|
||||
if (DokanFileInfo->Context)
|
||||
{
|
||||
::CloseHandle(reinterpret_cast<HANDLE>(DokanFileInfo->Context));
|
||||
std::lock_guard<std::mutex> l(_dokanMutex);
|
||||
_openFileMap.erase(DokanFileInfo->Context);
|
||||
{
|
||||
std::lock_guard<std::mutex> l(_dokanMutex);
|
||||
_openFileMap.erase(DokanFileInfo->Context);
|
||||
}
|
||||
DokanFileInfo->Context = 0;
|
||||
}
|
||||
else {
|
||||
@@ -823,11 +817,10 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static NTSTATUS DOKAN_CALLBACK Sia_FlushFileBuffers(LPCWSTR FileName, PDOKAN_FILE_INFO DokanFileInfo)
|
||||
{
|
||||
HANDLE handle = reinterpret_cast<HANDLE>(DokanFileInfo->Context);
|
||||
if (!handle || handle == INVALID_HANDLE_VALUE)
|
||||
if (!handle || (handle == INVALID_HANDLE_VALUE))
|
||||
{
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
@@ -877,14 +870,15 @@ public:
|
||||
ZeroMemory(&_dokanOptions, sizeof(DOKAN_OPTIONS));
|
||||
_dokanOptions.Version = DOKAN_VERSION;
|
||||
_dokanOptions.ThreadCount = 0; // use default
|
||||
#ifdef _DEBUG
|
||||
_dokanOptions.Options = DOKAN_OPTION_DEBUG;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void Mount(const wchar_t& driveLetter, const SString& cacheLocation)
|
||||
{
|
||||
if (_siaApi && !_mountThread)
|
||||
{
|
||||
// May spend a little wait time here while files are cleaned-up and re-added to queue
|
||||
_cacheLocation = cacheLocation;
|
||||
wchar_t tmp[] = { driveLetter, ':', '\\', 0 };
|
||||
_mountPoint = tmp;
|
||||
|
Reference in New Issue
Block a user