Raised This Month: $51 Target: $400
 12% 

[SOLVED] FileExists strangeness


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
dataviruset
AlliedModders Donor
Join Date: Feb 2009
Location: Hong Kong
Old 12-19-2009 , 11:02   [SOLVED] FileExists strangeness
Reply With Quote #1

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_SMfile255"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(filehbuffersizeof(buffer)))
        {
            if ( (
StrContains(buffer"//") == -1) && (!StrEqual(buffer"")) && (!StrEqual(buffer"\n")) )
            {
                
PrintToServer("Reading sounddownloads line :: %s"buffer);
                
Format(buffer_fullsizeof(buffer_full), "sound/%s"buffer);
                if (
FileExists(buffer_full))
                {
                    
PrintToServer("Precaching %s"buffer);
                    
PrecacheSound(buffertrue);
                    
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_SMfile255"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(filehbuffersizeof(buffer)))
        {
            
TrimString(buffer);
            if ( (
StrContains(buffer"//") == -1) && (!StrEqual(buffer"")) /*&& (!StrEqual(buffer, "\n"))*/ )
            {
                
PrintToServer("Reading sounddownloads line :: %s"buffer);
                
Format(buffer_fullsizeof(buffer_full), "sound/%s"buffer);
                if (
FileExists(buffer_full))
                {
                    
PrintToServer("Precaching %s"buffer);
                    
PrecacheSound(buffertrue);
                    
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);
            }
        }

    }


Last edited by dataviruset; 12-20-2009 at 08:47. Reason: Solved it myself =D
dataviruset is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:40.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode