Hello everyone.
I use this code to read sound downloads from a file and then download and precache them.
When I have one download listed in my file, it is downloaded and precached correctly, but when I have two or more, only the last file is downloaded and precached. I get "file does not exist" in my server console for those files who doesn't get downloaded. Any ideas?
PHP Code:
public OnMapStart()
{
new String:file[256];
BuildPath(Path_SM, file, 255, "configs/hosties_sounddownloads.ini");
new Handle:fileh = OpenFile(file, "r");
if (fileh != INVALID_HANDLE)
{
new String:buffer[256];
new String:buffer_full[PLATFORM_MAX_PATH];
while(ReadFileLine(fileh, buffer, sizeof(buffer)))
{
if ( (StrContains(buffer, "//") == -1) && (!StrEqual(buffer, "")) && (!StrEqual(buffer, "\n")) )
{
PrintToServer("Reading sounddownloads line :: %s", buffer);
Format(buffer_full, sizeof(buffer_full), "sound/%s", buffer);
if (FileExists(buffer_full))
{
PrintToServer("Precaching %s", buffer);
PrecacheSound(buffer, true);
AddFileToDownloadsTable(buffer_full);
PrintToServer("Adding %s to downloads table", buffer_full);
}
else
{
PrintToServer("File does not exist! %s", buffer_full);
}
}
else
{
PrintToServer("Ignoring sounddownloads line :: %s", buffer);
}
}
}
}
EDIT: Oh, never mind. I found the error myself. You have to use TrimString on the line before checking it (otherwise it will end with a line-break (\n) if it isn't the last line...):
PHP Code:
public OnMapStart()
{
new String:file[256];
BuildPath(Path_SM, file, 255, "configs/hosties_sounddownloads.ini");
new Handle:fileh = OpenFile(file, "r");
if (fileh != INVALID_HANDLE)
{
new String:buffer[256];
new String:buffer_full[PLATFORM_MAX_PATH];
while(ReadFileLine(fileh, buffer, sizeof(buffer)))
{
TrimString(buffer);
if ( (StrContains(buffer, "//") == -1) && (!StrEqual(buffer, "")) /*&& (!StrEqual(buffer, "\n"))*/ )
{
PrintToServer("Reading sounddownloads line :: %s", buffer);
Format(buffer_full, sizeof(buffer_full), "sound/%s", buffer);
if (FileExists(buffer_full))
{
PrintToServer("Precaching %s", buffer);
PrecacheSound(buffer, true);
AddFileToDownloadsTable(buffer_full);
PrintToServer("Adding %s to downloads table", buffer_full);
}
else
{
PrintToServer("File does not exist! %s", buffer_full);
}
}
else
{
PrintToServer("Ignoring sounddownloads line :: %s", buffer);
}
}
}
}