MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / buildFileList

Function buildFileList

Engine/source/console/fileSystemFunctions.cpp:53–136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51static U32 sgFindFilesPos = 0;
52
53static S32 buildFileList(const char* pattern, bool recurse, bool multiMatch)
54{
55 static const String sSlash( "/" );
56
57 sgFindFilesResults.clear();
58
59 String sPattern(Torque::Path::CleanSeparators(pattern));
60 if(sPattern.isEmpty())
61 {
62 Con::errorf("findFirstFile() requires a search pattern");
63 return -1;
64 }
65
66 if(!Con::expandScriptFilename(sgScriptFilenameBuffer, sizeof(sgScriptFilenameBuffer), sPattern.c_str()))
67 {
68 Con::errorf("findFirstFile() given initial directory cannot be expanded: '%s'", pattern);
69 return -1;
70 }
71 sPattern = String::ToString(sgScriptFilenameBuffer);
72
73 String::SizeType slashPos = sPattern.find('/', 0, String::Right);
74// if(slashPos == String::NPos)
75// {
76// Con::errorf("findFirstFile() missing search directory or expression: '%s'", sPattern.c_str());
77// return -1;
78// }
79
80 // Build the initial search path
81 Torque::Path givenPath(Torque::Path::CompressPath(sPattern));
82 givenPath.setFileName("*");
83 givenPath.setExtension("*");
84
85 if(givenPath.getPath().length() > 0 && givenPath.getPath().find('*', 0, String::Right) == givenPath.getPath().length()-1)
86 {
87 // Deal with legacy searches of the form '*/*.*'
88 String suspectPath = givenPath.getPath();
89 String::SizeType newLen = suspectPath.length()-1;
90 if(newLen > 0 && suspectPath.find('/', 0, String::Right) == suspectPath.length()-2)
91 {
92 --newLen;
93 }
94 givenPath.setPath(suspectPath.substr(0, newLen));
95 }
96
97 Torque::FS::FileSystemRef fs = Torque::FS::GetFileSystem(givenPath);
98 //Torque::Path path = fs->mapTo(givenPath);
99 Torque::Path path = givenPath;
100
101 // Make sure that we have a root so the correct file system can be determined when using zips
102 if(givenPath.isRelative())
103 path = Torque::Path::Join(Torque::FS::GetCwd(), '/', givenPath);
104
105 path.setFileName(String::EmptyString);
106 path.setExtension(String::EmptyString);
107 if(!Torque::FS::IsDirectory(path))
108 {
109 Con::errorf("findFirstFile() invalid initial search directory: '%s'", path.getFullPath().c_str());
110 return -1;

Callers 1

Calls 15

expandScriptFilenameFunction · 0.85
GetFileSystemFunction · 0.85
IsDirectoryFunction · 0.85
FindByPatternFunction · 0.85
substrMethod · 0.80
isRelativeMethod · 0.80
errorfFunction · 0.70
clearMethod · 0.45
isEmptyMethod · 0.45
c_strMethod · 0.45
findMethod · 0.45
setExtensionMethod · 0.45

Tested by

no test coverage detected