From 273d741a87de5255e5b688cf43a24b5b33f14491 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Mon, 13 Mar 2017 23:26:45 -0500 Subject: [PATCH] Standardize path creation --- SiaDrive.Dokan.Api/SiaDokanDrive.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/SiaDrive.Dokan.Api/SiaDokanDrive.cpp b/SiaDrive.Dokan.Api/SiaDokanDrive.cpp index b60d6ab..1368ca4 100644 --- a/SiaDrive.Dokan.Api/SiaDokanDrive.cpp +++ b/SiaDrive.Dokan.Api/SiaDokanDrive.cpp @@ -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);