//-------------------------------------------------------------------------- bool VeWildNameMatch(const VeChar8* pcName, const VeChar8* pcPattern) { bool bRes; while(*pcName) { if(*pcPattern == '*') { while((*pcPattern == '*') || (*pcPattern == '?')) ++pcPattern; if (!*pcPattern) return true; while (*pcName && (*pcName != *pcPattern)) ++pcName; if(!*pcName) return false; bRes = VeWildNameMatch(pcName, pcPattern); while((!bRes) && (*(pcName + 1)) && (*pcName == *pcPattern)) bRes = VeWildNameMatch(++pcName, pcPattern); return bRes; } else { if((*pcName == *pcPattern) || ('?' == *pcPattern)) { return VeWildNameMatch(++pcName, ++pcPattern); } else { return false; } } } return (*pcPattern) ? (*pcPattern == '*') && (*(pcPattern + 1) == 0) : true; }
//-------------------------------------------------------------------------- void VeAssetPath::FindFileList(const VeChar8* pcDesc, VeVector<VeFixedString>& kOut) const noexcept { const VeChar8* pcFile = VeStrrchr(pcDesc, '/'); pcFile = pcFile ? (pcFile + 1) : pcDesc; AAssetDir* pkDir(nullptr); if (pcFile == pcDesc) { pkDir = AAssetManager_openDir(s_pkAssetManager, m_kPath); } else { VeChar8 acBuffer[VE_MAX_PATH_LEN]; VeChar8* pcTemp = acBuffer; if (m_kPath.GetLength()) { pcTemp += VeSprintf(acBuffer, "%s/", m_kPath.GetStr()); } VeStrncpy(pcTemp, VE_MAX_PATH_LEN, pcDesc, pcFile - pcDesc - 1); pkDir = AAssetManager_openDir(s_pkAssetManager, acBuffer); } if (pkDir) { const VeChar8* pcEntry; while ((pcEntry = AAssetDir_getNextFileName(pkDir))) { if (VeWildNameMatch(pcEntry, pcFile)) { kOut.push_back(pcEntry); } } AAssetDir_close(pkDir); } }
//-------------------------------------------------------------------------- void VeFilePath::FindFileList(const VeChar8* pcDesc, VeVector<VeFixedString>& kOut) const noexcept { # ifdef VE_PLATFORM_WIN VeChar8 acBuffer[VE_MAX_PATH_LEN]; PATH_CAT(acBuffer, m_kPath, pcDesc); _finddata_t kData; VeSizeT stHandle = _findfirst(acBuffer, &kData); if (stHandle != VE_ELF) { do { if ((kData.attrib & 0xf0) == _A_ARCH) { kOut.push_back(kData.name); } } while (VE_SUCCEEDED(_findnext(stHandle, &kData))); VE_ASSERT_EQ(_findclose(stHandle), VE_S_OK); } # else const VeChar8* pcFile = VeStrrchr(pcDesc, '/'); pcFile = pcFile ? (pcFile + 1) : pcDesc; DIR* pkDir(nullptr); if (pcFile == pcDesc) { pkDir = opendir(m_kPath.GetLength() ? m_kPath : "."); } else { VeChar8 acBuffer[VE_MAX_PATH_LEN]; VeChar8* pcTemp = acBuffer; if (m_kPath.GetLength()) { pcTemp += VeSprintf(acBuffer, "%s/", m_kPath.GetStr()); } VeStrncpy(pcTemp, VE_MAX_PATH_LEN, pcDesc, pcFile - pcDesc - 1); pkDir = opendir(acBuffer); } if (pkDir) { struct dirent* pkEntry; while ((pkEntry = readdir(pkDir))) { if (pkEntry->d_type != DT_DIR) { if (VeWildNameMatch(pkEntry->d_name, pcFile)) { kOut.push_back(pkEntry->d_name); } } } VE_ASSERT_EQ(closedir(pkDir), VE_S_OK); } # endif }