Make portable
This commit is contained in:
@@ -18,14 +18,14 @@ public:
|
||||
virtual ~CAutoThread();
|
||||
|
||||
private:
|
||||
bool _stopRequested;
|
||||
std::unique_ptr<CSiaCurl> _siaCurl;
|
||||
CSiaDriveConfig* _siaDriveConfig;
|
||||
#ifdef _WIN32
|
||||
HANDLE _stopEvent;
|
||||
#endif
|
||||
std::function<void(const CSiaCurl&, CSiaDriveConfig*)> _AutoThreadCallback;
|
||||
std::unique_ptr<std::thread> _thread;
|
||||
std::mutex _startStopMutex;
|
||||
std::function<void(const CSiaCurl&, CSiaDriveConfig*)> _AutoThreadCallback;
|
||||
std::mutex _stopMutex;
|
||||
std::condition_variable _stopEvent;
|
||||
|
||||
protected:
|
||||
virtual void AutoThreadCallback(const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriveConfig);
|
||||
|
@@ -306,11 +306,6 @@ void CSiaDriveApp::OnContextCreated(
|
||||
_siaCurl.reset(new CSiaCurl(hostConfig));
|
||||
_siaApi.reset(new CSiaApi(hostConfig, _siaDriveConfig.get()));
|
||||
_siaApi->StartBackgroundRefresh();
|
||||
#ifdef _WIN32
|
||||
_siaDrive.reset(new Dokan::CSiaDokanDrive(*_siaApi, _siaDriveConfig.get()));
|
||||
#else
|
||||
a
|
||||
#endif
|
||||
|
||||
CefRefPtr<CefV8Value> global = context->GetGlobal();
|
||||
|
||||
@@ -492,6 +487,15 @@ void CSiaDriveApp::SiaApiRefreshCallback(CefRefPtr<CefV8Context> context, const
|
||||
}
|
||||
ExecuteSetter(context, renterActions, "setUploadProgress", list);
|
||||
}
|
||||
|
||||
if (!_siaDrive)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
_siaDrive.reset(new Dokan::CSiaDokanDrive(*_siaApi, _siaDriveConfig.get()));
|
||||
#else
|
||||
a
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (isOnline != wasOnline)
|
||||
|
@@ -2,6 +2,7 @@
|
||||
#include <siacurl.h>
|
||||
|
||||
using namespace Sia::Api;
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
CAutoThread::CAutoThread(const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriveConfig) :
|
||||
CAutoThread(siaCurl, siaDriveConfig, nullptr)
|
||||
@@ -9,13 +10,9 @@ CAutoThread::CAutoThread(const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriveConfi
|
||||
}
|
||||
|
||||
CAutoThread::CAutoThread(const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriveConfig, std::function<void(const CSiaCurl&, CSiaDriveConfig*)> autoThreadCallback) :
|
||||
_stopRequested(false),
|
||||
_siaCurl(new CSiaCurl(siaCurl)),
|
||||
_siaDriveConfig(siaDriveConfig),
|
||||
#ifdef _WIN32
|
||||
_stopEvent(::CreateEvent(nullptr, FALSE, FALSE, nullptr)),
|
||||
#else
|
||||
a
|
||||
#endif
|
||||
_AutoThreadCallback(autoThreadCallback)
|
||||
{
|
||||
}
|
||||
@@ -23,11 +20,6 @@ CAutoThread::CAutoThread(const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriveConfi
|
||||
CAutoThread::~CAutoThread()
|
||||
{
|
||||
StopAutoThread();
|
||||
#ifdef _WIN32
|
||||
::CloseHandle(_stopEvent);
|
||||
#else
|
||||
a
|
||||
#endif
|
||||
}
|
||||
|
||||
SiaHostConfig CAutoThread::GetHostConfig() const
|
||||
@@ -48,15 +40,14 @@ void CAutoThread::StartAutoThread()
|
||||
std::lock_guard<std::mutex> l(_startStopMutex);
|
||||
if (!_thread)
|
||||
{
|
||||
_stopRequested = false;
|
||||
_thread.reset(new std::thread([this]() {
|
||||
#ifdef _WIN32
|
||||
do
|
||||
{
|
||||
AutoThreadCallback(*_siaCurl, _siaDriveConfig);
|
||||
} while (::WaitForSingleObject(_stopEvent, 2000) == WAIT_TIMEOUT);
|
||||
#else
|
||||
a
|
||||
#endif
|
||||
std::unique_lock<std::mutex> l(_stopMutex);
|
||||
_stopEvent.wait_for(l, 2s);
|
||||
} while (!_stopRequested);
|
||||
}));
|
||||
}
|
||||
}
|
||||
@@ -66,11 +57,11 @@ void CAutoThread::StopAutoThread()
|
||||
std::lock_guard<std::mutex> l(_startStopMutex);
|
||||
if (_thread)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
::SetEvent(_stopEvent);
|
||||
#else
|
||||
a
|
||||
#endif
|
||||
{
|
||||
std::unique_lock<std::mutex> l(_stopMutex);
|
||||
_stopRequested = true;
|
||||
}
|
||||
_stopEvent.notify_all();
|
||||
_thread->join();
|
||||
_thread.reset(nullptr);
|
||||
}
|
||||
|
@@ -18,6 +18,6 @@ void CDebugConsumer::ProcessEvent(const CEvent& eventData)
|
||||
OutputDebugString(eventData.GetSingleLineMessage().str().c_str());
|
||||
OutputDebugString(L"\n");
|
||||
#else
|
||||
a
|
||||
|
||||
#endif
|
||||
}
|
||||
|
@@ -854,9 +854,13 @@ void CUploadManager::HandleFileRemove(const CSiaCurl& siaCurl, const SString& si
|
||||
{
|
||||
SQLite::Statement del(_uploadDatabase, DELETE_UPLOAD);
|
||||
del.bind("@sia_path", SString::ToUtf8(siaPath).c_str());
|
||||
auto delCount = del.exec();
|
||||
if (del.exec() >= 0)
|
||||
{
|
||||
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(FileRemovedFromSia(siaPath, removeFilePath)));
|
||||
if (delCount != 0)
|
||||
{
|
||||
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(FileRemovedFromSia(siaPath, removeFilePath)));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Reference in New Issue
Block a user