/* Copyright (c) 2002-2012 Croteam Ltd. This program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "stdh.h" #include #include #include #include #include extern CDynamicStackArray _afnmBaseBrowseInc; extern CDynamicStackArray _afnmBaseBrowseExc; class CDirToRead { public: CListNode dr_lnNode; CTString dr_strDir; }; int qsort_CompareCTFileName(const void *elem1, const void *elem2 ) { const CTFileName &fnm1 = **(CTFileName **)elem1; const CTFileName &fnm2 = **(CTFileName **)elem2; return strcmp(fnm1, fnm2); } extern BOOL FileMatchesList(CDynamicStackArray &afnm, const CTFileName &fnm); void FillDirList_internal(const CTFileName &fnmBasePath, CDynamicStackArray &afnm, const CTFileName &fnmDir, const CTString &strPattern, BOOL bRecursive, CDynamicStackArray *pafnmInclude, CDynamicStackArray *pafnmExclude) { // add the directory to list of directories to search CListHead lhDirs; CDirToRead *pdrFirst = new CDirToRead; pdrFirst->dr_strDir = fnmDir; lhDirs.AddTail(pdrFirst->dr_lnNode); // while the list of directories is not empty while (!lhDirs.IsEmpty()) { // take the first one CDirToRead *pdr = LIST_HEAD(lhDirs, CDirToRead, dr_lnNode); CTFileName fnmDir = pdr->dr_strDir; delete pdr; // if the dir is not allowed if (pafnmInclude!=NULL && (!FileMatchesList(*pafnmInclude, fnmDir) || FileMatchesList(*pafnmExclude, fnmDir)) ) { // skip it continue; } // start listing the directory struct _finddata_t c_file; long hFile; hFile = _findfirst( (const char *)(fnmBasePath+fnmDir+"*"), &c_file ); // for each file in the directory for ( BOOL bFileExists = hFile!=-1; bFileExists; bFileExists = _findnext( hFile, &c_file )==0) { // if dummy dir (this dir, parent dir, or any dir starting with '.') if (c_file.name[0]=='.') { // skip it continue; } // get the file's filepath CTFileName fnm = fnmDir+c_file.name; // if it is a directory if (c_file.attrib&_A_SUBDIR) { // if recursive reading if (bRecursive) { // add it to the list of directories to search CDirToRead *pdrNew = new CDirToRead; pdrNew->dr_strDir = fnm+"\\"; lhDirs.AddTail(pdrNew->dr_lnNode); } // if it matches the pattern } else if (strPattern=="" || fnm.Matches(strPattern)) { // add that file afnm.Push() = fnm; } } } } // make a list of all files in a directory ENGINE_API void MakeDirList( CDynamicStackArray &afnmDir, const CTFileName &fnmDir, const CTString &strPattern, ULONG ulFlags) { afnmDir.PopAll(); BOOL bRecursive = ulFlags&DLI_RECURSIVE; BOOL bSearchCD = ulFlags&DLI_SEARCHCD; // make one temporary array CDynamicStackArray afnm; if (_fnmMod!="") { FillDirList_internal(_fnmApplicationPath, afnm, fnmDir, strPattern, bRecursive, &_afnmBaseBrowseInc, &_afnmBaseBrowseExc); if (bSearchCD) { FillDirList_internal(_fnmCDPath, afnm, fnmDir, strPattern, bRecursive, &_afnmBaseBrowseInc, &_afnmBaseBrowseExc); } FillDirList_internal(_fnmApplicationPath+_fnmMod, afnm, fnmDir, strPattern, bRecursive, NULL, NULL); } else { FillDirList_internal(_fnmApplicationPath, afnm, fnmDir, strPattern, bRecursive, NULL, NULL); if (bSearchCD) { FillDirList_internal(_fnmCDPath, afnm, fnmDir, strPattern, bRecursive, NULL, NULL); } } // for each file in zip archives CTString strDirPattern = fnmDir; INDEX ctFilesInZips = UNZIPGetFileCount(); for(INDEX iFileInZip=0; iFileInZip