Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #if defined _dfile_included
- #endinput
- #endif
- #define _dfile_included
- #pragma library dfile
- /**/
- stock FixNumber[20];
- /* Criar */
- #define DFile_Create(%0) \
- if(!fexist(%0)) fclose(fopen(%0,io_write))
- /* Remover */
- #define DFile_Remove(%0) \
- if(fexist(%0)) fremove(%0)
- /* Verificar Existencia */
- #define DFile_Exists(%0) \
- fexist(%0)
- /* Getagem */
- #define DFile_GetInt(%0,%1) \
- strval(DFile_Get(%0, %1))
- #define DFile_GetString(%0,%1) \
- DFile_Get(%0, %1)
- #define DFile_GetBool(%0,%1) \
- DFile_Get(%0, %1)
- #define DFile_GetFloat(%0,%1) \
- floatstr(DFile_Get(%0, %1))
- /* Setagem */
- #define DFile_SetInt(%0,%1,%2) \
- format(FixNumber, sizeof(FixNumber), "%d", %2), DFile_SetEx(%0, %1, FixNumber)
- #define DFile_SetString(%0,%1,%2) \
- DFile_SetEx(%0, %1, %2)
- #define DFile_SetBool(%0,%1,%2) \
- DFile_SetEx(%0, %1, %2 ? "true" : "false" )
- #define DFile_SetFloat(%0,%1,%2) \
- format(FixNumber, sizeof(FixNumber), "%f", %2), DFile_SetEx(%0, %1, FixNumber)
- new _@strwritec[1000], _@strtoread[200], _@strtowrite[128];
- stock DFile_SetEx(file[], tag[], value[])
- {
- static File:_@filetoread, File:_@filetowrite;
- _@strwritec[0] = EOS;
- _@strtoread[0] = EOS;
- _@strtowrite[0] = EOS;
- format(_@strtowrite, sizeof(_@strtowrite), "%s=%s\r\n", tag, value);
- if(!fexist(file))
- return
- _@filetowrite = fopen(file, io_write),
- fwrite(_@filetowrite, _@strtowrite),
- fclose(_@filetowrite)
- ;
- _@filetoread = fopen(file, io_read), _@filetowrite = fopen(file, io_write);
- while(fread(_@filetoread, _@strtoread))
- {
- if(strfind(_@strtoread, tag, false) == -1)
- strcat(_@strwritec, _@strtoread);
- else
- strcat(_@strwritec, _@strtowrite);
- }
- fclose(_@filetoread);
- strcat(_@strwritec, _@strtowrite);
- fwrite(_@filetowrite, _@strwritec);
- return fclose(_@filetowrite);
- }
- stock DFile_Get(file[], tag[])
- {
- new _@read_s[128], _@idx;
- if(!file[0]) return _@read_s;
- if(!fexist(file)) return _@read_s;
- if(!tag[0]) return _@read_s;
- new File: _@arq = fopen(file, io_read);
- while (fread(_@arq, _@read_s))
- {
- if(~(_@idx = strfind(_@read_s, "=", false)))
- {
- _@read_s[_@idx] = '\0';
- if (strcmp(_@read_s, tag) == 0)
- {
- format(_@read_s, sizeof(_@read_s), "%s", _@read_s[++_@idx]);
- fclose(_@arq);
- return _@read_s;
- }
- }
- }
- return _@read_s;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement