diff --git a/source/core/BaseFileIterator.cpp b/source/core/BaseFileIterator.cpp index fb4ab2fe15bf608e513f5afb0d4df4ddbc92bad2..077e32d26dd0d66c6a9f372b22e816517479a8c7 100644 --- a/source/core/BaseFileIterator.cpp +++ b/source/core/BaseFileIterator.cpp @@ -1,14 +1,26 @@ #include "BaseFileIterator.h" -void CBaseFileIterator::canonizePath(String &sPath) +void CBaseFileIterator::canonizePath(char *szPath) { - char symbol = sPath[sPath.length() - 1]; + char symbol = szPath[strlen(szPath) - 1]; /*Дело в том что абсолютный путь к файлу может не иметь символ "/" или "\\" на конце строки, и, если его не будет путь будет некорректен*/ if (symbol != '\\' && symbol != '/') { - sPath += '/'; + strcat(szPath, "/"); + } +} + +void CBaseFileIterator::canonizePath(String *pPath) +{ + char symbol = (*pPath)[pPath->length() - 1]; + + /*Дело в том что абсолютный путь к файлу может не иметь символ "/" + или "\\" на конце строки, и, если его не будет путь будет некорректен*/ + if(symbol != '\\' && symbol != '/') + { + (*pPath) += '/'; } } @@ -16,11 +28,11 @@ void CBaseFileIterator::canonizePaths(Array<String> &paths) { for (int i = 0, I = paths.size(); i < I; ++i) { - canonizePath(paths[i]); + canonizePath(&paths[i]); } } -void CBaseFileIterator::fillExtensionsArray(Array<String> &extsArray, const char **exts, int iExtsSize) +void CBaseFileIterator::fillExtensionsArray(Array<AAString> &extsArray, const char **exts, int iExtsSize) { for (int i = 0; i < iExtsSize; ++i) { @@ -31,11 +43,11 @@ void CBaseFileIterator::fillExtensionsArray(Array<String> &extsArray, const char } } -bool CBaseFileIterator::findExtensionsInPath(const char *szPath, const Array<String> &exts) +bool CBaseFileIterator::findExtensionsInPath(const char *szPath, const Array<AAString> &exts) { for (int i = 0, I = exts.size(); i < I; ++i) { - if (strstr(szPath, exts[i].c_str()) != NULL) + if (strstr(szPath, exts[i].getName()) != NULL) { return true; } diff --git a/source/core/BaseFileIterator.h b/source/core/BaseFileIterator.h index 0110c448c2307e8a392a571f4f49f3dedca2d468..43fee541479fb8aab75c06f1983fc0fadb3b9a07 100644 --- a/source/core/BaseFileIterator.h +++ b/source/core/BaseFileIterator.h @@ -2,17 +2,20 @@ #define __CBASE_FILE_ITERATOR_ #include "FileSystem.h" +#include <common/AAString.h> class CBaseFileIterator : public IXUnknownImplementation<IFileIterator> { public: - void canonizePath(String &sPath); + void canonizePath(char *szPath); + + void canonizePath(String *pPath); void canonizePaths(Array<String> &paths); - void fillExtensionsArray(Array<String> &extsArray, const char **exts, int iExtsSize); + void fillExtensionsArray(Array<AAString> &extsArray, const char **exts, int iExtsSize); - bool findExtensionsInPath(const char *szPath, const Array<String> &exts); + bool findExtensionsInPath(const char *szPath, const Array<AAString> &exts); bool emptyOrRepeatPath(const char *szPath); }; diff --git a/source/core/FileExtsIterator.cpp b/source/core/FileExtsIterator.cpp index 6ae242e5005b65422069072861c6f06af2a38b19..88024d795f81397f6b5c15d70a40120768d2c0e7 100644 --- a/source/core/FileExtsIterator.cpp +++ b/source/core/FileExtsIterator.cpp @@ -1,13 +1,13 @@ #include "FileExtsIterator.h" -CFileExtsIterator::CFileExtsIterator(Array<String> &paths, String &sBasePath, const char **szExt, int iExtSize) +CFileExtsIterator::CFileExtsIterator(Array<String> &paths, const char *szBasePath, const char **szExt, int iExtSize) { - this->canonizePaths(paths); - this->canonizePath(sBasePath); - this->fillExtensionsArray(m_exts, szExt, iExtSize); + m_paths = std::move(paths); + strcpy(m_szBasePath, szBasePath); - this->m_paths = paths; - this->m_sBasePath = sBasePath; + canonizePaths(m_paths); + canonizePath(m_szBasePath); + fillExtensionsArray(m_exts, szExt, iExtSize); } const char *CFileExtsIterator::next() @@ -20,12 +20,14 @@ const char *CFileExtsIterator::next() int size = m_paths.size(); int sizeExt = m_exts.size(); + char szFileName[SIZE_PATH]; + while (index < size) { - const String &fileName = (m_paths[index] + "*.*"); + sprintf(szFileName, "%s*.*", m_paths[index].c_str()); //Проверяем указатель, если m_handle пустой, то ищем первый файл с расширением szExts - hf = INVALID_OR_NULL(m_handle) ? FindFirstFileW(CMB2WC(fileName.c_str()), &FindFileData) : m_handle; + hf = INVALID_OR_NULL(m_handle) ? FindFirstFileW(CMB2WC(szFileName), &FindFileData) : m_handle; if (hf != INVALID_HANDLE_VALUE) { @@ -33,9 +35,9 @@ const char *CFileExtsIterator::next() //Сохраняем HANDLE файла, что бы можно было продожлить с того места m_handle = hf; - m_pathStr = m_paths[index] + CWC2MB(FindFileData.cFileName); + sprintf(m_szPathStr, "%s%s", m_paths[index].c_str(), (const char*)CWC2MB(FindFileData.cFileName)); - DWORD flag = GetFileAttributesW(CMB2WC(m_pathStr.c_str())); + DWORD flag = GetFileAttributesW(CMB2WC(m_szPathStr)); if (flag != INVALID_FILE_ATTRIBUTES && !(flag & FILE_ATTRIBUTE_DIRECTORY)) { @@ -44,16 +46,17 @@ const char *CFileExtsIterator::next() continue; } - m_pathStr = (m_sBasePath + CWC2MB(FindFileData.cFileName)); - if (m_mapExistPath.KeyExists(m_pathStr)) + sprintf(m_szPathStr, "%s%s", m_szBasePath, (const char*)CWC2MB(FindFileData.cFileName)); + + if(m_mapExistPath.KeyExists(m_szPathStr)) { continue; } else { //Возвращаем относительный путь, вместе с именем файла и расширением - m_mapExistPath[m_pathStr] = index; - return m_pathStr.c_str(); + m_mapExistPath[m_szPathStr] = index; + return m_szPathStr; } } //Если указатель на файл валидный, то проверяем все отфильтрованные файлы по порядку diff --git a/source/core/FileExtsIterator.h b/source/core/FileExtsIterator.h index 6fcfc213808ebe18225fedff68bac67450d44b00..bc020156ef7335054963f805fc718563ab15afcd 100644 --- a/source/core/FileExtsIterator.h +++ b/source/core/FileExtsIterator.h @@ -12,9 +12,9 @@ class CFileExtsIterator final : public CBaseFileIterator { private: Array<String> m_paths; - String m_pathStr; - String m_sBasePath; - Array<String> m_exts; + char m_szPathStr[SIZE_PATH]; + char m_szBasePath[SIZE_PATH]; + Array<AAString> m_exts; AssotiativeArray<String, int> m_mapExistPath; int index = 0; @@ -24,7 +24,7 @@ private: int m_currentExt = 0; public: - CFileExtsIterator::CFileExtsIterator(Array<String> &paths, String &sBasePath, const char **szExt, int iExtSize); + CFileExtsIterator::CFileExtsIterator(Array<String> &paths, const char *szBasePath, const char **szExt, int iExtSize); const char* XMETHODCALLTYPE next() override; diff --git a/source/core/FileRecursiveExtPathsIterator.cpp b/source/core/FileRecursiveExtPathsIterator.cpp index 83c61563a51141dd68c334aca38103b99fea833c..62e506b44541bb994874521e277b0b558a91f7d1 100644 --- a/source/core/FileRecursiveExtPathsIterator.cpp +++ b/source/core/FileRecursiveExtPathsIterator.cpp @@ -1,51 +1,59 @@ #include "FileRecursiveExtPathsIterator.h" -CFileRecursiveExtPathsIterator::CFileRecursiveExtPathsIterator(Array<String> &paths, String &sBasePath, const char **szExts, int iExtSize) +CFileRecursiveExtPathsIterator::CFileRecursiveExtPathsIterator(Array<String> &paths, const char *szBasePath, const char **szExts, int iExtSize) { - this->canonizePaths(paths); - this->canonizePath(sBasePath); - this->fillExtensionsArray(m_exts, szExts, iExtSize); + strcpy(m_szBasePath, szBasePath); + m_sPaths = std::move(paths); - this->m_sPaths = paths; - this->m_sBasePath = sBasePath; + canonizePaths(m_sPaths); + canonizePath(m_szBasePath); + + fillExtensionsArray(m_exts, szExts, iExtSize); } const char *CFileRecursiveExtPathsIterator::next() { + char szFileName[SIZE_PATH]; + char szFullName[SIZE_PATH]; + WIN32_FIND_DATAW FindFileData; HANDLE hf; + UINT maxPathIndex = m_sPaths.size(); FindFileData.cFileName[0] = '\0'; - UINT maxPathIndex = m_sPaths.size(); while (pathIndex < maxPathIndex) { - m_currentFullPath = !m_currentFullPath.length() ? m_sPaths[pathIndex] : m_currentFullPath; + if(strlen(m_szCurrentFullPath) > 0) + { + strcpy(m_szCurrentFullPath, m_sPaths[pathIndex].c_str()); + } + do { - String fileName = m_sPaths[pathIndex] + "*.*"; + sprintf(szFileName, "%s*.*", m_sPaths[pathIndex].c_str()); //Проверяем указатель, если m_handle пустой, то ищем первый файл с расширением szExts - hf = INVALID_OR_NULL(m_handle) ? FindFirstFileW(CMB2WC(fileName.c_str()), &FindFileData) : m_handle; + hf = INVALID_OR_NULL(m_handle) ? FindFirstFileW(CMB2WC(szFileName), &FindFileData) : m_handle; if (hf != INVALID_HANDLE_VALUE) { - do { //Сохраняем HANDLE файла, что бы можно было продожлить с того места m_handle = hf; - String fullName = m_sPaths[pathIndex] + CWC2MB(FindFileData.cFileName); - - DWORD flag = GetFileAttributesW(CMB2WC(fullName.c_str())); - if (emptyOrRepeatPath(CWC2MB(FindFileData.cFileName))) { continue; } + sprintf(szFullName, "%s%s", m_sPaths[pathIndex].c_str(), (const char*)CWC2MB(FindFileData.cFileName)); + + DWORD flag = GetFileAttributesW(CMB2WC(szFullName)); + if (flag != INVALID_FILE_ATTRIBUTES && (flag & FILE_ATTRIBUTE_DIRECTORY)) { - m_folderList.push_back(fullName + '/'); + strcat(szFullName, "/"); + m_folderList.push_back(szFullName); continue; } @@ -56,16 +64,21 @@ const char *CFileRecursiveExtPathsIterator::next() continue; } //Если это файл - получаем относительный путь и ищем его в списке - m_pathStr = strstr(fullName.c_str(), m_sBasePath.c_str()); + char *pos = strstr(szFullName, m_szBasePath); + + if(pos) + { + strcpy(m_szPathStr, pos); + } - if (m_mapExistPath.KeyExists(m_pathStr)) + if(m_mapExistPath.KeyExists(m_szPathStr)) { continue; } else { - m_mapExistPath[m_pathStr] = pathIndex; - return m_pathStr.c_str(); + m_mapExistPath[m_szPathStr] = pathIndex; + return m_szPathStr; } } //Если указатель на файл валидный, то проверяем все отфильтрованные файлы по порядку @@ -80,12 +93,12 @@ const char *CFileRecursiveExtPathsIterator::next() } else { - m_sPaths[pathIndex] = m_currentFullPath; + m_sPaths[pathIndex] = m_szCurrentFullPath; } } - } while (m_sPaths[pathIndex] != m_currentFullPath); + } while (m_sPaths[pathIndex] != m_szCurrentFullPath); ++pathIndex; - m_currentFullPath.release(); + m_szCurrentFullPath[0] = 0; m_handle = NULL; } @@ -96,9 +109,9 @@ const char *CFileRecursiveExtPathsIterator::next() void CFileRecursiveExtPathsIterator::reset() { if (m_sPaths.size() < pathIndex) - m_sPaths[pathIndex] = m_currentFullPath; + m_sPaths[pathIndex] = m_szCurrentFullPath; - m_currentFullPath.release(); + m_szCurrentFullPath[0] = 0; m_mapExistPath.clear(); pathIndex = 0; CLOSE_HANDLE(m_handle); diff --git a/source/core/FileRecursiveExtPathsIterator.h b/source/core/FileRecursiveExtPathsIterator.h index 68d855c257d40aaca1d5930f623561740383674e..341dcd8b9802b7b18183461db9d51ba25391e19e 100644 --- a/source/core/FileRecursiveExtPathsIterator.h +++ b/source/core/FileRecursiveExtPathsIterator.h @@ -13,12 +13,12 @@ class CFileRecursiveExtPathsIterator final : public CBaseFileIterator private: Array<String> m_folderList; Array<String> m_sPaths; - Array<String> m_exts; + Array<AAString> m_exts; AssotiativeArray<String, int> m_mapExistPath; - String m_sBasePath; - String m_currentFullPath; - String m_pathStr; + char m_szBasePath[SIZE_PATH]; + char m_szCurrentFullPath[SIZE_PATH]; + char m_szPathStr[SIZE_PATH]; const char *m_szExt; UINT pathIndex = 0; @@ -26,7 +26,7 @@ private: HANDLE m_handle = nullptr; public: - CFileRecursiveExtPathsIterator(Array<String> &paths, String &sBasePath, const char **szExts, int iExtSize); + CFileRecursiveExtPathsIterator(Array<String> &paths, const char *szBasePath, const char **szExts, int iExtSize); const char* XMETHODCALLTYPE next() override; diff --git a/source/core/FileSystem.cpp b/source/core/FileSystem.cpp index d66a395f24b89dda2f5caf569246bee56127dd76..d406c070fa43b850e4240709144aea1c4b97c4c4 100644 --- a/source/core/FileSystem.cpp +++ b/source/core/FileSystem.cpp @@ -10,18 +10,20 @@ template <typename T> IFileIterator *CFileSystem::getListIterator(const char *szPath, const char **szExts, int extsCount) { Array<String> paths; - String basePath(szPath); + char szBasePath[SIZE_PATH]; + + strcpy(szBasePath, szPath); if(!isAbsolutePath(szPath)) { - getAllvariantsCanonizePath(szPath, paths); + getAllvariantsCanonizePath(szPath, &paths); } else { paths.push_back(szPath); } - return paths.size() ? new T(paths, basePath, szExts, extsCount) : nullptr; + return paths.size() ? new T(paths, szBasePath, szExts, extsCount) : nullptr; } void CFileSystem::addPathInPriorityArray(int id, int iPriority) @@ -55,7 +57,7 @@ bool CFileSystem::isFileOrDirectory(const char *szPath, bool isFile) return (flag != INVALID_FILE_ATTRIBUTES) && (isFile ? !(flag & FILE_ATTRIBUTE_DIRECTORY) : (flag & FILE_ATTRIBUTE_DIRECTORY)); } -void CFileSystem::getAllvariantsCanonizePath(const char *szPath, Array<String> &container) +void CFileSystem::getAllvariantsCanonizePath(const char *szPath, Array<String> *container) { char szBuff[SIZE_PATH]; @@ -65,7 +67,7 @@ void CFileSystem::getAllvariantsCanonizePath(const char *szPath, Array<String> & if(isDirectory(szBuff)) { - container.push_back(szBuff); + container->push_back(szBuff); } } } @@ -349,18 +351,20 @@ time_t CFileSystem::getFileModifyTime(const char *szPath) IFileIterator *CFileSystem::getFolderList(const char *szPath) { Array<String> paths; - String basePath(szPath); + char szBasePath[SIZE_PATH]; + + strcpy(szBasePath, szPath); if(!isAbsolutePath(szPath)) { - getAllvariantsCanonizePath(szPath, paths); + getAllvariantsCanonizePath(szPath, &paths); } else { paths.push_back(szPath); } - return paths.size() ? new CFolderPathsIterator(paths, basePath) : nullptr; + return paths.size() ? new CFolderPathsIterator(paths, szBasePath) : nullptr; } IFileIterator *CFileSystem::getFileList(const char *szPath, const char *szExt) diff --git a/source/core/FileSystem.h b/source/core/FileSystem.h index 72cece8e567de72ca33e443084058e68fe6a4297..fa1942b52f03b124d6839d50a7b50dbe88c192fe 100644 --- a/source/core/FileSystem.h +++ b/source/core/FileSystem.h @@ -106,7 +106,7 @@ private: //! Метод делает проверку, ведет ли путь к файлу или папке bool isFileOrDirectory(const char *szPath, bool isFile); - void getAllvariantsCanonizePath(const char *szPath, Array<String> &container); + void getAllvariantsCanonizePath(const char *szPath, Array<String> *container); //!Превращает канонизированный путь в неканонизированный void getNormalPath(const char *szPath, char *outBuff, int iOutMax); diff --git a/source/core/FolderPathsIterator.cpp b/source/core/FolderPathsIterator.cpp index 54e2b9cc752293849f0cdbe6572269becbdbe4e8..3aa269f16c0b1d1e9aacb4debc71261e917ac7b9 100644 --- a/source/core/FolderPathsIterator.cpp +++ b/source/core/FolderPathsIterator.cpp @@ -1,12 +1,12 @@ #include "FolderPathsIterator.h" -CFolderPathsIterator::CFolderPathsIterator(Array<String> &paths, String &sBasePath) +CFolderPathsIterator::CFolderPathsIterator(Array<String> &paths, const char *szBasePath) { - this->canonizePaths(paths); - this->canonizePath(sBasePath); + m_paths = std::move(paths); + strcpy(m_szBasePath, szBasePath); - this->m_paths = paths; - this->m_sBasePath = sBasePath; + canonizePaths(m_paths); + canonizePath(m_szBasePath); } const char *CFolderPathsIterator::next() @@ -27,9 +27,9 @@ const char *CFolderPathsIterator::next() do { m_handle = hf; - m_pathStr = (m_paths)[index] + CWC2MB(FindFileData.cFileName); + sprintf(m_szPathStr, "%s%s", (m_paths)[index].c_str(), (const char*)CWC2MB(FindFileData.cFileName)); - DWORD flag = GetFileAttributesW(CMB2WC(m_pathStr.c_str())); + DWORD flag = GetFileAttributesW(CMB2WC(m_szPathStr)); if (emptyOrRepeatPath(CWC2MB(FindFileData.cFileName))) { @@ -39,16 +39,17 @@ const char *CFolderPathsIterator::next() //Берет только имена директорий if (flag != INVALID_FILE_ATTRIBUTES && flag & FILE_ATTRIBUTE_DIRECTORY) { - m_pathStr = (m_sBasePath + CWC2MB(FindFileData.cFileName)); - if (m_mapExistPath.KeyExists(m_pathStr)) + sprintf(m_szPathStr, "%s%s", m_szBasePath, (const char*)CWC2MB(FindFileData.cFileName)); + + if(m_mapExistPath.KeyExists(m_szPathStr)) { continue; } else { //Возвращаем относительный путь к директории - m_mapExistPath[m_pathStr] = index; - return m_pathStr.c_str(); + m_mapExistPath[m_szPathStr] = index; + return m_szPathStr; } } } while (FindNextFileW(hf, &FindFileData) != 0); diff --git a/source/core/FolderPathsIterator.h b/source/core/FolderPathsIterator.h index ae74e5a345dd64722b56c9171d9821faedfdf021..ebf4359fdbbda7887b6e047e04a45e2443bafd62 100644 --- a/source/core/FolderPathsIterator.h +++ b/source/core/FolderPathsIterator.h @@ -13,8 +13,8 @@ class CFolderPathsIterator final : public CBaseFileIterator private: Array<String> m_paths; - String m_sBasePath; - String m_pathStr; + char m_szBasePath[SIZE_PATH]; + char m_szPathStr[SIZE_PATH]; AssotiativeArray<String, int> m_mapExistPath; int index = 0; @@ -22,7 +22,7 @@ private: HANDLE m_handle = nullptr; public: - CFolderPathsIterator(Array<String> &paths, String &sBasePath); + CFolderPathsIterator(Array<String> &paths, const char *szBasePath); const char* XMETHODCALLTYPE next() override;