All kinds of stuff
This commit is contained in:
8
3rd_party/CEF/create.cmd
vendored
8
3rd_party/CEF/create.cmd
vendored
@@ -69,9 +69,11 @@ if not exist "%MODE%.complete" (
|
||||
copy /y chromium_git\chromium\src\out\%MODE%_GN_x64\*.bin bin\%MODE%\
|
||||
copy /y chromium_git\chromium\src\out\%MODE%_GN_x64\cef_*.pak bin\%MODE%\
|
||||
|
||||
echo "Cleaning build output... Please wait..."
|
||||
rd /s /q chromium_git\chromium\src\out\%MODE%_GN_x64
|
||||
rd /s /q chromium_git\chromium\src\out\%MODE%_GN_x86
|
||||
if "%MODE%"=="Release" (
|
||||
echo "Cleaning build output... Please wait..."
|
||||
rd /s /q chromium_git\chromium\src\out\%MODE%_GN_x64
|
||||
rd /s /q chromium_git\chromium\src\out\%MODE%_GN_x86
|
||||
)
|
||||
|
||||
echo "1">%MODE%.complete
|
||||
)
|
||||
|
@@ -36,6 +36,7 @@ typedef std::shared_ptr<CEvent> CEventPtr;
|
||||
|
||||
#define CreateSystemEvent(E) CEventPtr(new E)
|
||||
#define CreateSystemEventConsumer(E) [=](const CEvent&) -> void { E(e); }
|
||||
CEventPtr SIADRIVE_EXPORTABLE CreateSystemCriticalEvent(const SString& reason);
|
||||
|
||||
// Singleton
|
||||
class SIADRIVE_EXPORTABLE CEventSystem
|
||||
|
@@ -55,7 +55,7 @@ private:
|
||||
private:
|
||||
CSiaDriveConfig* GetSiaDriveConfig() const { return _siaDriveConfig; }
|
||||
|
||||
bool HandleFileRemove(const CSiaCurl& siaCurl, const SString& siaPath);
|
||||
void HandleFileRemove(const CSiaCurl& siaCurl, const SString& siaPath);
|
||||
void DeleteFilesRemovedFromSia(const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriveConfig, const bool& isStartup = false);
|
||||
|
||||
protected:
|
||||
|
@@ -13,6 +13,8 @@ CAutoThread::CAutoThread(const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriveConfi
|
||||
_siaDriveConfig(siaDriveConfig),
|
||||
#ifdef _WIN32
|
||||
_stopEvent(::CreateEvent(nullptr, FALSE, FALSE, nullptr)),
|
||||
#else
|
||||
a
|
||||
#endif
|
||||
_AutoThreadCallback(autoThreadCallback)
|
||||
{
|
||||
@@ -23,6 +25,8 @@ CAutoThread::~CAutoThread()
|
||||
StopAutoThread();
|
||||
#ifdef _WIN32
|
||||
::CloseHandle(_stopEvent);
|
||||
#else
|
||||
a
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -50,6 +54,8 @@ void CAutoThread::StartAutoThread()
|
||||
{
|
||||
AutoThreadCallback(*_siaCurl, _siaDriveConfig);
|
||||
} while (::WaitForSingleObject(_stopEvent, 2000) == WAIT_TIMEOUT);
|
||||
#else
|
||||
a
|
||||
#endif
|
||||
}));
|
||||
}
|
||||
@@ -62,13 +68,14 @@ void CAutoThread::StopAutoThread()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
::SetEvent(_stopEvent);
|
||||
#else
|
||||
a
|
||||
#endif
|
||||
_thread->join();
|
||||
_thread.reset(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool CAutoThread::IsRunning() const
|
||||
{
|
||||
return (_thread != nullptr);
|
||||
|
@@ -118,4 +118,53 @@ void CEventSystem::Stop()
|
||||
_processThread->join();
|
||||
_processThread.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SystemCriticalEvent :
|
||||
public virtual CEvent
|
||||
{
|
||||
public:
|
||||
SystemCriticalEvent(const SString& reason) :
|
||||
CEvent(EventLevel::Error),
|
||||
_reason(reason)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~SystemCriticalEvent() {}
|
||||
private:
|
||||
const SString _reason;
|
||||
|
||||
public:
|
||||
virtual SString GetSingleLineMessage() const override
|
||||
{
|
||||
return GetEventName() +
|
||||
"|REASON|" + _reason;
|
||||
}
|
||||
|
||||
virtual std::shared_ptr<CEvent> Clone() const override
|
||||
{
|
||||
return CEventPtr(new SystemCriticalEvent(_reason));
|
||||
}
|
||||
|
||||
virtual SString GetEventName() const override
|
||||
{
|
||||
return "SystemCriticalEvent";
|
||||
}
|
||||
|
||||
virtual json GetEventJson() const override
|
||||
{
|
||||
return
|
||||
{
|
||||
{ "event", GetEventName()},
|
||||
{ "reason", _reason }
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
NS_BEGIN(Sia)
|
||||
NS_BEGIN(Api)
|
||||
CEventPtr CreateSystemCriticalEvent(const SString& reason)
|
||||
{
|
||||
return CEventPtr(new SystemCriticalEvent(reason));
|
||||
}
|
||||
NS_END(2)
|
@@ -677,9 +677,8 @@ void CUploadManager::DeleteFilesRemovedFromSia(const CSiaCurl& siaCurl, CSiaDriv
|
||||
}
|
||||
}
|
||||
|
||||
bool CUploadManager::HandleFileRemove(const CSiaCurl& siaCurl, const SString& siaPath)
|
||||
void CUploadManager::HandleFileRemove(const CSiaCurl& siaCurl, const SString& siaPath)
|
||||
{
|
||||
bool ret = false;
|
||||
FilePath removeFilePath(GetSiaDriveConfig()->GetCacheFolder(), siaPath);
|
||||
|
||||
json response;
|
||||
@@ -691,7 +690,6 @@ bool CUploadManager::HandleFileRemove(const CSiaCurl& siaCurl, const SString& si
|
||||
if (del.exec() >= 0)
|
||||
{
|
||||
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(FileRemovedFromSia(siaPath, removeFilePath)));
|
||||
ret = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -701,9 +699,8 @@ bool CUploadManager::HandleFileRemove(const CSiaCurl& siaCurl, const SString& si
|
||||
else
|
||||
{
|
||||
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(FailedToRemoveFileFromSia(siaPath, removeFilePath, cerror)));
|
||||
CEventSystem::EventSystem.NotifyEvent(CreateSystemCriticalEvent(cerror.GetReason()));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void CUploadManager::AutoThreadCallback(const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriveConfig)
|
||||
@@ -834,11 +831,19 @@ UploadError CUploadManager::AddOrUpdate(const SString& siaPath, SString filePath
|
||||
{
|
||||
std::uint64_t modifiedTime = query.getColumn(query.getColumnIndex("modified_time")).getInt64();
|
||||
UploadStatus uploadStatus = static_cast<UploadStatus>(static_cast<unsigned>(query.getColumn(query.getColumnIndex("status"))));
|
||||
addToDatabase = ((uploadStatus == UploadStatus::Uploading) || (uploadStatus == UploadStatus::Complete)) && (lastModified != modifiedTime) && HandleFileRemove(CSiaCurl(GetHostConfig()), siaPath);
|
||||
addToDatabase = (uploadStatus == UploadStatus::Uploading);
|
||||
if (!addToDatabase)
|
||||
{
|
||||
addToDatabase = (uploadStatus == UploadStatus::Complete) && (lastModified != modifiedTime);
|
||||
if (addToDatabase)
|
||||
{
|
||||
HandleFileRemove(CSiaCurl(GetHostConfig()), siaPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
else // Not in database, so assume is in Sia
|
||||
{
|
||||
addToDatabase = HandleFileRemove(CSiaCurl(GetHostConfig()), siaPath);
|
||||
HandleFileRemove(CSiaCurl(GetHostConfig()), siaPath);
|
||||
}
|
||||
|
||||
if (addToDatabase)
|
||||
@@ -889,10 +894,7 @@ UploadError CUploadManager::Remove(const SString& siaPath)
|
||||
try
|
||||
{
|
||||
std::lock_guard<std::mutex> l(_uploadMutex);
|
||||
if (!HandleFileRemove(CSiaCurl(GetHostConfig()), siaPath))
|
||||
{
|
||||
ret = UploadErrorCode::SourceFileNotFound;
|
||||
}
|
||||
HandleFileRemove(CSiaCurl(GetHostConfig()), siaPath);
|
||||
}
|
||||
catch (SQLite::Exception e)
|
||||
{
|
||||
|
@@ -7,10 +7,10 @@
|
||||
using namespace Sia::Api;
|
||||
using namespace Sia::Api::Dokan;
|
||||
|
||||
static __int64 FileSize(const wchar_t* name)
|
||||
static __int64 FileSize(const SString name)
|
||||
{
|
||||
struct _stat64 buf;
|
||||
if (_wstat64(name, &buf) != 0)
|
||||
if (_wstat64(&name[0], &buf) != 0)
|
||||
return -1; // error, could use errno to find out more
|
||||
|
||||
return buf.st_size;
|
||||
@@ -37,6 +37,7 @@ private:
|
||||
SECURITY_ATTRIBUTES SecurityAttrib;
|
||||
ULONG CreateDisp;
|
||||
DWORD AttributesAndFlags;
|
||||
PDOKAN_FILE_INFO DokanFileInfo;
|
||||
} OpenFileInfo;
|
||||
|
||||
class DownloadToCacheBegin :
|
||||
@@ -1245,6 +1246,7 @@ private:
|
||||
|
||||
static bool AddFileToCache(OpenFileInfo& openFileInfo, PDOKAN_FILE_INFO dokanFileInfo)
|
||||
{
|
||||
// TODO taking too long
|
||||
bool ret = true;
|
||||
if (openFileInfo.Dummy)
|
||||
{
|
||||
@@ -1259,8 +1261,8 @@ private:
|
||||
// Find all open handles for requested file
|
||||
std::vector<OpenFileInfo*> matched;
|
||||
matched.push_back(&openFileInfo);
|
||||
std::lock_guard<std::mutex> l(_openFileMutex);
|
||||
{
|
||||
std::lock_guard<std::mutex> l(_openFileMutex);
|
||||
std::for_each(_openFiles.begin(), _openFiles.end(), [&](OpenFileInfo* ofi)
|
||||
{
|
||||
if ((ofi->FileHandle != openFileInfo.FileHandle) && (ofi->SiaPath == openFileInfo.SiaPath))
|
||||
@@ -1271,9 +1273,13 @@ private:
|
||||
}
|
||||
|
||||
// Close all to allow move to complete
|
||||
for (auto* ofi : matched)
|
||||
for (auto& ofi : matched)
|
||||
{
|
||||
::CloseHandle(ofi->FileHandle);
|
||||
std::lock_guard<std::mutex> l(_openFileMutex);
|
||||
if (std::find(_openFiles.begin(), _openFiles.end(), ofi) != _openFiles.end())
|
||||
{
|
||||
::CloseHandle(ofi->FileHandle);
|
||||
}
|
||||
}
|
||||
|
||||
FilePath src(tempFilePath);
|
||||
@@ -1286,10 +1292,16 @@ private:
|
||||
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(MoveTempToCacheResult(openFileInfo, tempFilePath, ret)));
|
||||
|
||||
// Re-open all files
|
||||
for (auto& ofi : matched)
|
||||
{
|
||||
ofi->FileHandle = ::CreateFile(&ofi->CacheFilePath[0], ofi->DesiredAccess, ofi->ShareMode, ofi->SecurityAttrib.nLength ? &ofi->SecurityAttrib : nullptr, ofi->CreateDisp, ofi->AttributesAndFlags, nullptr);
|
||||
ofi->Dummy = !ret;
|
||||
std::lock_guard<std::mutex> l(_openFileMutex);
|
||||
for (auto& ofi : matched)
|
||||
{
|
||||
if (std::find(_openFiles.begin(), _openFiles.end(), ofi) != _openFiles.end())
|
||||
{
|
||||
ofi->FileHandle = ::CreateFile(&ofi->CacheFilePath[0], ofi->DesiredAccess, ofi->ShareMode, ofi->SecurityAttrib.nLength ? &ofi->SecurityAttrib : nullptr, ofi->CreateDisp, ofi->AttributesAndFlags, nullptr);
|
||||
ofi->Dummy = !ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1309,33 +1321,37 @@ private:
|
||||
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DokanCloseFile(openFileInfo.CacheFilePath)));
|
||||
if (deleteOnClose)
|
||||
{
|
||||
// TODO Handle failure
|
||||
::CloseHandle(openFileInfo.FileHandle);
|
||||
_uploadManager->Remove(openFileInfo.SiaPath);
|
||||
auto result = _uploadManager->Remove(openFileInfo.SiaPath);
|
||||
if (!ApiSuccess(result))
|
||||
{
|
||||
CEventSystem::EventSystem.NotifyEvent(CreateSystemCriticalEvent(result.GetReason()));
|
||||
}
|
||||
}
|
||||
else if (openFileInfo.Changed)
|
||||
{
|
||||
if (fileSize > 0)
|
||||
{
|
||||
// TODO Handle error return
|
||||
// Retrieve the file times for the file.
|
||||
FILETIME fileTimes[3];
|
||||
if (::GetFileTime(openFileInfo.FileHandle, &fileTimes[0], &fileTimes[1], &fileTimes[2]))
|
||||
::GetFileTime(openFileInfo.FileHandle, &fileTimes[0], &fileTimes[1], &fileTimes[2]);
|
||||
::CloseHandle(openFileInfo.FileHandle);
|
||||
auto result = _uploadManager->AddOrUpdate(openFileInfo.SiaPath, openFileInfo.CacheFilePath, *reinterpret_cast<std::uint64_t*>(&fileTimes[2]));
|
||||
if (!ApiSuccess(result))
|
||||
{
|
||||
::CloseHandle(openFileInfo.FileHandle);
|
||||
_uploadManager->AddOrUpdate(openFileInfo.SiaPath, openFileInfo.CacheFilePath, *reinterpret_cast<std::uint64_t*>(&fileTimes[2]));
|
||||
}
|
||||
else
|
||||
{
|
||||
::CloseHandle(openFileInfo.FileHandle);
|
||||
CEventSystem::EventSystem.NotifyEvent(CreateSystemCriticalEvent(result.GetReason()));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
::CloseHandle(openFileInfo.FileHandle);
|
||||
// TODO Handle error return
|
||||
|
||||
// Treat 0 length files as deleted in Sia - cache retains 0-length
|
||||
_uploadManager->Remove(openFileInfo.SiaPath);
|
||||
auto result = _uploadManager->Remove(openFileInfo.SiaPath);
|
||||
if (!ApiSuccess(result))
|
||||
{
|
||||
CEventSystem::EventSystem.NotifyEvent(CreateSystemCriticalEvent(result.GetReason()));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -1480,6 +1496,7 @@ private:
|
||||
ofi->Dummy = false;
|
||||
ofi->Changed = false;
|
||||
ofi->FileHandle = handle;
|
||||
ofi->DokanFileInfo = dokanFileInfo;
|
||||
dokanFileInfo->Context = reinterpret_cast<ULONG64>(ofi);
|
||||
}
|
||||
}
|
||||
@@ -1648,6 +1665,7 @@ private:
|
||||
ofi->SecurityAttrib = securityAttrib;
|
||||
ofi->CreateDisp = createDisposition;
|
||||
ofi->AttributesAndFlags = fileAttributesAndFlags;
|
||||
ofi->DokanFileInfo = dokanFileInfo;
|
||||
dokanFileInfo->Context = reinterpret_cast<ULONG64>(ofi);
|
||||
_openFiles.push_back(ofi);
|
||||
}
|
||||
@@ -1929,11 +1947,15 @@ private:
|
||||
PULONGLONG TotalNumberOfFreeBytes, PDOKAN_FILE_INFO dokanFileInfo)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(dokanFileInfo);
|
||||
SiaCurrency allocatedFunds = _siaApi->GetRenter()->GetFunds();
|
||||
SiaCurrency unspentFunds = _siaApi->GetRenter()->GetUnspent();
|
||||
SiaCurrency totalUsedGb = _siaApi->GetRenter()->GetTotalUsedBytes() ? _siaApi->GetRenter()->GetTotalUsedBytes() : 0.0;
|
||||
auto totalAvailable = (totalUsedGb / (allocatedFunds - unspentFunds)) * allocatedFunds;
|
||||
auto totalRemainGb = totalAvailable - totalUsedGb;
|
||||
|
||||
// TODO Implement this correctly
|
||||
*FreeBytesAvailable = static_cast<ULONGLONG>(1024 * 1024 * 1024);
|
||||
*TotalNumberOfBytes = 9223372036854775807;
|
||||
*TotalNumberOfFreeBytes = 9223372036854775807;
|
||||
*FreeBytesAvailable = totalRemainGb.ToUInt();
|
||||
*TotalNumberOfBytes = totalAvailable.ToUInt();
|
||||
*TotalNumberOfFreeBytes = totalAvailable.ToUInt();
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
@@ -1946,8 +1968,8 @@ private:
|
||||
UNREFERENCED_PARAMETER(dokanFileInfo);
|
||||
|
||||
wcscpy_s(VolumeNameBuffer, VolumeNameSize, L"SiaDrive");
|
||||
*VolumeSerialNumber = 0x19831186;
|
||||
*MaximumComponentLength = 256;
|
||||
*VolumeSerialNumber = 0x5E05140D;
|
||||
*MaximumComponentLength = MAX_PATH;
|
||||
*FileSystemFlags = FILE_CASE_SENSITIVE_SEARCH | FILE_CASE_PRESERVED_NAMES |
|
||||
FILE_SUPPORTS_REMOTE_STORAGE | FILE_UNICODE_ON_DISK |
|
||||
FILE_PERSISTENT_ACLS;
|
||||
@@ -1974,7 +1996,6 @@ private:
|
||||
auto openFileInfo = reinterpret_cast<OpenFileInfo*>(dokanFileInfo->Context);
|
||||
if (openFileInfo && openFileInfo->Dummy)
|
||||
{
|
||||
// TODO taking too long
|
||||
if (!AddFileToCache(*openFileInfo, dokanFileInfo))
|
||||
{
|
||||
ret = STATUS_INVALID_DEVICE_STATE;
|
||||
@@ -1986,7 +2007,6 @@ private:
|
||||
{
|
||||
if (!tempHandle || (tempHandle == INVALID_HANDLE_VALUE))
|
||||
{
|
||||
// TODO taking too long
|
||||
if (!filePath.IsFile())
|
||||
{
|
||||
if (!AddFileToCache(*openFileInfo, dokanFileInfo))
|
||||
@@ -2044,7 +2064,6 @@ private:
|
||||
auto openFileInfo = reinterpret_cast<OpenFileInfo*>(dokanFileInfo->Context);
|
||||
if (openFileInfo && openFileInfo->Dummy)
|
||||
{
|
||||
// TODO taking too long
|
||||
if (!AddFileToCache(*openFileInfo, dokanFileInfo))
|
||||
{
|
||||
ret = STATUS_INVALID_DEVICE_STATE;
|
||||
@@ -2055,7 +2074,6 @@ private:
|
||||
HANDLE tempHandle = openFileInfo ? openFileInfo->FileHandle : 0;
|
||||
if (!tempHandle || (tempHandle == INVALID_HANDLE_VALUE))
|
||||
{
|
||||
// TODO taking too long
|
||||
if (!filePath.IsFile())
|
||||
{
|
||||
if (!AddFileToCache(*openFileInfo, dokanFileInfo))
|
||||
@@ -2187,7 +2205,6 @@ private:
|
||||
auto openFileInfo = reinterpret_cast<OpenFileInfo*>(dokanFileInfo->Context);
|
||||
if (openFileInfo && openFileInfo->Dummy)
|
||||
{
|
||||
// TODO taking too long
|
||||
if (!AddFileToCache(*openFileInfo, dokanFileInfo))
|
||||
{
|
||||
ret = STATUS_INVALID_DEVICE_STATE;
|
||||
@@ -2255,24 +2272,26 @@ private:
|
||||
// if open with FILE_FLAG_DELETE_ON_CLOSE
|
||||
if (dokanFileInfo->IsDirectory)
|
||||
{
|
||||
// TODO Add event notification
|
||||
if (filePath.RemoveDirectory())
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
filePath.RemoveDirectory();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (filePath.DeleteFile())
|
||||
filePath.DeleteFile();
|
||||
|
||||
int count = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> l(_openFileMutex);
|
||||
std::count_if(_openFiles.begin(), _openFiles.end(), [&](const OpenFileInfo* inf) -> bool
|
||||
{
|
||||
return (inf->DokanFileInfo != dokanFileInfo) && (inf->DokanFileInfo->DeleteOnClose ? true : false);
|
||||
});
|
||||
}
|
||||
else
|
||||
|
||||
if (count <= 1)
|
||||
{
|
||||
RefreshActiveFileTree(true);
|
||||
}
|
||||
}
|
||||
RefreshActiveFileTree(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user