Mo changes
This commit is contained in:
@@ -56,12 +56,13 @@ public:
|
|||||||
|
|
||||||
// CefBrowserProcessHandler methods:
|
// CefBrowserProcessHandler methods:
|
||||||
virtual void OnContextInitialized() OVERRIDE;
|
virtual void OnContextInitialized() OVERRIDE;
|
||||||
virtual void OnContextCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context) OVERRIDE;
|
virtual void OnContextCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context) OVERRIDE;
|
||||||
virtual void OnContextReleased(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context) OVERRIDE;
|
virtual void OnContextReleased(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context) OVERRIDE;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void ExecuteSetter(CefRefPtr<CefV8Context> context, CefRefPtr<CefV8Value> obj, const SString& method, const SString& value);
|
static void ExecuteSetter(CefRefPtr<CefV8Context> context, CefRefPtr<CefV8Value> obj, const SString& method, const SString& value);
|
||||||
static void ExecuteSetter(CefRefPtr<CefV8Context> context, CefRefPtr<CefV8Value> obj, const SString& method, CefRefPtr<CefV8Value> value);
|
static void ExecuteSetter(CefRefPtr<CefV8Context> context, CefRefPtr<CefV8Value> obj, const SString& method, CefRefPtr<CefV8Value> value);
|
||||||
|
void ShutdownServices();
|
||||||
void SiaApiRefreshCallback(CefRefPtr<CefV8Context> context, const Api::CSiaCurl& siaCurl, Api::CSiaDriveConfig* siaDriveConfig);
|
void SiaApiRefreshCallback(CefRefPtr<CefV8Context> context, const Api::CSiaCurl& siaCurl, Api::CSiaDriveConfig* siaDriveConfig);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@@ -15,7 +15,7 @@ class CSiaDriveHandler :
|
|||||||
public CefLoadHandler
|
public CefLoadHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit CSiaDriveHandler(const bool& useViews);
|
explicit CSiaDriveHandler(const bool& useViews);
|
||||||
|
|
||||||
~CSiaDriveHandler();
|
~CSiaDriveHandler();
|
||||||
|
|
||||||
@@ -45,29 +45,21 @@ public:
|
|||||||
virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) OVERRIDE;
|
virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) OVERRIDE;
|
||||||
virtual bool DoClose(CefRefPtr<CefBrowser> browser) OVERRIDE;
|
virtual bool DoClose(CefRefPtr<CefBrowser> browser) OVERRIDE;
|
||||||
virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) OVERRIDE;
|
virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) OVERRIDE;
|
||||||
|
|
||||||
// CefLoadHandler methods:
|
|
||||||
virtual void OnLoadError(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, ErrorCode errorCode, const CefString& errorText, const CefString& failedUrl) OVERRIDE;
|
virtual void OnLoadError(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, ErrorCode errorCode, const CefString& errorText, const CefString& failedUrl) OVERRIDE;
|
||||||
|
|
||||||
// Request that all existing browser windows close.
|
|
||||||
void CloseAllBrowsers(bool forceClose);
|
void CloseAllBrowsers(bool forceClose);
|
||||||
|
|
||||||
bool IsClosing() const { return _isClosing; }
|
bool IsClosing() const { return _isClosing; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Platform-specific implementation.
|
|
||||||
void PlatformTitleChange(CefRefPtr<CefBrowser> browser, const CefString& title);
|
void PlatformTitleChange(CefRefPtr<CefBrowser> browser, const CefString& title);
|
||||||
|
private:
|
||||||
// True if the application is using the Views framework.
|
|
||||||
const bool _useViews;
|
const bool _useViews;
|
||||||
|
|
||||||
// List of existing browser windows. Only accessed on the CEF UI thread.
|
|
||||||
typedef std::list<CefRefPtr<CefBrowser> > BrowserList;
|
typedef std::list<CefRefPtr<CefBrowser> > BrowserList;
|
||||||
BrowserList _browserList;
|
BrowserList _browserList;
|
||||||
|
|
||||||
bool _isClosing;
|
bool _isClosing;
|
||||||
|
|
||||||
// Include the default reference counting implementation.
|
|
||||||
IMPLEMENT_REFCOUNTING(CSiaDriveHandler);
|
IMPLEMENT_REFCOUNTING(CSiaDriveHandler);
|
||||||
};
|
};
|
||||||
NS_END(1)
|
NS_END(1)
|
||||||
|
@@ -9,7 +9,6 @@
|
|||||||
using namespace Sia;
|
using namespace Sia;
|
||||||
using namespace Sia::Api;
|
using namespace Sia::Api;
|
||||||
|
|
||||||
// Entry point function for all processes.
|
|
||||||
int APIENTRY wWinMain(HINSTANCE hInstance,
|
int APIENTRY wWinMain(HINSTANCE hInstance,
|
||||||
HINSTANCE hPrevInstance,
|
HINSTANCE hPrevInstance,
|
||||||
LPTSTR lpCmdLine,
|
LPTSTR lpCmdLine,
|
||||||
@@ -30,8 +29,9 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
|
|||||||
CefSettings settings;
|
CefSettings settings;
|
||||||
settings.no_sandbox = true;
|
settings.no_sandbox = true;
|
||||||
settings.remote_debugging_port = 8080;
|
settings.remote_debugging_port = 8080;
|
||||||
|
#ifdef _DEBUG
|
||||||
settings.single_process = true;
|
settings.single_process = true;
|
||||||
|
#endif
|
||||||
CefInitialize(mainArgs, settings, app, nullptr);
|
CefInitialize(mainArgs, settings, app, nullptr);
|
||||||
|
|
||||||
CefRunMessageLoop();
|
CefRunMessageLoop();
|
||||||
|
@@ -154,12 +154,9 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Provide the reference counting implementation for this class.
|
|
||||||
IMPLEMENT_REFCOUNTING(FunctionHandler);
|
IMPLEMENT_REFCOUNTING(FunctionHandler);
|
||||||
};
|
};
|
||||||
|
|
||||||
// When using the Views framework this object provides the delegate
|
|
||||||
// implementation for the CefWindow that hosts the Views-based browser.
|
|
||||||
class SimpleWindowDelegate :
|
class SimpleWindowDelegate :
|
||||||
public CefWindowDelegate
|
public CefWindowDelegate
|
||||||
{
|
{
|
||||||
@@ -171,11 +168,9 @@ public:
|
|||||||
|
|
||||||
void OnWindowCreated(CefRefPtr<CefWindow> window) OVERRIDE
|
void OnWindowCreated(CefRefPtr<CefWindow> window) OVERRIDE
|
||||||
{
|
{
|
||||||
// Add the browser view and show the window.
|
|
||||||
window->AddChildView(_browserView);
|
window->AddChildView(_browserView);
|
||||||
window->Show();
|
window->Show();
|
||||||
|
|
||||||
// Give keyboard focus to the browser view.
|
|
||||||
_browserView->RequestFocus();
|
_browserView->RequestFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,7 +181,6 @@ public:
|
|||||||
|
|
||||||
bool CanClose(CefRefPtr<CefWindow> window) OVERRIDE
|
bool CanClose(CefRefPtr<CefWindow> window) OVERRIDE
|
||||||
{
|
{
|
||||||
// Allow the window to close if the browser says it's OK.
|
|
||||||
CefRefPtr<CefBrowser> browser = _browserView->GetBrowser();
|
CefRefPtr<CefBrowser> browser = _browserView->GetBrowser();
|
||||||
return (browser) ? browser->GetHost()->TryCloseBrowser() : true;
|
return (browser) ? browser->GetHost()->TryCloseBrowser() : true;
|
||||||
}
|
}
|
||||||
@@ -261,59 +255,58 @@ void CSiaDriveApp::OnContextInitialized()
|
|||||||
CefRefPtr<CefCommandLine> commandLine = CefCommandLine::GetGlobalCommandLine();
|
CefRefPtr<CefCommandLine> commandLine = CefCommandLine::GetGlobalCommandLine();
|
||||||
|
|
||||||
#if defined(OS_WIN) || defined(OS_LINUX)
|
#if defined(OS_WIN) || defined(OS_LINUX)
|
||||||
// Create the browser using the Views framework if "--use-views" is specified
|
|
||||||
// via the command-line. Otherwise, create the browser using the native
|
|
||||||
// platform framework. The Views framework is currently only supported on
|
|
||||||
// Windows and Linux.
|
|
||||||
const bool useViews = commandLine->HasSwitch("use-views");
|
const bool useViews = commandLine->HasSwitch("use-views");
|
||||||
#else
|
#else
|
||||||
const bool useViews = false;
|
const bool useViews = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// SimpleHandler implements browser-level callbacks.
|
CefRefPtr<CSiaDriveHandler> handler(new CSiaDriveHandler(useViews));
|
||||||
CefRefPtr<CSiaDriveHandler> handler(new CSiaDriveHandler(useViews));
|
|
||||||
|
|
||||||
// Specify CEF browser settings here.
|
|
||||||
CefBrowserSettings browserSettings;
|
CefBrowserSettings browserSettings;
|
||||||
|
|
||||||
SString url = "file:///./htdocs/index.html";
|
SString url = "file:///./htdocs/index.html";
|
||||||
if (useViews)
|
if (useViews)
|
||||||
{
|
{
|
||||||
// Create the BrowserView.
|
|
||||||
CefRefPtr<CefBrowserView> browserView = CefBrowserView::CreateBrowserView(handler, url.str(), browserSettings, nullptr, nullptr);
|
CefRefPtr<CefBrowserView> browserView = CefBrowserView::CreateBrowserView(handler, url.str(), browserSettings, nullptr, nullptr);
|
||||||
|
|
||||||
// Create the Window. It will show itself after creation.
|
|
||||||
CefWindow::CreateTopLevelWindow(new SimpleWindowDelegate(browserView));
|
CefWindow::CreateTopLevelWindow(new SimpleWindowDelegate(browserView));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Information used when creating the native window.
|
|
||||||
CefWindowInfo windowInfo;
|
CefWindowInfo windowInfo;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
// On Windows we need to specify certain flags that will be passed to
|
|
||||||
// CreateWindowEx().
|
|
||||||
windowInfo.SetAsPopup(nullptr, "SiaDrive");
|
windowInfo.SetAsPopup(nullptr, "SiaDrive");
|
||||||
#endif
|
#endif
|
||||||
windowInfo.width = 800;
|
windowInfo.width = 800;
|
||||||
windowInfo.height = 675;
|
windowInfo.height = 675;
|
||||||
|
|
||||||
// Create the first browser window.
|
|
||||||
CefBrowserHost::CreateBrowser(windowInfo, handler, url.str(), browserSettings, nullptr);
|
CefBrowserHost::CreateBrowser(windowInfo, handler, url.str(), browserSettings, nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSiaDriveApp::OnContextReleased(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context)
|
void CSiaDriveApp::ShutdownServices()
|
||||||
{
|
{
|
||||||
if (_refreshThread)
|
if (CefCurrentlyOn(TID_RENDERER))
|
||||||
{
|
{
|
||||||
_refreshThread->StopAutoThread();
|
if (_refreshThread)
|
||||||
_refreshThread.reset(nullptr);
|
{
|
||||||
|
_refreshThread->StopAutoThread();
|
||||||
|
_refreshThread.reset(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
if (_siaDrive)
|
if (_siaDrive)
|
||||||
{
|
{
|
||||||
_siaDrive->Unmount();
|
_siaDrive->Unmount();
|
||||||
_siaDrive.reset(nullptr);
|
_siaDrive.reset(nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CefPostTask(TID_RENDERER, base::Bind(&CSiaDriveApp::ShutdownServices, this));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSiaDriveApp::OnContextReleased(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context)
|
||||||
|
{
|
||||||
|
ShutdownServices();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSiaDriveApp::SiaApiRefreshCallback(CefRefPtr<CefV8Context> context, const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriveConfig)
|
void CSiaDriveApp::SiaApiRefreshCallback(CefRefPtr<CefV8Context> context, const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriveConfig)
|
||||||
@@ -402,4 +395,4 @@ void CSiaDriveApp::SiaApiRefreshCallback(CefRefPtr<CefV8Context> context, const
|
|||||||
{
|
{
|
||||||
CefPostTask(TID_RENDERER, base::Bind(&CSiaDriveApp::SiaApiRefreshCallback, this, context, siaCurl, siaDriveConfig));
|
CefPostTask(TID_RENDERER, base::Bind(&CSiaDriveApp::SiaApiRefreshCallback, this, context, siaCurl, siaDriveConfig));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -10,7 +10,7 @@ using namespace Sia;
|
|||||||
|
|
||||||
CSiaDriveHandler* g_instance = nullptr;
|
CSiaDriveHandler* g_instance = nullptr;
|
||||||
|
|
||||||
CSiaDriveHandler::CSiaDriveHandler(const bool& useViews) :
|
CSiaDriveHandler::CSiaDriveHandler(const bool& useViews) :
|
||||||
_useViews(useViews),
|
_useViews(useViews),
|
||||||
_isClosing(false)
|
_isClosing(false)
|
||||||
{
|
{
|
||||||
@@ -23,7 +23,6 @@ CSiaDriveHandler::~CSiaDriveHandler()
|
|||||||
g_instance = nullptr;
|
g_instance = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
|
||||||
CSiaDriveHandler* CSiaDriveHandler::GetInstance()
|
CSiaDriveHandler* CSiaDriveHandler::GetInstance()
|
||||||
{
|
{
|
||||||
return g_instance;
|
return g_instance;
|
||||||
@@ -35,7 +34,6 @@ void CSiaDriveHandler::OnTitleChange(CefRefPtr<CefBrowser> browser, const CefStr
|
|||||||
|
|
||||||
if (_useViews)
|
if (_useViews)
|
||||||
{
|
{
|
||||||
// Set the title of the window using the Views framework.
|
|
||||||
CefRefPtr<CefBrowserView> browserView = CefBrowserView::GetForBrowser(browser);
|
CefRefPtr<CefBrowserView> browserView = CefBrowserView::GetForBrowser(browser);
|
||||||
if (browserView)
|
if (browserView)
|
||||||
{
|
{
|
||||||
@@ -46,7 +44,6 @@ void CSiaDriveHandler::OnTitleChange(CefRefPtr<CefBrowser> browser, const CefStr
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Set the title of the window using platform APIs.
|
|
||||||
PlatformTitleChange(browser, title);
|
PlatformTitleChange(browser, title);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -55,7 +52,6 @@ void CSiaDriveHandler::OnAfterCreated(CefRefPtr<CefBrowser> browser)
|
|||||||
{
|
{
|
||||||
CEF_REQUIRE_UI_THREAD();
|
CEF_REQUIRE_UI_THREAD();
|
||||||
|
|
||||||
// Add to the list of existing browsers.
|
|
||||||
_browserList.push_back(browser);
|
_browserList.push_back(browser);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,9 +59,6 @@ bool CSiaDriveHandler::DoClose(CefRefPtr<CefBrowser> browser)
|
|||||||
{
|
{
|
||||||
CEF_REQUIRE_UI_THREAD();
|
CEF_REQUIRE_UI_THREAD();
|
||||||
|
|
||||||
// Closing the main window requires special handling. See the DoClose()
|
|
||||||
// documentation in the CEF header for a detailed destription of this
|
|
||||||
// process.
|
|
||||||
if (_browserList.size() == 1)
|
if (_browserList.size() == 1)
|
||||||
{
|
{
|
||||||
// Set a flag to indicate that the window close should be allowed.
|
// Set a flag to indicate that the window close should be allowed.
|
||||||
@@ -74,14 +67,13 @@ bool CSiaDriveHandler::DoClose(CefRefPtr<CefBrowser> browser)
|
|||||||
|
|
||||||
// Allow the close. For windowed browsers this will result in the OS close
|
// Allow the close. For windowed browsers this will result in the OS close
|
||||||
// event being sent.
|
// event being sent.
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSiaDriveHandler::OnBeforeClose(CefRefPtr<CefBrowser> browser)
|
void CSiaDriveHandler::OnBeforeClose(CefRefPtr<CefBrowser> browser)
|
||||||
{
|
{
|
||||||
CEF_REQUIRE_UI_THREAD();
|
CEF_REQUIRE_UI_THREAD();
|
||||||
|
|
||||||
// Remove from the list of existing browsers.
|
|
||||||
BrowserList::iterator bit = _browserList.begin();
|
BrowserList::iterator bit = _browserList.begin();
|
||||||
for (; bit != _browserList.end(); ++bit)
|
for (; bit != _browserList.end(); ++bit)
|
||||||
{
|
{
|
||||||
@@ -94,7 +86,6 @@ void CSiaDriveHandler::OnBeforeClose(CefRefPtr<CefBrowser> browser)
|
|||||||
|
|
||||||
if (_browserList.empty())
|
if (_browserList.empty())
|
||||||
{
|
{
|
||||||
// All browser windows have closed. Quit the application message loop.
|
|
||||||
CefQuitMessageLoop();
|
CefQuitMessageLoop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -107,34 +98,29 @@ void CSiaDriveHandler::OnLoadError(CefRefPtr<CefBrowser> browser,
|
|||||||
{
|
{
|
||||||
CEF_REQUIRE_UI_THREAD();
|
CEF_REQUIRE_UI_THREAD();
|
||||||
|
|
||||||
// Don't display an error for downloaded files.
|
if (errorCode != ERR_ABORTED)
|
||||||
if (errorCode == ERR_ABORTED)
|
{
|
||||||
return;
|
std::stringstream ss;
|
||||||
|
ss << "<html><body bgcolor=\"white\">"
|
||||||
// Display a load error message.
|
"<h2>Failed to load URL " << std::string(failedUrl) <<
|
||||||
std::stringstream ss;
|
" with error " << std::string(errorText) << " (" << errorCode <<
|
||||||
ss << "<html><body bgcolor=\"white\">"
|
").</h2></body></html>";
|
||||||
"<h2>Failed to load URL " << std::string(failedUrl) <<
|
frame->LoadString(ss.str(), failedUrl);
|
||||||
" with error " << std::string(errorText) << " (" << errorCode <<
|
}
|
||||||
").</h2></body></html>";
|
|
||||||
frame->LoadString(ss.str(), failedUrl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSiaDriveHandler::CloseAllBrowsers(bool forceClose)
|
void CSiaDriveHandler::CloseAllBrowsers(bool forceClose)
|
||||||
{
|
{
|
||||||
if (!CefCurrentlyOn(TID_UI))
|
if (CefCurrentlyOn(TID_UI))
|
||||||
{
|
{
|
||||||
// Execute on the UI thread.
|
BrowserList::const_iterator it = _browserList.begin();
|
||||||
CefPostTask(TID_UI, base::Bind(&CSiaDriveHandler::CloseAllBrowsers, this, forceClose));
|
for (; it != _browserList.end(); ++it)
|
||||||
return;
|
(*it)->GetHost()->CloseBrowser(forceClose);
|
||||||
}
|
}
|
||||||
|
else if (!_browserList.empty())
|
||||||
if (_browserList.empty())
|
{
|
||||||
return;
|
CefPostTask(TID_UI, base::Bind(&CSiaDriveHandler::CloseAllBrowsers, this, forceClose));
|
||||||
|
}
|
||||||
BrowserList::const_iterator it = _browserList.begin();
|
|
||||||
for (; it != _browserList.end(); ++it)
|
|
||||||
(*it)->GetHost()->CloseBrowser(forceClose);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
@@ -132,7 +132,7 @@ bool FilePath::IsUNC() const
|
|||||||
bool FilePath::CreateDirectory() const
|
bool FilePath::CreateDirectory() const
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
return ::CreateDirectory(&_path[0], nullptr) ? true : false;
|
return (::SHCreateDirectory(nullptr, &_path[0]) == ERROR_SUCCESS);
|
||||||
#else
|
#else
|
||||||
a
|
a
|
||||||
#endif
|
#endif
|
||||||
@@ -159,6 +159,8 @@ bool FilePath::DeleteFile() const
|
|||||||
bool FilePath::MoveFile(const FilePath& filePath)
|
bool FilePath::MoveFile(const FilePath& filePath)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
FilePath folder(filePath);
|
||||||
|
folder.RemoveFileName().CreateDirectory();
|
||||||
return ::MoveFile(&_path[0], &filePath[0]) ? true : false;
|
return ::MoveFile(&_path[0], &filePath[0]) ? true : false;
|
||||||
#else
|
#else
|
||||||
a
|
a
|
||||||
|
@@ -49,18 +49,20 @@ private:
|
|||||||
static bool AddFileToCache(const SString& siaPath, const SString& cacheLocation)
|
static bool AddFileToCache(const SString& siaPath, const SString& cacheLocation)
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
SString tempPath;
|
FilePath tempFilePath = FilePath::GetTempDirectory();
|
||||||
tempPath.Resize(MAX_PATH + 1);
|
tempFilePath.Append(GenerateSha256(siaPath) + ".siatmp");
|
||||||
if (::GetTempPath(MAX_PATH + 1, &tempPath[0]))
|
|
||||||
|
// 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
|
FilePath src(tempFilePath);
|
||||||
ret = ApiSuccess(_siaApi->GetRenter()->DownloadFile(siaPath, tempPath));
|
FilePath dest(GetCacheLocation(), siaPath);
|
||||||
if (ret)
|
ret = src.MoveFile(dest);
|
||||||
{
|
if (!ret)
|
||||||
FilePath src(tempPath, L"");
|
{
|
||||||
FilePath dest(GetCacheLocation(), siaPath);
|
src.DeleteFile();
|
||||||
ret = src.MoveFile(dest);
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@@ -68,6 +70,7 @@ private:
|
|||||||
|
|
||||||
static void QueueUploadIfChanged(const ULONG64& id, const std::uint64_t& size)
|
static void QueueUploadIfChanged(const ULONG64& id, const std::uint64_t& size)
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
if (!_openFileMap[id].ReadOnly)
|
if (!_openFileMap[id].ReadOnly)
|
||||||
{
|
{
|
||||||
if (size > 0)
|
if (size > 0)
|
||||||
@@ -175,7 +178,7 @@ private:
|
|||||||
{
|
{
|
||||||
if (creationDisposition == CREATE_NEW)
|
if (creationDisposition == CREATE_NEW)
|
||||||
{
|
{
|
||||||
if (!::CreateDirectory(&cacheFilePath[0], &securityAttrib))
|
if (!cacheFilePath.CreateDirectory())
|
||||||
{
|
{
|
||||||
DWORD error = GetLastError();
|
DWORD error = GetLastError();
|
||||||
ret = DokanNtStatusFromWin32(error);
|
ret = DokanNtStatusFromWin32(error);
|
||||||
@@ -183,10 +186,9 @@ private:
|
|||||||
}
|
}
|
||||||
else if (creationDisposition == OPEN_ALWAYS)
|
else if (creationDisposition == OPEN_ALWAYS)
|
||||||
{
|
{
|
||||||
if (!::CreateDirectory(&cacheFilePath[0], &securityAttrib))
|
if (cacheFilePath.CreateDirectory())
|
||||||
{
|
{
|
||||||
DWORD error = GetLastError();
|
DWORD error = GetLastError();
|
||||||
|
|
||||||
if (error != ERROR_ALREADY_EXISTS)
|
if (error != ERROR_ALREADY_EXISTS)
|
||||||
{
|
{
|
||||||
ret = DokanNtStatusFromWin32(error);
|
ret = DokanNtStatusFromWin32(error);
|
||||||
@@ -355,17 +357,6 @@ private:
|
|||||||
ofi.ReadOnly = false;
|
ofi.ReadOnly = false;
|
||||||
std::lock_guard<std::mutex> l(_dokanMutex);
|
std::lock_guard<std::mutex> l(_dokanMutex);
|
||||||
_openFileMap.insert({ DokanFileInfo->Context, ofi });
|
_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)
|
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));
|
_uploadManager.reset(new CUploadManager(CSiaCurl(_siaApi->GetHostConfig()), _siaDriveConfig));
|
||||||
StartFileListThread();
|
StartFileListThread();
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
@@ -791,8 +783,10 @@ private:
|
|||||||
if (DokanFileInfo->Context)
|
if (DokanFileInfo->Context)
|
||||||
{
|
{
|
||||||
::CloseHandle(reinterpret_cast<HANDLE>(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;
|
DokanFileInfo->Context = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -823,11 +817,10 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static NTSTATUS DOKAN_CALLBACK Sia_FlushFileBuffers(LPCWSTR FileName, PDOKAN_FILE_INFO DokanFileInfo)
|
static NTSTATUS DOKAN_CALLBACK Sia_FlushFileBuffers(LPCWSTR FileName, PDOKAN_FILE_INFO DokanFileInfo)
|
||||||
{
|
{
|
||||||
HANDLE handle = reinterpret_cast<HANDLE>(DokanFileInfo->Context);
|
HANDLE handle = reinterpret_cast<HANDLE>(DokanFileInfo->Context);
|
||||||
if (!handle || handle == INVALID_HANDLE_VALUE)
|
if (!handle || (handle == INVALID_HANDLE_VALUE))
|
||||||
{
|
{
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
@@ -877,14 +870,15 @@ public:
|
|||||||
ZeroMemory(&_dokanOptions, sizeof(DOKAN_OPTIONS));
|
ZeroMemory(&_dokanOptions, sizeof(DOKAN_OPTIONS));
|
||||||
_dokanOptions.Version = DOKAN_VERSION;
|
_dokanOptions.Version = DOKAN_VERSION;
|
||||||
_dokanOptions.ThreadCount = 0; // use default
|
_dokanOptions.ThreadCount = 0; // use default
|
||||||
|
#ifdef _DEBUG
|
||||||
_dokanOptions.Options = DOKAN_OPTION_DEBUG;
|
_dokanOptions.Options = DOKAN_OPTION_DEBUG;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Mount(const wchar_t& driveLetter, const SString& cacheLocation)
|
static void Mount(const wchar_t& driveLetter, const SString& cacheLocation)
|
||||||
{
|
{
|
||||||
if (_siaApi && !_mountThread)
|
if (_siaApi && !_mountThread)
|
||||||
{
|
{
|
||||||
// May spend a little wait time here while files are cleaned-up and re-added to queue
|
|
||||||
_cacheLocation = cacheLocation;
|
_cacheLocation = cacheLocation;
|
||||||
wchar_t tmp[] = { driveLetter, ':', '\\', 0 };
|
wchar_t tmp[] = { driveLetter, ':', '\\', 0 };
|
||||||
_mountPoint = tmp;
|
_mountPoint = tmp;
|
||||||
|
Reference in New Issue
Block a user