diff --git a/source/core/BaseFileIterator.cpp b/source/core/BaseFileIterator.cpp index fb4ab2fe15bf608e513f5afb0d4df4ddbc92bad2..97884dc6494e6c8aec8b822984862ec8015bc4dc 100644 --- a/source/core/BaseFileIterator.cpp +++ b/source/core/BaseFileIterator.cpp @@ -1,49 +1,66 @@ #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 != '/') + if(symbol != '\\' && symbol != '/') { - sPath += '/'; + strcat(szPath, "/"); + } +} + +void CBaseFileIterator::canonizePath(String *pPath) +{ + char symbol = (*pPath)[pPath->length() - 1]; + + /*Дело в том что абсолютный путь к файлу может не иметь символ "/" + или "\\" на конце строки, и, если его не будет путь будет некорректен*/ + if(symbol != '\\' && symbol != '/') + { + (*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]); + 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) + 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<String> &exts) +bool CBaseFileIterator::findExtensionsInPath(const char *szPath, const Array<AAString> &exts) { - for (int i = 0, I = exts.size(); i < I; ++i) + 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].c_str()) != 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(); + 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/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..67ab1aeefc2b7712e338f8fcf372f3c1ebc385ce 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.swap(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,51 +20,55 @@ const char *CFileExtsIterator::next() int size = m_paths.size(); int sizeExt = m_exts.size(); - while (index < 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) + if(hf != INVALID_HANDLE_VALUE) { do { //Сохраняем 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)) + if(flag != INVALID_FILE_ATTRIBUTES && !(flag & FILE_ATTRIBUTE_DIRECTORY)) { - if (!findExtensionsInPath(CWC2MB(FindFileData.cFileName), m_exts)) + if(!findExtensionsInPath(CWC2MB(FindFileData.cFileName), m_exts)) { 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); } } //Если указатель на файл валидный, то проверяем все отфильтрованные файлы по порядку - } 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/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..ab45a930589d41a75bacba31d031ab7e2d510473 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_aPaths.swap(paths); - this->m_sPaths = paths; - this->m_sBasePath = sBasePath; + canonizePaths(m_aPaths); + 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_aPaths.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_aPaths[pathIndex].c_str()); + } + do { - String fileName = m_sPaths[pathIndex] + "*.*"; + sprintf(szFileName, "%s*.*", m_aPaths[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_aPaths[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_aFolders.push_back(szFullName); continue; } @@ -56,49 +64,55 @@ 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); } } //Если указатель на файл валидный, то проверяем все отфильтрованные файлы по порядку } 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_currentFullPath; + m_aPaths[pathIndex] = m_szCurrentFullPath; } } - } while (m_sPaths[pathIndex] != m_currentFullPath); + } + while(m_aPaths[pathIndex] != m_szCurrentFullPath); ++pathIndex; - m_currentFullPath.release(); + m_szCurrentFullPath[0] = 0; m_handle = NULL; } //Если вообще не нашли файлов возвращаем nullptr - return nullptr; + return(NULL); } void CFileRecursiveExtPathsIterator::reset() { - if (m_sPaths.size() < pathIndex) - m_sPaths[pathIndex] = m_currentFullPath; + if(m_aPaths.size() < pathIndex) + m_aPaths[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..83a8d83fc13975b2d5480971c4a7b7f5ec4f4b13 100644 --- a/source/core/FileRecursiveExtPathsIterator.h +++ b/source/core/FileRecursiveExtPathsIterator.h @@ -11,14 +11,14 @@ See the license in LICENSE class CFileRecursiveExtPathsIterator final : public CBaseFileIterator { private: - Array<String> m_folderList; - Array<String> m_sPaths; - Array<String> m_exts; + Array<String> m_aFolders; + Array<String> m_aPaths; + 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..0d2df98e80c5742d4dd6fde652cc07d2847bb68b 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); } } } @@ -260,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]; @@ -275,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) @@ -293,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) @@ -316,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) @@ -336,53 +338,55 @@ 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) { 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) : 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) @@ -440,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]; @@ -449,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; @@ -461,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]; @@ -488,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) @@ -516,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/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..dd271e77cbcebc1dc26ba6f432f3adc5530d35bd 100644 --- a/source/core/FolderPathsIterator.cpp +++ b/source/core/FolderPathsIterator.cpp @@ -1,73 +1,75 @@ #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.swap(paths); + strcpy(m_szBasePath, szBasePath); - this->m_paths = paths; - this->m_sBasePath = sBasePath; + canonizePaths(m_paths); + canonizePath(m_szBasePath); } 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; - 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))) - { - continue; - } + if(emptyOrRepeatPath(CWC2MB(FindFileData.cFileName))) + { + continue; + } - //Берет только имена директорий - if (flag != INVALID_FILE_ATTRIBUTES && flag & FILE_ATTRIBUTE_DIRECTORY) - { - m_pathStr = (m_sBasePath + CWC2MB(FindFileData.cFileName)); - if (m_mapExistPath.KeyExists(m_pathStr)) + //Берет только имена директорий + 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)) { 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); - } + } + } + 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); } 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;