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] 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