Standardize path creation
This commit is contained in:
@@ -7,6 +7,13 @@ using namespace Sia::Api;
|
|||||||
using namespace Sia::Api::Dokan;
|
using namespace Sia::Api::Dokan;
|
||||||
|
|
||||||
// TODO Handle paths greater than MAX_PATH!!
|
// TODO Handle paths greater than MAX_PATH!!
|
||||||
|
static String StdConstructPath(const String& part1, const String& part2)
|
||||||
|
{
|
||||||
|
String path = part1;
|
||||||
|
path.resize(MAX_PATH + 1);
|
||||||
|
::PathAppend(&path[0], part2.c_str());
|
||||||
|
return path.c_str();
|
||||||
|
}
|
||||||
|
|
||||||
// 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.
|
// 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.
|
// 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.
|
||||||
@@ -153,9 +160,7 @@ private:
|
|||||||
{
|
{
|
||||||
// When filePath is a directory, needs to change the flag so that the file can
|
// When filePath is a directory, needs to change the flag so that the file can
|
||||||
// be opened.
|
// be opened.
|
||||||
String cacheFilePath;
|
String cacheFilePath = StdConstructPath(GetCacheLocation(), &FileName[1]);
|
||||||
cacheFilePath.resize(MAX_PATH + 1);
|
|
||||||
::PathCombine(&cacheFilePath[0], GetCacheLocation().c_str(), &FileName[1]);
|
|
||||||
DWORD fileAttr = ::GetFileAttributes(cacheFilePath.c_str());
|
DWORD fileAttr = ::GetFileAttributes(cacheFilePath.c_str());
|
||||||
|
|
||||||
if ((fileAttr != INVALID_FILE_ATTRIBUTES) &&
|
if ((fileAttr != INVALID_FILE_ATTRIBUTES) &&
|
||||||
@@ -364,14 +369,12 @@ private:
|
|||||||
String rootPath = siaQuery;
|
String rootPath = siaQuery;
|
||||||
if (wcscmp(FileName, L"\\") == 0)
|
if (wcscmp(FileName, L"\\") == 0)
|
||||||
{
|
{
|
||||||
cachePath = GetCacheLocation().c_str();
|
cachePath = GetCacheLocation();
|
||||||
siaQuery += L"/*.*";
|
siaQuery += L"/*.*";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cachePath.resize(MAX_PATH + 1);
|
cachePath = StdConstructPath(GetCacheLocation(), &FileName[1]);
|
||||||
::PathCombine(&cachePath[0], GetCacheLocation().c_str(), &FileName[1]);
|
|
||||||
cachePath = cachePath.c_str();
|
|
||||||
if (::GetFileAttributes(&cachePath[0]) & FILE_ATTRIBUTE_DIRECTORY)
|
if (::GetFileAttributes(&cachePath[0]) & FILE_ATTRIBUTE_DIRECTORY)
|
||||||
{
|
{
|
||||||
siaQuery += L"/*.*";
|
siaQuery += L"/*.*";
|
||||||
@@ -393,10 +396,7 @@ private:
|
|||||||
FillFindData(&fd, DokanFileInfo);
|
FillFindData(&fd, DokanFileInfo);
|
||||||
|
|
||||||
// Create cache sub-folder
|
// Create cache sub-folder
|
||||||
String subCachePath = cachePath.c_str();
|
String subCachePath = StdConstructPath(cachePath, dir);
|
||||||
subCachePath.resize(MAX_PATH + 1);
|
|
||||||
::PathAppend(&subCachePath[0], dir.c_str());
|
|
||||||
subCachePath = subCachePath.c_str();
|
|
||||||
if (!::PathIsDirectory(subCachePath.c_str()))
|
if (!::PathIsDirectory(subCachePath.c_str()))
|
||||||
{
|
{
|
||||||
::CreateDirectory(subCachePath.c_str(), nullptr);
|
::CreateDirectory(subCachePath.c_str(), nullptr);
|
||||||
@@ -459,7 +459,7 @@ private:
|
|||||||
BOOL opened = FALSE;
|
BOOL opened = FALSE;
|
||||||
NTSTATUS ret = STATUS_SUCCESS;
|
NTSTATUS ret = STATUS_SUCCESS;
|
||||||
|
|
||||||
String cachePath = GetCacheLocation().c_str();
|
String cachePath = GetCacheLocation();
|
||||||
if (wcscmp(FileName, L"\\") != 0)
|
if (wcscmp(FileName, L"\\") != 0)
|
||||||
{
|
{
|
||||||
cachePath.resize(MAX_PATH + 1);
|
cachePath.resize(MAX_PATH + 1);
|
||||||
|
Reference in New Issue
Block a user