msi: Store the full path to the database file in the MSIDATABASE structure.

This commit is contained in:
James Hawkins 2006-09-25 20:03:31 -07:00 committed by Alexandre Julliard
parent 1492950c8e
commit da14a4a25e
5 changed files with 60 additions and 18 deletions

View File

@ -28,6 +28,7 @@
#include "winreg.h"
#include "winnls.h"
#include "wine/debug.h"
#include "wine/unicode.h"
#include "msi.h"
#include "msiquery.h"
#include "msipriv.h"
@ -58,6 +59,7 @@ static VOID MSI_CloseDatabase( MSIOBJECTHDR *arg )
MSIDATABASE *db = (MSIDATABASE *) arg;
DWORD r;
msi_free(db->path);
free_cached_tables( db );
msi_free_transforms( db );
msi_destroy_stringtable( db->strings );
@ -77,15 +79,19 @@ UINT MSI_OpenDatabaseW(LPCWSTR szDBPath, LPCWSTR szPersist, MSIDATABASE **pdb)
HRESULT r;
MSIDATABASE *db = NULL;
UINT ret = ERROR_FUNCTION_FAILED;
LPCWSTR szMode;
LPCWSTR szMode, save_path;
STATSTG stat;
BOOL created = FALSE;
WCHAR path[MAX_PATH];
static const WCHAR backslash[] = {'\\',0};
TRACE("%s %s\n",debugstr_w(szDBPath),debugstr_w(szPersist) );
if( !pdb )
return ERROR_INVALID_PARAMETER;
save_path = szDBPath;
szMode = szPersist;
if( HIWORD( szPersist ) )
{
@ -162,6 +168,17 @@ UINT MSI_OpenDatabaseW(LPCWSTR szDBPath, LPCWSTR szPersist, MSIDATABASE **pdb)
goto end;
}
if (!strchrW( save_path, '\\' ))
{
GetCurrentDirectoryW( MAX_PATH, path );
lstrcatW( path, backslash );
lstrcatW( path, save_path );
}
else
lstrcpyW( path, save_path );
db->path = strdupW( path );
if( TRACE_ON( msi ) )
enum_stream_names( stg );

View File

@ -137,7 +137,7 @@ UINT msi_strcpy_to_awstring( LPCWSTR str, awstring *awbuf, DWORD *sz )
if (len)
len--;
WideCharToMultiByte( CP_ACP, 0, str, -1, awbuf->str.a, *sz, NULL, NULL );
if ( *sz && (len >= *sz) )
if ( awbuf->str.a && *sz && (len >= *sz) )
awbuf->str.a[*sz - 1] = 0;
}

View File

@ -71,6 +71,7 @@ typedef struct tagMSIDATABASE
MSIOBJECTHDR hdr;
IStorage *storage;
string_table *strings;
LPWSTR path;
LPWSTR deletefile;
LPCWSTR mode;
struct list tables;

View File

@ -513,6 +513,10 @@ UINT MSI_OpenPackageW(LPCWSTR szPackage, MSIPACKAGE **pPackage)
MSIHANDLE handle;
UINT r;
static const WCHAR OriginalDatabase[] =
{'O','r','i','g','i','n','a','l','D','a','t','a','b','a','s','e',0};
static const WCHAR Database[] = {'D','A','T','A','B','A','S','E',0};
TRACE("%s %p\n", debugstr_w(szPackage), pPackage);
if( szPackage[0] == '#' )
@ -551,20 +555,16 @@ UINT MSI_OpenPackageW(LPCWSTR szPackage, MSIPACKAGE **pPackage)
if( !package )
return ERROR_FUNCTION_FAILED;
/*
* FIXME: I don't think this is right. Maybe we should be storing the
* name of the database in the MSIDATABASE structure and fetching this
* info from there, or maybe this is only relevant to cached databases.
*/
if( szPackage[0] != '#' )
{
static const WCHAR OriginalDatabase[] =
{'O','r','i','g','i','n','a','l','D','a','t','a','b','a','s','e',0};
static const WCHAR Database[] = {'D','A','T','A','B','A','S','E',0};
MSI_SetPropertyW( package, OriginalDatabase, szPackage );
MSI_SetPropertyW( package, Database, szPackage );
}
else
{
MSI_SetPropertyW( package, OriginalDatabase, db->path );
MSI_SetPropertyW( package, Database, db->path );
}
*pPackage = package;

View File

@ -454,14 +454,16 @@ static void test_getsourcepath( void )
sz = sizeof buffer -1;
strcpy(buffer,"x bad");
r = MsiGetSourcePath( hpkg, "TARGETDIR", buffer, &sz );
todo_wine
{
ok( r == ERROR_DIRECTORY, "return value wrong\n");
}
r = MsiDoAction( hpkg, "CostInitialize");
ok( r == ERROR_SUCCESS, "cost init failed\n");
r = MsiDoAction( hpkg, "CostFinalize");
ok( r == ERROR_SUCCESS, "cost finalize failed\n");
todo_wine {
sz = sizeof buffer -1;
buffer[0] = 'x';
r = MsiGetSourcePath( hpkg, "TARGETDIR", buffer, &sz );
@ -472,13 +474,10 @@ static void test_getsourcepath( void )
strcpy(buffer,"x bad");
r = MsiGetSourcePath( hpkg, "TARGETDIR", buffer, &sz );
ok( r == ERROR_MORE_DATA, "return value wrong\n");
}
ok( buffer[0] == 'x', "buffer modified\n");
todo_wine {
r = MsiGetSourcePath( hpkg, "TARGETDIR", NULL, NULL );
ok( r == ERROR_SUCCESS, "return value wrong\n");
}
r = MsiGetSourcePath( hpkg, "TARGETDIR ", NULL, NULL );
ok( r == ERROR_DIRECTORY, "return value wrong\n");
@ -489,10 +488,8 @@ static void test_getsourcepath( void )
r = MsiGetSourcePath( hpkg, "TARGETDIR", buffer, NULL );
ok( r == ERROR_INVALID_PARAMETER, "return value wrong\n");
todo_wine {
r = MsiGetSourcePath( hpkg, "TARGETDIR", NULL, &sz );
ok( r == ERROR_SUCCESS, "return value wrong\n");
}
MsiCloseHandle( hpkg );
DeleteFile(msifile);
@ -2696,6 +2693,32 @@ static void test_featureparents(void)
MsiCloseHandle(hpkg);
}
static void test_installprops(void)
{
MSIHANDLE hpkg, hdb;
CHAR path[MAX_PATH];
CHAR buf[MAX_PATH];
DWORD size;
UINT r;
GetCurrentDirectory(MAX_PATH, path);
lstrcat(path, "\\");
lstrcat(path, msifile);
hdb = create_package_db();
ok( hdb, "failed to create database\n");
hpkg = package_from_db(hdb);
ok( hpkg, "failed to create package\n");
MsiCloseHandle(hdb);
size = MAX_PATH;
r = MsiGetProperty(hpkg, "DATABASE", buf, &size);
ok( r == ERROR_SUCCESS, "failed to get property: %d\n", r);
ok( !lstrcmp(buf, path), "Expected %s, got %s\n", path, buf);
}
START_TEST(package)
{
test_createpackage();
@ -2713,4 +2736,5 @@ START_TEST(package)
test_removefiles();
test_appsearch();
test_featureparents();
test_installprops();
}