📄 suminfo.c
字号:
memcpy( &data[sz], §ion_hdr, sizeof section_hdr );
sz += sizeof section_hdr;
memcpy( &data[sz], idofs, section_hdr.cProperties * sizeof idofs[0] );
sz += section_hdr.cProperties * sizeof idofs[0];
/* write out the data */
for( i = 0; i < MSI_MAX_PROPS; i++ )
sz += write_property_to_data( &si->property[i], &data[sz] );
r = IStream_Write( stm, data, sz, &count );
msi_free( data );
if( FAILED(r) || count != sz )
return ret;
return ERROR_SUCCESS;
}
MSISUMMARYINFO *MSI_GetSummaryInformationW( IStorage *stg, UINT uiUpdateCount )
{
IStream *stm = NULL;
MSISUMMARYINFO *si;
DWORD grfMode;
HRESULT r;
TRACE("%p %d\n", stg, uiUpdateCount );
si = alloc_msiobject( MSIHANDLETYPE_SUMMARYINFO,
sizeof (MSISUMMARYINFO), MSI_CloseSummaryInfo );
if( !si )
return si;
memset( &si->property, 0, sizeof si->property );
si->update_count = uiUpdateCount;
IStorage_AddRef( stg );
si->storage = stg;
/* read the stream... if we fail, we'll start with an empty property set */
grfMode = STGM_READ | STGM_SHARE_EXCLUSIVE;
r = IStorage_OpenStream( si->storage, szSumInfo, 0, grfMode, 0, &stm );
if( SUCCEEDED(r) )
{
load_summary_info( si, stm );
IStream_Release( stm );
}
return si;
}
UINT WINAPI MsiGetSummaryInformationW( MSIHANDLE hDatabase,
LPCWSTR szDatabase, UINT uiUpdateCount, MSIHANDLE *pHandle )
{
MSISUMMARYINFO *si;
MSIDATABASE *db;
UINT ret = ERROR_FUNCTION_FAILED;
TRACE("%ld %s %d %p\n", hDatabase, debugstr_w(szDatabase),
uiUpdateCount, pHandle);
if( !pHandle )
return ERROR_INVALID_PARAMETER;
if( szDatabase )
{
ret = MSI_OpenDatabaseW( szDatabase, NULL, &db );
if( ret != ERROR_SUCCESS )
return ret;
}
else
{
db = msihandle2msiinfo( hDatabase, MSIHANDLETYPE_DATABASE );
if( !db )
return ERROR_INVALID_PARAMETER;
}
si = MSI_GetSummaryInformationW( db->storage, uiUpdateCount );
if (si)
{
*pHandle = alloc_msihandle( &si->hdr );
if( *pHandle )
ret = ERROR_SUCCESS;
else
ret = ERROR_NOT_ENOUGH_MEMORY;
msiobj_release( &si->hdr );
}
if( db )
msiobj_release( &db->hdr );
return ret;
}
UINT WINAPI MsiGetSummaryInformationA(MSIHANDLE hDatabase,
LPCSTR szDatabase, UINT uiUpdateCount, MSIHANDLE *pHandle)
{
LPWSTR szwDatabase = NULL;
UINT ret;
TRACE("%ld %s %d %p\n", hDatabase, debugstr_a(szDatabase),
uiUpdateCount, pHandle);
if( szDatabase )
{
szwDatabase = strdupAtoW( szDatabase );
if( !szwDatabase )
return ERROR_FUNCTION_FAILED;
}
ret = MsiGetSummaryInformationW(hDatabase, szwDatabase, uiUpdateCount, pHandle);
msi_free( szwDatabase );
return ret;
}
UINT WINAPI MsiSummaryInfoGetPropertyCount(MSIHANDLE hSummaryInfo, UINT *pCount)
{
MSISUMMARYINFO *si;
TRACE("%ld %p\n", hSummaryInfo, pCount);
si = msihandle2msiinfo( hSummaryInfo, MSIHANDLETYPE_SUMMARYINFO );
if( !si )
return ERROR_INVALID_HANDLE;
if( pCount )
*pCount = get_property_count( si->property );
msiobj_release( &si->hdr );
return ERROR_SUCCESS;
}
static UINT get_prop( MSIHANDLE handle, UINT uiProperty, UINT *puiDataType,
INT *piValue, FILETIME *pftValue, awstring *str, DWORD *pcchValueBuf)
{
MSISUMMARYINFO *si;
PROPVARIANT *prop;
UINT ret = ERROR_SUCCESS;
TRACE("%ld %d %p %p %p %p %p\n", handle, uiProperty, puiDataType,
piValue, pftValue, str, pcchValueBuf);
si = msihandle2msiinfo( handle, MSIHANDLETYPE_SUMMARYINFO );
if( !si )
return ERROR_INVALID_HANDLE;
if ( uiProperty >= MSI_MAX_PROPS )
{
*puiDataType = VT_EMPTY;
return ret;
}
prop = &si->property[uiProperty];
if( puiDataType )
*puiDataType = prop->vt;
switch( prop->vt )
{
case VT_I2:
if( piValue )
*piValue = prop->u.iVal;
break;
case VT_I4:
if( piValue )
*piValue = prop->u.lVal;
break;
case VT_LPSTR:
if( pcchValueBuf )
{
DWORD len = 0;
if( str->unicode )
{
len = MultiByteToWideChar( CP_ACP, 0, prop->u.pszVal, -1,
str->str.w, *pcchValueBuf );
len--;
}
else
{
len = lstrlenA( prop->u.pszVal );
if( str->str.a )
lstrcpynA(str->str.a, prop->u.pszVal, *pcchValueBuf );
}
if (len >= *pcchValueBuf)
ret = ERROR_MORE_DATA;
*pcchValueBuf = len;
}
break;
case VT_FILETIME:
if( pftValue )
memcpy(pftValue, &prop->u.filetime, sizeof (FILETIME) );
break;
case VT_EMPTY:
break;
default:
FIXME("Unknown property variant type\n");
break;
}
msiobj_release( &si->hdr );
return ret;
}
LPWSTR msi_suminfo_dup_string( MSISUMMARYINFO *si, UINT uiProperty )
{
PROPVARIANT *prop;
if ( uiProperty >= MSI_MAX_PROPS )
return NULL;
prop = &si->property[uiProperty];
if( prop->vt != VT_LPSTR )
return NULL;
return strdupAtoW( prop->u.pszVal );
}
LPWSTR msi_get_suminfo_product( IStorage *stg )
{
MSISUMMARYINFO *si;
LPWSTR prod;
si = MSI_GetSummaryInformationW( stg, 0 );
if (!si)
{
ERR("no summary information!\n");
return NULL;
}
prod = msi_suminfo_dup_string( si, PID_REVNUMBER );
msiobj_release( &si->hdr );
return prod;
}
UINT WINAPI MsiSummaryInfoGetPropertyA(
MSIHANDLE handle, UINT uiProperty, UINT *puiDataType, INT *piValue,
FILETIME *pftValue, LPSTR szValueBuf, DWORD *pcchValueBuf)
{
awstring str;
TRACE("%ld %d %p %p %p %p %p\n", handle, uiProperty, puiDataType,
piValue, pftValue, szValueBuf, pcchValueBuf );
str.unicode = FALSE;
str.str.a = szValueBuf;
return get_prop( handle, uiProperty, puiDataType, piValue,
pftValue, &str, pcchValueBuf );
}
UINT WINAPI MsiSummaryInfoGetPropertyW(
MSIHANDLE handle, UINT uiProperty, UINT *puiDataType, INT *piValue,
FILETIME *pftValue, LPWSTR szValueBuf, DWORD *pcchValueBuf)
{
awstring str;
TRACE("%ld %d %p %p %p %p %p\n", handle, uiProperty, puiDataType,
piValue, pftValue, szValueBuf, pcchValueBuf );
str.unicode = TRUE;
str.str.w = szValueBuf;
return get_prop( handle, uiProperty, puiDataType, piValue,
pftValue, &str, pcchValueBuf );
}
static UINT set_prop( MSIHANDLE handle, UINT uiProperty, UINT uiDataType,
INT iValue, FILETIME* pftValue, awcstring *str )
{
MSISUMMARYINFO *si;
PROPVARIANT *prop;
UINT type, len, ret = ERROR_SUCCESS;
TRACE("%ld %u %u %i %p %p\n", handle, uiProperty, uiDataType,
iValue, pftValue, str );
type = get_type( uiProperty );
if( type == VT_EMPTY || type != uiDataType )
return ERROR_DATATYPE_MISMATCH;
if( uiDataType == VT_LPSTR && !str->str.w )
return ERROR_INVALID_PARAMETER;
if( uiDataType == VT_FILETIME && !pftValue )
return ERROR_INVALID_PARAMETER;
si = msihandle2msiinfo( handle, MSIHANDLETYPE_SUMMARYINFO );
if( !si )
return ERROR_INVALID_HANDLE;
prop = &si->property[uiProperty];
if( prop->vt == VT_EMPTY )
{
if( !si->update_count )
{
ret = ERROR_FUNCTION_FAILED;
goto end;
}
si->update_count--;
}
else if( prop->vt != type )
goto end;
free_prop( prop );
prop->vt = type;
switch( type )
{
case VT_I4:
prop->u.lVal = iValue;
break;
case VT_I2:
prop->u.iVal = iValue;
break;
case VT_FILETIME:
memcpy( &prop->u.filetime, pftValue, sizeof prop->u.filetime );
break;
case VT_LPSTR:
if( str->unicode )
{
len = WideCharToMultiByte( CP_ACP, 0, str->str.w, -1,
NULL, 0, NULL, NULL );
prop->u.pszVal = msi_alloc( len );
WideCharToMultiByte( CP_ACP, 0, str->str.w, -1,
prop->u.pszVal, len, NULL, NULL );
}
else
{
len = lstrlenA( str->str.a ) + 1;
prop->u.pszVal = msi_alloc( len );
lstrcpyA( prop->u.pszVal, str->str.a );
}
break;
}
end:
msiobj_release( &si->hdr );
return ret;
}
UINT WINAPI MsiSummaryInfoSetPropertyW( MSIHANDLE handle, UINT uiProperty,
UINT uiDataType, INT iValue, FILETIME* pftValue, LPCWSTR szValue )
{
awcstring str;
TRACE("%ld %u %u %i %p %s\n", handle, uiProperty, uiDataType,
iValue, pftValue, debugstr_w(szValue) );
str.unicode = TRUE;
str.str.w = szValue;
return set_prop( handle, uiProperty, uiDataType, iValue, pftValue, &str );
}
UINT WINAPI MsiSummaryInfoSetPropertyA( MSIHANDLE handle, UINT uiProperty,
UINT uiDataType, INT iValue, FILETIME* pftValue, LPCSTR szValue )
{
awcstring str;
TRACE("%ld %u %u %i %p %s\n", handle, uiProperty, uiDataType,
iValue, pftValue, debugstr_a(szValue) );
str.unicode = FALSE;
str.str.a = szValue;
return set_prop( handle, uiProperty, uiDataType, iValue, pftValue, &str );
}
UINT WINAPI MsiSummaryInfoPersist( MSIHANDLE handle )
{
IStream *stm = NULL;
MSISUMMARYINFO *si;
DWORD grfMode;
HRESULT r;
UINT ret = ERROR_FUNCTION_FAILED;
TRACE("%ld\n", handle );
si = msihandle2msiinfo( handle, MSIHANDLETYPE_SUMMARYINFO );
if( !si )
return ERROR_INVALID_HANDLE;
grfMode = STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE;
r = IStorage_CreateStream( si->storage, szSumInfo, grfMode, 0, 0, &stm );
if( SUCCEEDED(r) )
{
ret = save_summary_info( si, stm );
IStream_Release( stm );
}
msiobj_release( &si->hdr );
return ret;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -