1
0

UI changes

This commit is contained in:
Scott E. Graves
2017-03-21 01:32:21 -05:00
parent 92cc4bd769
commit c187ac45a3
10 changed files with 315 additions and 100 deletions

View File

@@ -38,7 +38,7 @@ div.footer {
margin: 0 auto;
position: absolute;
bottom: 10px;
width: 95%;
width: 98%;
}
.padded {

View File

@@ -43,7 +43,7 @@
</div>
<div class="box" id="receive_info">
<h1>Receive Address</h1>
<label id="ID_WalletReceiveAddress" style="text-align: center; width: inherit;display: block;"></label>
<label id="ID_WalletReceiveAddress" style="text-align: center; width: inherit;display: block;">...</label>
</div>
<div class="box" id="renter_info">
<h1>Renter Settings <a href="javascript:void(0)" id="ID_Renter_Edit">edit</a></h1>
@@ -96,27 +96,24 @@
</div>
</div>
<div class="box" id="mount_info">
<h1>Mount</h1>
<div class="box">
<h1>Mount Location</h1>
<p>Choose an available drive letter and click 'Mount'</p>
<table>
<tr>
<td style="text-align: left; vertical-align: top">
<select id="ID_MountDrives"></select>&nbsp;
<button id="ID_MountButton" type="button">Mount</button>
</td>
</tr>
</table>
</div>
<h1>Mount Location</h1>
<p>Choose an available drive letter and click 'Mount'</p>
<table>
<tr>
<td style="text-align: left; vertical-align: top">
<select id="ID_MountDrives"></select>&nbsp;
<button id="ID_MountButton" type="button">Mount</button>
</td>
</tr>
</table>
</div>
<div class="footer">
<table class="fill">
<table style="width: 100%">
<tr>
<td style="width: 70px; text-align: left"><b>Height:</b></td>
<td id="ID_BlockHeight">...</td>
<td style="text-align: right; vertical-align: bottom">
<button style="width: 100px" id="ButtonOK">OK</button>
<td style="text-align: left;white-space: nowrap;"><b>Height:</b></td>
<td style="white-space: nowrap;" id="ID_BlockHeight">...</td>
<td style="text-align: right; vertical-align: bottom;width: 100%;">
<button style="width: 110px;" id="ID_OKButton">OK</button>
</td>
</tr>
</table>
@@ -134,7 +131,7 @@
<div class="box">
<h1>Wallet Seed</h1>
<p>Please backup your generated wallet seed in a safe place. The seed is required to unlock your wallet and you will loose everything if this is lost. Click 'OK' when you are ready.</p>
<textarea id="ID_WalletSeed"></textarea>
<textarea style="width: 100%"; rows="3" id="ID_WalletSeed"></textarea>
<button id="ID_WalletCreatedButton">OK</button>
</div>
</div>

View File

@@ -52,7 +52,7 @@
setInnerText('ID_WalletReceiveAddress', address);
}
};
});
})();
return {
Renter: _renter,
@@ -63,6 +63,7 @@
};
})();
const UiState = (()=> {
function _clientVersion() {
return window.uiState.clientVersion;

View File

@@ -42,9 +42,7 @@ public:
// CefBrowserProcessHandler methods:
virtual void OnContextInitialized() 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;
private:

View File

@@ -0,0 +1,50 @@
#ifndef _FILEPATH_H
#define _FILEPATH_H
#include <siacommon.h>
NS_BEGIN(Sia)
NS_BEGIN(Api)
class SIADRIVE_EXPORTABLE FilePath
{
public:
FilePath();
FilePath(const FilePath& filePath);
FilePath(const SString& path);
FilePath(const FilePath& filePath1, const FilePath& filePath2);
FilePath(const FilePath& filePath1, const SString& path2);
FilePath(const SString& path1, const FilePath& filePath2);
FilePath(const SString& path1, const SString& path2);
FilePath(FilePath&& filePath);
public:
static const SString DirSep;
public:
static FilePath FinalizePath(const SString& path);
private:
SString _path;
public:
FilePath& Append(const FilePath& filePath);
FilePath& Append(const SString& path);
bool IsDirectory() const;
bool IsFile() const;
bool IsUNC() const;
bool CreateDirectory() const;
bool RemoveDirectory() const;
bool DeleteFile() const;
bool MoveFile(const FilePath& filePath);
FilePath& RemoveFileName();
public:
FilePath& operator=(const FilePath& filePath);
FilePath& operator=(FilePath&& filePath);
SString::SChar& operator[](const size_t& idx);
const SString::SChar& operator[](const size_t& idx) const;
operator SString() const;
};
NS_END(2)
#endif //_FILEPATH_H

View File

@@ -9,7 +9,7 @@
#include <ostream>
#include <unordered_map>
class SString
class SIADRIVE_EXPORTABLE SString
{
public:
#ifdef _UNICODE

View File

@@ -8,7 +8,9 @@
#include <siacurl.h>
#include <siadriveconfig.h>
#include "siadrivehandler.h"
/*
exotic stylishly alchemy deodorant rally younger ouch sensible rated boss nestle wipeout viking blip pairing rural dwarf rebel mumble shelter pager yodel object titans tidy virtual orders peculiar after
*/
using namespace Sia;
using namespace Sia::Api;
@@ -38,7 +40,7 @@ private:
}
cb->ExecuteFunctionWithContext(context, nullptr, args);
}
//wetsuit inline reorder agreed jabbed gnaw fever adjust object incur cousin jogger sack fading syllabus tufts stellar rays woes october nagged nasty warped sifting fountain gorilla mohawk yoyo afield
void CreateWalletCallback(CefRefPtr<CefV8Context> context, CefRefPtr<CefV8Value> cb) const
{
SString seed;
@@ -64,12 +66,12 @@ public:
CefRefPtr<CefV8Value>& retval,
CefString& exception) OVERRIDE
{
CefRefPtr<CefV8Context> context = CefV8Context::GetCurrentContext();
if (name == "unlockWallet")
{
retval = CefV8Value::CreateBool(true);
SString password = arguments[0]->GetStringValue().ToWString();
CefRefPtr<CefV8Value> cb = arguments[1];
CefRefPtr<CefV8Context> context = CefV8Context::GetCurrentContext();
CefPostTask(TID_RENDERER, base::Bind(&FunctionHandler::UnlockCallback, this, context, cb, password));
return true;
@@ -78,7 +80,6 @@ public:
{
retval = CefV8Value::CreateBool(true);
CefRefPtr<CefV8Value> cb = arguments[0];
CefRefPtr<CefV8Context> context = CefV8Context::GetCurrentContext();
CefPostTask(TID_RENDERER, base::Bind(&FunctionHandler::CreateWalletCallback, this, context, cb));
return true;
@@ -148,7 +149,7 @@ CSiaDriveApp::CSiaDriveApp()
SiaHostConfig hostConfig;
hostConfig.HostName = "127.0.0.1";
hostConfig.HostPort = 9980;
hostConfig.RequiredVersion = "1.1.1";
hostConfig.RequiredVersion = "1.1.2";
_siaCurl.reset(new CSiaCurl(hostConfig));
_siaApi.reset(new CSiaApi(hostConfig, _siaDriveConfig.get()));
}
@@ -205,11 +206,11 @@ void CSiaDriveApp::OnContextInitialized()
// Specify CEF browser settings here.
CefBrowserSettings browserSettings;
std::string url = "file:///./htdocs/index.html";
SString url = "file:///./htdocs/index.html";
if (useViews)
{
// Create the BrowserView.
CefRefPtr<CefBrowserView> browserView = CefBrowserView::CreateBrowserView(handler, url, 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));
@@ -224,10 +225,10 @@ void CSiaDriveApp::OnContextInitialized()
windowInfo.SetAsPopup(nullptr, "SiaDrive");
#endif
windowInfo.width = 800;
windowInfo.height = 600;
windowInfo.height = 675;
// Create the first browser window.
CefBrowserHost::CreateBrowser(windowInfo, handler, url, browserSettings, nullptr);
CefBrowserHost::CreateBrowser(windowInfo, handler, url.str(), browserSettings, nullptr);
}
}
@@ -257,38 +258,39 @@ void CSiaDriveApp::SiaApiRefreshCallback(CefRefPtr<CefV8Context> context, const
}
else if (_appStarted)
{
auto uiActions = global->GetValue("uiUpdate");
CefRefPtr<CefV8Value> uiActions = global->GetValue("uiUpdate");
// Display wallet data
auto walletActions = uiActions->GetValue("Wallet");
CefRefPtr<CefV8Value> walletActions = uiActions->GetValue("Wallet");
auto confirmedBalance = _siaApi->GetWallet()->GetConfirmedBalance();
auto unconfirmedBalance = _siaApi->GetWallet()->GetUnconfirmedBalance();
auto totalBalance = confirmedBalance + unconfirmedBalance;
{
auto setConfirmed = walletActions->GetValue("setConfirmedBalance");
CefRefPtr<CefV8Value> setConfirmed = walletActions->GetValue("setConfirmedBalance");
CefV8ValueList args;
args.push_back(CefV8Value::CreateString(SiaCurrencyToString(confirmedBalance).str()));
CefRefPtr<CefV8Value> retval;
setConfirmed->ExecuteFunctionWithContext(context, nullptr, args);
}
{
auto setUnconfirmed = walletActions->GetValue("setUnconfirmedBalance");
CefRefPtr<CefV8Value> setUnconfirmed = walletActions->GetValue("setUnconfirmedBalance");
CefV8ValueList args;
args.push_back(CefV8Value::CreateString(SiaCurrencyToString(unconfirmedBalance).str()));
setUnconfirmed->ExecuteFunctionWithContext(context, nullptr, args);
}
{
auto setTotalBal = walletActions->GetValue("setTotalBalance");
CefRefPtr<CefV8Value> setTotalBal = walletActions->GetValue("setTotalBalance");
CefV8ValueList args;
args.push_back(CefV8Value::CreateString(SiaCurrencyToString(totalBalance).str()));
setTotalBal->ExecuteFunctionWithContext(context, nullptr, args);
}
{
auto setReceiveAddress = walletActions->GetValue("setReceiveAddress");
CefRefPtr<CefV8Value> setReceiveAddress = walletActions->GetValue("setReceiveAddress");
CefV8ValueList args;
args.push_back(CefV8Value::CreateString(_siaApi->GetWallet()->GetReceiveAddress().str()));
setReceiveAddress->ExecuteFunctionWithContext(context, nullptr, args);

View File

@@ -0,0 +1,181 @@
#include <filepath.h>
#include <regex>
using namespace Sia::Api;
FilePath FilePath::FinalizePath(const SString& path)
{
std::wregex r(L"/+");
return FilePath(std::regex_replace(path.str(), r, L"/"));
}
FilePath::FilePath()
{
}
FilePath::FilePath(const FilePath& filePath) :
_path(filePath)
{
}
FilePath::FilePath(const SString& path)
{
_path = FinalizePath(path);
}
FilePath::FilePath(const FilePath& filePath1, const FilePath& filePath2)
{
_path = filePath1;
Append(filePath2);
}
FilePath::FilePath(const FilePath& filePath1, const SString& path2)
{
_path = filePath1;
Append(FinalizePath(path2));
}
FilePath::FilePath(const SString& path1, const FilePath& filePath2)
{
_path = FinalizePath(path1);
Append(filePath2);
}
FilePath::FilePath(const SString& path1, const SString& path2)
{
_path = FinalizePath(path1);
Append(FinalizePath(path2));
}
FilePath::FilePath(FilePath&& filePath) :
_path(std::move(filePath._path))
{
}
#ifdef _WIN32
const SString FilePath::DirSep = "\\";
#else
const SString FilePath::DirSep = "/";
#endif
FilePath& FilePath::Append(const FilePath& filePath)
{
_path += (DirSep + filePath);
return *this;
}
FilePath& FilePath::Append(const SString& path)
{
_path += (DirSep + FinalizePath(path));
return *this;
}
bool FilePath::IsDirectory() const
{
#ifdef _WIN32
return ::PathIsDirectory(&_path[0]) ? true : false;
#else
a
#endif
}
bool FilePath::IsFile() const
{
#ifdef _WIN32
return ::PathFileExists(&_path[0]) ? true : false;
#else
a
#endif
}
bool FilePath::IsUNC() const
{
#ifdef _WIN32
return ::PathIsUNC(&_path[0]) ? true : false;
#else
a
#endif
}
bool FilePath::CreateDirectory() const
{
#ifdef _WIN32
return ::CreateDirectory(&_path[0], nullptr) ? true : false;
#else
a
#endif
}
bool FilePath::RemoveDirectory() const
{
#ifdef _WIN32
return ::RemoveDirectory(&_path[0]) ? true : false;
#else
a
#endif
}
bool FilePath::DeleteFile() const
{
#ifdef _WIN32
return ::DeleteFile(&_path[0]) ? true : false;
#else
a
#endif
}
bool FilePath::MoveFile(const FilePath& filePath)
{
#ifdef _WIN32
return ::MoveFile(&_path[0], &filePath[0]) ? true : false;
#else
a
#endif
}
FilePath& FilePath::RemoveFileName()
{
#ifdef _WIN32
::PathRemoveFileSpec(&_path[0]);
_path = _path.str().c_str();
return *this;
#else
a
#endif
}
FilePath& FilePath::operator=(const FilePath& filePath)
{
if (this != &filePath)
{
_path = filePath._path;
}
return *this;
}
FilePath& FilePath::operator=(FilePath&& filePath)
{
if (this != &filePath)
{
_path = std::move(filePath._path);
}
return *this;
}
SString::SChar& FilePath::operator[](const size_t& idx)
{
return _path[idx];
}
const SString::SChar& FilePath::operator[](const size_t& idx) const
{
return _path[idx];
}
FilePath::operator SString() const
{
return _path;
}

View File

@@ -213,7 +213,9 @@ SiaCurlError CSiaCurl::Post(const SString& path, const HttpParameters& parameter
fields += (param.first + "=" + param.second);
}
curl_easy_setopt(curlHandle, CURLOPT_POSTFIELDS, &fields);
std::string utf8Fields = SString::ToUtf8(fields);
curl_easy_setopt(curlHandle, CURLOPT_POSTFIELDS, &utf8Fields[0]);
SString result;
curl_easy_setopt(curlHandle, CURLOPT_WRITEDATA, &result);

View File

@@ -2,18 +2,12 @@
#include <filesystem>
#include <uploadmanager.h>
#include <dokan.h>
#include <filepath.h>
using namespace Sia::Api;
using namespace Sia::Api::Dokan;
// TODO Handle paths greater than MAX_PATH!!
static SString StdConstructPath(const SString& part1, const SString& part2)
{
SString path = part1;
path.Resize(MAX_PATH + 1);
::PathAppend(&path[0], part2.str().c_str());
return path;
}
// The general idea is that normal file I/O occurs in a local cache folder and once the file is closed, it is scheduled for upload into Sia.
// Files requested to be openned that are not cached will be downloaded first. If the file is not found in Sia, it will be treated as new.
@@ -24,8 +18,8 @@ class SIADRIVE_DOKAN_EXPORTABLE DokanImpl
private:
typedef struct
{
SString SiaPath;
SString CacheFilePath;
FilePath SiaPath;
FilePath CacheFilePath;
bool ReadOnly;
} OpenFileInfo;
@@ -36,7 +30,7 @@ private:
static std::unique_ptr<CUploadManager> _uploadManager;
static DOKAN_OPERATIONS _dokanOps;
static DOKAN_OPTIONS _dokanOptions;
static SString _cacheLocation;
static FilePath _cacheLocation;
static std::unordered_map<ULONG64, OpenFileInfo> _openFileMap;
static std::unique_ptr<std::thread> _fileListThread;
static bool _fileListStopRequested;
@@ -47,7 +41,7 @@ private:
static SString _mountPoint;
private:
inline static const SString& GetCacheLocation()
inline static const FilePath& GetCacheLocation()
{
return _cacheLocation;
}
@@ -55,17 +49,17 @@ private:
static bool AddFileToCache(const SString& siaPath, const SString& cacheLocation)
{
bool ret = false;
std::wstring tempPath;
tempPath.resize(MAX_PATH + 1);
SString tempPath;
tempPath.Resize(MAX_PATH + 1);
if (::GetTempPath(MAX_PATH + 1, &tempPath[0]))
{
// Check cache size is large enough to hold new file
ret = ApiSuccess(_siaApi->GetRenter()->DownloadFile(siaPath, tempPath));
if (ret)
{
SString src = StdConstructPath(tempPath, L"");
SString dest = StdConstructPath(GetCacheLocation(), siaPath);
ret = ::MoveFile(src.str().c_str(), dest.str().c_str()) ? true : false;
FilePath src(tempPath, L"");
FilePath dest(GetCacheLocation(), siaPath);
ret = src.MoveFile(dest);
}
}
@@ -154,7 +148,7 @@ private:
NTSTATUS ret = STATUS_SUCCESS;
// Probably not going to happen, but just in case
if (PathIsUNC(FileName))
if (FilePath(FileName).IsUNC())
{
ret = STATUS_ILLEGAL_ELEMENT_ADDRESS;
}
@@ -162,8 +156,8 @@ private:
{
// When filePath is a directory, needs to change the flag so that the file can
// be opened.
SString cacheFilePath = StdConstructPath(GetCacheLocation(), &FileName[1]);
DWORD fileAttr = ::GetFileAttributes(cacheFilePath.str().c_str());
FilePath cacheFilePath(GetCacheLocation(), &FileName[1]);
DWORD fileAttr = ::GetFileAttributes(&cacheFilePath[0]);
if ((fileAttr != INVALID_FILE_ATTRIBUTES) &&
(fileAttr & FILE_ATTRIBUTE_DIRECTORY) &&
@@ -182,7 +176,7 @@ private:
{
if (creationDisposition == CREATE_NEW)
{
if (!::CreateDirectory(cacheFilePath.str().c_str(), &securityAttrib))
if (!::CreateDirectory(&cacheFilePath[0], &securityAttrib))
{
DWORD error = GetLastError();
ret = DokanNtStatusFromWin32(error);
@@ -190,7 +184,7 @@ private:
}
else if (creationDisposition == OPEN_ALWAYS)
{
if (!CreateDirectory(cacheFilePath.str().c_str(), &securityAttrib))
if (!::CreateDirectory(&cacheFilePath[0], &securityAttrib))
{
DWORD error = GetLastError();
@@ -212,7 +206,7 @@ private:
}
// FILE_FLAG_BACKUP_SEMANTICS is required for opening directory handles
HANDLE handle = CreateFile(cacheFilePath.str().c_str(), genericDesiredAccess, ShareAccess, &securityAttrib, OPEN_EXISTING, fileAttributesAndFlags | FILE_FLAG_BACKUP_SEMANTICS, nullptr);
HANDLE handle = ::CreateFile(&cacheFilePath[0], genericDesiredAccess, ShareAccess, &securityAttrib, OPEN_EXISTING, fileAttributesAndFlags | FILE_FLAG_BACKUP_SEMANTICS, nullptr);
if (handle == INVALID_HANDLE_VALUE)
{
DWORD error = GetLastError();
@@ -227,11 +221,11 @@ private:
else // File (cache and/or Sia operation)
{
// Formulate Sia path and cache path
SString siaPath = CSiaApi::FormatToSiaPath(PathSkipRoot(FileName)); // Strip drive letter to get Sia path
SString siaPath = CSiaApi::FormatToSiaPath(FilePath(FileName).RemoveFileName()); // Strip drive letter to get Sia path
if (siaPath.Length())
{
// If cache file already exists and is a directory, requested file operation isn't valid
DWORD attribs = ::GetFileAttributes(cacheFilePath.str().c_str());
DWORD attribs = ::GetFileAttributes(&cacheFilePath[0]);
if ((attribs != INVALID_FILE_ATTRIBUTES) && (attribs & FILE_ATTRIBUTE_DIRECTORY))
{
ret = STATUS_OBJECT_NAME_COLLISION;
@@ -310,7 +304,7 @@ private:
{
// Since this is a request to replace an existing file, make sure cache is deleted first.
// If file isn't cached, delete from Sia only
if (!::PathFileExists(cacheFilePath.str().c_str()) || ::DeleteFile(cacheFilePath.str().c_str()))
if (!cacheFilePath.IsFile() || cacheFilePath.DeleteFile())
{
if (!ApiSuccess(_uploadManager->Remove(siaPath)))
{
@@ -327,7 +321,7 @@ private:
{
// If file must exist, then check for it in cache location. If not found,
// it must be downloaded first and placed in cache
if (!isCreateOp && !PathFileExists(cacheFilePath.str().c_str()))
if (!isCreateOp && !cacheFilePath.IsFile())
{
if (!AddFileToCache(siaPath, cacheFilePath))
{
@@ -339,7 +333,7 @@ private:
{
// Create file as specified
HANDLE handle = ::CreateFile(
cacheFilePath.str().c_str(),
&cacheFilePath[0],
genericDesiredAccess,
ShareAccess,
&securityAttrib,
@@ -399,18 +393,18 @@ private:
auto siaFileTree = _siaFileTree;
if (siaFileTree)
{
SString siaQuery = CSiaApi::FormatToSiaPath(::PathSkipRoot(FileName));
SString siaQuery = CSiaApi::FormatToSiaPath(FilePath(FileName).RemoveFileName());
SString cachePath;
SString rootPath = siaQuery;
if (wcscmp(FileName, L"\\") == 0)
FilePath cachePath;
FilePath rootPath = siaQuery;
if (FilePath::DirSep == FileName)
{
cachePath = GetCacheLocation();
siaQuery += L"/*.*";
}
else
{
cachePath = StdConstructPath(GetCacheLocation(), &FileName[1]);
cachePath.Append(&FileName[1]);
if (::GetFileAttributes(&cachePath[0]) & FILE_ATTRIBUTE_DIRECTORY)
{
siaQuery += L"/*.*";
@@ -418,8 +412,7 @@ private:
else
{
rootPath = cachePath;
::PathRemoveFileSpec(&rootPath[0]);
rootPath = CSiaApi::FormatToSiaPath(rootPath);
rootPath = CSiaApi::FormatToSiaPath(rootPath.RemoveFileName());
}
}
@@ -432,10 +425,10 @@ private:
FillFindData(&fd, DokanFileInfo);
// Create cache sub-folder
SString subCachePath = StdConstructPath(cachePath, dir);
if (!::PathIsDirectory(subCachePath.str().c_str()))
FilePath subCachePath(cachePath, dir);
if (!subCachePath.IsDirectory())
{
::CreateDirectory(subCachePath.str().c_str(), nullptr);
subCachePath.CreateDirectory();
}
}
@@ -494,12 +487,10 @@ private:
BOOL opened = FALSE;
NTSTATUS ret = STATUS_SUCCESS;
SString cachePath = GetCacheLocation();
if (wcscmp(FileName, L"\\") != 0)
FilePath cachePath = GetCacheLocation();
if (FilePath::DirSep == FileName)
{
cachePath.Resize(MAX_PATH + 1);
::PathAppend(&cachePath[0], FileName);
cachePath = cachePath.str().c_str();
cachePath.Append(FileName);
}
if (!handle || (handle == INVALID_HANDLE_VALUE))
@@ -614,15 +605,14 @@ private:
LONGLONG Offset,
PDOKAN_FILE_INFO DokanFileInfo)
{
SString filePath = StdConstructPath(GetCacheLocation(), FileName);
FilePath filePath(GetCacheLocation(), FileName);
HANDLE handle = reinterpret_cast<HANDLE>(DokanFileInfo->Context);
ULONG offset = static_cast<ULONG>(Offset);
BOOL opened = FALSE;
if (!handle || (handle == INVALID_HANDLE_VALUE))
{
handle = ::CreateFile(filePath.str().c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, 0, nullptr);
handle = ::CreateFile(&filePath[0], GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, 0, nullptr);
if (handle == INVALID_HANDLE_VALUE)
{
DWORD error = GetLastError();
@@ -664,7 +654,7 @@ private:
LONGLONG Offset,
PDOKAN_FILE_INFO DokanFileInfo)
{
SString filePath = StdConstructPath(GetCacheLocation(), FileName);
FilePath filePath(GetCacheLocation(), FileName);
HANDLE handle = reinterpret_cast<HANDLE>(DokanFileInfo->Context);
BOOL opened = FALSE;
@@ -672,7 +662,7 @@ private:
if (!handle || (handle == INVALID_HANDLE_VALUE))
{
// TODO Get from cache if not found
handle = ::CreateFile(filePath.str().c_str(), GENERIC_WRITE, FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, 0, nullptr);
handle = ::CreateFile(&filePath[0], GENERIC_WRITE, FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, 0, nullptr);
if (handle == INVALID_HANDLE_VALUE)
{
DWORD error = GetLastError();
@@ -681,10 +671,8 @@ private:
opened = TRUE;
}
UINT64 fileSize = 0;
DWORD fileSizeLow = 0;
DWORD fileSizeHigh = 0;
fileSizeLow = ::GetFileSize(handle, &fileSizeHigh);
DWORD fileSizeLow = ::GetFileSize(handle, &fileSizeHigh);
if (fileSizeLow == INVALID_FILE_SIZE)
{
DWORD error = GetLastError();
@@ -693,7 +681,7 @@ private:
return DokanNtStatusFromWin32(error);
}
fileSize = (static_cast<UINT64>(fileSizeHigh) << 32) | fileSizeLow;
UINT64 fileSize = (static_cast<UINT64>(fileSizeHigh) << 32) | fileSizeLow;
LARGE_INTEGER distanceToMove;
if (DokanFileInfo->WriteToEndOfFile)
@@ -773,7 +761,6 @@ private:
static NTSTATUS DOKAN_CALLBACK Sia_SetEndOfFile(LPCWSTR FileName, LONGLONG ByteOffset, PDOKAN_FILE_INFO DokanFileInfo)
{
SString filePath = StdConstructPath(GetCacheLocation(), FileName);
HANDLE handle;
LARGE_INTEGER offset;
@@ -801,8 +788,7 @@ private:
static void DOKAN_CALLBACK Sia_Cleanup(LPCWSTR FileName, PDOKAN_FILE_INFO DokanFileInfo)
{
SString filePath = StdConstructPath(GetCacheLocation(), FileName);
FilePath filePath(GetCacheLocation(), FileName);
if (DokanFileInfo->Context)
{
::CloseHandle(reinterpret_cast<HANDLE>(DokanFileInfo->Context));
@@ -818,7 +804,7 @@ private:
// if open with FILE_FLAG_DELETE_ON_CLOSE
if (DokanFileInfo->IsDirectory)
{
if (::RemoveDirectory(filePath.str().c_str()))
if (filePath.RemoveDirectory())
{
}
else
@@ -827,7 +813,7 @@ private:
}
else
{
if (::DeleteFile(filePath.str().c_str()) == 0)
if (filePath.DeleteFile())
{
}
else
@@ -840,9 +826,7 @@ private:
static NTSTATUS DOKAN_CALLBACK Sia_FlushFileBuffers(LPCWSTR FileName, PDOKAN_FILE_INFO DokanFileInfo)
{
SString filePath = StdConstructPath(GetCacheLocation(), FileName);
HANDLE handle = reinterpret_cast<HANDLE>(DokanFileInfo->Context);
if (!handle || handle == INVALID_HANDLE_VALUE)
{
return STATUS_SUCCESS;
@@ -954,7 +938,7 @@ CSiaDriveConfig* DokanImpl::_siaDriveConfig = nullptr;
std::unique_ptr<CUploadManager> DokanImpl::_uploadManager;
DOKAN_OPERATIONS DokanImpl::_dokanOps;
DOKAN_OPTIONS DokanImpl::_dokanOptions;
SString DokanImpl::_cacheLocation;
FilePath DokanImpl::_cacheLocation;
bool DokanImpl::_fileListStopRequested;
CSiaFileTreePtr DokanImpl::_siaFileTree;
std::mutex DokanImpl::_fileTreeMutex;