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