Browse Source

Renaming a folder in project library no longer causes a full reimport of all files in that folder

BearishSun 9 years ago
parent
commit
9a8244ddc4

+ 46 - 10
Source/BansheeUtility/Source/BsPath.cpp

@@ -338,22 +338,58 @@ namespace BansheeEngine
 				return false;
 		}
 
-		if (mDirectories.size() != other.mDirectories.size())
+		if (!comparePathElem(mNode, other.mNode))
 			return false;
 
-		if (!comparePathElem(mFilename, other.mFilename))
-			return false;
+		UINT32 myNumElements = (UINT32)mDirectories.size();
+		UINT32 otherNumElements = (UINT32)other.mDirectories.size();
 
-		if (!comparePathElem(mNode, other.mNode))
-			return false;
+		if (!mFilename.empty())
+			myNumElements++;
 
-		auto iterMe = mDirectories.begin();
-		auto iterOther = other.mDirectories.begin();
+		if (!other.mFilename.empty())
+			otherNumElements++;
 
-		for (; iterMe != mDirectories.end(); ++iterMe, ++iterOther)
+		if (myNumElements != otherNumElements)
+			return false;
+
+		if(myNumElements > 0)
 		{
-			if (!comparePathElem(*iterMe, *iterOther))
-				return false;
+			auto iterMe = mDirectories.begin();
+			auto iterOther = other.mDirectories.begin();
+
+			for(UINT32 i = 0; i < (myNumElements - 1); i++, ++iterMe, ++iterOther)
+			{
+				if (!comparePathElem(*iterMe, *iterOther))
+					return false;
+			}
+
+			if (!mFilename.empty())
+			{
+				if (!other.mFilename.empty())
+				{
+					if (!comparePathElem(mFilename, other.mFilename))
+						return false;
+				}
+				else
+				{
+					if (!comparePathElem(mFilename, *iterOther))
+						return false;
+				}
+			}
+			else
+			{
+				if (!other.mFilename.empty())
+				{
+					if (!comparePathElem(*iterMe, other.mFilename))
+						return false;
+				}
+				else
+				{
+					if (!comparePathElem(*iterMe, *iterOther))
+						return false;
+				}
+			}
 		}
 
 		return true;

+ 67 - 59
Source/BansheeUtility/Source/Win32/BsWin32FileSystem.cpp

@@ -454,41 +454,45 @@ namespace BansheeEngine
 
 	void FileSystem::getChildren(const Path& dirPath, Vector<Path>& files, Vector<Path>& directories)
 	{
-		if (dirPath.isFile())
+		WString findPath = dirPath.toWString();
+
+		if (win32_isFile(findPath))
 			return;
 
-		WString findPath = dirPath.toWString();
-		findPath.append(L"*");
+		if(dirPath.isFile()) // Assuming the file is a folder, just improperly formatted in Path
+			findPath.append(L"\\*");
+		else
+			findPath.append(L"*");
 
 		WIN32_FIND_DATAW findData;
 		HANDLE fileHandle = FindFirstFileW(findPath.c_str(), &findData);
+		if(fileHandle == INVALID_HANDLE_VALUE)
+		{
+			win32_handleError(GetLastError(), findPath);
+			return;
+		}
 
-		bool lastFailed = false;
 		WString tempName;
 		do
 		{
-			if (lastFailed || fileHandle == INVALID_HANDLE_VALUE)
+			tempName = findData.cFileName;
+
+			if (tempName != L"." && tempName != L"..")
 			{
-				if (GetLastError() == ERROR_NO_MORE_FILES)
-					break;
+				Path fullPath = dirPath;
+				if ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0)
+					directories.push_back(fullPath.append(tempName + L"/"));
 				else
-					win32_handleError(GetLastError(), findPath);
+					files.push_back(fullPath.append(tempName));
 			}
-			else
+
+			if(FindNextFileW(fileHandle, &findData) == FALSE)
 			{
-				tempName = findData.cFileName;
+				if (GetLastError() != ERROR_NO_MORE_FILES)
+					win32_handleError(GetLastError(), findPath);
 
-				if (tempName != L"." && tempName != L"..")
-				{
-					Path fullPath = dirPath;
-					if ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0)
-						directories.push_back(fullPath.append(tempName + L"/"));
-					else
-						files.push_back(fullPath.append(tempName));
-				}
+				break;
 			}
-
-			lastFailed = FindNextFileW(fileHandle, &findData) == FALSE;
 		} while (true);
 
 		FindClose(fileHandle);
@@ -497,70 +501,74 @@ namespace BansheeEngine
 	bool FileSystem::iterate(const Path& dirPath, std::function<bool(const Path&)> fileCallback,
 		std::function<bool(const Path&)> dirCallback, bool recursive)
 	{
-		if (dirPath.isFile())
-			return true;
-
 		WString findPath = dirPath.toWString();
-		findPath.append(L"*");
+
+		if (win32_isFile(findPath))
+			return false;
+
+		if (dirPath.isFile()) // Assuming the file is a folder, just improperly formatted in Path
+			findPath.append(L"\\*");
+		else
+			findPath.append(L"*");
 
 		WIN32_FIND_DATAW findData;
 		HANDLE fileHandle = FindFirstFileW(findPath.c_str(), &findData);
+		if (fileHandle == INVALID_HANDLE_VALUE)
+		{
+			win32_handleError(GetLastError(), findPath);
+			return false;
+		}
 
-		bool lastFailed = false;
 		WString tempName;
 		do
 		{
-			if (lastFailed || fileHandle == INVALID_HANDLE_VALUE)
-			{
-				if (GetLastError() != ERROR_NO_MORE_FILES)
-					win32_handleError(GetLastError(), findPath);
+			tempName = findData.cFileName;
 
-				break;
-			}
-			else
+			if (tempName != L"." && tempName != L"..")
 			{
-				tempName = findData.cFileName;
-
-				if (tempName != L"." && tempName != L"..")
+				Path fullPath = dirPath;
+				if ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0)
 				{
-					Path fullPath = dirPath;
-					if ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0)
+					Path childDir = fullPath.append(tempName + L"/");
+					if (dirCallback != nullptr)
 					{
-						Path childDir = fullPath.append(tempName + L"/");
-						if (dirCallback != nullptr)
+						if (!dirCallback(childDir))
 						{
-							if (!dirCallback(childDir))
-							{
-								FindClose(fileHandle);
-								return false;
-							}
+							FindClose(fileHandle);
+							return false;
 						}
+					}
 
-						if (recursive)
+					if (recursive)
+					{
+						if (!iterate(childDir, fileCallback, dirCallback, recursive))
 						{
-							if (!iterate(childDir, fileCallback, dirCallback, recursive))
-							{
-								FindClose(fileHandle);
-								return false;
-							}
+							FindClose(fileHandle);
+							return false;
 						}
 					}
-					else
+				}
+				else
+				{
+					Path filePath = fullPath.append(tempName);
+					if (fileCallback != nullptr)
 					{
-						Path filePath = fullPath.append(tempName);
-						if (fileCallback != nullptr)
+						if (!fileCallback(filePath))
 						{
-							if (!fileCallback(filePath))
-							{
-								FindClose(fileHandle);
-								return false;
-							}
+							FindClose(fileHandle);
+							return false;
 						}
 					}
 				}
 			}
 
-			lastFailed = FindNextFileW(fileHandle, &findData) == FALSE;
+			if(FindNextFileW(fileHandle, &findData) == FALSE)
+			{
+				if (GetLastError() != ERROR_NO_MORE_FILES)
+					win32_handleError(GetLastError(), findPath);
+
+				break;
+			}
 		} while (true);
 
 		FindClose(fileHandle);