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

Alexandre Julliard julliard at wine.codeweavers.com
Tue Sep 26 15:04:53 CDT 2006


Module: wine
Branch: master
Commit: da14a4a25e686c5395164fb82c60d7b9590e7d50
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=da14a4a25e686c5395164fb82c60d7b9590e7d50

Author: James Hawkins <truiken at gmail.com>
Date:   Mon Sep 25 20:03:31 2006 -0700

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

---

 dlls/msi/database.c      |   19 ++++++++++++++++++-
 dlls/msi/install.c       |    2 +-
 dlls/msi/msipriv.h       |    1 +
 dlls/msi/package.c       |   18 +++++++++---------
 dlls/msi/tests/package.c |   38 +++++++++++++++++++++++++++++++-------
 5 files changed, 60 insertions(+), 18 deletions(-)

diff --git a/dlls/msi/database.c b/dlls/msi/database.c
index d984613..fa40c08 100644
--- a/dlls/msi/database.c
+++ b/dlls/msi/database.c
@@ -28,6 +28,7 @@ #include "winbase.h"
 #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( MSIOBJECT
     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,
     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,
         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 );
 
diff --git a/dlls/msi/install.c b/dlls/msi/install.c
index f80f68a..39db1f6 100644
--- a/dlls/msi/install.c
+++ b/dlls/msi/install.c
@@ -137,7 +137,7 @@ UINT msi_strcpy_to_awstring( LPCWSTR str
         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;
     }
 
diff --git a/dlls/msi/msipriv.h b/dlls/msi/msipriv.h
index a10be59..0d27ec8 100644
--- a/dlls/msi/msipriv.h
+++ b/dlls/msi/msipriv.h
@@ -71,6 +71,7 @@ typedef struct tagMSIDATABASE
     MSIOBJECTHDR hdr;
     IStorage *storage;
     string_table *strings;
+    LPWSTR path;
     LPWSTR deletefile;
     LPCWSTR mode;
     struct list tables;
diff --git a/dlls/msi/package.c b/dlls/msi/package.c
index c700bbf..1959dd0 100644
--- a/dlls/msi/package.c
+++ b/dlls/msi/package.c
@@ -513,6 +513,10 @@ UINT MSI_OpenPackageW(LPCWSTR szPackage,
     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,
     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;
 
diff --git a/dlls/msi/tests/package.c b/dlls/msi/tests/package.c
index cd55f89..ce94b92 100644
--- a/dlls/msi/tests/package.c
+++ b/dlls/msi/tests/package.c
@@ -454,14 +454,16 @@ static void test_getsourcepath( void )
     sz = sizeof buffer -1;
     strcpy(buffer,"x bad");
     r = MsiGetSourcePath( hpkg, "TARGETDIR", buffer, &sz );
-    ok( r == ERROR_DIRECTORY, "return value wrong\n");
+    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();
 }




More information about the wine-cvs mailing list