From d42cec07088e1ab21eb996f3061e74757218a3b9 Mon Sep 17 00:00:00 2001 From: huanghsiwu <375102906@qq.com> Date: Fri, 19 Sep 2014 15:54:18 +0800 Subject: [PATCH 1/2] fix wp8 directory control bug --- cocos/platform/CCFileUtils.cpp | 113 ++++++++++++++++++++++++--------- 1 file changed, 83 insertions(+), 30 deletions(-) diff --git a/cocos/platform/CCFileUtils.cpp b/cocos/platform/CCFileUtils.cpp index 30ed877233..34718a1111 100644 --- a/cocos/platform/CCFileUtils.cpp +++ b/cocos/platform/CCFileUtils.cpp @@ -1068,10 +1068,13 @@ bool FileUtils::createDirectory(const std::string& path) for(int i = 0 ; i < dirs.size() ; ++i) { subpath += dirs[i]; - BOOL ret = CreateDirectoryA(subpath.c_str(), NULL); - if (!ret && ERROR_ALREADY_EXISTS != GetLastError()) + if (i > 0 && !isDirectoryExist(subpath)) { - return false; + BOOL ret = CreateDirectoryA(subpath.c_str(), NULL); + if (!ret && ERROR_ALREADY_EXISTS != GetLastError()) + { + return false; + } } } } @@ -1081,14 +1084,17 @@ bool FileUtils::createDirectory(const std::string& path) if ((GetFileAttributesA(path.c_str())) == INVALID_FILE_ATTRIBUTES) { subpath = ""; - for(int i = 0 ; i < dirs.size() ; ++i) + for (int i = 0; i < dirs.size(); ++i) { subpath += dirs[i]; - BOOL ret = CreateDirectoryA(subpath.c_str(), NULL); - if (!ret && ERROR_ALREADY_EXISTS != GetLastError()) - { - return false; - } + if (!isDirectoryExist(subpath)) + { + BOOL ret = CreateDirectoryA(subpath.c_str(), NULL); + if (!ret && ERROR_ALREADY_EXISTS != GetLastError()) + { + return false; + } + } } } return true; @@ -1114,20 +1120,48 @@ bool FileUtils::removeDirectory(const std::string& path) return false; #endif #if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) - if (RemoveDirectoryA(path.c_str())) - { - return true; + std::string Files = path + "*.*"; + WIN32_FIND_DATA wfd; + HANDLE hFind = FindFirstFileEx(Files.c_str(), FindExInfoStandard, &wfd, FindExSearchNameMatch, NULL, 0); + bool Ret=true; + std::string Tmp; + if (hFind!=INVALID_HANDLE_VALUE) + { + bool bFind=true; + while (bFind) + { + //. .. + if(wfd.cFileName[0]!='.') + { + Tmp = path + wfd.cFileName; + if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + { + Tmp += '/'; + Ret = Ret && this->removeDirectory(Tmp); + } + else + { + SetFileAttributes(Tmp.c_str(), FILE_ATTRIBUTE_NORMAL); + Ret = Ret && DeleteFile(Tmp.c_str()); + } + } + bFind = FindNextFile(hFind, &wfd); + } + FindClose(hFind); } + if (Ret) + return RemoveDirectoryA(path.c_str()); return false; #endif #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) - std::string command = "rd /s /q "; - // Path may include space. - command += "\"" + path + "\""; + std::string command = "cmd /c rd /s /q "; + // Path may include space. + command += "\"" + path + "\""; + if (WinExec(command.c_str(), SW_HIDE) > 31) - return true; - else - return false; + return true; + else + return false; #endif } @@ -1151,13 +1185,22 @@ bool FileUtils::removeFile(const std::string &path) return false; #endif #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) - std::string command = "del /q "; - // Path may include space. - command += "\"" + path + "\""; + std::string command = "cmd /c del /q "; + std::string win32path = path; + int len = win32path.length(); + for (int i = 0; i < len; ++i) + { + if (win32path[i] == '/') + { + win32path[i] = '\\'; + } + } + command += win32path; + if (WinExec(command.c_str(), SW_HIDE) > 31) - return true; - else - return false; + return true; + else + return false; #endif } @@ -1176,13 +1219,23 @@ bool FileUtils::renameFile(const std::string &path, const std::string &oldname, } return true; #else - std::string command = "ren "; - // Path may include space. - command += "\"" + path + oldname + "\" \"" + name + "\""; + std::string command = "cmd /c ren "; + std::string win32path = path; + int len = win32path.length(); + for (int i = 0; i < len; ++i) + { + if (win32path[i] == '/') + { + win32path[i] = '\\'; + } + } + // Path may include space. + command += win32path + oldname + " " + name; + if (WinExec(command.c_str(), SW_HIDE) > 31) - return true; - else - return false; + return true; + else + return false; #endif } From f73f1a537915fb93a23ac03728201250bef34634 Mon Sep 17 00:00:00 2001 From: huanghsiwu <375102906@qq.com> Date: Fri, 19 Sep 2014 16:52:11 +0800 Subject: [PATCH 2/2] fix wp8 directory control bug --modify --- cocos/platform/CCFileUtils.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/cocos/platform/CCFileUtils.cpp b/cocos/platform/CCFileUtils.cpp index 34718a1111..19f3a69be1 100644 --- a/cocos/platform/CCFileUtils.cpp +++ b/cocos/platform/CCFileUtils.cpp @@ -1121,14 +1121,14 @@ bool FileUtils::removeDirectory(const std::string& path) #endif #if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) std::string Files = path + "*.*"; - WIN32_FIND_DATA wfd; + WIN32_FIND_DATA wfd; HANDLE hFind = FindFirstFileEx(Files.c_str(), FindExInfoStandard, &wfd, FindExSearchNameMatch, NULL, 0); - bool Ret=true; + bool ret=true; std::string Tmp; if (hFind!=INVALID_HANDLE_VALUE) { - bool bFind=true; - while (bFind) + bool find=true; + while (find) { //. .. if(wfd.cFileName[0]!='.') @@ -1137,19 +1137,19 @@ bool FileUtils::removeDirectory(const std::string& path) if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { Tmp += '/'; - Ret = Ret && this->removeDirectory(Tmp); + ret = ret && this->removeDirectory(Tmp); } else { SetFileAttributes(Tmp.c_str(), FILE_ATTRIBUTE_NORMAL); - Ret = Ret && DeleteFile(Tmp.c_str()); + ret = ret && DeleteFile(Tmp.c_str()); } } - bFind = FindNextFile(hFind, &wfd); + find = FindNextFile(find, &wfd); } - FindClose(hFind); + FindClose(find); } - if (Ret) + if (ret) return RemoveDirectoryA(path.c_str()); return false; #endif