PHP Code:
// Folders what we looking for
new String:SearchFolders[][] = {
"materials",
"models",
"sound",
"particles",
"scripts",
"classes",
"shaders"
}
// File extensions what we look in each folder
new String:SearchFiles[][][] = {
{ "vmt", "vtf", "", "", "" }, // materials
{ "mdl", "phy", "ani", "vtx", "vvd" }, // models
{ "wav", "mp3", "", "", "" }, // sound
{ "pcf", "txt", "", "", "" }, // particles
{ "res", "txt", "", "", "" }, // scripts
{ "res", "", "", "", "" }, // classes
{ "vcs", "", "", "", "" } // shaders
}
public OnConfigsExecuted()
{
for(new a = 0; a < sizeof(SearchFolders); a++)
{
ReadDirectories(a);
}
}
ReadDirectories(index)
{
// Store path history
new Handle:folder_history = CreateArray(ByteCountToCells(PLATFORM_MAX_PATH));
new String:file[PLATFORM_MAX_PATH]; // Buffer file name
new String:location[PLATFORM_MAX_PATH]; // Buffer current location path
new String:next_location[PLATFORM_MAX_PATH]; // Buffer next location path
strcopy(location, sizeof(location), SearchFolders[index]);
new Handle:dir = OpenDirectory(location);
new FileType:type;
new charact;
// No such folder
if(dir == INVALID_HANDLE)
{
CloseHandle(folder_history);
return;
}
// Read files from root folder (ex. materials)
while(ReadDirEntry(dir, file, sizeof(file), type))
{
if(type == FileType_File)
{
charact = FindCharInString(file, '.', true);
if(charact != -1)
{
for(new a = 0; a < sizeof(SearchFiles[][]); a++)
{
if(StrEqual(file[charact+1], SearchFiles[index][a], false)) // File extension match with SearchFiles[folder index]
{
PrintToServer("-%s/%s", location, file);
}
}
}
}
}
CloseHandle(dir);
dir = OpenDirectory(location);
// Loop as long as we are back root folder (ex. materials)
while(dir != INVALID_HANDLE)
{
// Loop to read files from current directory
while(ReadDirEntry(dir, file, sizeof(file), type))
{
if(type == FileType_Directory) // folders only
{
if( !StrEqual(file, ".", false) && !StrEqual(file, "..", false) ) // skip "levels"
{
// Next location
Format(next_location, sizeof(next_location), "%s/%s", location, file);
// We already visit there... skip
if( FindStringInArray(folder_history, next_location) != -1 )
{
continue;
}
else // NEW directory!
{
// Save path location in history
PushArrayString(folder_history, next_location);
strcopy(location, sizeof(location), next_location);
//PrintToServer("location %s", location);
// Let's read files from here new directory
CloseHandle(dir);
dir = OpenDirectory(location);
while(ReadDirEntry(dir, file, sizeof(file), type))
{
if(type == FileType_File)
{
charact = FindCharInString(file, '.', true);
if(charact != -1)
{
for(new a = 0; a < sizeof(SearchFiles[][]); a++)
{
if(StrEqual(file[charact+1], SearchFiles[index][a], false)) // File extension match with SearchFiles[folder index]
{
PrintToServer("-%s/%s", location, file);
}
}
}
}
}
CloseHandle(dir);
dir = OpenDirectory(location);
}
}
}
}
CloseHandle(dir);
// Go directories/like/this <- backwards
charact = FindCharInString(location, '/', true);
if(charact != -1)
{
// remove last folder name from string.
location[charact] = '\0';
dir = OpenDirectory(location);
}
else // we have visit on all sub folders
{
dir = INVALID_HANDLE;
}
}
CloseHandle(folder_history);
}