From c72e44f44ed768a46d2e35673e5489c86eabe741 Mon Sep 17 00:00:00 2001 From: Oleg Korshul Date: Tue, 25 Jul 2023 13:30:08 +0300 Subject: [PATCH] Refactoring --- DesktopEditor/common/Directory.cpp | 698 +++++++++--------- DesktopEditor/common/Directory.h | 60 +- DesktopEditor/common/File.h | 7 + DesktopEditor/common/File_ios.mm | 46 +- DesktopEditor/fontengine/ApplicationFonts.cpp | 6 +- .../fontengine/ApplicationFonts_ios.mm | 75 -- DesktopEditor/graphics/pro/fontengine.pri | 4 - OfficeUtils/OfficeUtils.pri | 3 - OfficeUtils/src/ZipUtilsCP.cpp | 13 +- OfficeUtils/src/ZipUtilsCP.h | 1 - OfficeUtils/src/ZipUtilsCP_ios.mm | 57 -- 11 files changed, 440 insertions(+), 530 deletions(-) delete mode 100644 DesktopEditor/fontengine/ApplicationFonts_ios.mm delete mode 100644 OfficeUtils/src/ZipUtilsCP_ios.mm diff --git a/DesktopEditor/common/Directory.cpp b/DesktopEditor/common/Directory.cpp index 29204ded88..298031f4b2 100644 --- a/DesktopEditor/common/Directory.cpp +++ b/DesktopEditor/common/Directory.cpp @@ -31,25 +31,25 @@ */ #if defined(_WIN32) || defined (_WIN64) - #include "windows.h" - #include "windef.h" - #include - #include +#include "windows.h" +#include "windef.h" +#include +#include #elif __linux__ - #include - #include - #include - #include +#include +#include +#include +#include #elif MAC - #include - #include - #include - #include +#include +#include +#include +#include #elif _IOS - #include - #include - #include - #include +#include +#include +#include +#include #endif #include @@ -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& oArray, bool bIsRecursion) - { + void GetFiles2(std::wstring strDirectory, std::vector& 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 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 GetFiles(std::wstring strDirectory, bool bIsRecursion) { std::vector oArray; if (!strDirectory.empty()) - { + { GetFiles2(strDirectory, oArray, bIsRecursion); } return oArray; } - std::vector GetDirectories(std::wstring strDirectory) + std::vector GetDirectories(std::wstring strDirectory) { std::vector 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 (pcTemplate.c_str())); - if (NULL == pcRes) - return L""; + std::string pcTemplate = U_TO_UTF8(strFolderPathRoot) + "/ascXXXXXX"; + char *pcRes = mkdtemp(const_cast (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 arrFiles = NSDirectory::GetFiles(path, recursive); + int GetFilesCount(const std::wstring& path, const bool& recursive) + { + std::vector 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); + } } diff --git a/DesktopEditor/common/Directory.h b/DesktopEditor/common/Directory.h index 3a2c63f45b..6d3cf9e897 100644 --- a/DesktopEditor/common/Directory.h +++ b/DesktopEditor/common/Directory.h @@ -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 GetFiles(std::wstring strDirectory, bool bIsRecursion = false); + KERNEL_DECL void GetFiles2(std::wstring strDirectory, std::vector& oArray, bool bIsRecursion = false); + + KERNEL_DECL std::vector 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& oArray, bool bIsRecursion); + namespace IOS + { + KERNEL_DECL void GetFiles2(std::wstring strDirectory, std::vector& oArray, bool bIsRecursion = false); + } #endif - KERNEL_DECL void GetFiles2(std::wstring strDirectory, std::vector& oArray, bool bIsRecursion = false); - - KERNEL_DECL std::vector GetFiles(std::wstring strDirectory, bool bIsRecursion = false); - KERNEL_DECL std::vector 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_ diff --git a/DesktopEditor/common/File.h b/DesktopEditor/common/File.h index 43d163755e..a051a9208c 100644 --- a/DesktopEditor/common/File.h +++ b/DesktopEditor/common/File.h @@ -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 IOS + { + KERNEL_DECL std::string GetFileSystemRepresentation(const std::wstring& path); + } +#endif } namespace NSFile diff --git a/DesktopEditor/common/File_ios.mm b/DesktopEditor/common/File_ios.mm index 05a6a50ceb..e7183e8aee 100644 --- a/DesktopEditor/common/File_ios.mm +++ b/DesktopEditor/common/File_ios.mm @@ -31,21 +31,49 @@ */ #ifdef __OBJC__ - #import +#import #else - #include +#include #endif #include "./File.h" +#include #import -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 IOS + { + 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 IOS + { + void GetFiles2(std::wstring strDirectory, std::vector& 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))); + } + } + } } diff --git a/DesktopEditor/fontengine/ApplicationFonts.cpp b/DesktopEditor/fontengine/ApplicationFonts.cpp index 2d60f06cb3..54a83a46bd 100644 --- a/DesktopEditor/fontengine/ApplicationFonts.cpp +++ b/DesktopEditor/fontengine/ApplicationFonts.cpp @@ -1794,8 +1794,10 @@ std::vector CApplicationFonts::GetSetupFontFiles() #endif #ifdef _IOS - // own realization (objective c code) - return GetSetupFontFiles_ios(); + std::vector _array = NSDirectory::GetFiles2(L"/System/Library/Fonts", oArray, true); + if (_array.empty()) + NSDirectory::GetFiles2(L"/Library/Fonts", _array, true); + return _array; #endif #ifdef __ANDROID__ diff --git a/DesktopEditor/fontengine/ApplicationFonts_ios.mm b/DesktopEditor/fontengine/ApplicationFonts_ios.mm deleted file mode 100644 index 643410b4e4..0000000000 --- a/DesktopEditor/fontengine/ApplicationFonts_ios.mm +++ /dev/null @@ -1,75 +0,0 @@ -/* - * (c) Copyright Ascensio System SIA 2010-2023 - * - * This program is a free software product. You can redistribute it and/or - * modify it under the terms of the GNU Affero General Public License (AGPL) - * version 3 as published by the Free Software Foundation. In accordance with - * Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect - * that Ascensio System SIA expressly excludes the warranty of non-infringement - * of any third-party rights. - * - * This program is distributed WITHOUT ANY WARRANTY; without even the implied - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For - * details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html - * - * You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish - * street, Riga, Latvia, EU, LV-1050. - * - * The interactive user interfaces in modified source and object code versions - * of the Program must display Appropriate Legal Notices, as required under - * Section 5 of the GNU AGPL version 3. - * - * Pursuant to Section 7(b) of the License you must retain the original Product - * logo when distributing the program. Pursuant to Section 7(e) we decline to - * grant you any rights under trademark law for use of our trademarks. - * - * All the Product's GUI elements, including illustrations and icon sets, as - * well as technical writing content are licensed under the terms of the - * Creative Commons Attribution-ShareAlike 4.0 International. See the License - * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode - * - */ -#include "ApplicationFonts.h" -#include "../common/Directory.h" - -#ifdef BOOL -#undef BOOL -#endif - -#import - -std::vector CApplicationFonts::GetSetupFontFiles_ios() -{ - std::vector oArray; - NSDirectory::GetFiles2(L"/System/Library/Fonts", oArray, true); - - if (oArray.size() == 0) - { - NSDirectory::GetFiles2(L"/Library/Fonts", oArray, true); - } - - return oArray; -} - -namespace NSDirectory -{ - void GetFiles2_ios(std::wstring strDirectory, std::vector& oArray, bool bIsRecursion) - { - NSString* directoryPath = [ [ NSString alloc ] - initWithBytes : (char*)strDirectory.data() - length : strDirectory.size() * sizeof(wchar_t) - encoding : CFStringConvertEncodingToNSStringEncoding ( kCFStringEncodingUTF32LE ) ]; - - int count; - - NSArray* directoryContent = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:directoryPath error:NULL]; - for (count = 0; count < (int)[directoryContent count]; count++) - { - NSStringEncoding pEncode = CFStringConvertEncodingToNSStringEncoding ( kCFStringEncodingUTF32LE ); - NSData* pSData = [[ directoryContent objectAtIndex:count] dataUsingEncoding : pEncode ]; - - std::wstring sTmp( (wchar_t*) [ pSData bytes ], [ pSData length] / sizeof ( wchar_t ) ); - oArray.push_back(sTmp); - } - } -} diff --git a/DesktopEditor/graphics/pro/fontengine.pri b/DesktopEditor/graphics/pro/fontengine.pri index 92a9aea8a8..18ba73dbe4 100644 --- a/DesktopEditor/graphics/pro/fontengine.pri +++ b/DesktopEditor/graphics/pro/fontengine.pri @@ -39,10 +39,6 @@ enable_support_shaper { # ------------------------------------------------- core_ios { - - OBJECTIVE_SOURCES += \ - $$FONT_ENGINE_PATH/ApplicationFonts_ios.mm \ - LIBS += -framework Foundation } diff --git a/OfficeUtils/OfficeUtils.pri b/OfficeUtils/OfficeUtils.pri index bca022331e..b4e1f497a8 100644 --- a/OfficeUtils/OfficeUtils.pri +++ b/OfficeUtils/OfficeUtils.pri @@ -64,6 +64,3 @@ HEADERS += \ $$PWD/src/zlib-1.2.11/contrib/minizip/zip.h \ $$PWD/src/zlib-1.2.11/contrib/minizip/ioapibuf.h -core_ios { -OBJECTIVE_SOURCES += $$PWD/src/ZipUtilsCP_ios.mm -} diff --git a/OfficeUtils/src/ZipUtilsCP.cpp b/OfficeUtils/src/ZipUtilsCP.cpp index 5849708957..9554ed3481 100644 --- a/OfficeUtils/src/ZipUtilsCP.cpp +++ b/OfficeUtils/src/ZipUtilsCP.cpp @@ -123,19 +123,23 @@ namespace ZLibZipUtils return m_unzFile; } -#ifndef _IOS zipFile zipOpenHelp(const wchar_t* filename) { #if defined(_WIN32) || defined (_WIN64) zlib_filefunc64_def ffunc; fill_win32_filefunc64W(&ffunc); zipFile zf = zipOpen2_64(filename, APPEND_STATUS_CREATE, NULL, &ffunc); +#else +#ifdef _IOS + std::string filePath = NSFile::IOS::GetFileSystemRepresentation(filename); + zipFile zf = filePath.empty() ? NULL : zipOpen(filePath.c_str(), APPEND_STATUS_CREATE); #else BYTE* pUtf8 = NULL; LONG lLen = 0; NSFile::CUtf8Converter::GetUtf8StringFromUnicode(filename, wcslen(filename), pUtf8, lLen, false); zipFile zf = zipOpen( (char*)pUtf8, APPEND_STATUS_CREATE ); delete [] pUtf8; +#endif #endif return zf; } @@ -145,16 +149,21 @@ namespace ZLibZipUtils zlib_filefunc64_def ffunc; fill_win32_filefunc64W(&ffunc); unzFile uf = unzOpen2_64(filename, &ffunc); +#else +#ifdef _IOS + std::string filePath = NSFile::IOS::GetFileSystemRepresentation(filename); + unzFile zf = filePath.empty() ? NULL : unzOpen(filePath.c_str()); #else BYTE* pUtf8 = NULL; LONG lLen = 0; NSFile::CUtf8Converter::GetUtf8StringFromUnicode(filename, wcslen(filename), pUtf8, lLen, false); unzFile uf = unzOpen( (char*)pUtf8 ); delete [] pUtf8; +#endif #endif return uf; } -#endif + static std::wstring ascii_to_unicode(const char *src) { // TODO: check codepage of system (for "bad" archive) diff --git a/OfficeUtils/src/ZipUtilsCP.h b/OfficeUtils/src/ZipUtilsCP.h index b9826396d0..30324a8f44 100644 --- a/OfficeUtils/src/ZipUtilsCP.h +++ b/OfficeUtils/src/ZipUtilsCP.h @@ -57,7 +57,6 @@ using namespace std; namespace ZLibZipUtils { - zipFile zipOpenHelp(const wchar_t* filename); unzFile unzOpenHelp(const wchar_t* filename); diff --git a/OfficeUtils/src/ZipUtilsCP_ios.mm b/OfficeUtils/src/ZipUtilsCP_ios.mm deleted file mode 100644 index d981674386..0000000000 --- a/OfficeUtils/src/ZipUtilsCP_ios.mm +++ /dev/null @@ -1,57 +0,0 @@ -/* - * (c) Copyright Ascensio System SIA 2010-2023 - * - * This program is a free software product. You can redistribute it and/or - * modify it under the terms of the GNU Affero General Public License (AGPL) - * version 3 as published by the Free Software Foundation. In accordance with - * Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect - * that Ascensio System SIA expressly excludes the warranty of non-infringement - * of any third-party rights. - * - * This program is distributed WITHOUT ANY WARRANTY; without even the implied - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For - * details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html - * - * You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish - * street, Riga, Latvia, EU, LV-1050. - * - * The interactive user interfaces in modified source and object code versions - * of the Program must display Appropriate Legal Notices, as required under - * Section 5 of the GNU AGPL version 3. - * - * Pursuant to Section 7(b) of the License you must retain the original Product - * logo when distributing the program. Pursuant to Section 7(e) we decline to - * grant you any rights under trademark law for use of our trademarks. - * - * All the Product's GUI elements, including illustrations and icon sets, as - * well as technical writing content are licensed under the terms of the - * Creative Commons Attribution-ShareAlike 4.0 International. See the License - * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode - * - */ -#include "ZipUtilsCP.h" -#import - -namespace ZLibZipUtils -{ - zipFile zipOpenHelp(const wchar_t* filename) - { - NSString *path =[[NSString alloc] initWithBytes:filename - length:wcslen(filename)*sizeof(*filename) - encoding:NSUTF32LittleEndianStringEncoding]; - if (path && path.length > 0) { - return zipOpen( (const char*)[path fileSystemRepresentation], APPEND_STATUS_CREATE ); - } - return NULL; - } - unzFile unzOpenHelp(const wchar_t* filename) - { - NSString *path =[[NSString alloc] initWithBytes:filename - length:wcslen(filename)*sizeof(*filename) - encoding:NSUTF32LittleEndianStringEncoding]; - if (path && path.length > 0) { - return unzOpen ((const char*)[path fileSystemRepresentation]); - } - return NULL; - } -}