View Single Post
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 01-25-2010 , 14:48   Re: FVault - A new vault system!
Reply With Quote #30

Here is a note about some of the functions/examples:

Looping through the vault for each key is VERY BAD!

Here is a better substitution:
Code:
stock fvault_load( const szVaultName[ ], Array:aKeys=Invalid_Array, Array:aData=Invalid_Array, Array:aTimeStamps=Invalid_Array ) {     new szFilename[ 128 ];     _FormatVaultName( szVaultName, szFilename, 127 );         new iFile = fopen( szFilename, "rt" );     if( !iFile ) {         return 0;     }         new iTotal;         new szFileData[ 1024 ];     new szKey[ 64 ], szData[ 512 ], szTimeStamp[ 32 ];     while( !feof( iFile ) ) {         fgets( iFile, szFileData, 1023 );         if( parse( szFileData, szKey, 63, szData, 511, szTimeStamp, 31 ) < 2 ) {             continue;         }                 if( aKeys != Invalid_Array ) {             ArrayPushString( aKeys, szKey );         }         if( aData != Invalid_Array ) {             ArrayPushString( aData, szData );         }         if( aTimeStamps != Invalid_Array ) {             ArrayPushCell( aTimeStamps, str_to_num( szTimeStamp ) );         }                 iTotal++;     }         fclose( iFile );         return iTotal; }
Code:
new Array:aKeys = ArrayCreate( 64 ); // MUST BE 64 OR GREATER new Array:aData = ArrayCreate( 512 ); // MUST BE 512 OR GREATER new iTotal = fvault_load( "myvault", aKeys, aData ); new szKey[ 64 ], szData[ 512 ]; for( new i = 0; i < iTotal; i++ ) {     ArrayGetString( aKeys, i, szKey, 63 );     ArrayGetString( aData, i, szData, 511 );         // szData for szKey }
To add timestamps:
Code:
new Array:aKeys = ArrayCreate( 64 ); // MUST BE 64 OR GREATER new Array:aData = ArrayCreate( 512 ); // MUST BE 512 OR GREATER new Array:aTimeStamps = ArrayCreate( 1 ); // MUST BE 1 new iTotal = fvault_load( "myvault", aKeys, aData, aTimeStamps ); new szKey[ 64 ], szData[ 512 ], iTimeStamp; for( new i = 0; i < iTotal; i++ ) {     ArrayGetString( aKeys, i, szKey, 63 );     ArrayGetString( aData, i, szData, 511 );     iTimeStamp = ArrayGetCell( aTimeStamps, i );         // szData for szKey last updated at iTimeStamp }
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline