Merge pull request #8108 from huangshiwu/v3_wp8test

fix wp8 directory control bug
This commit is contained in:
minggo 2014-09-19 16:57:02 +08:00
commit 6569f1a7f0
1 changed files with 83 additions and 30 deletions

View File

@ -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 find=true;
while (find)
{
//. ..
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());
}
}
find = FindNextFile(find, &wfd);
}
FindClose(find);
}
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
}