@@ -1310,17 +1310,19 @@ static UINT validate_package( MSIPACKAGE *package )
13101310 return ERROR_INSTALL_LANGUAGE_UNSUPPORTED ;
13111311}
13121312
1313- static WCHAR * get_product_code ( MSIDATABASE * db )
1313+ static WCHAR * get_property ( MSIDATABASE * db , const WCHAR * prop )
13141314{
1315- static const WCHAR query [] = {
1315+ static const WCHAR select_query [] = {
13161316 'S' ,'E' ,'L' ,'E' ,'C' ,'T' ,' ' ,'`' ,'V' ,'a' ,'l' ,'u' ,'e' ,'`' ,' ' ,
13171317 'F' ,'R' ,'O' ,'M' ,' ' ,'`' ,'P' ,'r' ,'o' ,'p' ,'e' ,'r' ,'t' ,'y' ,'`' ,' ' ,
13181318 'W' ,'H' ,'E' ,'R' ,'E' ,' ' ,'`' ,'P' ,'r' ,'o' ,'p' ,'e' ,'r' ,'t' ,'y' ,'`' ,'=' ,
1319- '\'' ,'P' ,'r' ,'o' ,'d' ,'u' ,'c' ,'t' ,'C' ,'o' ,'d' ,'e' ,'\'' ,0 };
1319+ '\'' ,'%' ,'s' ,'\'' ,0 };
1320+ WCHAR query [MAX_PATH ];
13201321 MSIQUERY * view ;
13211322 MSIRECORD * rec ;
13221323 WCHAR * ret = NULL ;
13231324
1325+ sprintfW (query , select_query , prop );
13241326 if (MSI_DatabaseOpenViewW ( db , query , & view ) != ERROR_SUCCESS )
13251327 {
13261328 return NULL ;
@@ -1341,48 +1343,39 @@ static WCHAR *get_product_code( MSIDATABASE *db )
13411343 return ret ;
13421344}
13431345
1344- static UINT get_registered_local_package ( const WCHAR * product , const WCHAR * package , WCHAR * localfile )
1346+ static WCHAR * get_product_code ( MSIDATABASE * db )
1347+ {
1348+ return get_property ( db , szProductCode );
1349+ }
1350+
1351+ static WCHAR * get_product_version ( MSIDATABASE * db )
1352+ {
1353+ return get_property ( db , szProductVersion );
1354+ }
1355+
1356+ static UINT get_registered_local_package ( const WCHAR * product , WCHAR * localfile )
13451357{
13461358 MSIINSTALLCONTEXT context ;
1347- HKEY product_key , props_key ;
1348- WCHAR * registered_package = NULL , unsquashed [ GUID_SIZE ] ;
1359+ WCHAR * filename ;
1360+ HKEY props_key ;
13491361 UINT r ;
13501362
13511363 r = msi_locate_product ( product , & context );
13521364 if (r != ERROR_SUCCESS )
13531365 return r ;
13541366
1355- r = MSIREG_OpenProductKey ( product , NULL , context , & product_key , FALSE );
1356- if (r != ERROR_SUCCESS )
1357- return r ;
1358-
13591367 r = MSIREG_OpenInstallProps ( product , context , NULL , & props_key , FALSE );
13601368 if (r != ERROR_SUCCESS )
1361- {
1362- RegCloseKey ( product_key );
13631369 return r ;
1364- }
1365- r = ERROR_FUNCTION_FAILED ;
1366- registered_package = msi_reg_get_val_str ( product_key , INSTALLPROPERTY_PACKAGECODEW );
1367- if (!registered_package )
1368- goto done ;
1369-
1370- unsquash_guid ( registered_package , unsquashed );
1371- if (!strcmpiW ( package , unsquashed ))
1372- {
1373- WCHAR * filename = msi_reg_get_val_str ( props_key , INSTALLPROPERTY_LOCALPACKAGEW );
1374- if (!filename )
1375- goto done ;
13761370
1377- strcpyW ( localfile , filename );
1378- msi_free ( filename );
1379- r = ERROR_SUCCESS ;
1380- }
1381- done :
1382- msi_free ( registered_package );
1371+ filename = msi_reg_get_val_str ( props_key , INSTALLPROPERTY_LOCALPACKAGEW );
13831372 RegCloseKey ( props_key );
1384- RegCloseKey ( product_key );
1385- return r ;
1373+ if (!filename )
1374+ return ERROR_FUNCTION_FAILED ;
1375+
1376+ strcpyW ( localfile , filename );
1377+ msi_free ( filename );
1378+ return ERROR_SUCCESS ;
13861379}
13871380
13881381WCHAR * msi_get_package_code ( MSIDATABASE * db )
@@ -1406,33 +1399,15 @@ WCHAR *msi_get_package_code( MSIDATABASE *db )
14061399 return ret ;
14071400}
14081401
1409- static UINT get_local_package ( const WCHAR * filename , WCHAR * localfile )
1402+ static UINT get_local_package ( MSIDATABASE * db , WCHAR * localfile )
14101403{
1411- WCHAR * product_code , * package_code ;
1412- MSIDATABASE * db ;
1404+ WCHAR * product_code ;
14131405 UINT r ;
14141406
1415- if ((r = MSI_OpenDatabaseW ( filename , MSIDBOPEN_READONLY , & db )) != ERROR_SUCCESS )
1416- {
1417- if (GetFileAttributesW ( filename ) == INVALID_FILE_ATTRIBUTES )
1418- return ERROR_FILE_NOT_FOUND ;
1419- return r ;
1420- }
14211407 if (!(product_code = get_product_code ( db )))
1422- {
1423- msiobj_release ( & db -> hdr );
1424- return ERROR_INSTALL_PACKAGE_INVALID ;
1425- }
1426- if (!(package_code = msi_get_package_code ( db )))
1427- {
1428- msi_free ( product_code );
1429- msiobj_release ( & db -> hdr );
14301408 return ERROR_INSTALL_PACKAGE_INVALID ;
1431- }
1432- r = get_registered_local_package ( product_code , package_code , localfile );
1433- msi_free ( package_code );
1409+ r = get_registered_local_package ( product_code , localfile );
14341410 msi_free ( product_code );
1435- msiobj_release ( & db -> hdr );
14361411 return r ;
14371412}
14381413
@@ -1497,6 +1472,8 @@ UINT MSI_OpenPackageW(LPCWSTR szPackage, MSIPACKAGE **pPackage)
14971472 }
14981473 else
14991474 {
1475+ WCHAR * product_version = NULL ;
1476+
15001477 if ( UrlIsW ( szPackage , URLIS_URL ) )
15011478 {
15021479 r = msi_download_file ( szPackage , cachefile );
@@ -1505,20 +1482,31 @@ UINT MSI_OpenPackageW(LPCWSTR szPackage, MSIPACKAGE **pPackage)
15051482
15061483 file = cachefile ;
15071484 }
1508- r = get_local_package ( file , localfile );
1485+ r = MSI_OpenDatabaseW ( file , MSIDBOPEN_READONLY , & db );
1486+ if (r != ERROR_SUCCESS )
1487+ {
1488+ if (GetFileAttributesW ( file ) == INVALID_FILE_ATTRIBUTES )
1489+ return ERROR_FILE_NOT_FOUND ;
1490+ return r ;
1491+ }
1492+ r = get_local_package ( db , localfile );
15091493 if (r != ERROR_SUCCESS || GetFileAttributesW ( localfile ) == INVALID_FILE_ATTRIBUTES )
15101494 {
15111495 DWORD localfile_attr ;
15121496
15131497 r = msi_create_empty_local_file ( localfile , dotmsi );
15141498 if (r != ERROR_SUCCESS )
1499+ {
1500+ msiobj_release ( & db -> hdr );
15151501 return r ;
1502+ }
15161503
15171504 if (!CopyFileW ( file , localfile , FALSE ))
15181505 {
15191506 r = GetLastError ();
15201507 WARN ("unable to copy package %s to %s (%u)\n" , debugstr_w (file ), debugstr_w (localfile ), r );
15211508 DeleteFileW ( localfile );
1509+ msiobj_release ( & db -> hdr );
15221510 return r ;
15231511 }
15241512 delete_on_close = TRUE;
@@ -1528,10 +1516,28 @@ UINT MSI_OpenPackageW(LPCWSTR szPackage, MSIPACKAGE **pPackage)
15281516 if (localfile_attr & FILE_ATTRIBUTE_READONLY )
15291517 SetFileAttributesW ( localfile , localfile_attr & ~FILE_ATTRIBUTE_READONLY );
15301518 }
1519+ else
1520+ product_version = get_product_version ( db );
1521+ msiobj_release ( & db -> hdr );
15311522 TRACE ("opening package %s\n" , debugstr_w ( localfile ));
15321523 r = MSI_OpenDatabaseW ( localfile , MSIDBOPEN_TRANSACT , & db );
15331524 if (r != ERROR_SUCCESS )
15341525 return r ;
1526+
1527+ if (product_version )
1528+ {
1529+ WCHAR * cache_version = get_product_version ( db );
1530+ if (!product_version != !cache_version ||
1531+ (product_version && strcmpW (product_version , cache_version )))
1532+ {
1533+ msiobj_release ( & db -> hdr );
1534+ msi_free (product_version );
1535+ msi_free (cache_version );
1536+ return ERROR_PRODUCT_VERSION ;
1537+ }
1538+ msi_free (product_version );
1539+ msi_free (cache_version );
1540+ }
15351541 }
15361542 package = MSI_CreatePackage ( db );
15371543 msiobj_release ( & db -> hdr );
0 commit comments