2014-03-29 03:52:16 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2010 cocos2d-x.org
|
|
|
|
Copyright (c) Microsoft Open Technologies, Inc.
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2014-03-29 03:52:16 +08:00
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
2016-03-20 21:53:44 +08:00
|
|
|
#include "platform/winrt/CCFileUtilsWinRT.h"
|
2015-07-13 17:06:01 +08:00
|
|
|
#include <regex>
|
2016-03-20 21:53:44 +08:00
|
|
|
#include "platform/winrt/CCWinRTUtils.h"
|
2014-03-29 03:52:16 +08:00
|
|
|
#include "platform/CCCommon.h"
|
2017-05-18 09:18:18 +08:00
|
|
|
#include "tinydir/tinydir.h"
|
2014-03-29 03:52:16 +08:00
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
|
|
|
static std::string s_pszResourcePath;
|
|
|
|
|
|
|
|
// D:\aaa\bbb\ccc\ddd\abc.txt --> D:/aaa/bbb/ccc/ddd/abc.txt
|
|
|
|
static inline std::string convertPathFormatToUnixStyle(const std::string& path)
|
|
|
|
{
|
|
|
|
std::string ret = path;
|
2016-05-29 13:43:28 +08:00
|
|
|
size_t len = ret.length();
|
|
|
|
for (size_t i = 0; i < len; ++i)
|
2014-03-29 03:52:16 +08:00
|
|
|
{
|
|
|
|
if (ret[i] == '\\')
|
|
|
|
{
|
|
|
|
ret[i] = '/';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-07-13 17:06:01 +08:00
|
|
|
static std::string UTF8StringToMultiByte(const std::string& strUtf8)
|
|
|
|
{
|
|
|
|
std::string ret;
|
|
|
|
if (!strUtf8.empty())
|
|
|
|
{
|
|
|
|
std::wstring strWideChar = StringUtf8ToWideChar(strUtf8);
|
|
|
|
int nNum = WideCharToMultiByte(CP_ACP, 0, strWideChar.c_str(), -1, nullptr, 0, nullptr, FALSE);
|
|
|
|
if (nNum)
|
|
|
|
{
|
|
|
|
char* ansiString = new char[nNum + 1];
|
|
|
|
ansiString[0] = 0;
|
|
|
|
|
|
|
|
nNum = WideCharToMultiByte(CP_ACP, 0, strWideChar.c_str(), -1, ansiString, nNum + 1, nullptr, FALSE);
|
|
|
|
|
|
|
|
ret = ansiString;
|
|
|
|
delete[] ansiString;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CCLOG("Wrong convert to Ansi code:0x%x", GetLastError());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2014-03-29 03:52:16 +08:00
|
|
|
|
|
|
|
static void _checkPath()
|
|
|
|
{
|
|
|
|
if (s_pszResourcePath.empty())
|
|
|
|
{
|
2015-07-07 14:06:59 +08:00
|
|
|
// TODO: needs to be tested
|
|
|
|
s_pszResourcePath = convertPathFormatToUnixStyle(CCFileUtilsWinRT::getAppPath() + '\\' + "Assets\\Resources" + '\\');
|
2014-03-29 03:52:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FileUtils* FileUtils::getInstance()
|
|
|
|
{
|
2016-06-23 11:39:23 +08:00
|
|
|
if (s_sharedFileUtils == nullptr)
|
2014-03-29 03:52:16 +08:00
|
|
|
{
|
|
|
|
s_sharedFileUtils = new CCFileUtilsWinRT();
|
|
|
|
if(!s_sharedFileUtils->init())
|
|
|
|
{
|
|
|
|
delete s_sharedFileUtils;
|
2016-06-23 11:39:23 +08:00
|
|
|
s_sharedFileUtils = nullptr;
|
2014-03-29 03:52:16 +08:00
|
|
|
CCLOG("ERROR: Could not init CCFileUtilsWinRT");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return s_sharedFileUtils;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCFileUtilsWinRT::CCFileUtilsWinRT()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CCFileUtilsWinRT::init()
|
|
|
|
{
|
|
|
|
_checkPath();
|
|
|
|
_defaultResRootPath = s_pszResourcePath;
|
|
|
|
return FileUtils::init();
|
|
|
|
}
|
|
|
|
|
2015-04-07 22:15:15 +08:00
|
|
|
std::string CCFileUtilsWinRT::getPathForFilename(const std::string& filename, const std::string& resolutionDirectory, const std::string& searchPath) const
|
2014-03-29 03:52:16 +08:00
|
|
|
{
|
|
|
|
std::string unixFileName = convertPathFormatToUnixStyle(filename);
|
|
|
|
std::string unixResolutionDirectory = convertPathFormatToUnixStyle(resolutionDirectory);
|
|
|
|
std::string unixSearchPath = convertPathFormatToUnixStyle(searchPath);
|
|
|
|
|
|
|
|
return FileUtils::getPathForFilename(unixFileName, unixResolutionDirectory, unixSearchPath);
|
|
|
|
}
|
|
|
|
|
2015-04-07 22:15:15 +08:00
|
|
|
std::string CCFileUtilsWinRT::getFullPathForDirectoryAndFilename(const std::string& strDirectory, const std::string& strFilename) const
|
2014-03-29 03:52:16 +08:00
|
|
|
{
|
|
|
|
std::string unixDirectory = convertPathFormatToUnixStyle(strDirectory);
|
|
|
|
std::string unixFilename = convertPathFormatToUnixStyle(strFilename);
|
|
|
|
return FileUtils::getFullPathForDirectoryAndFilename(unixDirectory, unixFilename);
|
|
|
|
}
|
|
|
|
|
2015-07-13 17:06:01 +08:00
|
|
|
std::string CCFileUtilsWinRT::getSuitableFOpen(const std::string& filenameUtf8) const
|
|
|
|
{
|
|
|
|
return UTF8StringToMultiByte(filenameUtf8);
|
|
|
|
}
|
|
|
|
|
2016-01-20 04:36:10 +08:00
|
|
|
long CCFileUtilsWinRT::getFileSize(const std::string &filepath)
|
|
|
|
{
|
|
|
|
WIN32_FILE_ATTRIBUTE_DATA fad;
|
|
|
|
if (!GetFileAttributesEx(StringUtf8ToWideChar(filepath).c_str(), GetFileExInfoStandard, &fad))
|
|
|
|
{
|
|
|
|
return 0; // error condition, could call GetLastError to find out more
|
|
|
|
}
|
|
|
|
LARGE_INTEGER size;
|
|
|
|
size.HighPart = fad.nFileSizeHigh;
|
|
|
|
size.LowPart = fad.nFileSizeLow;
|
|
|
|
return (long)size.QuadPart;
|
|
|
|
}
|
|
|
|
|
2016-04-26 13:37:22 +08:00
|
|
|
FileUtils::Status CCFileUtilsWinRT::getContents(const std::string& filename, ResizableBuffer* buffer)
|
|
|
|
{
|
|
|
|
if (filename.empty())
|
|
|
|
return FileUtils::Status::NotExists;
|
|
|
|
|
|
|
|
// read the file from hardware
|
|
|
|
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(filename);
|
|
|
|
|
|
|
|
HANDLE fileHandle = ::CreateFile2(StringUtf8ToWideChar(fullPath).c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, OPEN_EXISTING, nullptr);
|
|
|
|
if (fileHandle == INVALID_HANDLE_VALUE)
|
|
|
|
return FileUtils::Status::OpenFailed;
|
|
|
|
|
|
|
|
FILE_STANDARD_INFO info = {0};
|
|
|
|
if (::GetFileInformationByHandleEx(fileHandle, FileStandardInfo, &info, sizeof(info)) == 0)
|
|
|
|
{
|
|
|
|
::CloseHandle(fileHandle);
|
|
|
|
return FileUtils::Status::OpenFailed;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info.EndOfFile.HighPart > 0)
|
|
|
|
{
|
|
|
|
::CloseHandle(fileHandle);
|
|
|
|
return FileUtils::Status::TooLarge;
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer->resize(info.EndOfFile.LowPart);
|
|
|
|
DWORD sizeRead = 0;
|
|
|
|
BOOL successed = ::ReadFile(fileHandle, buffer->buffer(), info.EndOfFile.LowPart, &sizeRead, nullptr);
|
|
|
|
::CloseHandle(fileHandle);
|
|
|
|
|
|
|
|
if (!successed)
|
|
|
|
{
|
|
|
|
buffer->resize(sizeRead);
|
|
|
|
CCLOG("Get data from file(%s) failed, error code is %s", filename.data(), std::to_string(::GetLastError()).data());
|
2016-06-25 11:58:55 +08:00
|
|
|
return FileUtils::Status::ReadFailed;
|
2016-04-26 13:37:22 +08:00
|
|
|
}
|
|
|
|
return FileUtils::Status::OK;
|
|
|
|
}
|
|
|
|
|
2014-04-02 15:35:09 +08:00
|
|
|
bool CCFileUtilsWinRT::isFileExistInternal(const std::string& strFilePath) const
|
2014-03-29 03:52:16 +08:00
|
|
|
{
|
|
|
|
bool ret = false;
|
2016-06-23 11:39:23 +08:00
|
|
|
FILE * pf = nullptr;
|
2014-03-29 03:52:16 +08:00
|
|
|
|
|
|
|
std::string strPath = strFilePath;
|
|
|
|
if (!isAbsolutePath(strPath))
|
|
|
|
{ // Not absolute path, add the default root path at the beginning.
|
|
|
|
strPath.insert(0, _defaultResRootPath);
|
|
|
|
}
|
|
|
|
|
2015-05-04 16:06:04 +08:00
|
|
|
strPath = getSuitableFOpen(strPath);
|
2014-03-29 03:52:16 +08:00
|
|
|
|
2015-05-04 16:06:04 +08:00
|
|
|
if (!strPath.empty() && (pf = fopen(strPath.c_str(), "rb")))
|
2014-03-29 03:52:16 +08:00
|
|
|
{
|
|
|
|
ret = true;
|
|
|
|
fclose(pf);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-07-10 14:37:42 +08:00
|
|
|
bool CCFileUtilsWinRT::isDirectoryExistInternal(const std::string& dirPath) const
|
|
|
|
{
|
2015-07-10 16:17:34 +08:00
|
|
|
WIN32_FILE_ATTRIBUTE_DATA wfad;
|
2015-08-18 04:04:05 +08:00
|
|
|
std::wstring wdirPath = StringUtf8ToWideChar(dirPath);
|
2015-07-10 16:17:34 +08:00
|
|
|
if (GetFileAttributesEx(wdirPath.c_str(), GetFileExInfoStandard, &wfad))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2015-07-10 14:37:42 +08:00
|
|
|
}
|
|
|
|
|
2015-07-13 17:06:01 +08:00
|
|
|
bool CCFileUtilsWinRT::createDirectory(const std::string& path)
|
|
|
|
{
|
|
|
|
CCASSERT(!path.empty(), "Invalid path");
|
|
|
|
|
|
|
|
if (isDirectoryExist(path))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Split the path
|
|
|
|
size_t start = 0;
|
|
|
|
size_t found = path.find_first_of("/\\", start);
|
|
|
|
std::string subpath;
|
|
|
|
std::vector<std::string> dirs;
|
|
|
|
|
|
|
|
if (found != std::string::npos)
|
|
|
|
{
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
subpath = path.substr(start, found - start + 1);
|
|
|
|
if (!subpath.empty())
|
|
|
|
dirs.push_back(subpath);
|
|
|
|
start = found + 1;
|
|
|
|
found = path.find_first_of("/\\", start);
|
|
|
|
if (found == std::string::npos)
|
|
|
|
{
|
|
|
|
if (start < path.length())
|
|
|
|
{
|
|
|
|
dirs.push_back(path.substr(start));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WIN32_FILE_ATTRIBUTE_DATA wfad;
|
2016-04-26 13:37:22 +08:00
|
|
|
|
2015-08-16 17:51:41 +08:00
|
|
|
if (!(GetFileAttributesEx(StringUtf8ToWideChar(path).c_str(), GetFileExInfoStandard, &wfad)))
|
2015-07-13 17:06:01 +08:00
|
|
|
{
|
|
|
|
subpath = "";
|
2016-10-27 15:10:24 +08:00
|
|
|
for (unsigned int i = 0, size = dirs.size(); i < size; ++i)
|
2015-07-13 17:06:01 +08:00
|
|
|
{
|
|
|
|
subpath += dirs[i];
|
|
|
|
if (i > 0 && !isDirectoryExist(subpath))
|
|
|
|
{
|
2015-08-16 17:51:41 +08:00
|
|
|
BOOL ret = CreateDirectory(StringUtf8ToWideChar(subpath).c_str(), NULL);
|
2015-07-13 17:06:01 +08:00
|
|
|
if (!ret && ERROR_ALREADY_EXISTS != GetLastError())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CCFileUtilsWinRT::removeDirectory(const std::string& path)
|
|
|
|
{
|
2015-08-16 17:51:41 +08:00
|
|
|
std::wstring wpath = StringUtf8ToWideChar(path);
|
2015-07-13 17:06:01 +08:00
|
|
|
std::wstring files = wpath + L"*.*";
|
|
|
|
WIN32_FIND_DATA wfd;
|
|
|
|
HANDLE search = FindFirstFileEx(files.c_str(), FindExInfoStandard, &wfd, FindExSearchNameMatch, NULL, 0);
|
|
|
|
bool ret = true;
|
|
|
|
if (search != INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
BOOL find = true;
|
|
|
|
while (find)
|
|
|
|
{
|
|
|
|
//. ..
|
|
|
|
if (wfd.cFileName[0] != '.')
|
|
|
|
{
|
|
|
|
std::wstring temp = wpath + wfd.cFileName;
|
|
|
|
if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
|
|
|
{
|
|
|
|
temp += '/';
|
2017-05-15 17:10:36 +08:00
|
|
|
ret = ret && this->removeDirectory(StringWideCharToUtf8(temp));
|
2015-07-13 17:06:01 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetFileAttributes(temp.c_str(), FILE_ATTRIBUTE_NORMAL);
|
|
|
|
ret = ret && DeleteFile(temp.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
find = FindNextFile(search, &wfd);
|
|
|
|
}
|
|
|
|
FindClose(search);
|
|
|
|
}
|
|
|
|
if (ret && RemoveDirectory(wpath.c_str()))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-03-29 03:52:16 +08:00
|
|
|
bool CCFileUtilsWinRT::isAbsolutePath(const std::string& strPath) const
|
|
|
|
{
|
2015-07-07 14:06:59 +08:00
|
|
|
if ( strPath.length() > 2
|
2014-03-29 03:52:16 +08:00
|
|
|
&& ( (strPath[0] >= 'a' && strPath[0] <= 'z') || (strPath[0] >= 'A' && strPath[0] <= 'Z') )
|
|
|
|
&& strPath[1] == ':')
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-07-13 17:06:01 +08:00
|
|
|
bool CCFileUtilsWinRT::removeFile(const std::string &path)
|
|
|
|
{
|
2015-08-16 17:51:41 +08:00
|
|
|
std::wstring wpath = StringUtf8ToWideChar(path);
|
2015-07-13 17:06:01 +08:00
|
|
|
if (DeleteFile(wpath.c_str()))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2015-08-16 17:51:41 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
CCLOG("Remove file failed with error: %d", GetLastError());
|
|
|
|
return false;
|
|
|
|
}
|
2015-07-13 17:06:01 +08:00
|
|
|
}
|
|
|
|
|
2015-08-13 15:14:10 +08:00
|
|
|
bool CCFileUtilsWinRT::renameFile(const std::string &oldfullpath, const std::string& newfullpath)
|
|
|
|
{
|
|
|
|
CCASSERT(!oldfullpath.empty(), "Invalid path");
|
|
|
|
CCASSERT(!newfullpath.empty(), "Invalid path");
|
|
|
|
|
2015-07-13 17:06:01 +08:00
|
|
|
std::regex pat("\\/");
|
2015-08-16 17:51:41 +08:00
|
|
|
std::string _oldfullpath = std::regex_replace(oldfullpath, pat, "\\");
|
|
|
|
std::string _newfullpath = std::regex_replace(newfullpath, pat, "\\");
|
2015-07-13 17:06:01 +08:00
|
|
|
|
2015-08-16 17:51:41 +08:00
|
|
|
std::wstring _wNewfullpath = StringUtf8ToWideChar(_newfullpath);
|
2015-07-07 14:06:59 +08:00
|
|
|
|
2015-08-16 17:51:41 +08:00
|
|
|
if (FileUtils::getInstance()->isFileExist(_newfullpath))
|
2014-03-29 03:52:16 +08:00
|
|
|
{
|
2015-08-16 17:51:41 +08:00
|
|
|
if (!DeleteFile(_wNewfullpath.c_str()))
|
2014-03-29 03:52:16 +08:00
|
|
|
{
|
2015-08-16 17:51:41 +08:00
|
|
|
CCLOGERROR("Fail to delete file %s !Error code is 0x%x", newfullpath.c_str(), GetLastError());
|
2014-03-29 03:52:16 +08:00
|
|
|
}
|
2015-08-16 17:51:41 +08:00
|
|
|
}
|
2015-07-07 14:06:59 +08:00
|
|
|
|
2015-08-16 17:51:41 +08:00
|
|
|
if (MoveFileEx(StringUtf8ToWideChar(_oldfullpath).c_str(), _wNewfullpath.c_str(),
|
|
|
|
MOVEFILE_REPLACE_EXISTING & MOVEFILE_WRITE_THROUGH))
|
2014-03-29 03:52:16 +08:00
|
|
|
{
|
2015-08-16 17:51:41 +08:00
|
|
|
return true;
|
2014-03-29 03:52:16 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-08-16 17:51:41 +08:00
|
|
|
CCLOGERROR("Fail to rename file %s to %s !Error code is 0x%x", oldfullpath.c_str(), newfullpath.c_str(), GetLastError());
|
|
|
|
return false;
|
2014-03-29 03:52:16 +08:00
|
|
|
}
|
2015-08-16 17:51:41 +08:00
|
|
|
}
|
2015-07-07 14:06:59 +08:00
|
|
|
|
2015-08-16 17:51:41 +08:00
|
|
|
bool CCFileUtilsWinRT::renameFile(const std::string &path, const std::string &oldname, const std::string &name)
|
|
|
|
{
|
|
|
|
CCASSERT(!path.empty(), "Invalid path");
|
|
|
|
std::string oldPath = path + oldname;
|
|
|
|
std::string newPath = path + name;
|
|
|
|
|
|
|
|
return renameFile(oldPath, newPath);
|
2014-03-29 03:52:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
string CCFileUtilsWinRT::getWritablePath() const
|
|
|
|
{
|
2015-07-07 14:06:59 +08:00
|
|
|
auto localFolderPath = Windows::Storage::ApplicationData::Current->LocalFolder->Path;
|
|
|
|
return convertPathFormatToUnixStyle(std::string(PlatformStringToString(localFolderPath)) + '\\');
|
2014-03-29 03:52:16 +08:00
|
|
|
}
|
|
|
|
|
2017-05-18 09:18:18 +08:00
|
|
|
void CCFileUtilsWinRT::listFilesRecursively(const std::string& dirPath, std::vector<std::string> *files) const
|
|
|
|
{
|
|
|
|
std::string fullpath = fullPathForFilename(dirPath);
|
|
|
|
if (isDirectoryExist(fullpath))
|
|
|
|
{
|
|
|
|
tinydir_dir dir;
|
|
|
|
std::wstring fullpathstr = StringUtf8ToWideChar(fullpath);
|
|
|
|
|
|
|
|
if (tinydir_open(&dir, &fullpathstr[0]) != -1)
|
|
|
|
{
|
|
|
|
while (dir.has_next)
|
|
|
|
{
|
|
|
|
tinydir_file file;
|
|
|
|
if (tinydir_readfile(&dir, &file) == -1)
|
|
|
|
{
|
|
|
|
// Error getting file
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
std::string fileName = StringWideCharToUtf8(file.name);
|
|
|
|
|
|
|
|
if (fileName != "." && fileName != "..")
|
|
|
|
{
|
|
|
|
std::string filepath = StringWideCharToUtf8(file.path);
|
|
|
|
if (file.is_dir)
|
|
|
|
{
|
|
|
|
filepath.append("/");
|
|
|
|
files->push_back(filepath);
|
|
|
|
listFilesRecursively(filepath, files);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
files->push_back(filepath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tinydir_next(&dir) == -1)
|
|
|
|
{
|
|
|
|
// Error getting next file
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tinydir_close(&dir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> CCFileUtilsWinRT::listFiles(const std::string& dirPath) const
|
|
|
|
{
|
|
|
|
std::string fullpath = fullPathForFilename(dirPath);
|
|
|
|
std::vector<std::string> files;
|
|
|
|
if (isDirectoryExist(fullpath))
|
|
|
|
{
|
|
|
|
tinydir_dir dir;
|
|
|
|
std::wstring fullpathstr = StringUtf8ToWideChar(fullpath);
|
|
|
|
|
|
|
|
if (tinydir_open(&dir, &fullpathstr[0]) != -1)
|
|
|
|
{
|
|
|
|
while (dir.has_next)
|
|
|
|
{
|
|
|
|
tinydir_file file;
|
|
|
|
if (tinydir_readfile(&dir, &file) == -1)
|
|
|
|
{
|
|
|
|
// Error getting file
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string filepath = StringWideCharToUtf8(file.path);
|
|
|
|
if (file.is_dir)
|
|
|
|
{
|
|
|
|
filepath.append("/");
|
|
|
|
}
|
|
|
|
files.push_back(filepath);
|
|
|
|
|
|
|
|
if (tinydir_next(&dir) == -1)
|
|
|
|
{
|
|
|
|
// Error getting next file
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tinydir_close(&dir);
|
|
|
|
}
|
|
|
|
return files;
|
|
|
|
}
|
|
|
|
|
2014-03-29 03:52:16 +08:00
|
|
|
string CCFileUtilsWinRT::getAppPath()
|
|
|
|
{
|
2015-07-07 14:06:59 +08:00
|
|
|
Windows::ApplicationModel::Package^ package = Windows::ApplicationModel::Package::Current;
|
|
|
|
return convertPathFormatToUnixStyle(std::string(PlatformStringToString(package->InstalledLocation->Path)));
|
2014-03-29 03:52:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_CC_END
|