From 3da2770923c80c4de191deb79719213227db8031 Mon Sep 17 00:00:00 2001 From: EyeGuy <vanya619@list.ru> Date: Sun, 2 Feb 2025 02:47:29 +0300 Subject: [PATCH 1/3] Update fs iterators --- source/core/BaseFileIterator.cpp | 26 +++++--- source/core/BaseFileIterator.h | 9 ++- source/core/FileExtsIterator.cpp | 31 ++++----- source/core/FileExtsIterator.h | 8 +-- source/core/FileRecursiveExtPathsIterator.cpp | 63 +++++++++++-------- source/core/FileRecursiveExtPathsIterator.h | 10 +-- source/core/FileSystem.cpp | 20 +++--- source/core/FileSystem.h | 2 +- source/core/FolderPathsIterator.cpp | 23 +++---- source/core/FolderPathsIterator.h | 6 +- 10 files changed, 117 insertions(+), 81 deletions(-) diff --git a/source/core/BaseFileIterator.cpp b/source/core/BaseFileIterator.cpp index fb4ab2fe1..077e32d26 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 0110c448c..43fee5414 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 6ae242e50..88024d795 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 6fcfc2138..bc020156e 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 83c61563a..62e506b44 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 68d855c25..341dcd8b9 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 d66a395f2..d406c070f 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 72cece8e5..fa1942b52 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 54e2b9cc7..3aa269f16 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 ae74e5a34..ebf4359fd 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; -- GitLab From 655422c0f84a252ddd96ab0cf4a15e32cf79b0f4 Mon Sep 17 00:00:00 2001 From: EyeGuy <vanya619@list.ru> Date: Sun, 2 Feb 2025 03:12:29 +0300 Subject: [PATCH 2/3] Small refactor --- source/core/BaseFileIterator.cpp | 18 +++---- source/core/FileExtsIterator.cpp | 15 +++--- source/core/FileRecursiveExtPathsIterator.cpp | 4 +- source/core/FileSystem.cpp | 38 +++++++------- source/core/FolderPathsIterator.cpp | 51 ++++++++++--------- 5 files changed, 64 insertions(+), 62 deletions(-) diff --git a/source/core/BaseFileIterator.cpp b/source/core/BaseFileIterator.cpp index 077e32d26..fc42cf4d6 100644 --- a/source/core/BaseFileIterator.cpp +++ b/source/core/BaseFileIterator.cpp @@ -6,7 +6,7 @@ void CBaseFileIterator::canonizePath(char *szPath) /*Дело в том что абсолютный путь к файлу может не иметь символ "/" или "\\" на конце строки, и, если его не будет путь будет некорректен*/ - if (symbol != '\\' && symbol != '/') + if(symbol != '\\' && symbol != '/') { strcat(szPath, "/"); } @@ -26,7 +26,7 @@ void CBaseFileIterator::canonizePath(String *pPath) void CBaseFileIterator::canonizePaths(Array<String> &paths) { - for (int i = 0, I = paths.size(); i < I; ++i) + for(int i = 0, I = paths.size(); i < I; ++i) { canonizePath(&paths[i]); } @@ -34,28 +34,28 @@ void CBaseFileIterator::canonizePaths(Array<String> &paths) void CBaseFileIterator::fillExtensionsArray(Array<AAString> &extsArray, const char **exts, int iExtsSize) { - for (int i = 0; i < iExtsSize; ++i) + for(int i = 0; i < iExtsSize; ++i) { - if (exts[i]) + if(exts[i]) { - extsArray.push_back(exts[i]); + extsArray[i].setName(exts[i]); } } } bool CBaseFileIterator::findExtensionsInPath(const char *szPath, const Array<AAString> &exts) { - for (int i = 0, I = exts.size(); i < I; ++i) + for(int i = 0, I = exts.size(); i < I; ++i) { - if (strstr(szPath, exts[i].getName()) != NULL) + if(strstr(szPath, exts[i].getName()) != NULL) { return true; } } - return !exts.size(); + return(!exts.size()); } bool CBaseFileIterator::emptyOrRepeatPath(const char * szPath) { - return !strcmp(szPath, "..") || !strcmp(szPath, ".") || !strcmp(szPath, ""); + return(!strcmp(szPath, "..") || !strcmp(szPath, ".") || !strcmp(szPath, "")); } \ No newline at end of file diff --git a/source/core/FileExtsIterator.cpp b/source/core/FileExtsIterator.cpp index 88024d795..b4e22059f 100644 --- a/source/core/FileExtsIterator.cpp +++ b/source/core/FileExtsIterator.cpp @@ -22,14 +22,14 @@ const char *CFileExtsIterator::next() char szFileName[SIZE_PATH]; - while (index < size) + while(index < size) { sprintf(szFileName, "%s*.*", m_paths[index].c_str()); //Проверяем указатель, если m_handle пустой, то ищем первый файл с расширением szExts hf = INVALID_OR_NULL(m_handle) ? FindFirstFileW(CMB2WC(szFileName), &FindFileData) : m_handle; - if (hf != INVALID_HANDLE_VALUE) + if(hf != INVALID_HANDLE_VALUE) { do { //Сохраняем HANDLE файла, что бы можно было продожлить с того места @@ -39,9 +39,9 @@ const char *CFileExtsIterator::next() DWORD flag = GetFileAttributesW(CMB2WC(m_szPathStr)); - if (flag != INVALID_FILE_ATTRIBUTES && !(flag & FILE_ATTRIBUTE_DIRECTORY)) + if(flag != INVALID_FILE_ATTRIBUTES && !(flag & FILE_ATTRIBUTE_DIRECTORY)) { - if (!findExtensionsInPath(CWC2MB(FindFileData.cFileName), m_exts)) + if(!findExtensionsInPath(CWC2MB(FindFileData.cFileName), m_exts)) { continue; } @@ -56,18 +56,19 @@ const char *CFileExtsIterator::next() { //Возвращаем относительный путь, вместе с именем файла и расширением m_mapExistPath[m_szPathStr] = index; - return m_szPathStr; + return(m_szPathStr); } } //Если указатель на файл валидный, то проверяем все отфильтрованные файлы по порядку - } while (FindNextFileW(hf, &FindFileData) != 0); + } + while(FindNextFileW(hf, &FindFileData) != 0); } ++index; FIND_CLOSE(m_handle); } //Если вообще не нашли файлов возвращаем nullptr - return nullptr; + return(NULL); } void CFileExtsIterator::reset() diff --git a/source/core/FileRecursiveExtPathsIterator.cpp b/source/core/FileRecursiveExtPathsIterator.cpp index 62e506b44..b8ce1f9fb 100644 --- a/source/core/FileRecursiveExtPathsIterator.cpp +++ b/source/core/FileRecursiveExtPathsIterator.cpp @@ -78,7 +78,7 @@ const char *CFileRecursiveExtPathsIterator::next() else { m_mapExistPath[m_szPathStr] = pathIndex; - return m_szPathStr; + return(m_szPathStr); } } //Если указатель на файл валидный, то проверяем все отфильтрованные файлы по порядку @@ -103,7 +103,7 @@ const char *CFileRecursiveExtPathsIterator::next() } //Если вообще не нашли файлов возвращаем nullptr - return nullptr; + return(NULL); } void CFileRecursiveExtPathsIterator::reset() diff --git a/source/core/FileSystem.cpp b/source/core/FileSystem.cpp index d406c070f..0d2df98e8 100644 --- a/source/core/FileSystem.cpp +++ b/source/core/FileSystem.cpp @@ -262,7 +262,7 @@ bool CFileSystem::resolvePath(const char *szPath, char *szOut, size_t iOutMax) CHECK_SIZE(len, iOutMax); memcpy(szOut, szPath, len); - return true; + return(true); } char szBuff[SIZE_PATH]; @@ -277,11 +277,11 @@ bool CFileSystem::resolvePath(const char *szPath, char *szOut, size_t iOutMax) CHECK_SIZE(len, iOutMax); strcpy(szOut, szBuff); - return true; + return(true); } } - return false; + return(false); } bool CFileSystem::fileExists(const char *szPath) @@ -295,7 +295,7 @@ bool CFileSystem::fileExists(const char *szPath) return false; } - return fileGetSize(path) != FILE_NOT_FOUND; + return(fileGetSize(path) != FILE_NOT_FOUND); } size_t CFileSystem::fileGetSize(const char *szPath) @@ -318,17 +318,17 @@ size_t CFileSystem::fileGetSize(const char *szPath) lpFileInformation.nFileSizeLow; //Если result != 0 то все хорошо, если 0 то файл не найден - return result != 0 ? FileSize : FILE_NOT_FOUND; + return(result != 0 ? FileSize : FILE_NOT_FOUND); } bool CFileSystem::isFile(const char *szPath) { - return isFileOrDirectory(szPath, true); + return(isFileOrDirectory(szPath, true)); } bool CFileSystem::isDirectory(const char *szPath) { - return isFileOrDirectory(szPath, false); + return(isFileOrDirectory(szPath, false)); } time_t CFileSystem::getFileModifyTime(const char *szPath) @@ -338,14 +338,14 @@ time_t CFileSystem::getFileModifyTime(const char *szPath) if(CHECK_CORRECT_PATH(path)) { - return 0; + return(0); } WIN32_FILE_ATTRIBUTE_DATA lpFileInformation; GetFileAttributesExW(CMB2WC(path), GetFileExInfoStandard, &lpFileInformation); - return filetimeToTime_t(lpFileInformation.ftLastWriteTime); + return(filetimeToTime_t(lpFileInformation.ftLastWriteTime)); } IFileIterator *CFileSystem::getFolderList(const char *szPath) @@ -364,29 +364,29 @@ IFileIterator *CFileSystem::getFolderList(const char *szPath) paths.push_back(szPath); } - return paths.size() ? new CFolderPathsIterator(paths, szBasePath) : nullptr; + return(paths.size() ? new CFolderPathsIterator(paths, szBasePath) : NULL); } IFileIterator *CFileSystem::getFileList(const char *szPath, const char *szExt) { const char *exts[] = {szExt}; - return getFileList(szPath, exts, 1); + return(getFileList(szPath, exts, 1)); } IFileIterator *CFileSystem::getFileList(const char *szPath, const char **szExts, int extsCount) { - return getListIterator<CFileExtsIterator>(szPath, szExts, extsCount); + return(getListIterator<CFileExtsIterator>(szPath, szExts, extsCount)); } IFileIterator *CFileSystem::getFileListRecursive(const char *szPath, const char *szExt) { const char *exts[] = {szExt}; - return getFileListRecursive(szPath, exts, 1); + return(getFileListRecursive(szPath, exts, 1)); } IFileIterator *CFileSystem::getFileListRecursive(const char *szPath, const char **szExts, int extsCount) { - return getListIterator<CFileRecursiveExtPathsIterator>(szPath, szExts, extsCount); + return(getListIterator<CFileRecursiveExtPathsIterator>(szPath, szExts, extsCount)); } bool CFileSystem::createDirectory(const char *szPath) @@ -444,7 +444,7 @@ IFile *CFileSystem::openFile(const char *szPath, FILE_OPEN_MODE mode = FILE_MODE //Выходим если режим открытия - не для чтения и нет пути для записи if(m_writableRoot == -1 && mode != FILE_MODE_READ) { - return nullptr; + return(NULL); } char fullPath[SIZE_PATH]; @@ -453,7 +453,7 @@ IFile *CFileSystem::openFile(const char *szPath, FILE_OPEN_MODE mode = FILE_MODE //Если по каким либо причинам нельзя вернуть полный путь - на выход if(CHECK_CORRECT_PATH(fullPath) && mode == FILE_MODE_READ) { - return nullptr; + return(NULL); } IFile *file = new CFile; @@ -465,7 +465,7 @@ IFile *CFileSystem::openFile(const char *szPath, FILE_OPEN_MODE mode = FILE_MODE { mem_delete(file); } - return file; + return(file); } char szNewFileName[SIZE_PATH]; @@ -492,7 +492,7 @@ IFile *CFileSystem::openFile(const char *szPath, FILE_OPEN_MODE mode = FILE_MODE else if(!fileExists(fullPath)) { mem_delete(file); - return nullptr; + return(NULL); } //Если путь вне корня - тогда копируем в корень else if(!inRoot) @@ -520,5 +520,5 @@ IFile *CFileSystem::openFile(const char *szPath, FILE_OPEN_MODE mode = FILE_MODE mem_delete(file); } - return file; + return(file); } \ No newline at end of file diff --git a/source/core/FolderPathsIterator.cpp b/source/core/FolderPathsIterator.cpp index 3aa269f16..7687571f1 100644 --- a/source/core/FolderPathsIterator.cpp +++ b/source/core/FolderPathsIterator.cpp @@ -11,34 +11,34 @@ CFolderPathsIterator::CFolderPathsIterator(Array<String> &paths, const char *szB const char *CFolderPathsIterator::next() { - WIN32_FIND_DATAW FindFileData; - HANDLE hf; + WIN32_FIND_DATAW FindFileData; + HANDLE hf; FindFileData.cFileName[0] = '\0'; UINT size = m_paths.size(); - while (index < size) - { + while(index < size) + { hf = INVALID_OR_NULL(m_handle) ? FindFirstFileW(CMB2WC((m_paths[index] + "*.*").c_str()), &FindFileData) : m_handle; - if (hf != INVALID_HANDLE_VALUE) - { - do { - m_handle = hf; + if(hf != INVALID_HANDLE_VALUE) + { + do { + m_handle = hf; sprintf(m_szPathStr, "%s%s", (m_paths)[index].c_str(), (const char*)CWC2MB(FindFileData.cFileName)); DWORD flag = GetFileAttributesW(CMB2WC(m_szPathStr)); - if (emptyOrRepeatPath(CWC2MB(FindFileData.cFileName))) - { - continue; - } + if(emptyOrRepeatPath(CWC2MB(FindFileData.cFileName))) + { + continue; + } - //Берет только имена директорий - if (flag != INVALID_FILE_ATTRIBUTES && flag & FILE_ATTRIBUTE_DIRECTORY) - { + //Берет только имена директорий + if(flag != INVALID_FILE_ATTRIBUTES && flag & FILE_ATTRIBUTE_DIRECTORY) + { sprintf(m_szPathStr, "%s%s", m_szBasePath, (const char*)CWC2MB(FindFileData.cFileName)); if(m_mapExistPath.KeyExists(m_szPathStr)) @@ -49,26 +49,27 @@ const char *CFolderPathsIterator::next() { //Возвращаем относительный путь к директории m_mapExistPath[m_szPathStr] = index; - return m_szPathStr; + return(m_szPathStr); } - } - } while (FindNextFileW(hf, &FindFileData) != 0); - } + } + } + while(FindNextFileW(hf, &FindFileData) != 0); + } FIND_CLOSE(m_handle); ++index; - } + } - //Если вообще не нашли файлов возвращаем nullptr - return nullptr; + //Если вообще не нашли файлов возвращаем nullptr + return(NULL); } void CFolderPathsIterator::reset() { - index = 0; - FIND_CLOSE(m_handle); + index = 0; + FIND_CLOSE(m_handle); } CFolderPathsIterator::~CFolderPathsIterator() { - FIND_CLOSE(m_handle); + FIND_CLOSE(m_handle); } -- GitLab From e7a0bde38fe2701a6b8444b3f61dfe00989131df Mon Sep 17 00:00:00 2001 From: EyeGuy <vanya619@list.ru> Date: Sun, 2 Feb 2025 04:25:21 +0300 Subject: [PATCH 3/3] Fix small problems --- source/core/BaseFileIterator.cpp | 9 ++++-- source/core/FileExtsIterator.cpp | 2 +- source/core/FileRecursiveExtPathsIterator.cpp | 29 ++++++++++--------- source/core/FileRecursiveExtPathsIterator.h | 4 +-- source/core/FolderPathsIterator.cpp | 2 +- 5 files changed, 26 insertions(+), 20 deletions(-) diff --git a/source/core/BaseFileIterator.cpp b/source/core/BaseFileIterator.cpp index fc42cf4d6..97884dc64 100644 --- a/source/core/BaseFileIterator.cpp +++ b/source/core/BaseFileIterator.cpp @@ -45,11 +45,16 @@ void CBaseFileIterator::fillExtensionsArray(Array<AAString> &extsArray, const ch bool CBaseFileIterator::findExtensionsInPath(const char *szPath, const Array<AAString> &exts) { + size_t len = strlen(szPath), extLen = 0; + char szExt[32]; + for(int i = 0, I = exts.size(); i < I; ++i) { - if(strstr(szPath, exts[i].getName()) != NULL) + extLen = strlen(exts[i].getName()) + 1; + sprintf(szExt, ".%s", exts[i].getName()); + if(!strcmp(szPath + len - extLen, szExt)) { - return true; + return(true); } } return(!exts.size()); diff --git a/source/core/FileExtsIterator.cpp b/source/core/FileExtsIterator.cpp index b4e22059f..67ab1aeef 100644 --- a/source/core/FileExtsIterator.cpp +++ b/source/core/FileExtsIterator.cpp @@ -2,7 +2,7 @@ CFileExtsIterator::CFileExtsIterator(Array<String> &paths, const char *szBasePath, const char **szExt, int iExtSize) { - m_paths = std::move(paths); + m_paths.swap(paths); strcpy(m_szBasePath, szBasePath); canonizePaths(m_paths); diff --git a/source/core/FileRecursiveExtPathsIterator.cpp b/source/core/FileRecursiveExtPathsIterator.cpp index b8ce1f9fb..ab45a9305 100644 --- a/source/core/FileRecursiveExtPathsIterator.cpp +++ b/source/core/FileRecursiveExtPathsIterator.cpp @@ -3,9 +3,9 @@ CFileRecursiveExtPathsIterator::CFileRecursiveExtPathsIterator(Array<String> &paths, const char *szBasePath, const char **szExts, int iExtSize) { strcpy(m_szBasePath, szBasePath); - m_sPaths = std::move(paths); + m_aPaths.swap(paths); - canonizePaths(m_sPaths); + canonizePaths(m_aPaths); canonizePath(m_szBasePath); fillExtensionsArray(m_exts, szExts, iExtSize); @@ -18,7 +18,7 @@ const char *CFileRecursiveExtPathsIterator::next() WIN32_FIND_DATAW FindFileData; HANDLE hf; - UINT maxPathIndex = m_sPaths.size(); + UINT maxPathIndex = m_aPaths.size(); FindFileData.cFileName[0] = '\0'; @@ -26,11 +26,11 @@ const char *CFileRecursiveExtPathsIterator::next() { if(strlen(m_szCurrentFullPath) > 0) { - strcpy(m_szCurrentFullPath, m_sPaths[pathIndex].c_str()); + strcpy(m_szCurrentFullPath, m_aPaths[pathIndex].c_str()); } do { - sprintf(szFileName, "%s*.*", m_sPaths[pathIndex].c_str()); + sprintf(szFileName, "%s*.*", m_aPaths[pathIndex].c_str()); //Проверяем указатель, если m_handle пустой, то ищем первый файл с расширением szExts hf = INVALID_OR_NULL(m_handle) ? FindFirstFileW(CMB2WC(szFileName), &FindFileData) : m_handle; @@ -46,14 +46,14 @@ const char *CFileRecursiveExtPathsIterator::next() continue; } - sprintf(szFullName, "%s%s", m_sPaths[pathIndex].c_str(), (const char*)CWC2MB(FindFileData.cFileName)); + sprintf(szFullName, "%s%s", m_aPaths[pathIndex].c_str(), (const char*)CWC2MB(FindFileData.cFileName)); DWORD flag = GetFileAttributesW(CMB2WC(szFullName)); if (flag != INVALID_FILE_ATTRIBUTES && (flag & FILE_ATTRIBUTE_DIRECTORY)) { strcat(szFullName, "/"); - m_folderList.push_back(szFullName); + m_aFolders.push_back(szFullName); continue; } @@ -84,19 +84,20 @@ const char *CFileRecursiveExtPathsIterator::next() //Если указатель на файл валидный, то проверяем все отфильтрованные файлы по порядку } while (FindNextFileW(hf, &FindFileData) != 0); - if (m_folderList.size() != 0) + if (m_aFolders.size() != 0) { UINT index = 0; - m_sPaths[pathIndex] = m_folderList[index]; - m_folderList.erase(index); + m_aPaths[pathIndex] = m_aFolders[index]; + m_aFolders.erase(index); m_handle = NULL; } else { - m_sPaths[pathIndex] = m_szCurrentFullPath; + m_aPaths[pathIndex] = m_szCurrentFullPath; } } - } while (m_sPaths[pathIndex] != m_szCurrentFullPath); + } + while(m_aPaths[pathIndex] != m_szCurrentFullPath); ++pathIndex; m_szCurrentFullPath[0] = 0; m_handle = NULL; @@ -108,8 +109,8 @@ const char *CFileRecursiveExtPathsIterator::next() void CFileRecursiveExtPathsIterator::reset() { - if (m_sPaths.size() < pathIndex) - m_sPaths[pathIndex] = m_szCurrentFullPath; + if(m_aPaths.size() < pathIndex) + m_aPaths[pathIndex] = m_szCurrentFullPath; m_szCurrentFullPath[0] = 0; m_mapExistPath.clear(); diff --git a/source/core/FileRecursiveExtPathsIterator.h b/source/core/FileRecursiveExtPathsIterator.h index 341dcd8b9..83a8d83fc 100644 --- a/source/core/FileRecursiveExtPathsIterator.h +++ b/source/core/FileRecursiveExtPathsIterator.h @@ -11,8 +11,8 @@ See the license in LICENSE class CFileRecursiveExtPathsIterator final : public CBaseFileIterator { private: - Array<String> m_folderList; - Array<String> m_sPaths; + Array<String> m_aFolders; + Array<String> m_aPaths; Array<AAString> m_exts; AssotiativeArray<String, int> m_mapExistPath; diff --git a/source/core/FolderPathsIterator.cpp b/source/core/FolderPathsIterator.cpp index 7687571f1..dd271e77c 100644 --- a/source/core/FolderPathsIterator.cpp +++ b/source/core/FolderPathsIterator.cpp @@ -2,7 +2,7 @@ CFolderPathsIterator::CFolderPathsIterator(Array<String> &paths, const char *szBasePath) { - m_paths = std::move(paths); + m_paths.swap(paths); strcpy(m_szBasePath, szBasePath); canonizePaths(m_paths); -- GitLab