msi: Break out field exporting into a separate routine.

msi_export_record is a lot more complicated than necessary, this patch
splits out the field export part of that functionality as
msi_export_field.  This also needs to be separate for exporting binary
stream data (next patch).

Signed-off-by: Erich E. Hoover <erich.e.hoover@gmail.com>
Signed-off-by: Hans Leidekker <hans@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Erich E. Hoover 2019-03-15 10:03:58 +01:00 committed by Alexandre Julliard
parent 79fd42fc1a
commit b08d999863
1 changed files with 47 additions and 31 deletions

View File

@ -918,50 +918,66 @@ end:
return r;
}
static UINT msi_export_record( HANDLE handle, MSIRECORD *row, UINT start )
static UINT msi_export_field( HANDLE handle, MSIRECORD *row, UINT field )
{
UINT i, count, len, r = ERROR_SUCCESS;
const char *sep;
char *buffer;
DWORD sz;
BOOL ret;
DWORD sz = 0x100;
UINT r;
len = 0x100;
buffer = msi_alloc( len );
if ( !buffer )
buffer = msi_alloc( sz );
if (!buffer)
return ERROR_OUTOFMEMORY;
count = MSI_RecordGetFieldCount( row );
for ( i=start; i<=count; i++ )
r = MSI_RecordGetStringA( row, field, buffer, &sz );
if (r == ERROR_MORE_DATA)
{
sz = len;
r = MSI_RecordGetStringA( row, i, buffer, &sz );
if (r == ERROR_MORE_DATA)
{
char *p = msi_realloc( buffer, sz + 1 );
if (!p)
break;
len = sz + 1;
buffer = p;
}
sz = len;
r = MSI_RecordGetStringA( row, i, buffer, &sz );
if (r != ERROR_SUCCESS)
break;
char *tmp;
if (!WriteFile( handle, buffer, sz, &sz, NULL ))
sz++; /* leave room for NULL terminator */
tmp = msi_realloc( buffer, sz );
if (!tmp)
{
r = ERROR_FUNCTION_FAILED;
break;
msi_free( buffer );
return ERROR_OUTOFMEMORY;
}
buffer = tmp;
r = MSI_RecordGetStringA( row, field, buffer, &sz );
if (r != ERROR_SUCCESS)
{
msi_free( buffer );
return r;
}
}
else if (r != ERROR_SUCCESS)
{
msi_free( buffer );
return r;
}
ret = WriteFile( handle, buffer, sz, &sz, NULL );
msi_free( buffer );
return ret ? ERROR_SUCCESS : ERROR_FUNCTION_FAILED;
}
static UINT msi_export_record( HANDLE handle, MSIRECORD *row, UINT start )
{
UINT i, count, r = ERROR_SUCCESS;
const char *sep;
DWORD sz;
count = MSI_RecordGetFieldCount( row );
for (i = start; i <= count; i++)
{
r = msi_export_field( handle, row, i );
if (r != ERROR_SUCCESS)
return r;
sep = (i < count) ? "\t" : "\r\n";
if (!WriteFile( handle, sep, strlen(sep), &sz, NULL ))
{
r = ERROR_FUNCTION_FAILED;
break;
}
return ERROR_FUNCTION_FAILED;
}
msi_free( buffer );
return r;
}