fwrite & fdelete bug
#1

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.
Reply
#2

Anyone?
Reply
#3

Please ?
Reply
#4

Come on guys ...
Reply
#5

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
Reply
#6

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
Reply
#7

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
Reply
#8

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);
    } 
Reply
#9

Use SQL.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)