Fix move file
This commit is contained in:
@@ -177,12 +177,13 @@ public:
|
||||
void Refresh(const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriveConfig);
|
||||
|
||||
public:
|
||||
CSiaError<_SiaApiErrorCode> FileExists(const SString& siaPath, bool& exists) const;
|
||||
CSiaError<_SiaApiErrorCode> DownloadFile(const SString& siaPath, const SString& location) const;
|
||||
CSiaError<_SiaApiErrorCode> GetFileTree(std::shared_ptr<_CSiaFileTree>& siaFileTree) const;
|
||||
CSiaError<_SiaApiErrorCode> FileExists(const SString& siaPath, bool& exists) const;
|
||||
_SiaRenterAllowance GetAllowance() const;
|
||||
CSiaError<_SiaApiErrorCode> SetAllowance(const _SiaRenterAllowance& renterAllowance);
|
||||
CSiaError<_SiaApiErrorCode> GetFileTree(std::shared_ptr<_CSiaFileTree>& siaFileTree) const;
|
||||
CSiaError<_SiaApiErrorCode> RefreshFileTree( );
|
||||
CSiaError<_SiaApiErrorCode> RenameFile(const SString& siaPath, const SString& newSiaPath);
|
||||
CSiaError<_SiaApiErrorCode> SetAllowance(const _SiaRenterAllowance& renterAllowance);
|
||||
};
|
||||
|
||||
class SIADRIVE_EXPORTABLE _CSiaConsensus :
|
||||
|
@@ -685,10 +685,11 @@ class SIADRIVE_DOKAN_EXPORTABLE DokanMoveFileW :
|
||||
public CEvent
|
||||
{
|
||||
public:
|
||||
DokanMoveFileW(const SString& srcPath, const SString& destPath) :
|
||||
DokanMoveFileW(const SString& srcPath, const SString& destPath, const NTSTATUS& result) :
|
||||
CEvent(EventLevel::Debug),
|
||||
_srcPath(srcPath),
|
||||
_destPath(destPath)
|
||||
_destPath(destPath),
|
||||
_result(result)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -700,16 +701,19 @@ public:
|
||||
private:
|
||||
const SString _srcPath;
|
||||
const SString _destPath;
|
||||
const NTSTATUS _result;
|
||||
|
||||
public:
|
||||
virtual std::shared_ptr<CEvent> Clone() const override
|
||||
{
|
||||
return std::shared_ptr<CEvent>(new DokanMoveFileW(_srcPath, _destPath));
|
||||
return std::shared_ptr<CEvent>(new DokanMoveFileW(_srcPath, _destPath, _result));
|
||||
}
|
||||
|
||||
virtual SString GetSingleLineMessage() const override
|
||||
{
|
||||
return L"DokanMoveFileW|SRC|" + _srcPath + "|DEST|" + _destPath;
|
||||
return L"DokanMoveFileW|SRC|" + _srcPath +
|
||||
"|DEST|" + _destPath +
|
||||
"|RES|" + SString::FromUInt64(_result);
|
||||
}
|
||||
};
|
||||
NS_END(3)
|
||||
|
@@ -155,6 +155,19 @@ SiaApiError CSiaApi::_CSiaRenter::RefreshFileTree( )
|
||||
return ret;
|
||||
}
|
||||
|
||||
SiaApiError CSiaApi::_CSiaRenter::RenameFile(const SString& siaPath, const SString& newSiaPath)
|
||||
{
|
||||
SiaApiError ret;
|
||||
json result;
|
||||
SiaCurlError cerror = GetSiaCurl().Get(L"/renter/rename/" + siaPath, { { L"newsiapath", newSiaPath } }, result);
|
||||
if (!ApiSuccess(cerror))
|
||||
{
|
||||
ret = { SiaApiErrorCode::RequestError, cerror.GetReason() };
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
SiaApiError CSiaApi::_CSiaRenter::FileExists(const SString& siaPath, bool& exists) const
|
||||
{
|
||||
CSiaFileTreePtr siaFileTree;
|
||||
|
@@ -125,17 +125,9 @@ private:
|
||||
::CloseHandle(openFileInfo.FileHandle);
|
||||
_uploadManager->Remove(openFileInfo.SiaPath);
|
||||
}
|
||||
else
|
||||
else if (openFileInfo.Changed)
|
||||
{
|
||||
QueueUploadIfChanged(openFileInfo, fileSize);
|
||||
}
|
||||
}
|
||||
|
||||
static void QueueUploadIfChanged(const OpenFileInfo& openFileInfo, const std::uint64_t& size)
|
||||
{
|
||||
if (openFileInfo.Changed)
|
||||
{
|
||||
if (size > 0)
|
||||
if (fileSize > 0)
|
||||
{
|
||||
// TODO Handle error return
|
||||
// Retrieve the file times for the file.
|
||||
@@ -666,7 +658,7 @@ private:
|
||||
|
||||
if (ret == STATUS_SUCCESS)
|
||||
{
|
||||
if (openFileInfo && openFileInfo->Dummy)
|
||||
if ((openFileInfo && openFileInfo->Dummy) || (siaFile && !FilePath(cachFileLocation).IsFile()))
|
||||
{
|
||||
LARGE_INTEGER li = { 0 };
|
||||
li.QuadPart = siaFile->GetFileSize();
|
||||
@@ -1057,6 +1049,7 @@ private:
|
||||
{
|
||||
LARGE_INTEGER li = { 0 };
|
||||
::GetFileSizeEx(openFileInfo->FileHandle, &li);
|
||||
// !!! File handle will be closed in this method !!!
|
||||
HandleSiaFileClose(*openFileInfo, li.QuadPart, dokanFileInfo->DeleteOnClose ? true : false);
|
||||
}
|
||||
|
||||
@@ -1070,6 +1063,7 @@ private:
|
||||
// if open with FILE_FLAG_DELETE_ON_CLOSE
|
||||
if (dokanFileInfo->IsDirectory)
|
||||
{
|
||||
// TODO Add event notification
|
||||
if (filePath.RemoveDirectory())
|
||||
{
|
||||
}
|
||||
@@ -1153,7 +1147,6 @@ private:
|
||||
|
||||
static NTSTATUS DOKAN_CALLBACK Sia_DeleteFileW(LPCWSTR fileName, PDOKAN_FILE_INFO dokanFileInfo)
|
||||
{
|
||||
// TODO Check dummy and add to cache if not found
|
||||
NTSTATUS ret = STATUS_SUCCESS;
|
||||
|
||||
auto openFileInfo = reinterpret_cast<OpenFileInfo*>(dokanFileInfo->Context);
|
||||
@@ -1180,13 +1173,10 @@ private:
|
||||
|
||||
static NTSTATUS DOKAN_CALLBACK Sia_MoveFileW(LPCWSTR fileName, LPCWSTR NewFileName, BOOL ReplaceIfExisting, PDOKAN_FILE_INFO dokanFileInfo)
|
||||
{
|
||||
// TODO Check dummy and add to cache if not found
|
||||
// TODO Implement Sia rename
|
||||
NTSTATUS ret = STATUS_SUCCESS;
|
||||
|
||||
FilePath filePath(GetCacheLocation(), fileName);
|
||||
FilePath newFilePath(GetCacheLocation(), NewFileName);
|
||||
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DokanMoveFileW(filePath, newFilePath)));
|
||||
|
||||
auto openFileInfo = reinterpret_cast<OpenFileInfo*>(dokanFileInfo->Context);
|
||||
if (!openFileInfo || !openFileInfo->FileHandle || (openFileInfo->FileHandle == INVALID_HANDLE_VALUE))
|
||||
@@ -1212,7 +1202,14 @@ private:
|
||||
BOOL result = ::SetFileInformationByHandle(openFileInfo->FileHandle, FileRenameInfo, renameInfo, bufferSize);
|
||||
free(renameInfo);
|
||||
|
||||
if (!result)
|
||||
if (result)
|
||||
{
|
||||
if (!ApiSuccess(_siaApi->GetRenter()->RenameFile(openFileInfo->SiaPath, CSiaApi::FormatToSiaPath(NewFileName))))
|
||||
{
|
||||
ret = STATUS_INTERNAL_ERROR;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
ret = DokanNtStatusFromWin32(error);
|
||||
@@ -1224,6 +1221,7 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DokanMoveFileW(filePath, newFilePath, ret)));
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user