2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2002,2003,2004,2005 Mike McCormack for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #define NONAMELESSUNION
30 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(msi);
42 * The MSVC headers define the MSIDBOPEN_* macros cast to LPCTSTR,
43 * which is a problem because LPCTSTR isn't defined when compiling wine.
44 * To work around this problem, we need to define LPCTSTR as LPCWSTR here,
45 * and make sure to only use it in W functions.
47 #define LPCTSTR LPCWSTR
49 DEFINE_GUID( CLSID_MsiDatabase, 0x000c1084, 0x0000, 0x0000,
50 0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
55 * An .msi file is a structured storage file.
56 * It contains a number of streams.
57 * A stream for each table in the database.
58 * Two streams for the string table in the database.
59 * Any binary data in a table is a reference to a stream.
62 VOID MSI_CloseDatabase( MSIOBJECTHDR *arg )
64 MSIDATABASE *db = (MSIDATABASE *) arg;
67 free_cached_tables( db );
68 r = IStorage_Release( db->storage );
70 ERR("database reference count was not zero (%ld)\n", r);
73 UINT MSI_OpenDatabaseW(LPCWSTR szDBPath, LPCWSTR szPersist, MSIDATABASE **pdb)
77 MSIDATABASE *db = NULL;
78 UINT ret = ERROR_FUNCTION_FAILED;
82 TRACE("%s %s\n",debugstr_w(szDBPath),debugstr_w(szPersist) );
85 return ERROR_INVALID_PARAMETER;
87 szMode = (LPWSTR) szPersist;
88 if( HIWORD( szPersist ) )
90 /* UINT len = lstrlenW( szPerist ) + 1; */
91 FIXME("don't support persist files yet\b");
92 return ERROR_INVALID_PARAMETER;
93 /* szMode = HeapAlloc( GetProcessHeap(), 0, len * sizeof (DWORD) ); */
95 else if( szPersist == MSIDBOPEN_READONLY )
97 r = StgOpenStorage( szDBPath, NULL,
98 STGM_DIRECT|STGM_READ|STGM_SHARE_DENY_WRITE, NULL, 0, &stg);
100 else if( szPersist == MSIDBOPEN_CREATE )
102 r = StgCreateDocfile( szDBPath,
103 STGM_DIRECT|STGM_READWRITE|STGM_SHARE_EXCLUSIVE, 0, &stg);
104 if( r == ERROR_SUCCESS )
106 IStorage_SetClass( stg, &CLSID_MsiDatabase );
107 r = init_string_table( stg );
110 else if( szPersist == MSIDBOPEN_TRANSACT )
112 r = StgOpenStorage( szDBPath, NULL,
113 STGM_DIRECT|STGM_READWRITE|STGM_SHARE_EXCLUSIVE, NULL, 0, &stg);
117 ERR("unknown flag %p\n",szPersist);
118 return ERROR_INVALID_PARAMETER;
123 FIXME("open failed r = %08lx!\n",r);
124 return ERROR_FUNCTION_FAILED;
127 r = IStorage_Stat( stg, &stat, STATFLAG_NONAME );
130 FIXME("Failed to stat storage\n");
134 if( memcmp( &stat.clsid, &CLSID_MsiDatabase, sizeof (GUID) ) )
136 ERR("storage GUID is not a MSI database GUID %s\n",
137 debugstr_guid(&stat.clsid) );
142 db = alloc_msiobject( MSIHANDLETYPE_DATABASE, sizeof (MSIDATABASE),
146 FIXME("Failed to allocate a handle\n");
150 if( TRACE_ON( msi ) )
151 enum_stream_names( stg );
156 ret = load_string_table( db );
157 if( ret != ERROR_SUCCESS )
160 msiobj_addref( &db->hdr );
161 IStorage_AddRef( stg );
166 msiobj_release( &db->hdr );
168 IStorage_Release( stg );
173 UINT WINAPI MsiOpenDatabaseW(LPCWSTR szDBPath, LPCWSTR szPersist, MSIHANDLE *phDB)
178 TRACE("%s %s %p\n",debugstr_w(szDBPath),debugstr_w(szPersist), phDB);
180 ret = MSI_OpenDatabaseW( szDBPath, szPersist, &db );
181 if( ret == ERROR_SUCCESS )
183 *phDB = alloc_msihandle( &db->hdr );
184 msiobj_release( &db->hdr );
190 UINT WINAPI MsiOpenDatabaseA(LPCSTR szDBPath, LPCSTR szPersist, MSIHANDLE *phDB)
192 HRESULT r = ERROR_FUNCTION_FAILED;
193 LPWSTR szwDBPath = NULL, szwPersist = NULL;
195 TRACE("%s %s %p\n", debugstr_a(szDBPath), debugstr_a(szPersist), phDB);
199 szwDBPath = strdupAtoW( szDBPath );
204 if( HIWORD(szPersist) )
206 szwPersist = strdupAtoW( szPersist );
211 szwPersist = (LPWSTR) szPersist;
213 r = MsiOpenDatabaseW( szwDBPath, szwPersist, phDB );
216 HeapFree( GetProcessHeap(), 0, szwPersist );
217 HeapFree( GetProcessHeap(), 0, szwDBPath );
222 UINT MSI_DatabaseImport( MSIDATABASE *db, LPCWSTR folder, LPCWSTR file )
224 FIXME("%p %s %s\n", db, debugstr_w(folder), debugstr_w(file) );
226 if( folder == NULL || file == NULL )
227 return ERROR_INVALID_PARAMETER;
229 return ERROR_CALL_NOT_IMPLEMENTED;
232 UINT WINAPI MsiDatabaseImportW(MSIHANDLE handle, LPCWSTR szFolder, LPCWSTR szFilename)
237 TRACE("%lx %s %s\n",handle,debugstr_w(szFolder), debugstr_w(szFilename));
239 db = msihandle2msiinfo( handle, MSIHANDLETYPE_DATABASE );
241 return ERROR_INVALID_HANDLE;
242 r = MSI_DatabaseImport( db, szFolder, szFilename );
243 msiobj_release( &db->hdr );
247 UINT WINAPI MsiDatabaseImportA( MSIHANDLE handle,
248 LPCSTR szFolder, LPCSTR szFilename )
250 LPWSTR path = NULL, file = NULL;
251 UINT r = ERROR_OUTOFMEMORY;
253 TRACE("%lx %s %s\n", handle, debugstr_a(szFolder), debugstr_a(szFilename));
257 path = strdupAtoW( szFolder );
264 file = strdupAtoW( szFilename );
269 r = MsiDatabaseImportW( handle, path, file );
272 HeapFree( GetProcessHeap(), 0, path );
273 HeapFree( GetProcessHeap(), 0, file );
278 UINT MSI_DatabaseExport( MSIDATABASE *db, LPCWSTR table,
279 LPCWSTR folder, LPCWSTR file )
281 FIXME("%p %s %s %s\n", db, debugstr_w(table),
282 debugstr_w(folder), debugstr_w(file) );
284 if( folder == NULL || file == NULL )
285 return ERROR_INVALID_PARAMETER;
287 return ERROR_CALL_NOT_IMPLEMENTED;
290 UINT WINAPI MsiDatabaseExportW( MSIHANDLE handle, LPCWSTR szTable,
291 LPCWSTR szFolder, LPCWSTR szFilename )
296 TRACE("%lx %s %s %s\n", handle, debugstr_w(szTable),
297 debugstr_w(szFolder), debugstr_w(szFilename));
299 db = msihandle2msiinfo( handle, MSIHANDLETYPE_DATABASE );
301 return ERROR_INVALID_HANDLE;
302 r = MSI_DatabaseExport( db, szTable, szFolder, szFilename );
303 msiobj_release( &db->hdr );
307 UINT WINAPI MsiDatabaseExportA( MSIHANDLE handle, LPCSTR szTable,
308 LPCSTR szFolder, LPCSTR szFilename )
310 LPWSTR path = NULL, file = NULL, table = NULL;
311 UINT r = ERROR_OUTOFMEMORY;
313 TRACE("%lx %s %s %s\n", handle, debugstr_a(szTable),
314 debugstr_a(szFolder), debugstr_a(szFilename));
318 table = strdupAtoW( szTable );
325 path = strdupAtoW( szFolder );
332 file = strdupAtoW( szFilename );
337 r = MsiDatabaseExportW( handle, table, path, file );
340 HeapFree( GetProcessHeap(), 0, table );
341 HeapFree( GetProcessHeap(), 0, path );
342 HeapFree( GetProcessHeap(), 0, file );