📄 package.c
字号:
WCHAR number[3];
static const WCHAR format[] = { '%','i',':',' ',0};
static const WCHAR space[] = { ' ',0};
sz = 0;
MSI_RecordGetStringW(record,i,NULL,&sz);
sz+=4;
total_size+=sz*sizeof(WCHAR);
tmp = msi_alloc(sz*sizeof(WCHAR));
message = msi_realloc(message,total_size*sizeof (WCHAR));
MSI_RecordGetStringW(record,i,tmp,&sz);
if (msg_field > 1)
{
sprintfW(number,format,i);
strcatW(message,number);
}
strcatW(message,tmp);
if (msg_field > 1)
strcatW(message,space);
msi_free(tmp);
}
}
TRACE("(%p %x %x %s)\n", gUIHandlerA, gUIFilter, log_type,
debugstr_w(message));
/* convert it to ASCII */
len = WideCharToMultiByte( CP_ACP, 0, message, -1,
NULL, 0, NULL, NULL );
msg = msi_alloc( len );
WideCharToMultiByte( CP_ACP, 0, message, -1,
msg, len, NULL, NULL );
if (gUIHandlerA && (gUIFilter & log_type))
{
rc = gUIHandlerA(gUIContext,eMessageType,msg);
}
if ((!rc) && (gszLogFile[0]) && !((eMessageType & 0xff000000) ==
INSTALLMESSAGE_PROGRESS))
{
DWORD write;
HANDLE log_file = CreateFileW(gszLogFile,GENERIC_WRITE, 0, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (log_file != INVALID_HANDLE_VALUE)
{
SetFilePointer(log_file,0, NULL, FILE_END);
WriteFile(log_file,msg,strlen(msg),&write,NULL);
WriteFile(log_file,"\n",1,&write,NULL);
CloseHandle(log_file);
}
}
msi_free( msg );
msi_free( message);
switch (eMessageType & 0xff000000)
{
case INSTALLMESSAGE_ACTIONDATA:
/* FIXME: format record here instead of in ui_actiondata to get the
* correct action data for external scripts */
ControlEvent_FireSubscribedEvent(package, szActionData, record);
break;
case INSTALLMESSAGE_ACTIONSTART:
{
MSIRECORD *uirow;
LPWSTR deformated;
LPCWSTR action_text = MSI_RecordGetString(record, 2);
deformat_string(package, action_text, &deformated);
uirow = MSI_CreateRecord(1);
MSI_RecordSetStringW(uirow, 1, deformated);
TRACE("INSTALLMESSAGE_ACTIONSTART: %s\n", debugstr_w(deformated));
msi_free(deformated);
ControlEvent_FireSubscribedEvent(package, szActionText, uirow);
msiobj_release(&uirow->hdr);
break;
}
case INSTALLMESSAGE_PROGRESS:
ControlEvent_FireSubscribedEvent(package, szSetProgress, record);
break;
}
return ERROR_SUCCESS;
}
INT WINAPI MsiProcessMessage( MSIHANDLE hInstall, INSTALLMESSAGE eMessageType,
MSIHANDLE hRecord)
{
UINT ret = ERROR_INVALID_HANDLE;
MSIPACKAGE *package = NULL;
MSIRECORD *record = NULL;
package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
if( !package )
return ERROR_INVALID_HANDLE;
record = msihandle2msiinfo( hRecord, MSIHANDLETYPE_RECORD );
if( !record )
goto out;
ret = MSI_ProcessMessage( package, eMessageType, record );
out:
msiobj_release( &package->hdr );
if( record )
msiobj_release( &record->hdr );
return ret;
}
/* property code */
typedef struct msi_property {
struct list entry;
LPWSTR key;
LPWSTR value;
} msi_property;
static UINT msi_prop_makehash( const WCHAR *str )
{
UINT hash = 0;
if (str==NULL)
return hash;
while( *str )
{
hash ^= *str++;
hash *= 53;
hash = (hash<<5) | (hash>>27);
}
return hash % PROPERTY_HASH_SIZE;
}
static msi_property *msi_prop_find( MSIPACKAGE *package, LPCWSTR key )
{
UINT hash = msi_prop_makehash( key );
msi_property *prop;
LIST_FOR_EACH_ENTRY( prop, &package->props[hash], msi_property, entry )
if (!lstrcmpW( prop->key, key ))
return prop;
return NULL;
}
static msi_property *msi_prop_add( MSIPACKAGE *package, LPCWSTR key )
{
UINT hash = msi_prop_makehash( key );
msi_property *prop;
prop = msi_alloc( sizeof *prop );
if (prop)
{
prop->key = strdupW( key );
prop->value = NULL;
list_add_head( &package->props[hash], &prop->entry );
}
return prop;
}
static void msi_delete_property( msi_property *prop )
{
list_remove( &prop->entry );
msi_free( prop->key );
msi_free( prop->value );
msi_free( prop );
}
static void msi_free_properties( MSIPACKAGE *package )
{
int i;
for ( i=0; i<PROPERTY_HASH_SIZE; i++ )
{
while ( !list_empty(&package->props[i]) )
{
msi_property *prop;
prop = LIST_ENTRY( list_head( &package->props[i] ),
msi_property, entry );
msi_delete_property( prop );
}
}
}
UINT WINAPI MsiSetPropertyA( MSIHANDLE hInstall, LPCSTR szName, LPCSTR szValue )
{
LPWSTR szwName = NULL, szwValue = NULL;
UINT r = ERROR_OUTOFMEMORY;
szwName = strdupAtoW( szName );
if( szName && !szwName )
goto end;
szwValue = strdupAtoW( szValue );
if( szValue && !szwValue )
goto end;
r = MsiSetPropertyW( hInstall, szwName, szwValue);
end:
msi_free( szwName );
msi_free( szwValue );
return r;
}
UINT MSI_SetPropertyW( MSIPACKAGE *package, LPCWSTR szName, LPCWSTR szValue)
{
msi_property *prop;
TRACE("%p %s %s\n", package, debugstr_w(szName), debugstr_w(szValue));
if (!szName)
return ERROR_INVALID_PARAMETER;
/* this one is weird... */
if (!szName[0])
return szValue ? ERROR_FUNCTION_FAILED : ERROR_SUCCESS;
prop = msi_prop_find( package, szName );
if (!prop)
prop = msi_prop_add( package, szName );
if (!prop)
return ERROR_OUTOFMEMORY;
if (szValue)
{
msi_free( prop->value );
prop->value = strdupW( szValue );
}
else
msi_delete_property( prop );
return ERROR_SUCCESS;
}
UINT WINAPI MsiSetPropertyW( MSIHANDLE hInstall, LPCWSTR szName, LPCWSTR szValue)
{
MSIPACKAGE *package;
UINT ret;
package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
if( !package )
return ERROR_INVALID_HANDLE;
ret = MSI_SetPropertyW( package, szName, szValue);
msiobj_release( &package->hdr );
return ret;
}
/* internal function, not compatible with MsiGetPropertyW */
UINT MSI_GetPropertyW( MSIPACKAGE *package, LPCWSTR szName,
LPWSTR szValueBuf, DWORD* pchValueBuf )
{
msi_property *prop;
UINT r, len;
if (*pchValueBuf > 0)
szValueBuf[0] = 0;
prop = msi_prop_find( package, szName );
if (!prop)
{
*pchValueBuf = 0;
TRACE("property %s not found\n", debugstr_w(szName));
return ERROR_FUNCTION_FAILED;
}
if (prop->value)
{
len = lstrlenW( prop->value );
lstrcpynW(szValueBuf, prop->value, *pchValueBuf);
}
else
{
len = 1;
if( *pchValueBuf > 0 )
szValueBuf[0] = 0;
}
TRACE("%s -> %s\n", debugstr_w(szName), debugstr_w(szValueBuf));
if ( *pchValueBuf <= len )
{
TRACE("have %u, need %u -> ERROR_MORE_DATA\n", *pchValueBuf, len);
r = ERROR_MORE_DATA;
}
else
r = ERROR_SUCCESS;
*pchValueBuf = len;
return r;
}
LPWSTR msi_dup_property( MSIPACKAGE *package, LPCWSTR szName )
{
msi_property *prop;
LPWSTR value = NULL;
prop = msi_prop_find( package, szName );
if (prop)
value = strdupW( prop->value );
return value;
}
int msi_get_property_int( MSIPACKAGE *package, LPCWSTR name, int value )
{
msi_property *prop;
prop = msi_prop_find( package, name );
if (prop)
value = atoiW( prop->value );
return value;
}
static UINT MSI_GetProperty( MSIHANDLE handle, LPCWSTR name,
awstring *szValueBuf, DWORD* pchValueBuf )
{
static const WCHAR empty[] = {0};
msi_property *prop;
MSIPACKAGE *package;
UINT r;
LPCWSTR val = NULL;
TRACE("%lu %s %p %p\n", handle, debugstr_w(name),
szValueBuf->str.w, pchValueBuf );
if (!name)
return ERROR_INVALID_PARAMETER;
package = msihandle2msiinfo( handle, MSIHANDLETYPE_PACKAGE );
if (!package)
return ERROR_INVALID_HANDLE;
prop = msi_prop_find( package, name );
if (prop)
val = prop->value;
if (!val)
val = empty;
r = msi_strcpy_to_awstring( val, szValueBuf, pchValueBuf );
msiobj_release( &package->hdr );
return r;
}
UINT WINAPI MsiGetPropertyA( MSIHANDLE hInstall, LPCSTR szName,
LPSTR szValueBuf, DWORD* pchValueBuf )
{
awstring val;
LPWSTR name;
UINT r;
val.unicode = FALSE;
val.str.a = szValueBuf;
name = strdupAtoW( szName );
if (szName && !name)
return ERROR_OUTOFMEMORY;
r = MSI_GetProperty( hInstall, name, &val, pchValueBuf );
msi_free( name );
return r;
}
UINT WINAPI MsiGetPropertyW( MSIHANDLE hInstall, LPCWSTR szName,
LPWSTR szValueBuf, DWORD* pchValueBuf )
{
awstring val;
val.unicode = TRUE;
val.str.w = szValueBuf;
return MSI_GetProperty( hInstall, szName, &val, pchValueBuf );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -