📄 helpers.c
字号:
msi_free( file->File );
msi_free( file->FileName );
msi_free( file->ShortName );
msi_free( file->LongName );
msi_free( file->Version );
msi_free( file->Language );
msi_free( file->SourcePath );
msi_free( file->TargetPath );
msi_free( file );
}
/* clean up extension, progid, class and verb structures */
LIST_FOR_EACH_SAFE( item, cursor, &package->classes )
{
MSICLASS *cls = LIST_ENTRY( item, MSICLASS, entry );
list_remove( &cls->entry );
msi_free( cls->clsid );
msi_free( cls->Context );
msi_free( cls->Description );
msi_free( cls->FileTypeMask );
msi_free( cls->IconPath );
msi_free( cls->DefInprocHandler );
msi_free( cls->DefInprocHandler32 );
msi_free( cls->Argument );
msi_free( cls->ProgIDText );
msi_free( cls );
}
LIST_FOR_EACH_SAFE( item, cursor, &package->extensions )
{
MSIEXTENSION *ext = LIST_ENTRY( item, MSIEXTENSION, entry );
list_remove( &ext->entry );
free_extension( ext );
}
LIST_FOR_EACH_SAFE( item, cursor, &package->progids )
{
MSIPROGID *progid = LIST_ENTRY( item, MSIPROGID, entry );
list_remove( &progid->entry );
msi_free( progid->ProgID );
msi_free( progid->Description );
msi_free( progid->IconPath );
msi_free( progid );
}
LIST_FOR_EACH_SAFE( item, cursor, &package->mimes )
{
MSIMIME *mt = LIST_ENTRY( item, MSIMIME, entry );
list_remove( &mt->entry );
msi_free( mt->clsid );
msi_free( mt->ContentType );
msi_free( mt );
}
LIST_FOR_EACH_SAFE( item, cursor, &package->appids )
{
MSIAPPID *appid = LIST_ENTRY( item, MSIAPPID, entry );
list_remove( &appid->entry );
msi_free( appid->AppID );
msi_free( appid->RemoteServerName );
msi_free( appid->LocalServer );
msi_free( appid->ServiceParameters );
msi_free( appid->DllSurrogate );
msi_free( appid );
}
if (package->script)
{
for (i = 0; i < TOTAL_SCRIPTS; i++)
msi_free_action_script(package, i);
for (i = 0; i < package->script->UniqueActionsCount; i++)
msi_free(package->script->UniqueActions[i]);
msi_free(package->script->UniqueActions);
msi_free(package->script);
}
msi_free(package->BaseURL);
msi_free(package->PackagePath);
msi_free(package->ProductCode);
msi_free(package->ActionFormat);
msi_free(package->LastAction);
/* cleanup control event subscriptions */
ControlEvent_CleanupSubscriptions(package);
}
/*
* build_directory_name()
*
* This function is to save messing round with directory names
* It handles adding backslashes between path segments,
* and can add \ at the end of the directory name if told to.
*
* It takes a variable number of arguments.
* It always allocates a new string for the result, so make sure
* to free the return value when finished with it.
*
* The first arg is the number of path segments that follow.
* The arguments following count are a list of path segments.
* A path segment may be NULL.
*
* Path segments will be added with a \ separating them.
* A \ will not be added after the last segment, however if the
* last segment is NULL, then the last character will be a \
*
*/
LPWSTR build_directory_name(DWORD count, ...)
{
DWORD sz = 1, i;
LPWSTR dir;
va_list va;
va_start(va,count);
for(i=0; i<count; i++)
{
LPCWSTR str = va_arg(va,LPCWSTR);
if (str)
sz += strlenW(str) + 1;
}
va_end(va);
dir = msi_alloc(sz*sizeof(WCHAR));
dir[0]=0;
va_start(va,count);
for(i=0; i<count; i++)
{
LPCWSTR str = va_arg(va,LPCWSTR);
if (!str)
continue;
strcatW(dir, str);
if( ((i+1)!=count) && dir[strlenW(dir)-1]!='\\')
strcatW(dir, cszbs);
}
return dir;
}
/***********************************************************************
* create_full_pathW
*
* Recursively create all directories in the path.
*
* shamelessly stolen from setupapi/queue.c
*/
BOOL create_full_pathW(const WCHAR *path)
{
BOOL ret = TRUE;
int len;
WCHAR *new_path;
new_path = msi_alloc( (strlenW(path) + 1) * sizeof(WCHAR));
strcpyW(new_path, path);
while((len = strlenW(new_path)) && new_path[len - 1] == '\\')
new_path[len - 1] = 0;
while(!CreateDirectoryW(new_path, NULL))
{
WCHAR *slash;
DWORD last_error = GetLastError();
if(last_error == ERROR_ALREADY_EXISTS)
break;
if(last_error != ERROR_PATH_NOT_FOUND)
{
ret = FALSE;
break;
}
if(!(slash = strrchrW(new_path, '\\')))
{
ret = FALSE;
break;
}
len = slash - new_path;
new_path[len] = 0;
if(!create_full_pathW(new_path))
{
ret = FALSE;
break;
}
new_path[len] = '\\';
}
msi_free(new_path);
return ret;
}
void ui_progress(MSIPACKAGE *package, int a, int b, int c, int d )
{
MSIRECORD * row;
row = MSI_CreateRecord(4);
MSI_RecordSetInteger(row,1,a);
MSI_RecordSetInteger(row,2,b);
MSI_RecordSetInteger(row,3,c);
MSI_RecordSetInteger(row,4,d);
MSI_ProcessMessage(package, INSTALLMESSAGE_PROGRESS, row);
msiobj_release(&row->hdr);
msi_dialog_check_messages(NULL);
}
void ui_actiondata(MSIPACKAGE *package, LPCWSTR action, MSIRECORD * record)
{
static const WCHAR Query_t[] =
{'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
'`','A','c','t','i','o', 'n','T','e','x','t','`',' ',
'W','H','E','R','E',' ', '`','A','c','t','i','o','n','`',' ','=',
' ','\'','%','s','\'',0};
WCHAR message[1024];
MSIRECORD * row = 0;
DWORD size;
if (!package->LastAction || strcmpW(package->LastAction,action))
{
row = MSI_QueryGetRecord(package->db, Query_t, action);
if (!row)
return;
if (MSI_RecordIsNull(row,3))
{
msiobj_release(&row->hdr);
return;
}
/* update the cached actionformat */
msi_free(package->ActionFormat);
package->ActionFormat = msi_dup_record_field(row,3);
msi_free(package->LastAction);
package->LastAction = strdupW(action);
msiobj_release(&row->hdr);
}
MSI_RecordSetStringW(record,0,package->ActionFormat);
size = 1024;
MSI_FormatRecordW(package,record,message,&size);
row = MSI_CreateRecord(1);
MSI_RecordSetStringW(row,1,message);
MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONDATA, row);
msiobj_release(&row->hdr);
}
BOOL ACTION_VerifyComponentForAction( MSICOMPONENT* comp, INSTALLSTATE check )
{
if (!comp)
return FALSE;
if (comp->Installed == check)
return FALSE;
if (comp->ActionRequest == check)
return TRUE;
else
return FALSE;
}
BOOL ACTION_VerifyFeatureForAction( MSIFEATURE* feature, INSTALLSTATE check )
{
if (!feature)
return FALSE;
if (feature->Installed == check)
return FALSE;
if (feature->ActionRequest == check)
return TRUE;
else
return FALSE;
}
void reduce_to_longfilename(WCHAR* filename)
{
LPWSTR p = strchrW(filename,'|');
if (p)
memmove(filename, p+1, (strlenW(p+1)+1)*sizeof(WCHAR));
}
void reduce_to_shortfilename(WCHAR* filename)
{
LPWSTR p = strchrW(filename,'|');
if (p)
*p = 0;
}
LPWSTR create_component_advertise_string(MSIPACKAGE* package,
MSICOMPONENT* component, LPCWSTR feature)
{
static const WCHAR fmt[] = {'%','s','%','s','%','c','%','s',0};
WCHAR productid_85[21], component_85[21];
LPWSTR output = NULL;
DWORD sz = 0;
GUID clsid;
/* > is used if there is a component GUID and < if not. */
productid_85[0] = 0;
component_85[0] = 0;
CLSIDFromString(package->ProductCode, &clsid);
encode_base85_guid(&clsid, productid_85);
if (component)
{
CLSIDFromString(component->ComponentId, &clsid);
encode_base85_guid(&clsid, component_85);
}
TRACE("prod=%s feat=%s comp=%s\n", debugstr_w(productid_85),
debugstr_w(feature), debugstr_w(component_85));
sz = 20 + lstrlenW(feature) + 20 + 3;
output = msi_alloc_zero(sz*sizeof(WCHAR));
sprintfW(output, fmt, productid_85, feature,
component?'>':'<', component_85);
return output;
}
/* update compoennt state based on a feature change */
void ACTION_UpdateComponentStates(MSIPACKAGE *package, LPCWSTR szFeature)
{
INSTALLSTATE newstate;
MSIFEATURE *feature;
ComponentList *cl;
feature = get_loaded_feature(package,szFeature);
if (!feature)
return;
newstate = feature->ActionRequest;
if (newstate == INSTALLSTATE_ABSENT)
newstate = INSTALLSTATE_UNKNOWN;
LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry )
{
MSICOMPONENT* component = cl->component;
TRACE("MODIFYING(%i): Component %s (Installed %i, Action %i, Request %i)\n",
newstate, debugstr_w(component->Component), component->Installed,
component->Action, component->ActionRequest);
if (!component->Enabled)
continue;
if (newstate == INSTALLSTATE_LOCAL)
msi_component_set_state( component, INSTALLSTATE_LOCAL );
else
{
ComponentList *clist;
MSIFEATURE *f;
msi_component_set_state( component, newstate );
/*if any other feature wants is local we need to set it local*/
LIST_FOR_EACH_ENTRY( f, &package->features, MSIFEATURE, entry )
{
if ( f->ActionRequest != INSTALLSTATE_LOCAL &&
f->ActionRequest != INSTALLSTATE_SOURCE )
{
continue;
}
LIST_FOR_EACH_ENTRY( clist, &f->Components, ComponentList, entry )
{
if ( clist->component == component &&
(f->ActionRequest == INSTALLSTATE_LOCAL ||
f->ActionRequest == INSTALLSTATE_SOURCE) )
{
TRACE("Saved by %s\n", debugstr_w(f->Feature));
if (component->Attributes & msidbComponentAttributesOptional)
{
if (f->Attributes & msidbFeatureAttributesFavorSource)
msi_component_set_state( component, INSTALLSTATE_SOURCE );
else
msi_component_set_state( component, INSTALLSTATE_LOCAL );
}
else if (component->Attributes & msidbComponentAttributesSourceOnly)
msi_component_set_state( component, INSTALLSTATE_SOURCE );
else
msi_component_set_state( component, INSTALLSTATE_LOCAL );
}
}
}
}
TRACE("Result (%i): Component %s (Installed %i, Action %i, Request %i)\n",
newstate, debugstr_w(component->Component), component->Installed,
component->Action, component->ActionRequest);
}
}
UINT register_unique_action(MSIPACKAGE *package, LPCWSTR action)
{
UINT count;
LPWSTR *newbuf = NULL;
if (!package->script)
return FALSE;
TRACE("Registering Action %s as having fun\n",debugstr_w(action));
count = package->script->UniqueActionsCount;
package->script->UniqueActionsCount++;
if (count != 0)
newbuf = msi_realloc( package->script->UniqueActions,
package->script->UniqueActionsCount* sizeof(LPWSTR));
else
newbuf = msi_alloc( sizeof(LPWSTR));
newbuf[count] = strdupW(action);
package->script->UniqueActions = newbuf;
return ERROR_SUCCESS;
}
BOOL check_unique_action(MSIPACKAGE *package, LPCWSTR action)
{
INT i;
if (!package->script)
return FALSE;
for (i = 0; i < package->script->UniqueActionsCount; i++)
if (!strcmpW(package->script->UniqueActions[i],action))
return TRUE;
return FALSE;
}
WCHAR* generate_error_string(MSIPACKAGE *package, UINT error, DWORD count, ... )
{
static const WCHAR query[] = {'S','E','L','E','C','T',' ','`','M','e','s','s','a','g','e','`',' ','F','R','O','M',' ','`','E','r','r','o','r','`',' ','W','H','E','R','E',' ','`','E','r','r','o','r','`',' ','=',' ','%','i',0};
MSIRECORD *rec;
MSIRECORD *row;
DWORD size = 0;
DWORD i;
va_list va;
LPCWSTR str;
LPWSTR data;
row = MSI_QueryGetRecord(package->db, query, error);
if (!row)
return 0;
rec = MSI_CreateRecord(count+2);
str = MSI_RecordGetString(row,1);
MSI_RecordSetStringW(rec,0,str);
msiobj_release( &row->hdr );
MSI_RecordSetInteger(rec,1,error);
va_start(va,count);
for (i = 0; i < count; i++)
{
str = va_arg(va,LPCWSTR);
MSI_RecordSetStringW(rec,(i+2),str);
}
va_end(va);
MSI_FormatRecordW(package,rec,NULL,&size);
if (size >= 0)
{
size++;
data = msi_alloc(size*sizeof(WCHAR));
if (size > 1)
MSI_FormatRecordW(package,rec,data,&size);
else
data[0] = 0;
msiobj_release( &rec->hdr );
return data;
}
msiobj_release( &rec->hdr );
data = NULL;
return data;
}
void msi_ui_error( DWORD msg_id, DWORD type )
{
WCHAR text[2048];
static const WCHAR title[] = {
'W','i','n','d','o','w','s',' ','I','n','s','t','a','l','l','e','r',0
};
if (!MsiLoadStringW( -1, msg_id, text, sizeof(text) / sizeof(text[0]),
MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL) ))
return;
MessageBoxW( NULL, text, title, type );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -