mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-04-07 13:55:33 +08:00
Merge remote-tracking branch 'origin/develop' into feature/pdfForms
# Conflicts: # DesktopEditor/xmlsec/src/src/Certificate_mscrypto.h # PdfFile/PdfFile.cpp # PdfFile/PdfFile.h # PdfFile/PdfReader.cpp # PdfFile/PdfReader.h
This commit is contained in:
@ -31,25 +31,25 @@
|
||||
*/
|
||||
|
||||
#if defined(_WIN32) || defined (_WIN64)
|
||||
#include "windows.h"
|
||||
#include "windef.h"
|
||||
#include <shlobj.h>
|
||||
#include <Rpc.h>
|
||||
#include "windows.h"
|
||||
#include "windef.h"
|
||||
#include <shlobj.h>
|
||||
#include <Rpc.h>
|
||||
#elif __linux__
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#elif MAC
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#elif _IOS
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
@ -58,187 +58,187 @@
|
||||
namespace NSDirectory
|
||||
{
|
||||
#if !defined(_WIN32) && !defined (_WIN64)
|
||||
static bool is_directory_exist(char* dir)
|
||||
{
|
||||
struct stat st;
|
||||
bool bRes = (0 == stat(dir, &st)) && S_ISDIR(st.st_mode);
|
||||
return bRes;
|
||||
}
|
||||
static bool is_directory_exist(char* dir)
|
||||
{
|
||||
struct stat st;
|
||||
bool bRes = (0 == stat(dir, &st)) && S_ISDIR(st.st_mode);
|
||||
return bRes;
|
||||
}
|
||||
|
||||
static bool _mkdir (const char *dir)
|
||||
{
|
||||
char tmp[MAX_PATH];
|
||||
char *p = NULL;
|
||||
size_t len;
|
||||
bool res = true;
|
||||
static bool _mkdir (const char *dir)
|
||||
{
|
||||
char tmp[MAX_PATH];
|
||||
char *p = NULL;
|
||||
size_t len;
|
||||
bool res = true;
|
||||
|
||||
snprintf(tmp, sizeof(tmp),"%s",dir);
|
||||
len = strlen(tmp);
|
||||
if(tmp[len - 1] == '/')
|
||||
tmp[len - 1] = 0;
|
||||
for(p = tmp + 1; *p; p++)
|
||||
if(*p == '/') {
|
||||
*p = 0;
|
||||
res = is_directory_exist(tmp);
|
||||
if (!res)
|
||||
res = (0 == mkdir(tmp, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH));
|
||||
*p = '/';
|
||||
if (!res)
|
||||
break;
|
||||
}
|
||||
if (res)
|
||||
res = (0 == mkdir(tmp, S_IRWXU));
|
||||
return res;
|
||||
}
|
||||
snprintf(tmp, sizeof(tmp),"%s",dir);
|
||||
len = strlen(tmp);
|
||||
if(tmp[len - 1] == '/')
|
||||
tmp[len - 1] = 0;
|
||||
for(p = tmp + 1; *p; p++)
|
||||
if(*p == '/') {
|
||||
*p = 0;
|
||||
res = is_directory_exist(tmp);
|
||||
if (!res)
|
||||
res = (0 == mkdir(tmp, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH));
|
||||
*p = '/';
|
||||
if (!res)
|
||||
break;
|
||||
}
|
||||
if (res)
|
||||
res = (0 == mkdir(tmp, S_IRWXU));
|
||||
return res;
|
||||
}
|
||||
#endif
|
||||
|
||||
void GetFiles2(std::wstring strDirectory, std::vector<std::wstring>& oArray, bool bIsRecursion)
|
||||
{
|
||||
void GetFiles2(std::wstring strDirectory, std::vector<std::wstring>& oArray, bool bIsRecursion)
|
||||
{
|
||||
#if defined(_WIN32) || defined (_WIN64)
|
||||
WIN32_FIND_DATAW oFD;
|
||||
WIN32_FIND_DATAW oFD;
|
||||
|
||||
std::wstring sSpec = strDirectory + L"\\*.*";
|
||||
HANDLE hRes = FindFirstFileW( sSpec.c_str(), &oFD );
|
||||
if( INVALID_HANDLE_VALUE == hRes )
|
||||
return;
|
||||
do
|
||||
{
|
||||
sSpec = oFD.cFileName;
|
||||
if (sSpec != L"." && sSpec != L"..")
|
||||
{
|
||||
sSpec = strDirectory + L"\\" + sSpec;
|
||||
if( !( oFD.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) )
|
||||
{
|
||||
oArray.push_back(sSpec);
|
||||
}
|
||||
else if (bIsRecursion)
|
||||
{
|
||||
GetFiles2(sSpec, oArray, bIsRecursion);
|
||||
}
|
||||
}
|
||||
} while( FindNextFileW( hRes, &oFD ) );
|
||||
FindClose( hRes );
|
||||
std::wstring sSpec = strDirectory + L"\\*.*";
|
||||
HANDLE hRes = FindFirstFileW( sSpec.c_str(), &oFD );
|
||||
if( INVALID_HANDLE_VALUE == hRes )
|
||||
return;
|
||||
do
|
||||
{
|
||||
sSpec = oFD.cFileName;
|
||||
if (sSpec != L"." && sSpec != L"..")
|
||||
{
|
||||
sSpec = strDirectory + L"\\" + sSpec;
|
||||
if( !( oFD.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) )
|
||||
{
|
||||
oArray.push_back(sSpec);
|
||||
}
|
||||
else if (bIsRecursion)
|
||||
{
|
||||
GetFiles2(sSpec, oArray, bIsRecursion);
|
||||
}
|
||||
}
|
||||
} while( FindNextFileW( hRes, &oFD ) );
|
||||
FindClose( hRes );
|
||||
#endif
|
||||
|
||||
#ifdef __linux__
|
||||
BYTE* pUtf8 = NULL;
|
||||
LONG lLen = 0;
|
||||
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strDirectory.c_str(), strDirectory.length(), pUtf8, lLen, false);
|
||||
DIR *dp;
|
||||
struct dirent *dirp;
|
||||
if((dp = opendir((char*)pUtf8)) != NULL)
|
||||
{
|
||||
while ((dirp = readdir(dp)) != NULL)
|
||||
{
|
||||
int nType = 0;
|
||||
if(DT_REG == dirp->d_type)
|
||||
nType = 2;
|
||||
else if (DT_DIR == dirp->d_type)
|
||||
nType = 1;
|
||||
else if (DT_UNKNOWN == dirp->d_type)
|
||||
{
|
||||
// XFS problem
|
||||
struct stat buff;
|
||||
std::string sTmp = std::string((char*)pUtf8) + "/" + std::string(dirp->d_name);
|
||||
stat(sTmp.c_str(), &buff);
|
||||
if (S_ISREG(buff.st_mode))
|
||||
nType = 2;
|
||||
else if (S_ISDIR(buff.st_mode))
|
||||
nType = 1;
|
||||
}
|
||||
BYTE* pUtf8 = NULL;
|
||||
LONG lLen = 0;
|
||||
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strDirectory.c_str(), strDirectory.length(), pUtf8, lLen, false);
|
||||
DIR *dp;
|
||||
struct dirent *dirp;
|
||||
if((dp = opendir((char*)pUtf8)) != NULL)
|
||||
{
|
||||
while ((dirp = readdir(dp)) != NULL)
|
||||
{
|
||||
int nType = 0;
|
||||
if(DT_REG == dirp->d_type)
|
||||
nType = 2;
|
||||
else if (DT_DIR == dirp->d_type)
|
||||
nType = 1;
|
||||
else if (DT_UNKNOWN == dirp->d_type)
|
||||
{
|
||||
// XFS problem
|
||||
struct stat buff;
|
||||
std::string sTmp = std::string((char*)pUtf8) + "/" + std::string(dirp->d_name);
|
||||
stat(sTmp.c_str(), &buff);
|
||||
if (S_ISREG(buff.st_mode))
|
||||
nType = 2;
|
||||
else if (S_ISDIR(buff.st_mode))
|
||||
nType = 1;
|
||||
}
|
||||
|
||||
if (2 == nType)
|
||||
{
|
||||
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
|
||||
oArray.push_back(strDirectory + L"/" + sName);
|
||||
}
|
||||
if (2 == nType)
|
||||
{
|
||||
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
|
||||
oArray.push_back(strDirectory + L"/" + sName);
|
||||
}
|
||||
|
||||
if (bIsRecursion && (1 == nType))
|
||||
{
|
||||
if(dirp->d_name[0] != '.')
|
||||
{
|
||||
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
|
||||
GetFiles2(strDirectory + L"/" + sName, oArray, bIsRecursion);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dp);
|
||||
}
|
||||
delete [] pUtf8;
|
||||
if (bIsRecursion && (1 == nType))
|
||||
{
|
||||
if(dirp->d_name[0] != '.')
|
||||
{
|
||||
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
|
||||
GetFiles2(strDirectory + L"/" + sName, oArray, bIsRecursion);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dp);
|
||||
}
|
||||
delete [] pUtf8;
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(MAC) || defined (_IOS)
|
||||
BYTE* pUtf8 = NULL;
|
||||
LONG lLen = 0;
|
||||
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strDirectory.c_str(), strDirectory.length(), pUtf8, lLen, false);
|
||||
DIR *dp;
|
||||
struct dirent *dirp;
|
||||
if((dp = opendir((char*)pUtf8)) != NULL)
|
||||
{
|
||||
while ((dirp = readdir(dp)) != NULL)
|
||||
{
|
||||
if(DT_REG == dirp->d_type)
|
||||
{
|
||||
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
|
||||
oArray.push_back(strDirectory + L"/" + sName);
|
||||
}
|
||||
|
||||
if (bIsRecursion && DT_DIR == dirp->d_type)
|
||||
{
|
||||
if(dirp->d_name[0] != '.')
|
||||
{
|
||||
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
|
||||
GetFiles2(strDirectory + L"/" + sName, oArray, bIsRecursion);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dp);
|
||||
}
|
||||
delete [] pUtf8;
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
BYTE* pUtf8 = NULL;
|
||||
LONG lLen = 0;
|
||||
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strDirectory.c_str(), strDirectory.length(), pUtf8, lLen, false);
|
||||
DIR *dp;
|
||||
struct dirent *dirp;
|
||||
if((dp = opendir((char*)pUtf8)) != NULL)
|
||||
{
|
||||
while ((dirp = readdir(dp)) != NULL)
|
||||
{
|
||||
if(DT_REG == dirp->d_type)
|
||||
{
|
||||
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
|
||||
oArray.push_back(strDirectory + L"/" + sName);
|
||||
}
|
||||
|
||||
std::vector<std::wstring> GetFiles(std::wstring strDirectory, bool bIsRecursion)
|
||||
if (bIsRecursion && DT_DIR == dirp->d_type)
|
||||
{
|
||||
if(dirp->d_name[0] != '.')
|
||||
{
|
||||
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
|
||||
GetFiles2(strDirectory + L"/" + sName, oArray, bIsRecursion);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dp);
|
||||
}
|
||||
delete [] pUtf8;
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
|
||||
std::vector<std::wstring> GetFiles(std::wstring strDirectory, bool bIsRecursion)
|
||||
{
|
||||
std::vector<std::wstring> oArray;
|
||||
|
||||
if (!strDirectory.empty())
|
||||
{
|
||||
{
|
||||
GetFiles2(strDirectory, oArray, bIsRecursion);
|
||||
}
|
||||
return oArray;
|
||||
}
|
||||
std::vector<std::wstring> GetDirectories(std::wstring strDirectory)
|
||||
std::vector<std::wstring> GetDirectories(std::wstring strDirectory)
|
||||
{
|
||||
std::vector<std::wstring> oArray;
|
||||
|
||||
if (strDirectory.empty()) return oArray;
|
||||
|
||||
#if defined(_WIN32) || defined (_WIN64)
|
||||
WIN32_FIND_DATAW oFD;
|
||||
WIN32_FIND_DATAW oFD;
|
||||
|
||||
std::wstring sSpec = strDirectory + L"\\*";
|
||||
HANDLE hRes = FindFirstFileW( sSpec.c_str(), &oFD );
|
||||
if( INVALID_HANDLE_VALUE == hRes )
|
||||
return oArray;
|
||||
do
|
||||
do
|
||||
{
|
||||
sSpec = oFD.cFileName;
|
||||
if (sSpec != L"." && sSpec != L"..")
|
||||
{
|
||||
sSpec = strDirectory + L"\\" + sSpec;
|
||||
if( oFD.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
|
||||
if( oFD.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
|
||||
{
|
||||
oArray.push_back(sSpec);
|
||||
}
|
||||
}
|
||||
} while( FindNextFileW( hRes, &oFD ) );
|
||||
} while( FindNextFileW( hRes, &oFD ) );
|
||||
FindClose( hRes );
|
||||
#elif __linux__
|
||||
BYTE* pUtf8 = NULL;
|
||||
LONG lLen = 0;
|
||||
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strDirectory.c_str(), strDirectory.length(), pUtf8, lLen, false);
|
||||
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strDirectory.c_str(), strDirectory.length(), pUtf8, lLen, false);
|
||||
DIR *dp;
|
||||
struct dirent *dirp;
|
||||
if((dp = opendir((char*)pUtf8)) != NULL)
|
||||
@ -270,54 +270,54 @@ namespace NSDirectory
|
||||
}
|
||||
delete [] pUtf8;
|
||||
#elif MAC
|
||||
BYTE* pUtf8 = NULL;
|
||||
LONG lLen = 0;
|
||||
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strDirectory.c_str(), strDirectory.length(), pUtf8, lLen, false);
|
||||
DIR *dp;
|
||||
struct dirent *dirp;
|
||||
if((dp = opendir((char*)pUtf8)) != NULL)
|
||||
{
|
||||
while ((dirp = readdir(dp)) != NULL)
|
||||
{
|
||||
if(DT_DIR == dirp->d_type)
|
||||
{
|
||||
if(dirp->d_name[0] != '.')
|
||||
{
|
||||
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
|
||||
oArray.push_back(strDirectory + L"/" + sName);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dp);
|
||||
}
|
||||
delete [] pUtf8;
|
||||
BYTE* pUtf8 = NULL;
|
||||
LONG lLen = 0;
|
||||
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strDirectory.c_str(), strDirectory.length(), pUtf8, lLen, false);
|
||||
DIR *dp;
|
||||
struct dirent *dirp;
|
||||
if((dp = opendir((char*)pUtf8)) != NULL)
|
||||
{
|
||||
while ((dirp = readdir(dp)) != NULL)
|
||||
{
|
||||
if(DT_DIR == dirp->d_type)
|
||||
{
|
||||
if(dirp->d_name[0] != '.')
|
||||
{
|
||||
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
|
||||
oArray.push_back(strDirectory + L"/" + sName);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dp);
|
||||
}
|
||||
delete [] pUtf8;
|
||||
#endif
|
||||
return oArray;
|
||||
}
|
||||
bool Exists(const std::wstring& strDirectory)
|
||||
bool Exists(const std::wstring& strDirectory)
|
||||
{
|
||||
#if defined(_WIN32) || defined (_WIN64)
|
||||
DWORD dwAttrib = ::GetFileAttributesW(strDirectory.c_str());
|
||||
return (dwAttrib != INVALID_FILE_ATTRIBUTES && 0 != (dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
|
||||
#elif __linux__
|
||||
BYTE* pUtf8 = NULL;
|
||||
LONG lLen = 0;
|
||||
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strDirectory.c_str(), strDirectory.length(), pUtf8, lLen, false);
|
||||
bool bRes = is_directory_exist((char*)pUtf8);
|
||||
delete [] pUtf8;
|
||||
return bRes;
|
||||
BYTE* pUtf8 = NULL;
|
||||
LONG lLen = 0;
|
||||
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strDirectory.c_str(), strDirectory.length(), pUtf8, lLen, false);
|
||||
bool bRes = is_directory_exist((char*)pUtf8);
|
||||
delete [] pUtf8;
|
||||
return bRes;
|
||||
#elif MAC
|
||||
BYTE* pUtf8 = NULL;
|
||||
LONG lLen = 0;
|
||||
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strDirectory.c_str(), strDirectory.length(), pUtf8, lLen, false);
|
||||
struct stat st;
|
||||
bool bRes = is_directory_exist((char*)pUtf8);
|
||||
delete [] pUtf8;
|
||||
return bRes;
|
||||
BYTE* pUtf8 = NULL;
|
||||
LONG lLen = 0;
|
||||
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strDirectory.c_str(), strDirectory.length(), pUtf8, lLen, false);
|
||||
struct stat st;
|
||||
bool bRes = is_directory_exist((char*)pUtf8);
|
||||
delete [] pUtf8;
|
||||
return bRes;
|
||||
#endif
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
bool CreateDirectory(const std::wstring& strDirectory)
|
||||
bool CreateDirectory(const std::wstring& strDirectory)
|
||||
{
|
||||
if (Exists(strDirectory) == true) return true;
|
||||
|
||||
@ -326,7 +326,7 @@ namespace NSDirectory
|
||||
#else
|
||||
BYTE* pUtf8 = NULL;
|
||||
LONG lLen = 0;
|
||||
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strDirectory.c_str(), strDirectory.length(), pUtf8, lLen, false);
|
||||
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strDirectory.c_str(), strDirectory.length(), pUtf8, lLen, false);
|
||||
struct stat st;
|
||||
int nRes = 0;
|
||||
if (stat((char*)pUtf8, &st) == -1) {
|
||||
@ -336,7 +336,7 @@ namespace NSDirectory
|
||||
return 0 == nRes;
|
||||
#endif
|
||||
}
|
||||
bool CreateDirectories(const std::wstring& strDirectory)
|
||||
bool CreateDirectories(const std::wstring& strDirectory)
|
||||
{
|
||||
if (Exists(strDirectory) == true) return true;
|
||||
|
||||
@ -367,119 +367,119 @@ namespace NSDirectory
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
bool CopyDirectory(const std::wstring& strSrc, const std::wstring& strDst, bool bIsRecursion)
|
||||
{
|
||||
if (!NSDirectory::Exists(strDst))
|
||||
NSDirectory::CreateDirectory(strDst);
|
||||
bool CopyDirectory(const std::wstring& strSrc, const std::wstring& strDst, bool bIsRecursion)
|
||||
{
|
||||
if (!NSDirectory::Exists(strDst))
|
||||
NSDirectory::CreateDirectory(strDst);
|
||||
|
||||
#ifdef WIN32
|
||||
WIN32_FIND_DATAW oFD;
|
||||
WIN32_FIND_DATAW oFD;
|
||||
|
||||
std::wstring sSpec = strSrc + L"\\*.*";
|
||||
HANDLE hRes = FindFirstFileW( sSpec.c_str(), &oFD );
|
||||
if( INVALID_HANDLE_VALUE == hRes )
|
||||
return false;
|
||||
do
|
||||
{
|
||||
sSpec = oFD.cFileName;
|
||||
if (sSpec != L"." && sSpec != L"..")
|
||||
{
|
||||
if( !( oFD.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) )
|
||||
{
|
||||
NSFile::CFileBinary::Copy(strSrc + L"/" + sSpec, strDst + L"/" + sSpec);
|
||||
}
|
||||
else if (bIsRecursion)
|
||||
{
|
||||
CopyDirectory(strSrc + L"/" + sSpec, strDst + L"/" + sSpec, bIsRecursion);
|
||||
}
|
||||
}
|
||||
} while( FindNextFileW( hRes, &oFD ) );
|
||||
FindClose( hRes );
|
||||
return true;
|
||||
std::wstring sSpec = strSrc + L"\\*.*";
|
||||
HANDLE hRes = FindFirstFileW( sSpec.c_str(), &oFD );
|
||||
if( INVALID_HANDLE_VALUE == hRes )
|
||||
return false;
|
||||
do
|
||||
{
|
||||
sSpec = oFD.cFileName;
|
||||
if (sSpec != L"." && sSpec != L"..")
|
||||
{
|
||||
if( !( oFD.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) )
|
||||
{
|
||||
NSFile::CFileBinary::Copy(strSrc + L"/" + sSpec, strDst + L"/" + sSpec);
|
||||
}
|
||||
else if (bIsRecursion)
|
||||
{
|
||||
CopyDirectory(strSrc + L"/" + sSpec, strDst + L"/" + sSpec, bIsRecursion);
|
||||
}
|
||||
}
|
||||
} while( FindNextFileW( hRes, &oFD ) );
|
||||
FindClose( hRes );
|
||||
return true;
|
||||
#endif
|
||||
|
||||
#ifdef __linux__
|
||||
BYTE* pUtf8 = NULL;
|
||||
LONG lLen = 0;
|
||||
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strSrc.c_str(), strSrc.length(), pUtf8, lLen, false);
|
||||
DIR *dp;
|
||||
struct dirent *dirp;
|
||||
if((dp = opendir((char*)pUtf8)) != NULL)
|
||||
{
|
||||
while ((dirp = readdir(dp)) != NULL)
|
||||
{
|
||||
int nType = 0;
|
||||
if(DT_REG == dirp->d_type)
|
||||
nType = 2;
|
||||
else if (DT_DIR == dirp->d_type)
|
||||
nType = 1;
|
||||
else if (DT_UNKNOWN == dirp->d_type)
|
||||
{
|
||||
// XFS problem
|
||||
struct stat buff;
|
||||
std::string sTmp = std::string((char*)pUtf8) + "/" + std::string(dirp->d_name);
|
||||
stat(sTmp.c_str(), &buff);
|
||||
if (S_ISREG(buff.st_mode))
|
||||
nType = 2;
|
||||
else if (S_ISDIR(buff.st_mode))
|
||||
nType = 1;
|
||||
}
|
||||
BYTE* pUtf8 = NULL;
|
||||
LONG lLen = 0;
|
||||
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strSrc.c_str(), strSrc.length(), pUtf8, lLen, false);
|
||||
DIR *dp;
|
||||
struct dirent *dirp;
|
||||
if((dp = opendir((char*)pUtf8)) != NULL)
|
||||
{
|
||||
while ((dirp = readdir(dp)) != NULL)
|
||||
{
|
||||
int nType = 0;
|
||||
if(DT_REG == dirp->d_type)
|
||||
nType = 2;
|
||||
else if (DT_DIR == dirp->d_type)
|
||||
nType = 1;
|
||||
else if (DT_UNKNOWN == dirp->d_type)
|
||||
{
|
||||
// XFS problem
|
||||
struct stat buff;
|
||||
std::string sTmp = std::string((char*)pUtf8) + "/" + std::string(dirp->d_name);
|
||||
stat(sTmp.c_str(), &buff);
|
||||
if (S_ISREG(buff.st_mode))
|
||||
nType = 2;
|
||||
else if (S_ISDIR(buff.st_mode))
|
||||
nType = 1;
|
||||
}
|
||||
|
||||
if (2 == nType)
|
||||
{
|
||||
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
|
||||
NSFile::CFileBinary::Copy(strSrc + L"/" + sName, strDst + L"/" + sName);
|
||||
}
|
||||
if (2 == nType)
|
||||
{
|
||||
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
|
||||
NSFile::CFileBinary::Copy(strSrc + L"/" + sName, strDst + L"/" + sName);
|
||||
}
|
||||
|
||||
if (bIsRecursion && (1 == nType))
|
||||
{
|
||||
if(dirp->d_name[0] != '.')
|
||||
{
|
||||
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
|
||||
CopyDirectory(strSrc + L"/" + sName, strDst + L"/" + sName, bIsRecursion);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dp);
|
||||
}
|
||||
delete [] pUtf8;
|
||||
return true;
|
||||
if (bIsRecursion && (1 == nType))
|
||||
{
|
||||
if(dirp->d_name[0] != '.')
|
||||
{
|
||||
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
|
||||
CopyDirectory(strSrc + L"/" + sName, strDst + L"/" + sName, bIsRecursion);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dp);
|
||||
}
|
||||
delete [] pUtf8;
|
||||
return true;
|
||||
#endif
|
||||
|
||||
#if defined(MAC) || defined (_IOS)
|
||||
BYTE* pUtf8 = NULL;
|
||||
LONG lLen = 0;
|
||||
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strSrc.c_str(), strSrc.length(), pUtf8, lLen, false);
|
||||
DIR *dp;
|
||||
struct dirent *dirp;
|
||||
if((dp = opendir((char*)pUtf8)) != NULL)
|
||||
{
|
||||
while ((dirp = readdir(dp)) != NULL)
|
||||
{
|
||||
if(DT_REG == dirp->d_type)
|
||||
{
|
||||
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
|
||||
NSFile::CFileBinary::Copy(strSrc + L"/" + sName, strDst + L"/" + sName);
|
||||
}
|
||||
BYTE* pUtf8 = NULL;
|
||||
LONG lLen = 0;
|
||||
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strSrc.c_str(), strSrc.length(), pUtf8, lLen, false);
|
||||
DIR *dp;
|
||||
struct dirent *dirp;
|
||||
if((dp = opendir((char*)pUtf8)) != NULL)
|
||||
{
|
||||
while ((dirp = readdir(dp)) != NULL)
|
||||
{
|
||||
if(DT_REG == dirp->d_type)
|
||||
{
|
||||
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
|
||||
NSFile::CFileBinary::Copy(strSrc + L"/" + sName, strDst + L"/" + sName);
|
||||
}
|
||||
|
||||
if (bIsRecursion && DT_DIR == dirp->d_type)
|
||||
{
|
||||
if(dirp->d_name[0] != '.')
|
||||
{
|
||||
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
|
||||
CopyDirectory(strSrc + L"/" + sName, strDst + L"/" + sName, bIsRecursion);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dp);
|
||||
}
|
||||
delete [] pUtf8;
|
||||
return true;
|
||||
if (bIsRecursion && DT_DIR == dirp->d_type)
|
||||
{
|
||||
if(dirp->d_name[0] != '.')
|
||||
{
|
||||
std::wstring sName = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)dirp->d_name, strlen(dirp->d_name));
|
||||
CopyDirectory(strSrc + L"/" + sName, strDst + L"/" + sName, bIsRecursion);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dp);
|
||||
}
|
||||
delete [] pUtf8;
|
||||
return true;
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
void DeleteDirectory(const std::wstring& strDirectory, bool deleteRoot)
|
||||
return false;
|
||||
}
|
||||
void DeleteDirectory(const std::wstring& strDirectory, bool deleteRoot)
|
||||
{
|
||||
if (strDirectory.empty()) return;
|
||||
|
||||
@ -498,22 +498,22 @@ namespace NSDirectory
|
||||
#elif __linux__
|
||||
BYTE* pUtf8 = NULL;
|
||||
LONG lLen = 0;
|
||||
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strDirectory.c_str(), strDirectory.length(), pUtf8, lLen, false);
|
||||
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strDirectory.c_str(), strDirectory.length(), pUtf8, lLen, false);
|
||||
rmdir((char*)pUtf8);
|
||||
delete [] pUtf8;
|
||||
|
||||
if (deleteRoot = false)CreateDirectory(strDirectory);
|
||||
#elif MAC
|
||||
BYTE* pUtf8 = NULL;
|
||||
LONG lLen = 0;
|
||||
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strDirectory.c_str(), strDirectory.length(), pUtf8, lLen, false);
|
||||
rmdir((char*)pUtf8);
|
||||
delete [] pUtf8;
|
||||
|
||||
if (deleteRoot = false)CreateDirectory(strDirectory);
|
||||
BYTE* pUtf8 = NULL;
|
||||
LONG lLen = 0;
|
||||
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strDirectory.c_str(), strDirectory.length(), pUtf8, lLen, false);
|
||||
rmdir((char*)pUtf8);
|
||||
delete [] pUtf8;
|
||||
|
||||
if (deleteRoot = false)CreateDirectory(strDirectory);
|
||||
#endif
|
||||
}
|
||||
std::wstring GetFolderPath(const std::wstring& wsFolderPath)
|
||||
std::wstring GetFolderPath(const std::wstring& wsFolderPath)
|
||||
{
|
||||
int n1 = (int)wsFolderPath.rfind('\\');
|
||||
if (n1 < 0)
|
||||
@ -527,64 +527,64 @@ namespace NSDirectory
|
||||
}
|
||||
return wsFolderPath.substr(0, n1);
|
||||
}
|
||||
std::wstring CreateTempFileWithUniqueName (const std::wstring & strFolderPathRoot, std::wstring Prefix)
|
||||
{
|
||||
return NSFile::CFileBinary::CreateTempFileWithUniqueName(strFolderPathRoot, Prefix);
|
||||
}
|
||||
std::wstring CreateDirectoryWithUniqueName (const std::wstring & strFolderPathRoot)
|
||||
{
|
||||
std::wstring CreateTempFileWithUniqueName (const std::wstring & strFolderPathRoot, std::wstring Prefix)
|
||||
{
|
||||
return NSFile::CFileBinary::CreateTempFileWithUniqueName(strFolderPathRoot, Prefix);
|
||||
}
|
||||
std::wstring CreateDirectoryWithUniqueName (const std::wstring & strFolderPathRoot)
|
||||
{
|
||||
#if defined(_WIN32) || defined (_WIN64)
|
||||
UUID uuid;
|
||||
RPC_WSTR str_uuid;
|
||||
UuidCreate (&uuid);
|
||||
UuidToStringW (&uuid, &str_uuid);
|
||||
std::wstring pcTemplate = strFolderPathRoot + FILE_SEPARATOR_STR;
|
||||
pcTemplate += (wchar_t *) str_uuid;
|
||||
RpcStringFreeW (&str_uuid);
|
||||
UUID uuid;
|
||||
RPC_WSTR str_uuid;
|
||||
UuidCreate (&uuid);
|
||||
UuidToStringW (&uuid, &str_uuid);
|
||||
std::wstring pcTemplate = strFolderPathRoot + FILE_SEPARATOR_STR;
|
||||
pcTemplate += (wchar_t *) str_uuid;
|
||||
RpcStringFreeW (&str_uuid);
|
||||
|
||||
int attemps = 10;
|
||||
while (!CreateDirectory(pcTemplate))
|
||||
{
|
||||
UuidCreate (&uuid);
|
||||
UuidToStringW (&uuid, &str_uuid);
|
||||
pcTemplate = strFolderPathRoot + FILE_SEPARATOR_STR;
|
||||
pcTemplate += (wchar_t *) str_uuid;
|
||||
RpcStringFreeW (&str_uuid);
|
||||
attemps--;
|
||||
int attemps = 10;
|
||||
while (!CreateDirectory(pcTemplate))
|
||||
{
|
||||
UuidCreate (&uuid);
|
||||
UuidToStringW (&uuid, &str_uuid);
|
||||
pcTemplate = strFolderPathRoot + FILE_SEPARATOR_STR;
|
||||
pcTemplate += (wchar_t *) str_uuid;
|
||||
RpcStringFreeW (&str_uuid);
|
||||
attemps--;
|
||||
|
||||
if (0 == attemps)
|
||||
{
|
||||
pcTemplate = L"";
|
||||
break;
|
||||
}
|
||||
}
|
||||
return pcTemplate;
|
||||
if (0 == attemps)
|
||||
{
|
||||
pcTemplate = L"";
|
||||
break;
|
||||
}
|
||||
}
|
||||
return pcTemplate;
|
||||
#else
|
||||
std::string pcTemplate = U_TO_UTF8(strFolderPathRoot) + "/ascXXXXXX";
|
||||
char *pcRes = mkdtemp(const_cast <char *> (pcTemplate.c_str()));
|
||||
if (NULL == pcRes)
|
||||
return L"";
|
||||
std::string pcTemplate = U_TO_UTF8(strFolderPathRoot) + "/ascXXXXXX";
|
||||
char *pcRes = mkdtemp(const_cast <char *> (pcTemplate.c_str()));
|
||||
if (NULL == pcRes)
|
||||
return L"";
|
||||
|
||||
std::string sRes = pcRes;
|
||||
return NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)sRes.c_str(), (LONG)sRes.length());
|
||||
std::string sRes = pcRes;
|
||||
return NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)sRes.c_str(), (LONG)sRes.length());
|
||||
#endif
|
||||
}
|
||||
std::wstring GetTempPath()
|
||||
{
|
||||
return NSFile::CFileBinary::GetTempPath();
|
||||
}
|
||||
}
|
||||
std::wstring GetTempPath()
|
||||
{
|
||||
return NSFile::CFileBinary::GetTempPath();
|
||||
}
|
||||
|
||||
int GetFilesCount(const std::wstring& path, const bool& recursive)
|
||||
{
|
||||
std::vector<std::wstring> arrFiles = NSDirectory::GetFiles(path, recursive);
|
||||
int GetFilesCount(const std::wstring& path, const bool& recursive)
|
||||
{
|
||||
std::vector<std::wstring> arrFiles = NSDirectory::GetFiles(path, recursive);
|
||||
#if defined(_WIN32) || defined (_WIN64)
|
||||
return (int)arrFiles.size();
|
||||
return (int)arrFiles.size();
|
||||
#endif
|
||||
return (int)arrFiles.size() + 1;
|
||||
// ???
|
||||
}
|
||||
bool PathIsDirectory(const std::wstring& pathName)
|
||||
{
|
||||
return Exists(pathName);
|
||||
}
|
||||
return (int)arrFiles.size() + 1;
|
||||
// ???
|
||||
}
|
||||
bool PathIsDirectory(const std::wstring& pathName)
|
||||
{
|
||||
return Exists(pathName);
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,41 +46,45 @@
|
||||
#include "File.h"
|
||||
|
||||
#ifndef FILE_SEPARATOR
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#define FILE_SEPARATOR
|
||||
#define FILE_SEPARATOR_CHAR '\\'
|
||||
#define FILE_SEPARATOR_STR L"\\"
|
||||
#define FILE_SEPARATOR_STRA "\\"
|
||||
#else
|
||||
#define FILE_SEPARATOR
|
||||
#define FILE_SEPARATOR_CHAR '/'
|
||||
#define FILE_SEPARATOR_STR L"/"
|
||||
#define FILE_SEPARATOR_STRA "/"
|
||||
#endif
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#define FILE_SEPARATOR
|
||||
#define FILE_SEPARATOR_CHAR '\\'
|
||||
#define FILE_SEPARATOR_STR L"\\"
|
||||
#define FILE_SEPARATOR_STRA "\\"
|
||||
#else
|
||||
#define FILE_SEPARATOR
|
||||
#define FILE_SEPARATOR_CHAR '/'
|
||||
#define FILE_SEPARATOR_STR L"/"
|
||||
#define FILE_SEPARATOR_STRA "/"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "../../Common/kernel_config.h"
|
||||
namespace NSDirectory
|
||||
{
|
||||
KERNEL_DECL std::vector<std::wstring> GetFiles(std::wstring strDirectory, bool bIsRecursion = false);
|
||||
KERNEL_DECL void GetFiles2(std::wstring strDirectory, std::vector<std::wstring>& oArray, bool bIsRecursion = false);
|
||||
|
||||
KERNEL_DECL std::vector<std::wstring> GetDirectories(std::wstring strDirectory);
|
||||
KERNEL_DECL bool Exists(const std::wstring& strDirectory);
|
||||
KERNEL_DECL bool CreateDirectory(const std::wstring& strDirectory);
|
||||
KERNEL_DECL bool CreateDirectories(const std::wstring& strDirectory);
|
||||
KERNEL_DECL bool CopyDirectory(const std::wstring& strSrc, const std::wstring& strDst, bool bIsRecursion = true);
|
||||
KERNEL_DECL void DeleteDirectory(const std::wstring& strDirectory, bool deleteRoot = true);
|
||||
KERNEL_DECL std::wstring GetFolderPath(const std::wstring& wsFolderPath);
|
||||
KERNEL_DECL std::wstring CreateTempFileWithUniqueName (const std::wstring & strFolderPathRoot, std::wstring Prefix);
|
||||
KERNEL_DECL std::wstring CreateDirectoryWithUniqueName (const std::wstring & strFolderPathRoot);
|
||||
KERNEL_DECL std::wstring GetTempPath();
|
||||
|
||||
KERNEL_DECL int GetFilesCount(const std::wstring& path, const bool& recursive);
|
||||
KERNEL_DECL bool PathIsDirectory(const std::wstring& pathName);
|
||||
|
||||
#ifdef _IOS
|
||||
KERNEL_DECL void GetFiles2_ios(std::wstring strDirectory, std::vector<std::wstring>& oArray, bool bIsRecursion);
|
||||
namespace NSIOS
|
||||
{
|
||||
KERNEL_DECL void GetFiles2(std::wstring strDirectory, std::vector<std::wstring>& oArray, bool bIsRecursion = false);
|
||||
}
|
||||
#endif
|
||||
KERNEL_DECL void GetFiles2(std::wstring strDirectory, std::vector<std::wstring>& oArray, bool bIsRecursion = false);
|
||||
|
||||
KERNEL_DECL std::vector<std::wstring> GetFiles(std::wstring strDirectory, bool bIsRecursion = false);
|
||||
KERNEL_DECL std::vector<std::wstring> GetDirectories(std::wstring strDirectory);
|
||||
KERNEL_DECL bool Exists(const std::wstring& strDirectory);
|
||||
KERNEL_DECL bool CreateDirectory(const std::wstring& strDirectory);
|
||||
KERNEL_DECL bool CreateDirectories(const std::wstring& strDirectory);
|
||||
KERNEL_DECL bool CopyDirectory(const std::wstring& strSrc, const std::wstring& strDst, bool bIsRecursion = true);
|
||||
KERNEL_DECL void DeleteDirectory(const std::wstring& strDirectory, bool deleteRoot = true);
|
||||
KERNEL_DECL std::wstring GetFolderPath(const std::wstring& wsFolderPath);
|
||||
KERNEL_DECL std::wstring CreateTempFileWithUniqueName (const std::wstring & strFolderPathRoot, std::wstring Prefix);
|
||||
KERNEL_DECL std::wstring CreateDirectoryWithUniqueName (const std::wstring & strFolderPathRoot);
|
||||
KERNEL_DECL std::wstring GetTempPath();
|
||||
|
||||
KERNEL_DECL int GetFilesCount(const std::wstring& path, const bool& recursive);
|
||||
KERNEL_DECL bool PathIsDirectory(const std::wstring& pathName);
|
||||
}
|
||||
|
||||
#endif //_BUILD_DIRECTORY_CROSSPLATFORM_H_
|
||||
|
||||
@ -45,10 +45,6 @@
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
#ifdef _IOS
|
||||
const char* fileSystemRepresentation(const std::wstring& sFileName);
|
||||
#endif
|
||||
|
||||
#ifdef _MAC
|
||||
#include <mach-o/dyld.h>
|
||||
#endif
|
||||
@ -624,7 +620,7 @@ namespace NSFile
|
||||
}
|
||||
}
|
||||
|
||||
lOutputCount = pUnicodeString - pStart;
|
||||
lOutputCount = (LONG)(pUnicodeString - pStart);
|
||||
*pUnicodeString++ = 0;
|
||||
}
|
||||
void CUtf8Converter::GetUnicodeStringFromUTF8WithHHHH( const BYTE* pBuffer, LONG lCount, wchar_t*& pUnicodes, LONG& lOutputCount )
|
||||
@ -959,64 +955,15 @@ namespace NSFile
|
||||
return (unsigned long)m_lFilePosition;
|
||||
}
|
||||
|
||||
#ifdef _IOS
|
||||
|
||||
bool CFileBinary::OpenFile(const std::wstring& sFileName, bool bRewrite)
|
||||
{
|
||||
m_pFile = fopen(fileSystemRepresentation(sFileName), bRewrite ? "rb+" : "rb");
|
||||
|
||||
if (NULL == m_pFile) {
|
||||
#if DEBUG
|
||||
// printf ("NSFile::OpenFile - error open file : %s\n",strerror(errno));
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
fseek(m_pFile, 0, SEEK_END);
|
||||
m_lFileSize = ftell(m_pFile);
|
||||
fseek(m_pFile, 0, SEEK_SET);
|
||||
|
||||
m_lFilePosition = 0;
|
||||
|
||||
if (0 < sFileName.length())
|
||||
{
|
||||
if (((wchar_t)'/') == sFileName.c_str()[sFileName.length() - 1])
|
||||
m_lFileSize = 0x7FFFFFFF;
|
||||
}
|
||||
|
||||
unsigned int err = 0x7FFFFFFF;
|
||||
unsigned int cur = (unsigned int)m_lFileSize;
|
||||
if (err == cur)
|
||||
{
|
||||
CloseFile();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CFileBinary::CreateFileW(const std::wstring& sFileName)
|
||||
{
|
||||
m_pFile = fopen(fileSystemRepresentation(sFileName), "wb");
|
||||
|
||||
if (NULL == m_pFile) {
|
||||
#if DEBUG
|
||||
// printf ("NSFile::CreateFileW - error create file : %s\n",strerror(errno));
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
m_lFilePosition = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
bool CFileBinary::OpenFile(const std::wstring& sFileName, bool bRewrite)
|
||||
{
|
||||
#if defined(_WIN32) || defined(_WIN32_WCE) || defined(_WIN64)
|
||||
if ( NULL == (m_pFile = _wfsopen( sFileName.c_str(), bRewrite ? L"rb+" : L"rb", _SH_DENYNO)))
|
||||
return false;
|
||||
#else
|
||||
#ifdef _IOS
|
||||
std::string sFilePath = NSIOS::GetFileSystemRepresentation(sFileName);
|
||||
m_pFile = fopen((char*)sFilePath.c_str(), bRewrite ? "rb+" : "rb");
|
||||
#else
|
||||
BYTE* pUtf8 = NULL;
|
||||
LONG lLen = 0;
|
||||
@ -1027,9 +974,10 @@ namespace NSFile
|
||||
return false;
|
||||
|
||||
m_pFile = fopen((char*)pUtf8, bRewrite ? "rb+" : "rb");
|
||||
|
||||
delete [] pUtf8;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (NULL == m_pFile)
|
||||
return false;
|
||||
|
||||
@ -1061,12 +1009,17 @@ namespace NSFile
|
||||
#if defined(_WIN32) || defined(_WIN32_WCE) || defined(_WIN64)
|
||||
if ( 0 != _wfopen_s(&m_pFile, sFileName.c_str(), L"wb"))
|
||||
return false;
|
||||
#else
|
||||
#ifdef _IOS
|
||||
std::string sFilePath = NSIOS::GetFileSystemRepresentation(sFileName);
|
||||
m_pFile = fopen((char*)sFilePath.c_str(), "wb");
|
||||
#else
|
||||
BYTE* pUtf8 = NULL;
|
||||
LONG lLen = 0;
|
||||
CUtf8Converter::GetUtf8StringFromUnicode(sFileName.c_str(), sFileName.length(), pUtf8, lLen, false);
|
||||
m_pFile = fopen((char*)pUtf8, "wb");
|
||||
delete [] pUtf8;
|
||||
#endif
|
||||
#endif
|
||||
if (NULL == m_pFile)
|
||||
return false;
|
||||
@ -1075,8 +1028,6 @@ namespace NSFile
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
bool CFileBinary::CreateFile(const std::wstring& sFileName)
|
||||
{
|
||||
return CreateFileW(sFileName);
|
||||
@ -1414,6 +1365,12 @@ namespace NSFile
|
||||
close(dst);
|
||||
return (-1 != read_size_marker) ? true : false;
|
||||
#else
|
||||
|
||||
#ifdef _WIN32
|
||||
if (0 != ::CopyFileW(strSrc.c_str(), strDst.c_str(), 1))
|
||||
return true;
|
||||
#endif
|
||||
|
||||
std::ifstream src;
|
||||
std::ofstream dst;
|
||||
|
||||
|
||||
@ -201,6 +201,13 @@ namespace NSFile
|
||||
static bool Encode(BYTE* pDataSrc, int nLenSrc, char*& pDataDst, int& nLenDst, DWORD dwFlags = NSBase64::B64_BASE64_FLAG_NONE);
|
||||
static bool Decode(const char* pDataSrc, int nLenSrc, BYTE*& pDataDst, int& nLenDst);
|
||||
};
|
||||
|
||||
#ifdef _IOS
|
||||
namespace NSIOS
|
||||
{
|
||||
KERNEL_DECL std::string GetFileSystemRepresentation(const std::wstring& path);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
namespace NSFile
|
||||
|
||||
@ -31,21 +31,49 @@
|
||||
*/
|
||||
|
||||
#ifdef __OBJC__
|
||||
#import <CoreFoundation/CoreFoundation.h>
|
||||
#import <CoreFoundation/CoreFoundation.h>
|
||||
#else
|
||||
#include <objc/objc.h>
|
||||
#include <objc/objc.h>
|
||||
#endif
|
||||
|
||||
#include "./File.h"
|
||||
#include <vector>
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
const char* fileSystemRepresentation(const std::wstring& sFileName)
|
||||
namespace NSFile
|
||||
{
|
||||
if (sFileName.empty())
|
||||
return NULL;
|
||||
NSString *path = [[NSString alloc] initWithBytes:(char*)sFileName.data()
|
||||
length:sFileName.size()* sizeof(wchar_t)
|
||||
encoding:CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingUTF32LE)];
|
||||
namespace NSIOS
|
||||
{
|
||||
std::string GetFileSystemRepresentation(const std::wstring& path)
|
||||
{
|
||||
if (path.empty())
|
||||
return "";
|
||||
|
||||
return (const char*)[path fileSystemRepresentation];
|
||||
NSString* _path = [[NSString alloc] initWithBytes:(char*)path.data() length:path.size() * sizeof(wchar_t)
|
||||
encoding:CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingUTF32LE)];
|
||||
|
||||
return std::string((const char*)[_path fileSystemRepresentation]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace NSDirectory
|
||||
{
|
||||
namespace NSIOS
|
||||
{
|
||||
void GetFiles2(std::wstring strDirectory, std::vector<std::wstring>& oArray, bool bIsRecursion)
|
||||
{
|
||||
NSStringEncoding pEncode = CFStringConvertEncodingToNSStringEncoding ( kCFStringEncodingUTF32LE );
|
||||
|
||||
NSString* directoryPath = [[NSString alloc] initWithBytes : (char*)strDirectory.data()
|
||||
length : strDirectory.size() * sizeof(wchar_t) encoding : pEncode];
|
||||
|
||||
NSArray* directoryContent = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:directoryPath error:NULL];
|
||||
for (int count = 0; count < (int)[directoryContent count]; count++)
|
||||
{
|
||||
NSData* pSData = [[directoryContent objectAtIndex:count] dataUsingEncoding : pEncode];
|
||||
oArray.emplace_back(std::wstring((wchar_t*)[pSData bytes], [pSData length] / sizeof (wchar_t)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,49 +43,49 @@ class IGrObject
|
||||
protected:
|
||||
|
||||
#ifdef __APPLE__
|
||||
volatile int32_t m_lRef;
|
||||
volatile int32_t m_lRef;
|
||||
#else
|
||||
ULONG m_lRef;
|
||||
ULONG m_lRef;
|
||||
#endif
|
||||
|
||||
public:
|
||||
IGrObject()
|
||||
{
|
||||
m_lRef = 1;
|
||||
}
|
||||
IGrObject()
|
||||
{
|
||||
m_lRef = 1;
|
||||
}
|
||||
|
||||
virtual ~IGrObject()
|
||||
{
|
||||
}
|
||||
virtual ~IGrObject()
|
||||
{
|
||||
}
|
||||
|
||||
#ifdef __APPLE__
|
||||
virtual ULONG AddRef()
|
||||
{
|
||||
OSAtomicIncrement32(&m_lRef);
|
||||
return (ULONG)m_lRef;
|
||||
}
|
||||
virtual ULONG Release()
|
||||
{
|
||||
int32_t ret = OSAtomicDecrement32(&m_lRef);
|
||||
if (0 == m_lRef)
|
||||
delete this;
|
||||
virtual ULONG AddRef()
|
||||
{
|
||||
OSAtomicIncrement32(&m_lRef);
|
||||
return (ULONG)m_lRef;
|
||||
}
|
||||
virtual ULONG Release()
|
||||
{
|
||||
int32_t ret = OSAtomicDecrement32(&m_lRef);
|
||||
if (0 == m_lRef)
|
||||
delete this;
|
||||
|
||||
return (ULONG)ret;
|
||||
}
|
||||
return (ULONG)ret;
|
||||
}
|
||||
#else
|
||||
virtual ULONG AddRef()
|
||||
{
|
||||
++m_lRef;
|
||||
return m_lRef;
|
||||
}
|
||||
virtual ULONG AddRef()
|
||||
{
|
||||
++m_lRef;
|
||||
return m_lRef;
|
||||
}
|
||||
|
||||
virtual ULONG Release()
|
||||
{
|
||||
ULONG ret = --m_lRef;
|
||||
if (0 == m_lRef)
|
||||
delete this;
|
||||
return ret;
|
||||
}
|
||||
virtual ULONG Release()
|
||||
{
|
||||
ULONG ret = --m_lRef;
|
||||
if (0 == m_lRef)
|
||||
delete this;
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
@ -33,9 +33,9 @@
|
||||
#include "File.h"
|
||||
|
||||
#if defined(_WIN32) || defined (_WIN64)
|
||||
#include <tchar.h>
|
||||
#include <tchar.h>
|
||||
#elif __linux__ || MAC
|
||||
#include <libgen.h>
|
||||
#include <libgen.h>
|
||||
#endif
|
||||
|
||||
namespace NSSystemPath
|
||||
@ -61,7 +61,7 @@ namespace NSSystemPath
|
||||
sRes = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)pDirName, strlen(pDirName));
|
||||
delete [] pUtf8;
|
||||
#endif
|
||||
return sRes;
|
||||
return sRes;
|
||||
}
|
||||
std::wstring GetFileName(const std::wstring& strFileName)
|
||||
{
|
||||
@ -103,17 +103,19 @@ namespace NSSystemPath
|
||||
sRes = strLeft + strRight.substr(1);
|
||||
}
|
||||
else if(!bLeftSlash && !bRightSlash)
|
||||
sRes = strLeft + L"/" + strRight;
|
||||
sRes = strLeft + L"/" + strRight;
|
||||
else
|
||||
sRes = strLeft + strRight;
|
||||
return sRes;
|
||||
}
|
||||
std::string NormalizePath(const std::string& strFileName)
|
||||
{
|
||||
const char* pData = strFileName.c_str();
|
||||
int nLen = (int) strFileName.length();
|
||||
|
||||
char* pDataNorm = new char[nLen + 1];
|
||||
template<class CHAR, class STRING = std::basic_string<CHAR, std::char_traits<CHAR>, std::allocator<CHAR>>>
|
||||
STRING NormalizePathTemplate(const STRING& strFileName)
|
||||
{
|
||||
const CHAR* pData = strFileName.c_str();
|
||||
int nLen = (int) strFileName.length();
|
||||
|
||||
CHAR* pDataNorm = new CHAR[nLen + 1];
|
||||
int* pSlashPoints = new int[nLen + 1];
|
||||
|
||||
int nStart = 0;
|
||||
@ -122,10 +124,15 @@ namespace NSSystemPath
|
||||
int nCurrentW = 0;
|
||||
bool bIsUp = false;
|
||||
|
||||
#if !defined(_WIN32) && !defined (_WIN64)
|
||||
if (pData[nCurrent] == '/' || pData[nCurrent] == '\\')
|
||||
{
|
||||
#if !defined(_WIN32) && !defined (_WIN64)
|
||||
pDataNorm[nCurrentW++] = pData[nCurrent];
|
||||
#endif
|
||||
#endif
|
||||
++nCurrentSlash;
|
||||
pSlashPoints[nCurrentSlash] = nCurrentW;
|
||||
}
|
||||
|
||||
while (nCurrent < nLen)
|
||||
{
|
||||
if (pData[nCurrent] == '/' || pData[nCurrent] == '\\')
|
||||
@ -135,7 +142,7 @@ namespace NSSystemPath
|
||||
bIsUp = false;
|
||||
if ((nCurrent - nStart) == 2)
|
||||
{
|
||||
if (pData[nStart] == (char)'.' && pData[nStart + 1] == (char)'.')
|
||||
if (pData[nStart] == (CHAR)'.' && pData[nStart + 1] == (CHAR)'.')
|
||||
{
|
||||
if (nCurrentSlash > 0)
|
||||
{
|
||||
@ -147,7 +154,7 @@ namespace NSSystemPath
|
||||
}
|
||||
if (!bIsUp)
|
||||
{
|
||||
pDataNorm[nCurrentW++] = (char)'/';
|
||||
pDataNorm[nCurrentW++] = (CHAR)'/';
|
||||
++nCurrentSlash;
|
||||
pSlashPoints[nCurrentSlash] = nCurrentW;
|
||||
}
|
||||
@ -160,13 +167,22 @@ namespace NSSystemPath
|
||||
++nCurrent;
|
||||
}
|
||||
|
||||
pDataNorm[nCurrentW] = (char)'\0';
|
||||
pDataNorm[nCurrentW] = (CHAR)'\0';
|
||||
|
||||
std::string result = std::string(pDataNorm, nCurrentW);
|
||||
STRING result = STRING(pDataNorm, nCurrentW);
|
||||
|
||||
delete[] pDataNorm;
|
||||
delete[] pSlashPoints;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string NormalizePath(const std::string& strFileName)
|
||||
{
|
||||
return NormalizePathTemplate<char>(strFileName);
|
||||
}
|
||||
std::wstring NormalizePath(const std::wstring& strFileName)
|
||||
{
|
||||
return NormalizePathTemplate<wchar_t>(strFileName);
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,10 +38,11 @@
|
||||
|
||||
namespace NSSystemPath
|
||||
{
|
||||
KERNEL_DECL std::wstring GetDirectoryName(const std::wstring& strFileName);
|
||||
KERNEL_DECL std::wstring GetFileName(const std::wstring& strFileName);
|
||||
KERNEL_DECL std::wstring Combine(const std::wstring& strLeft, const std::wstring& strRight);
|
||||
KERNEL_DECL std::string NormalizePath(const std::string& strFileName);
|
||||
KERNEL_DECL std::wstring GetDirectoryName(const std::wstring& strFileName);
|
||||
KERNEL_DECL std::wstring GetFileName(const std::wstring& strFileName);
|
||||
KERNEL_DECL std::wstring Combine(const std::wstring& strLeft, const std::wstring& strRight);
|
||||
KERNEL_DECL std::string NormalizePath(const std::string& strFileName);
|
||||
KERNEL_DECL std::wstring NormalizePath(const std::wstring& strFileName);
|
||||
}
|
||||
|
||||
#endif //_BUILD_PATH_CROSSPLATFORM_H_
|
||||
|
||||
Reference in New Issue
Block a user