Commit 41c788f5 authored by Mike McCormack's avatar Mike McCormack Committed by Alexandre Julliard

Don't create MSI handles unless we have to pass one through the API.

parent b3563dac
...@@ -430,11 +430,11 @@ static DWORD WINAPI ACTION_CallDllFunction(thread_struct *stuff) ...@@ -430,11 +430,11 @@ static DWORD WINAPI ACTION_CallDllFunction(thread_struct *stuff)
MSIPACKAGE *package = stuff->package; MSIPACKAGE *package = stuff->package;
TRACE("Calling function %s\n", proc); TRACE("Calling function %s\n", proc);
hPackage = msiobj_findhandle( &package->hdr ); hPackage = alloc_msihandle( &package->hdr );
if (hPackage ) if (hPackage)
{ {
rc = fn(hPackage); rc = fn( hPackage );
msiobj_release( &package->hdr ); MsiCloseHandle( hPackage );
} }
else else
ERR("Handle for object %p not found\n", package ); ERR("Handle for object %p not found\n", package );
......
...@@ -109,25 +109,6 @@ out: ...@@ -109,25 +109,6 @@ out:
return (void*) ret; return (void*) ret;
} }
MSIHANDLE msiobj_findhandle( MSIOBJECTHDR *hdr )
{
MSIHANDLE ret = 0;
UINT i;
TRACE("%p\n", hdr);
EnterCriticalSection( &MSI_handle_cs );
for(i=0; (i<MSIMAXHANDLES) && !ret; i++)
if( msihandletable[i].obj == hdr )
ret = i+1;
LeaveCriticalSection( &MSI_handle_cs );
TRACE("%p -> %ld\n", hdr, ret);
msiobj_addref( hdr );
return ret;
}
void *alloc_msiobject(UINT type, UINT size, msihandledestructor destroy ) void *alloc_msiobject(UINT type, UINT size, msihandledestructor destroy )
{ {
MSIOBJECTHDR *info; MSIOBJECTHDR *info;
......
...@@ -81,14 +81,14 @@ UINT WINAPI MsiOpenProductA(LPCSTR szProduct, MSIHANDLE *phProduct) ...@@ -81,14 +81,14 @@ UINT WINAPI MsiOpenProductA(LPCSTR szProduct, MSIHANDLE *phProduct)
return r; return r;
} }
UINT WINAPI MsiOpenProductW(LPCWSTR szProduct, MSIHANDLE *phProduct) static UINT MSI_OpenProductW( LPCWSTR szProduct, MSIPACKAGE **ppackage )
{ {
LPWSTR path = NULL; LPWSTR path = NULL;
UINT r; UINT r;
HKEY hKeyProduct = NULL; HKEY hKeyProduct = NULL;
DWORD count, type; DWORD count, type;
TRACE("%s %p\n",debugstr_w(szProduct), phProduct); TRACE("%s %p\n", debugstr_w(szProduct), ppackage );
r = MSIREG_OpenUninstallKey(szProduct,&hKeyProduct,FALSE); r = MSIREG_OpenUninstallKey(szProduct,&hKeyProduct,FALSE);
if( r != ERROR_SUCCESS ) if( r != ERROR_SUCCESS )
...@@ -120,7 +120,7 @@ UINT WINAPI MsiOpenProductW(LPCWSTR szProduct, MSIHANDLE *phProduct) ...@@ -120,7 +120,7 @@ UINT WINAPI MsiOpenProductW(LPCWSTR szProduct, MSIHANDLE *phProduct)
goto end; goto end;
} }
r = MsiOpenPackageW( path, phProduct ); r = MSI_OpenPackageW( path, ppackage );
end: end:
msi_free( path ); msi_free( path );
...@@ -130,6 +130,20 @@ end: ...@@ -130,6 +130,20 @@ end:
return r; return r;
} }
UINT WINAPI MsiOpenProductW( LPCWSTR szProduct, MSIHANDLE *phProduct )
{
MSIPACKAGE *package = NULL;
UINT r;
r = MSI_OpenProductW( szProduct, &package );
if( r == ERROR_SUCCESS )
{
*phProduct = alloc_msihandle( &package->hdr );
msiobj_release( &package->hdr );
}
return r;
}
UINT WINAPI MsiAdvertiseProductA(LPCSTR szPackagePath, LPCSTR szScriptfilePath, UINT WINAPI MsiAdvertiseProductA(LPCSTR szPackagePath, LPCSTR szScriptfilePath,
LPCSTR szTransforms, LANGID lgidLanguage) LPCSTR szTransforms, LANGID lgidLanguage)
{ {
...@@ -198,21 +212,15 @@ UINT WINAPI MsiInstallProductW(LPCWSTR szPackagePath, LPCWSTR szCommandLine) ...@@ -198,21 +212,15 @@ UINT WINAPI MsiInstallProductW(LPCWSTR szPackagePath, LPCWSTR szCommandLine)
{ {
MSIPACKAGE *package = NULL; MSIPACKAGE *package = NULL;
UINT r; UINT r;
MSIHANDLE handle;
FIXME("%s %s\n",debugstr_w(szPackagePath), debugstr_w(szCommandLine)); FIXME("%s %s\n",debugstr_w(szPackagePath), debugstr_w(szCommandLine));
r = MSI_OpenPackageW( szPackagePath, &package ); r = MSI_OpenPackageW( szPackagePath, &package );
if (r != ERROR_SUCCESS) if (r == ERROR_SUCCESS)
return r; {
r = ACTION_DoTopLevelINSTALL(package, szPackagePath, szCommandLine, szPackagePath );
handle = alloc_msihandle( &package->hdr ); msiobj_release( &package->hdr );
}
r = ACTION_DoTopLevelINSTALL(package, szPackagePath, szCommandLine,
szPackagePath);
MsiCloseHandle(handle);
msiobj_release( &package->hdr );
return r; return r;
} }
...@@ -248,9 +256,8 @@ UINT WINAPI MsiApplyPatchW(LPCWSTR szPatchPackage, LPCWSTR szInstallPackage, ...@@ -248,9 +256,8 @@ UINT WINAPI MsiApplyPatchW(LPCWSTR szPatchPackage, LPCWSTR szInstallPackage,
UINT WINAPI MsiConfigureProductExW(LPCWSTR szProduct, int iInstallLevel, UINT WINAPI MsiConfigureProductExW(LPCWSTR szProduct, int iInstallLevel,
INSTALLSTATE eInstallState, LPCWSTR szCommandLine) INSTALLSTATE eInstallState, LPCWSTR szCommandLine)
{ {
MSIHANDLE handle = -1; MSIPACKAGE* package = NULL;
MSIPACKAGE* package; UINT r;
UINT rc;
DWORD sz; DWORD sz;
WCHAR sourcepath[MAX_PATH]; WCHAR sourcepath[MAX_PATH];
WCHAR filename[MAX_PATH]; WCHAR filename[MAX_PATH];
...@@ -277,7 +284,7 @@ UINT WINAPI MsiConfigureProductExW(LPCWSTR szProduct, int iInstallLevel, ...@@ -277,7 +284,7 @@ UINT WINAPI MsiConfigureProductExW(LPCWSTR szProduct, int iInstallLevel,
MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED, MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAMEW, filename, &sz); MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
strcatW(sourcepath,filename); lstrcatW(sourcepath,filename);
/* /*
* ok 1, we need to find the msi file for this product. * ok 1, we need to find the msi file for this product.
...@@ -286,42 +293,37 @@ UINT WINAPI MsiConfigureProductExW(LPCWSTR szProduct, int iInstallLevel, ...@@ -286,42 +293,37 @@ UINT WINAPI MsiConfigureProductExW(LPCWSTR szProduct, int iInstallLevel,
* 4, cleanupany runonce entry. * 4, cleanupany runonce entry.
*/ */
rc = MsiOpenProductW(szProduct,&handle); r = MSI_OpenProductW( szProduct, &package );
if (rc != ERROR_SUCCESS) if (r != ERROR_SUCCESS)
goto end; return r;
package = msihandle2msiinfo(handle, MSIHANDLETYPE_PACKAGE);
if (!package)
{
rc = ERROR_INVALID_HANDLE;
goto end;
}
sz = lstrlenW(szInstalled); sz = lstrlenW(szInstalled) + 1;
if (szCommandLine) if (szCommandLine)
sz += lstrlenW(szCommandLine); sz += lstrlenW(szCommandLine);
commandline = msi_alloc(sz * sizeof(WCHAR)); commandline = msi_alloc(sz * sizeof(WCHAR));
if (!commandline )
{
r = ERROR_OUTOFMEMORY;
goto end;
}
commandline[0] = 0;
if (szCommandLine) if (szCommandLine)
lstrcpyW(commandline,szCommandLine); lstrcpyW(commandline,szCommandLine);
else
commandline[0] = 0;
if (MsiQueryProductStateW(szProduct) != INSTALLSTATE_UNKNOWN) if (MsiQueryProductStateW(szProduct) != INSTALLSTATE_UNKNOWN)
lstrcatW(commandline,szInstalled); lstrcatW(commandline,szInstalled);
rc = ACTION_DoTopLevelINSTALL(package, sourcepath, commandline, sourcepath); r = ACTION_DoTopLevelINSTALL(package, sourcepath, commandline, sourcepath);
msiobj_release( &package->hdr );
msi_free(commandline); msi_free(commandline);
end: end:
if (handle != -1) msiobj_release( &package->hdr );
MsiCloseHandle(handle);
return rc; return r;
} }
UINT WINAPI MsiConfigureProductExA(LPCSTR szProduct, int iInstallLevel, UINT WINAPI MsiConfigureProductExA(LPCSTR szProduct, int iInstallLevel,
...@@ -1753,9 +1755,8 @@ UINT WINAPI MsiGetShortcutTargetW( LPCWSTR szShortcutTarget, ...@@ -1753,9 +1755,8 @@ UINT WINAPI MsiGetShortcutTargetW( LPCWSTR szShortcutTarget,
UINT WINAPI MsiReinstallFeatureW( LPCWSTR szProduct, LPCWSTR szFeature, UINT WINAPI MsiReinstallFeatureW( LPCWSTR szProduct, LPCWSTR szFeature,
DWORD dwReinstallMode ) DWORD dwReinstallMode )
{ {
MSIHANDLE handle = -1; MSIPACKAGE* package = NULL;
MSIPACKAGE* package; UINT r;
UINT rc;
DWORD sz; DWORD sz;
WCHAR sourcepath[MAX_PATH]; WCHAR sourcepath[MAX_PATH];
WCHAR filename[MAX_PATH]; WCHAR filename[MAX_PATH];
...@@ -1805,20 +1806,13 @@ UINT WINAPI MsiReinstallFeatureW( LPCWSTR szProduct, LPCWSTR szFeature, ...@@ -1805,20 +1806,13 @@ UINT WINAPI MsiReinstallFeatureW( LPCWSTR szProduct, LPCWSTR szFeature,
strcatW(sourcepath,filename); strcatW(sourcepath,filename);
if (!(dwReinstallMode & REINSTALLMODE_PACKAGE)) if (dwReinstallMode & REINSTALLMODE_PACKAGE)
rc = MsiOpenProductW(szProduct,&handle); r = MSI_OpenPackageW( sourcepath, &package );
else else
rc = MsiOpenPackageW(sourcepath,&handle); r = MSI_OpenProductW( szProduct, &package );
if (rc != ERROR_SUCCESS)
goto end;
package = msihandle2msiinfo(handle, MSIHANDLETYPE_PACKAGE); if (r != ERROR_SUCCESS)
if (!package) return r;
{
rc = ERROR_INVALID_HANDLE;
goto end;
}
MSI_SetPropertyW(package,REINSTALLMODE,reinstallmode); MSI_SetPropertyW(package,REINSTALLMODE,reinstallmode);
...@@ -1831,16 +1825,13 @@ UINT WINAPI MsiReinstallFeatureW( LPCWSTR szProduct, LPCWSTR szFeature, ...@@ -1831,16 +1825,13 @@ UINT WINAPI MsiReinstallFeatureW( LPCWSTR szProduct, LPCWSTR szFeature,
sprintfW(commandline,fmt,szFeature); sprintfW(commandline,fmt,szFeature);
lstrcatW(commandline,szInstalled); lstrcatW(commandline,szInstalled);
rc = ACTION_DoTopLevelINSTALL(package, sourcepath, commandline, sourcepath); r = ACTION_DoTopLevelINSTALL(package, sourcepath, commandline, sourcepath);
msiobj_release( &package->hdr ); msiobj_release( &package->hdr );
msi_free(commandline); msi_free(commandline);
end:
if (handle != -1)
MsiCloseHandle(handle);
return rc; return r;
} }
UINT WINAPI MsiReinstallFeatureA( LPCSTR szProduct, LPCSTR szFeature, UINT WINAPI MsiReinstallFeatureA( LPCSTR szProduct, LPCSTR szFeature,
......
...@@ -267,7 +267,6 @@ extern void msiobj_addref(MSIOBJECTHDR *); ...@@ -267,7 +267,6 @@ extern void msiobj_addref(MSIOBJECTHDR *);
extern int msiobj_release(MSIOBJECTHDR *); extern int msiobj_release(MSIOBJECTHDR *);
extern void msiobj_lock(MSIOBJECTHDR *); extern void msiobj_lock(MSIOBJECTHDR *);
extern void msiobj_unlock(MSIOBJECTHDR *); extern void msiobj_unlock(MSIOBJECTHDR *);
extern MSIHANDLE msiobj_findhandle( MSIOBJECTHDR *hdr );
extern void free_cached_tables( MSIDATABASE *db ); extern void free_cached_tables( MSIDATABASE *db );
extern string_table *load_string_table( IStorage *stg ); extern string_table *load_string_table( IStorage *stg );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment