SA-MP Forums Archive
fwrite & fdelete bug - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: fwrite & fdelete bug (/showthread.php?tid=620851)



fwrite & fdelete bug - NeXoR - 03.11.2016

Hey guys, I am improving my updates system, so here's my bug:
I can add GMX Required/Implemented/Update/BugFix as a new update using /addupdate, now I wanted to do that once the game mode starts, every GMX Required turns to Implemented automatically
I am parsing the updates to their types using a "type:%d" parameter
type:1 = implemented
type:2 = bugfix and so on

The problem is that, the update gets removed, but it's not re-written as Implemented

Here is the code:
PHP код:
if(!fexist("updates.cfg"))
    {
        new 
File:handle fopen("updates.cfg"io_readwrite);
        
fclose(handle);
    }
    else
    {
        new 
File:file fopen("updates.cfg"io_readwrite), idx 1string[128];
        while(
fread(filestring))
           {
            if(
strfind(string"type:2") != -1)
            {
                
fdeleteline("updates.cfg"idx);
                
strdel(stringstrlen(string) - 8strlen(string));
                
strins(string"type:0"strlen(string), sizeof(string));
                
fwrite(filestring);
            }
            
idx++;
           }
           
fclose(file);
    } 
Thanks in advance.


Re: fwrite & fdelete bug - NeXoR - 04.11.2016

Anyone?


Re: fwrite & fdelete bug - NeXoR - 04.11.2016

Please ?


Re: fwrite & fdelete bug - NeXoR - 05.11.2016

Come on guys ...


Re: fwrite & fdelete bug - Nero_3D - 05.11.2016

you need to close the file before using fdeleteline otherwise it can't open the file as it is already opened
fdeleteline is always a bad option, implement the code by yourself than you can write new lines at the deleted position (or create a freplace function)

Also if you use io_readwrite, you need to work with fseek and remeber that fwrite can overwrite existing content of the file
If you need an example / solution for io_readwrite I could show you


Re: fwrite & fdelete bug - NeXoR - 05.11.2016

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
you need to close the file before using fdeleteline otherwise it can't open the file as it is already opened
fdeleteline is always a bad option, implement the code by yourself than you can write new lines at the deleted position (or create a freplace function)

Also if you use io_readwrite, you need to work with fseek and remeber that fwrite can overwrite existing content of the file
If you need an example / solution for io_readwrite I could show you
Yeah I never actually used file functions, it could be nice if you explain yourself better


Re: fwrite & fdelete bug - Yaa - 05.11.2016

PHP код:
if(!fexist("updates.cfg")) 
    { 
        new 
File:handle fopen("updates.cfg"io_readwrite); 
        
fclose(handle); 
    } 
    else 
    { 
        new 
File:file fopen("updates.cfg"io_readwrite), idx 1string[128]; 
        while(
fread(filestring)) 
           { 
            if(
strfind(string"type:2") != -1
            { 
                
fdeleteline("updates.cfg"idx); 
                
strdel(stringstrlen(string) - 8strlen(string)); 
                
strins(string"type:0"strlen(string), sizeof(string)); 
                
fwrite(filestring); 
                
fclose(file); 
            } 
            
idx++; 
           } 
    } 
i think he means that


Re: fwrite & fdelete bug - ZiGGi - 05.11.2016

try this:
PHP код:
if(!fexist("updates.cfg"))
    {
        new 
File:handle fopen("updates.cfg"io_readwrite);
        
fclose(handle);
    }
    else
    {
        new 
File:file fopen("updates.cfg"io_readwrite), string[128];
        while(
fread(filestring))
            {
                if(
strfind(string"type:2") != -1)
                {
                    
string[5] = '1'// mark as implemented
                    
fwrite(filestring);
                }
            }
        
fclose(file);
    } 



Re: fwrite & fdelete bug - SickAttack - 05.11.2016

Use SQL.