int xWrite(sqlite3_file*file, const void*buffer, int iAmt, sqlite3_int64 iOfst) { struct my_file_data *my_file = (struct my_file_data*)file; size_t actual; #ifdef LOG_OPERATIONS lprintf( "Write %s %d at %d", my_file->filename, iAmt, iOfst ); //LogBinary( buffer, iAmt ); #endif { size_t filesize = sack_fsize( my_file->file ); if( filesize < iOfst ) { static unsigned char *filler; if( !filler ) { filler = NewArray( unsigned char, 512 ); MemSet( filler, 0, 512 ); } sack_fseek( my_file->file, 0, SEEK_END ); while( filesize < iOfst ) { if( ( iOfst - filesize ) >= 512 ) { sack_fwrite( filler, 1, 512, my_file->file ); filesize += 512; } else { sack_fwrite( filler, 1, ( iOfst - filesize ), my_file->file ); filesize += ( iOfst - filesize ); } } } }
static LOGICAL CPROC ExtractFile( CTEXTSTR name ) { if( StrCmp( name, ".app.config" ) == 0 ) { FILE *file = sack_fopenEx( 0, name, "rb", l.rom ); if( file ) { size_t sz = sack_fsize( file ); if( sz ) { POINTER data = NewArray( uint8_t, sz ); sack_fread( data, 1, sz, file ); ProcessConfigurationInput( l.pch, data, sz, 0 ); if( !l.target_path ) l.target_path = "."; Release( data ); } sack_fclose( file ); } } else { FILE *file; file = sack_fopenEx( 0, name, "rb", l.rom ); if( file ) { size_t sz = sack_fsize( file ); if( sz ) { POINTER data = NewArray( uint8_t, sz ); sack_fread( data, 1, sz, file ); /* this is where the file should be output */ { char target[256]; char *tmp; snprintf( target, 256, "%s/%s", l.target_path, name ); tmp = (char*)pathrchr( target ); if( tmp ) { tmp[0] = 0; if( !l.prior_output_path || StrCmp( l.prior_output_path, target ) ) { l.prior_output_path = strdup( target ); MakePath( target ); } tmp[0] = '/'; } { FILE *out; out = sack_fopenEx( 0, target, "wb", sack_get_default_mount() ); if( out ) { if( !l.first_file ) l.first_file = strdup( target ); sack_fwrite( data, 1, sz, out ); sack_fclose( out ); } } } Release( data ); } sack_fclose( file ); return TRUE; } } return FALSE; }