From cf84e2df5b2da6d4843b9566039cab1e07c2ed00 Mon Sep 17 00:00:00 2001 From: James Hawkins Date: Tue, 26 Feb 2008 01:55:01 -0600 Subject: [PATCH] msi: Allow setting a media disk as the last used source in the internal msi_set_last_used_source. --- dlls/msi/action.c | 10 ++++++--- dlls/msi/msipriv.h | 2 ++ dlls/msi/source.c | 51 ++++++++++++++++++++++++++++++---------------- 3 files changed, 42 insertions(+), 21 deletions(-) diff --git a/dlls/msi/action.c b/dlls/msi/action.c index dee64d1be8a..d5fad0c345c 100644 --- a/dlls/msi/action.c +++ b/dlls/msi/action.c @@ -3508,9 +3508,13 @@ static UINT ACTION_PublishProduct(MSIPACKAGE *package) /* publish the SourceList info */ LIST_FOR_EACH_ENTRY(info, &package->sourcelist_info, MSISOURCELISTINFO, entry) { - MsiSourceListSetInfoW(package->ProductCode, NULL, - info->context, info->options, - info->property, info->value); + if (!lstrcmpW(info->property, INSTALLPROPERTY_LASTUSEDSOURCEW)) + msi_set_last_used_source(package->ProductCode, NULL, info->context, + info->options, info->value); + else + MsiSourceListSetInfoW(package->ProductCode, NULL, + info->context, info->options, + info->property, info->value); } LIST_FOR_EACH_ENTRY(disk, &package->sourcelist_media, MSIMEDIADISK, entry) diff --git a/dlls/msi/msipriv.h b/dlls/msi/msipriv.h index e23261bdabf..975ebb62add 100644 --- a/dlls/msi/msipriv.h +++ b/dlls/msi/msipriv.h @@ -885,6 +885,8 @@ extern BOOL check_unique_action(const MSIPACKAGE *, LPCWSTR); extern WCHAR* generate_error_string(MSIPACKAGE *, UINT, DWORD, ... ); extern UINT msi_create_component_directories( MSIPACKAGE *package ); extern void msi_ui_error( DWORD msg_id, DWORD type ); +extern UINT msi_set_last_used_source(LPCWSTR product, LPCWSTR usersid, + MSIINSTALLCONTEXT context, DWORD options, LPCWSTR value); /* control event stuff */ extern VOID ControlEvent_FireSubscribedEvent(MSIPACKAGE *package, LPCWSTR event, diff --git a/dlls/msi/source.c b/dlls/msi/source.c index b5085694365..37a0b8b78e2 100644 --- a/dlls/msi/source.c +++ b/dlls/msi/source.c @@ -701,15 +701,16 @@ UINT WINAPI MsiSourceListSetInfoA(LPCSTR szProduct, LPCSTR szUserSid, return ret; } -static UINT set_last_used_source(HKEY source, LPCWSTR product, LPCWSTR usersid, - MSIINSTALLCONTEXT context, DWORD options, - LPCWSTR value) +UINT msi_set_last_used_source(LPCWSTR product, LPCWSTR usersid, + MSIINSTALLCONTEXT context, DWORD options, + LPCWSTR value) { + HKEY source; LPWSTR buffer; WCHAR typechar; DWORD size; UINT r; - int index = 0; + int index = 1; static const WCHAR format[] = {'%','c',';','%','i',';','%','s',0}; @@ -717,27 +718,36 @@ static UINT set_last_used_source(HKEY source, LPCWSTR product, LPCWSTR usersid, typechar = 'n'; else if (options & MSISOURCETYPE_URL) typechar = 'u'; + else if (options & MSISOURCETYPE_MEDIA) + typechar = 'm'; else return ERROR_INVALID_PARAMETER; - /* make sure the source is registered */ - r = MsiSourceListAddSourceExW(product, usersid, context, - options, value, 0); - if (r != ERROR_SUCCESS) - return r; + if (!(options & MSISOURCETYPE_MEDIA)) + { + r = MsiSourceListAddSourceExW(product, usersid, context, + options, value, 0); + if (r != ERROR_SUCCESS) + return r; - while ((r = MsiSourceListEnumSourcesW(product, usersid, context, options, - index, NULL, NULL)) == ERROR_SUCCESS) - index++; + index = 0; + while ((r = MsiSourceListEnumSourcesW(product, usersid, context, options, + index, NULL, NULL)) == ERROR_SUCCESS) + index++; - if (r != ERROR_NO_MORE_ITEMS) - return r; + if (r != ERROR_NO_MORE_ITEMS) + return r; + } size = (lstrlenW(format) + lstrlenW(value) + 7) * sizeof(WCHAR); buffer = msi_alloc(size); if (!buffer) return ERROR_OUTOFMEMORY; + r = OpenSourceKey(product, &source, MSICODE_PRODUCT, context, FALSE); + if (r != ERROR_SUCCESS) + return r; + sprintfW(buffer, format, typechar, index, value); size = (lstrlenW(buffer) + 1) * sizeof(WCHAR); @@ -745,6 +755,7 @@ static UINT set_last_used_source(HKEY source, LPCWSTR product, LPCWSTR usersid, REG_SZ, (LPBYTE)buffer, size); msi_free(buffer); + RegCloseKey(source); return r; } @@ -818,15 +829,19 @@ UINT WINAPI MsiSourceListSetInfoW( LPCWSTR szProduct, LPCWSTR szUserSid, if (rc != ERROR_SUCCESS) rc = ERROR_UNKNOWN_PROPERTY; } - else if (strcmpW(szProperty, INSTALLPROPERTY_LASTUSEDSOURCEW)==0) - rc = set_last_used_source(sourcekey, szProduct, szUserSid, dwContext, - dwOptions, szValue); + else if (!lstrcmpW(szProperty, INSTALLPROPERTY_LASTUSEDSOURCEW)) + { + if (!(dwOptions & (MSISOURCETYPE_NETWORK | MSISOURCETYPE_URL))) + rc = ERROR_INVALID_PARAMETER; + else + rc = msi_set_last_used_source(szProduct, szUserSid, dwContext, + dwOptions, szValue); + } else rc = ERROR_UNKNOWN_PROPERTY; RegCloseKey(sourcekey); return rc; - } /******************************************************************