//----------------------------------------------------------------------- void FileSystemArchive::findFiles(const String& pattern, bool recursive, bool dirs, StringVector* simpleList, FileInfoList* detailList) const { long lHandle, res; struct _finddata_t tagData; // pattern can contain a directory name, separate it from mask size_t pos1 = pattern.rfind ('/'); size_t pos2 = pattern.rfind ('\\'); if (pos1 == pattern.npos || ((pos2 != pattern.npos) && (pos1 < pos2))) pos1 = pos2; String directory; if (pos1 != pattern.npos) directory = pattern.substr (0, pos1 + 1); String base_dir = mName; if (!directory.empty ()) { base_dir = concatenate_path(mName, directory); // Remove the last '/' base_dir.erase (base_dir.length () - 1); } //if there's a file with the name "norecurse" we shouldn't recurse further std::ifstream norecurseFile((base_dir + "/norecurse").c_str()); if (!norecurseFile.fail()) { return; } base_dir.append ("/*"); String full_pattern = concatenate_path(mName, pattern); lHandle = _findfirst(full_pattern.c_str(), &tagData); res = 0; while (lHandle != -1 && res != -1) { if ((dirs == ((tagData.attrib & _A_SUBDIR) != 0)) && (!dirs || !is_reserved_dir (tagData.name))) { if (simpleList) { simpleList->push_back(directory + tagData.name); } else if (detailList) { FileInfo fi; fi.archive = this; fi.filename = directory + tagData.name; fi.basename = tagData.name; fi.path = directory; fi.compressedSize = tagData.size; fi.uncompressedSize = tagData.size; detailList->push_back(fi); } } res = _findnext( lHandle, &tagData ); } // Close if we found any files if(lHandle != -1) _findclose(lHandle); // Now find directories if (recursive) { // Remove directory name from pattern String mask ("/"); if (pos1 != pattern.npos) mask.append (pattern.substr (pos1 + 1)); else mask.append (pattern); lHandle = _findfirst(base_dir.c_str (), &tagData); res = 0; while (lHandle != -1 && res != -1) { //if the name of the directory is "source" we should ignore it, since these are directories //containing raw source materials (.psd files, .blend files etc) which we don't want to bring //into the client (they tend to be rather large) if ((tagData.attrib & _A_SUBDIR) && !is_reserved_dir (tagData.name) && !(tagData.attrib & _A_HIDDEN) && std::strcmp(tagData.name, "source") != 0) { // recurse base_dir = directory; base_dir.append (tagData.name).append (mask); findFiles(base_dir, recursive, dirs, simpleList, detailList); } res = _findnext( lHandle, &tagData ); } // Close if we found any files if(lHandle != -1) _findclose(lHandle); } }
//----------------------------------------------------------------------- void FileSystemArchive::findFiles(const String& pattern, bool recursive, bool dirs, StringVector* simpleList, FileInfoList* detailList) const { intptr_t lHandle, res; struct _finddata_t tagData; // pattern can contain a directory name, separate it from mask size_t pos1 = pattern.rfind ('/'); size_t pos2 = pattern.rfind ('\\'); if (pos1 == pattern.npos || ((pos2 != pattern.npos) && (pos1 < pos2))) pos1 = pos2; String directory; if (pos1 != pattern.npos) directory = pattern.substr (0, pos1 + 1); String full_pattern = concatenate_path(mName, pattern); lHandle = _findfirst(full_pattern.c_str(), &tagData); res = 0; while (lHandle != -1 && res != -1) { if ((dirs == ((tagData.attrib & _A_SUBDIR) != 0)) && ( !msIgnoreHidden || (tagData.attrib & _A_HIDDEN) == 0 ) && (!dirs || !is_reserved_dir (tagData.name))) { if (simpleList) { simpleList->push_back(directory + tagData.name); } else if (detailList) { FileInfo fi; fi.archive = this; fi.filename = directory + tagData.name; fi.basename = tagData.name; fi.path = directory; fi.compressedSize = tagData.size; fi.uncompressedSize = tagData.size; detailList->push_back(fi); } } res = _findnext( lHandle, &tagData ); } // Close if we found any files if(lHandle != -1) _findclose(lHandle); // Now find directories if (recursive) { String base_dir = mName; if (!directory.empty ()) { base_dir = concatenate_path(mName, directory); // Remove the last '/' base_dir.erase (base_dir.length () - 1); } base_dir.append ("/*"); // Remove directory name from pattern String mask ("/"); if (pos1 != pattern.npos) mask.append (pattern.substr (pos1 + 1)); else mask.append (pattern); lHandle = _findfirst(base_dir.c_str (), &tagData); res = 0; while (lHandle != -1 && res != -1) { if ((tagData.attrib & _A_SUBDIR) && ( !msIgnoreHidden || (tagData.attrib & _A_HIDDEN) == 0 ) && !is_reserved_dir (tagData.name)) { // recurse base_dir = directory; base_dir.append (tagData.name).append (mask); findFiles(base_dir, recursive, dirs, simpleList, detailList); } res = _findnext( lHandle, &tagData ); } // Close if we found any files if(lHandle != -1) _findclose(lHandle); } }
void findFiles(const std::string& pattern, bool recursives, bool dirs, std::vector<std::string>& simpleList) { intptr_t lHandle, res; struct _finddata_t tagData; size_t pos1 = pattern.rfind('/'); size_t pos2 = pattern.rfind('\\'); if (pos1 == pattern.npos || ((pos2 != pattern.npos) && (pos1 < pos2))) pos1 = pos2; std::string directory; if (pos1 != pattern.npos) directory = pattern.substr(0, pos1 + 1); lHandle = _findfirst(pattern.c_str(), &tagData); res = 0; while (lHandle != -1 && res != -1) { if (dirs && ((tagData.attrib & _A_SUBDIR) != 0) && !is_reserved_dir(tagData.name)) { simpleList.push_back(directory + tagData.name); } if ((tagData.attrib & _A_SUBDIR) == 0) { simpleList.push_back(directory + tagData.name); } res = _findnext(lHandle, &tagData); } if (lHandle != -1) _findclose(lHandle); if (recursives) { std::string base_dir = directory; base_dir.erase(base_dir.length() - 1); base_dir.append("/*"); std::string mask("/"); if (pos1 != pattern.npos) mask.append(pattern.substr(pos1 + 1)); else mask.append(pattern); lHandle = _findfirst(base_dir.c_str(), &tagData); res = 0; while (lHandle != -1 && res != -1) { if ((tagData.attrib & _A_SUBDIR)) { base_dir = directory; base_dir.append(tagData.name).append(mask); findFiles(base_dir, recursives, dirs, simpleList); } res = _findnext(lHandle, &tagData); } if (lHandle != -1) _findclose(lHandle); } }