Надеюсь, что утечек памяти не получил.
Код
...
ArrayList g_SoundsArray;
...
public OnPluginStart()
{
g_SoundsArray = new ArrayList(ByteCountToCells(PLATFORM_MAX_PATH));
GetSounds(g_SoundsArray, "sound/hit/", "kevlar");
}
void GetSounds(ArrayList array, const char[] sPath, const char[] sFiltr)
{
DirectoryListing dir;
if ((dir = OpenDirectory(sPath)))
{
char name[PLATFORM_MAX_PATH];
char path[PLATFORM_MAX_PATH];
FileType type;
while (dir.GetNext(name, sizeof(name), type))
{
if (type == FileType_File)
{
if (StrEqual(name[strlen(name) - 4], ".wav", false) || StrEqual(name[strlen(name) - 4], ".mp3", false))
{
if (!strlen(sFiltr))
{
FormatEx(path, sizeof(path), "%s%s", sPath, name);
array.PushString(path);
}
else
{
if (StrContains(name, sFiltr, false) != -1)
{
FormatEx(path, sizeof(path), "%s%s", sPath, name);
array.PushString(path);
}
}
}
}
}
dir.Close();
}
else
LogError("Failed to open directory: %s", sPath);
}