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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #define NONAMELESSUNION
30 #include "wine/debug.h"
31 #include "wine/unicode.h"
37 #include "msiserver.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(msi);
43 DEFINE_GUID( CLSID_MsiDatabase, 0x000c1084, 0x0000, 0x0000,
44 0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
45 DEFINE_GUID( CLSID_MsiPatch, 0x000c1086, 0x0000, 0x0000,
46 0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
51 * An .msi file is a structured storage file.
52 * It contains a number of streams.
53 * A stream for each table in the database.
54 * Two streams for the string table in the database.
55 * Any binary data in a table is a reference to a stream.
58 static VOID MSI_CloseDatabase( MSIOBJECTHDR *arg )
60 MSIDATABASE *db = (MSIDATABASE *) arg;
63 free_cached_tables( db );
64 msi_free_transforms( db );
65 msi_destroy_stringtable( db->strings );
66 IStorage_Release( db->storage );
69 DeleteFileW( db->deletefile );
70 msi_free( db->deletefile );
74 UINT MSI_OpenDatabaseW(LPCWSTR szDBPath, LPCWSTR szPersist, MSIDATABASE **pdb)
78 MSIDATABASE *db = NULL;
79 UINT ret = ERROR_FUNCTION_FAILED;
80 LPCWSTR szMode, save_path;
85 static const WCHAR backslash[] = {'\\',0};
86 static WCHAR szTables[] = { '_','T','a','b','l','e','s',0 };
88 TRACE("%s %s\n",debugstr_w(szDBPath),debugstr_w(szPersist) );
91 return ERROR_INVALID_PARAMETER;
95 if( HIWORD( szPersist ) )
97 if (!CopyFileW( szDBPath, szPersist, FALSE ))
98 return ERROR_OPEN_FAILED;
100 szDBPath = szPersist;
101 szPersist = MSIDBOPEN_TRANSACT;
105 if( szPersist == MSIDBOPEN_READONLY )
107 r = StgOpenStorage( szDBPath, NULL,
108 STGM_DIRECT|STGM_READ|STGM_SHARE_DENY_WRITE, NULL, 0, &stg);
110 else if( szPersist == MSIDBOPEN_CREATE || szPersist == MSIDBOPEN_CREATEDIRECT )
112 /* FIXME: MSIDBOPEN_CREATE should case STGM_TRANSACTED flag to be
114 r = StgCreateDocfile( szDBPath,
115 STGM_CREATE|STGM_DIRECT|STGM_READWRITE|STGM_SHARE_EXCLUSIVE, 0, &stg);
116 if( r == ERROR_SUCCESS )
118 IStorage_SetClass( stg, &CLSID_MsiDatabase );
119 /* create the _Tables stream */
120 r = write_stream_data(stg, szTables, NULL, 0, TRUE);
122 r = msi_init_string_table( stg );
126 else if( szPersist == MSIDBOPEN_TRANSACT )
128 /* FIXME: MSIDBOPEN_TRANSACT should case STGM_TRANSACTED flag to be
130 r = StgOpenStorage( szDBPath, NULL,
131 STGM_DIRECT|STGM_READWRITE|STGM_SHARE_EXCLUSIVE, NULL, 0, &stg);
133 else if( szPersist == MSIDBOPEN_DIRECT )
135 r = StgOpenStorage( szDBPath, NULL,
136 STGM_DIRECT|STGM_READWRITE|STGM_SHARE_EXCLUSIVE, NULL, 0, &stg);
140 ERR("unknown flag %p\n",szPersist);
141 return ERROR_INVALID_PARAMETER;
144 if( FAILED( r ) || !stg )
146 FIXME("open failed r = %08x for %s\n", r, debugstr_w(szDBPath));
147 return ERROR_FUNCTION_FAILED;
150 r = IStorage_Stat( stg, &stat, STATFLAG_NONAME );
153 FIXME("Failed to stat storage\n");
157 if ( !IsEqualGUID( &stat.clsid, &CLSID_MsiDatabase ) &&
158 !IsEqualGUID( &stat.clsid, &CLSID_MsiPatch ) )
160 ERR("storage GUID is not a MSI database GUID %s\n",
161 debugstr_guid(&stat.clsid) );
165 db = alloc_msiobject( MSIHANDLETYPE_DATABASE, sizeof (MSIDATABASE),
169 FIXME("Failed to allocate a handle\n");
173 if (!strchrW( save_path, '\\' ))
175 GetCurrentDirectoryW( MAX_PATH, path );
176 lstrcatW( path, backslash );
177 lstrcatW( path, save_path );
180 lstrcpyW( path, save_path );
182 db->path = strdupW( path );
184 if( TRACE_ON( msi ) )
185 enum_stream_names( stg );
190 db->deletefile = strdupW( szDBPath );
192 db->deletefile = NULL;
193 list_init( &db->tables );
194 list_init( &db->transforms );
196 db->strings = msi_load_string_table( stg, &db->bytes_per_strref );
200 msi_table_set_strref( db->bytes_per_strref );
203 msiobj_addref( &db->hdr );
204 IStorage_AddRef( stg );
209 msiobj_release( &db->hdr );
211 IStorage_Release( stg );
216 UINT WINAPI MsiOpenDatabaseW(LPCWSTR szDBPath, LPCWSTR szPersist, MSIHANDLE *phDB)
221 TRACE("%s %s %p\n",debugstr_w(szDBPath),debugstr_w(szPersist), phDB);
223 ret = MSI_OpenDatabaseW( szDBPath, szPersist, &db );
224 if( ret == ERROR_SUCCESS )
226 *phDB = alloc_msihandle( &db->hdr );
228 ret = ERROR_NOT_ENOUGH_MEMORY;
229 msiobj_release( &db->hdr );
235 UINT WINAPI MsiOpenDatabaseA(LPCSTR szDBPath, LPCSTR szPersist, MSIHANDLE *phDB)
237 HRESULT r = ERROR_FUNCTION_FAILED;
238 LPWSTR szwDBPath = NULL, szwPersist = NULL;
240 TRACE("%s %s %p\n", debugstr_a(szDBPath), debugstr_a(szPersist), phDB);
244 szwDBPath = strdupAtoW( szDBPath );
249 if( HIWORD(szPersist) )
251 szwPersist = strdupAtoW( szPersist );
256 szwPersist = (LPWSTR)(DWORD_PTR)szPersist;
258 r = MsiOpenDatabaseW( szwDBPath, szwPersist, phDB );
261 if( HIWORD(szPersist) )
262 msi_free( szwPersist );
263 msi_free( szwDBPath );
268 static LPWSTR msi_read_text_archive(LPCWSTR path)
273 DWORD read, size = 0;
275 file = CreateFileW( path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL );
276 if (file == INVALID_HANDLE_VALUE)
279 size = GetFileSize( file, NULL );
280 data = msi_alloc( size + 1 );
284 if (!ReadFile( file, data, size, &read, NULL ))
288 wdata = strdupAtoW( data );
296 static void msi_parse_line(LPWSTR *line, LPWSTR **entries, DWORD *num_entries)
298 LPWSTR ptr = *line, save;
303 /* stay on this line */
304 while (*ptr && *ptr != '\n')
306 /* entries are separated by tabs */
313 *entries = msi_alloc(count * sizeof(LPWSTR));
317 /* store pointers into the data */
318 for (i = 0, ptr = *line; i < count; i++)
320 while (*ptr && *ptr == '\r') ptr++;
323 while (*ptr && *ptr != '\t' && *ptr != '\n' && *ptr != '\r') ptr++;
325 /* NULL-separate the data */
326 if (*ptr == '\n' || *ptr == '\r')
328 while (*ptr == '\n' || *ptr == '\r')
334 (*entries)[i] = save;
337 /* move to the next line if there's more, else EOF */
341 *num_entries = count;
344 static LPWSTR msi_build_createsql_prelude(LPWSTR table)
349 static const WCHAR create_fmt[] = {'C','R','E','A','T','E',' ','T','A','B','L','E',' ','`','%','s','`',' ','(',' ',0};
351 size = sizeof(create_fmt) + lstrlenW(table) - 2;
352 prelude = msi_alloc(size * sizeof(WCHAR));
356 sprintfW(prelude, create_fmt, table);
360 static LPWSTR msi_build_createsql_columns(LPWSTR *columns_data, LPWSTR *types, DWORD num_columns)
364 DWORD sql_size = 1, i, len;
365 WCHAR expanded[128], *ptr;
366 WCHAR size[10], comma[2], extra[30];
368 static const WCHAR column_fmt[] = {'`','%','s','`',' ','%','s','%','s','%','s','%','s',' ',0};
369 static const WCHAR size_fmt[] = {'(','%','s',')',0};
370 static const WCHAR type_char[] = {'C','H','A','R',0};
371 static const WCHAR type_int[] = {'I','N','T',0};
372 static const WCHAR type_long[] = {'L','O','N','G',0};
373 static const WCHAR type_notnull[] = {' ','N','O','T',' ','N','U','L','L',0};
374 static const WCHAR localizable[] = {' ','L','O','C','A','L','I','Z','A','B','L','E',0};
376 columns = msi_alloc_zero(sql_size * sizeof(WCHAR));
380 for (i = 0; i < num_columns; i++)
383 comma[1] = size[0] = extra[0] = '\0';
385 if (i == num_columns - 1)
397 lstrcpyW(extra, type_notnull);
399 lstrcatW(extra, localizable);
401 sprintfW(size, size_fmt, ptr);
404 lstrcpyW(extra, type_notnull);
407 sprintfW(size, size_fmt, ptr);
410 lstrcpyW(extra, type_notnull);
418 ERR("Unknown type: %c\n", types[i][0]);
423 sprintfW(expanded, column_fmt, columns_data[i], type, size, extra, comma);
424 sql_size += lstrlenW(expanded);
426 p = msi_realloc(columns, sql_size * sizeof(WCHAR));
434 lstrcatW(columns, expanded);
440 static LPWSTR msi_build_createsql_postlude(LPWSTR *primary_keys, DWORD num_keys)
442 LPWSTR postlude, keys, ptr;
443 DWORD size, key_size, i;
445 static const WCHAR key_fmt[] = {'`','%','s','`',',',' ',0};
446 static const WCHAR postlude_fmt[] = {'P','R','I','M','A','R','Y',' ','K','E','Y',' ','%','s',')',0};
448 for (i = 0, size = 1; i < num_keys; i++)
449 size += lstrlenW(key_fmt) + lstrlenW(primary_keys[i]) - 2;
451 keys = msi_alloc(size * sizeof(WCHAR));
455 for (i = 0, ptr = keys; i < num_keys; i++)
457 key_size = lstrlenW(key_fmt) + lstrlenW(primary_keys[i]) -2;
458 sprintfW(ptr, key_fmt, primary_keys[i]);
462 /* remove final ', ' */
465 size = lstrlenW(postlude_fmt) + size - 1;
466 postlude = msi_alloc(size * sizeof(WCHAR));
470 sprintfW(postlude, postlude_fmt, keys);
477 static UINT msi_add_table_to_db(MSIDATABASE *db, LPWSTR *columns, LPWSTR *types, LPWSTR *labels, DWORD num_labels, DWORD num_columns)
483 LPWSTR prelude, columns_sql, postlude;
485 prelude = msi_build_createsql_prelude(labels[0]);
486 columns_sql = msi_build_createsql_columns(columns, types, num_columns);
487 postlude = msi_build_createsql_postlude(labels + 1, num_labels - 1); /* skip over table name */
489 if (!prelude || !columns_sql || !postlude)
490 return ERROR_OUTOFMEMORY;
492 size = lstrlenW(prelude) + lstrlenW(columns_sql) + lstrlenW(postlude) + 1;
493 create_sql = msi_alloc(size * sizeof(WCHAR));
495 return ERROR_OUTOFMEMORY;
497 lstrcpyW(create_sql, prelude);
498 lstrcatW(create_sql, columns_sql);
499 lstrcatW(create_sql, postlude);
502 msi_free(columns_sql);
505 r = MSI_DatabaseOpenViewW( db, create_sql, &view );
506 msi_free(create_sql);
508 if (r != ERROR_SUCCESS)
511 r = MSI_ViewExecute(view, NULL);
513 msiobj_release(&view->hdr);
518 static UINT construct_record(DWORD num_columns, LPWSTR *types,
519 LPWSTR *data, MSIRECORD **rec)
523 *rec = MSI_CreateRecord(num_columns);
525 return ERROR_OUTOFMEMORY;
527 for (i = 0; i < num_columns; i++)
531 case 'L': case 'l': case 'S': case 's':
532 MSI_RecordSetStringW(*rec, i + 1, data[i]);
536 MSI_RecordSetInteger(*rec, i + 1, atoiW(data[i]));
539 ERR("Unhandled column type: %c\n", types[i][0]);
540 msiobj_release(&(*rec)->hdr);
541 return ERROR_FUNCTION_FAILED;
545 return ERROR_SUCCESS;
548 static UINT msi_add_records_to_table(MSIDATABASE *db, LPWSTR *columns, LPWSTR *types,
549 LPWSTR *labels, LPWSTR **records,
550 int num_columns, int num_records)
558 static const WCHAR select[] = {
559 'S','E','L','E','C','T',' ','*',' ',
560 'F','R','O','M',' ','`','%','s','`',0
563 size = lstrlenW(select) + lstrlenW(labels[0]) - 1;
564 query = msi_alloc(size * sizeof(WCHAR));
566 return ERROR_OUTOFMEMORY;
568 sprintfW(query, select, labels[0]);
570 r = MSI_DatabaseOpenViewW(db, query, &view);
572 if (r != ERROR_SUCCESS)
575 while (MSI_ViewFetch(view, &rec) != ERROR_NO_MORE_ITEMS)
577 r = MSI_ViewModify(view, MSIMODIFY_DELETE, rec);
578 if (r != ERROR_SUCCESS)
582 for (i = 0; i < num_records; i++)
584 r = construct_record(num_columns, types, records[i], &rec);
585 if (r != ERROR_SUCCESS)
588 r = MSI_ViewModify(view, MSIMODIFY_INSERT, rec);
589 if (r != ERROR_SUCCESS)
591 msiobj_release(&rec->hdr);
595 msiobj_release(&rec->hdr);
599 msiobj_release(&view->hdr);
603 UINT MSI_DatabaseImport(MSIDATABASE *db, LPCWSTR folder, LPCWSTR file)
607 DWORD num_labels, num_types;
608 DWORD num_columns, num_records = 0;
609 LPWSTR *columns, *types, *labels;
610 LPWSTR path, ptr, data;
611 LPWSTR **records = NULL;
612 LPWSTR **temp_records;
614 static const WCHAR backslash[] = {'\\',0};
616 TRACE("%p %s %s\n", db, debugstr_w(folder), debugstr_w(file) );
618 if( folder == NULL || file == NULL )
619 return ERROR_INVALID_PARAMETER;
621 len = lstrlenW(folder) + lstrlenW(backslash) + lstrlenW(file) + 1;
622 path = msi_alloc( len * sizeof(WCHAR) );
624 return ERROR_OUTOFMEMORY;
626 lstrcpyW( path, folder );
627 lstrcatW( path, backslash );
628 lstrcatW( path, file );
630 data = msi_read_text_archive( path );
633 msi_parse_line( &ptr, &columns, &num_columns );
634 msi_parse_line( &ptr, &types, &num_types );
635 msi_parse_line( &ptr, &labels, &num_labels );
637 if (num_columns != num_types)
639 r = ERROR_FUNCTION_FAILED;
643 records = msi_alloc(sizeof(LPWSTR *));
646 r = ERROR_OUTOFMEMORY;
650 /* read in the table records */
653 msi_parse_line( &ptr, &records[num_records], NULL );
656 temp_records = msi_realloc(records, (num_records + 1) * sizeof(LPWSTR *));
659 r = ERROR_OUTOFMEMORY;
662 records = temp_records;
665 if (!TABLE_Exists(db, labels[0]))
667 r = msi_add_table_to_db( db, columns, types, labels, num_labels, num_columns );
668 if (r != ERROR_SUCCESS)
670 r = ERROR_FUNCTION_FAILED;
675 r = msi_add_records_to_table( db, columns, types, labels, records, num_columns, num_records );
684 for (i = 0; i < num_records; i++)
685 msi_free(records[i]);
692 UINT WINAPI MsiDatabaseImportW(MSIHANDLE handle, LPCWSTR szFolder, LPCWSTR szFilename)
697 TRACE("%lx %s %s\n",handle,debugstr_w(szFolder), debugstr_w(szFilename));
699 db = msihandle2msiinfo( handle, MSIHANDLETYPE_DATABASE );
702 IWineMsiRemoteDatabase *remote_database;
704 remote_database = (IWineMsiRemoteDatabase *)msi_get_remote( handle );
705 if ( !remote_database )
706 return ERROR_INVALID_HANDLE;
708 IWineMsiRemoteDatabase_Release( remote_database );
709 WARN("MsiDatabaseImport not allowed during a custom action!\n");
711 return ERROR_SUCCESS;
714 r = MSI_DatabaseImport( db, szFolder, szFilename );
715 msiobj_release( &db->hdr );
719 UINT WINAPI MsiDatabaseImportA( MSIHANDLE handle,
720 LPCSTR szFolder, LPCSTR szFilename )
722 LPWSTR path = NULL, file = NULL;
723 UINT r = ERROR_OUTOFMEMORY;
725 TRACE("%lx %s %s\n", handle, debugstr_a(szFolder), debugstr_a(szFilename));
729 path = strdupAtoW( szFolder );
736 file = strdupAtoW( szFilename );
741 r = MsiDatabaseImportW( handle, path, file );
750 static UINT msi_export_record( HANDLE handle, MSIRECORD *row, UINT start )
752 UINT i, count, len, r = ERROR_SUCCESS;
758 buffer = msi_alloc( len );
760 return ERROR_OUTOFMEMORY;
762 count = MSI_RecordGetFieldCount( row );
763 for ( i=start; i<=count; i++ )
766 r = MSI_RecordGetStringA( row, i, buffer, &sz );
767 if (r == ERROR_MORE_DATA)
769 char *p = msi_realloc( buffer, sz + 1 );
776 r = MSI_RecordGetStringA( row, i, buffer, &sz );
777 if (r != ERROR_SUCCESS)
780 if (!WriteFile( handle, buffer, sz, &sz, NULL ))
782 r = ERROR_FUNCTION_FAILED;
786 sep = (i < count) ? "\t" : "\r\n";
787 if (!WriteFile( handle, sep, strlen(sep), &sz, NULL ))
789 r = ERROR_FUNCTION_FAILED;
797 static UINT msi_export_row( MSIRECORD *row, void *arg )
799 return msi_export_record( arg, row, 1 );
802 static UINT msi_export_forcecodepage( HANDLE handle )
806 static const char data[] = "\r\n\r\n0\t_ForceCodepage\r\n";
808 FIXME("Read the codepage from the strings table!\n");
810 sz = lstrlenA(data) + 1;
811 if (!WriteFile(handle, data, sz, &sz, NULL))
812 return ERROR_FUNCTION_FAILED;
814 return ERROR_SUCCESS;
817 UINT MSI_DatabaseExport( MSIDATABASE *db, LPCWSTR table,
818 LPCWSTR folder, LPCWSTR file )
820 static const WCHAR query[] = {
821 's','e','l','e','c','t',' ','*',' ','f','r','o','m',' ','%','s',0 };
822 static const WCHAR szbs[] = { '\\', 0 };
823 static const WCHAR forcecodepage[] = {
824 '_','F','o','r','c','e','C','o','d','e','p','a','g','e',0 };
825 MSIRECORD *rec = NULL;
826 MSIQUERY *view = NULL;
831 TRACE("%p %s %s %s\n", db, debugstr_w(table),
832 debugstr_w(folder), debugstr_w(file) );
834 if( folder == NULL || file == NULL )
835 return ERROR_INVALID_PARAMETER;
837 len = lstrlenW(folder) + lstrlenW(file) + 2;
838 filename = msi_alloc(len * sizeof (WCHAR));
840 return ERROR_OUTOFMEMORY;
842 lstrcpyW( filename, folder );
843 lstrcatW( filename, szbs );
844 lstrcatW( filename, file );
846 handle = CreateFileW( filename, GENERIC_READ | GENERIC_WRITE, 0,
847 NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
848 msi_free( filename );
849 if (handle == INVALID_HANDLE_VALUE)
850 return ERROR_FUNCTION_FAILED;
852 if (!lstrcmpW( table, forcecodepage ))
854 r = msi_export_forcecodepage( handle );
858 r = MSI_OpenQuery( db, &view, query, table );
859 if (r == ERROR_SUCCESS)
861 /* write out row 1, the column names */
862 r = MSI_ViewGetColumnInfo(view, MSICOLINFO_NAMES, &rec);
863 if (r == ERROR_SUCCESS)
865 msi_export_record( handle, rec, 1 );
866 msiobj_release( &rec->hdr );
869 /* write out row 2, the column types */
870 r = MSI_ViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
871 if (r == ERROR_SUCCESS)
873 msi_export_record( handle, rec, 1 );
874 msiobj_release( &rec->hdr );
877 /* write out row 3, the table name + keys */
878 r = MSI_DatabaseGetPrimaryKeys( db, table, &rec );
879 if (r == ERROR_SUCCESS)
881 MSI_RecordSetStringW( rec, 0, table );
882 msi_export_record( handle, rec, 0 );
883 msiobj_release( &rec->hdr );
886 /* write out row 4 onwards, the data */
887 r = MSI_IterateRecords( view, 0, msi_export_row, handle );
888 msiobj_release( &view->hdr );
892 CloseHandle( handle );
896 /***********************************************************************
897 * MsiExportDatabaseW [MSI.@]
899 * Writes a file containing the table data as tab separated ASCII.
901 * The format is as follows:
903 * row1 : colname1 <tab> colname2 <tab> .... colnameN <cr> <lf>
904 * row2 : coltype1 <tab> coltype2 <tab> .... coltypeN <cr> <lf>
905 * row3 : tablename <tab> key1 <tab> key2 <tab> ... keyM <cr> <lf>
907 * Followed by the data, starting at row 1 with one row per line
909 * row4 : data <tab> data <tab> data <tab> ... data <cr> <lf>
911 UINT WINAPI MsiDatabaseExportW( MSIHANDLE handle, LPCWSTR szTable,
912 LPCWSTR szFolder, LPCWSTR szFilename )
917 TRACE("%lx %s %s %s\n", handle, debugstr_w(szTable),
918 debugstr_w(szFolder), debugstr_w(szFilename));
920 db = msihandle2msiinfo( handle, MSIHANDLETYPE_DATABASE );
923 IWineMsiRemoteDatabase *remote_database;
925 remote_database = (IWineMsiRemoteDatabase *)msi_get_remote( handle );
926 if ( !remote_database )
927 return ERROR_INVALID_HANDLE;
929 IWineMsiRemoteDatabase_Release( remote_database );
930 WARN("MsiDatabaseExport not allowed during a custom action!\n");
932 return ERROR_SUCCESS;
935 r = MSI_DatabaseExport( db, szTable, szFolder, szFilename );
936 msiobj_release( &db->hdr );
940 UINT WINAPI MsiDatabaseExportA( MSIHANDLE handle, LPCSTR szTable,
941 LPCSTR szFolder, LPCSTR szFilename )
943 LPWSTR path = NULL, file = NULL, table = NULL;
944 UINT r = ERROR_OUTOFMEMORY;
946 TRACE("%lx %s %s %s\n", handle, debugstr_a(szTable),
947 debugstr_a(szFolder), debugstr_a(szFilename));
951 table = strdupAtoW( szTable );
958 path = strdupAtoW( szFolder );
965 file = strdupAtoW( szFilename );
970 r = MsiDatabaseExportW( handle, table, path, file );
980 MSIDBSTATE WINAPI MsiGetDatabaseState( MSIHANDLE handle )
982 MSIDBSTATE ret = MSIDBSTATE_READ;
985 TRACE("%ld\n", handle);
987 db = msihandle2msiinfo( handle, MSIHANDLETYPE_DATABASE );
990 IWineMsiRemoteDatabase *remote_database;
992 remote_database = (IWineMsiRemoteDatabase *)msi_get_remote( handle );
993 if ( !remote_database )
994 return MSIDBSTATE_ERROR;
996 IWineMsiRemoteDatabase_Release( remote_database );
997 WARN("MsiGetDatabaseState not allowed during a custom action!\n");
999 return MSIDBSTATE_READ;
1002 if (db->mode != MSIDBOPEN_READONLY )
1003 ret = MSIDBSTATE_WRITE;
1004 msiobj_release( &db->hdr );
1009 typedef struct _msi_remote_database_impl {
1010 const IWineMsiRemoteDatabaseVtbl *lpVtbl;
1013 } msi_remote_database_impl;
1015 static inline msi_remote_database_impl* mrd_from_IWineMsiRemoteDatabase( IWineMsiRemoteDatabase* iface )
1017 return (msi_remote_database_impl *)iface;
1020 static HRESULT WINAPI mrd_QueryInterface( IWineMsiRemoteDatabase *iface,
1021 REFIID riid,LPVOID *ppobj)
1023 if( IsEqualCLSID( riid, &IID_IUnknown ) ||
1024 IsEqualCLSID( riid, &IID_IWineMsiRemoteDatabase ) )
1026 IUnknown_AddRef( iface );
1031 return E_NOINTERFACE;
1034 static ULONG WINAPI mrd_AddRef( IWineMsiRemoteDatabase *iface )
1036 msi_remote_database_impl* This = mrd_from_IWineMsiRemoteDatabase( iface );
1038 return InterlockedIncrement( &This->refs );
1041 static ULONG WINAPI mrd_Release( IWineMsiRemoteDatabase *iface )
1043 msi_remote_database_impl* This = mrd_from_IWineMsiRemoteDatabase( iface );
1046 r = InterlockedDecrement( &This->refs );
1049 MsiCloseHandle( This->database );
1055 HRESULT WINAPI mrd_IsTablePersistent( IWineMsiRemoteDatabase *iface,
1056 BSTR table, MSICONDITION *persistent )
1058 msi_remote_database_impl *This = mrd_from_IWineMsiRemoteDatabase( iface );
1059 *persistent = MsiDatabaseIsTablePersistentW(This->database, (LPWSTR)table);
1063 HRESULT WINAPI mrd_GetPrimaryKeys( IWineMsiRemoteDatabase *iface,
1064 BSTR table, MSIHANDLE *keys )
1066 msi_remote_database_impl *This = mrd_from_IWineMsiRemoteDatabase( iface );
1067 UINT r = MsiDatabaseGetPrimaryKeysW(This->database, (LPWSTR)table, keys);
1068 return HRESULT_FROM_WIN32(r);
1071 HRESULT WINAPI mrd_GetSummaryInformation( IWineMsiRemoteDatabase *iface,
1072 UINT updatecount, MSIHANDLE *suminfo )
1074 msi_remote_database_impl *This = mrd_from_IWineMsiRemoteDatabase( iface );
1075 UINT r = MsiGetSummaryInformationW(This->database, NULL, updatecount, suminfo);
1076 return HRESULT_FROM_WIN32(r);
1079 HRESULT WINAPI mrd_OpenView( IWineMsiRemoteDatabase *iface,
1080 BSTR query, MSIHANDLE *view )
1082 msi_remote_database_impl *This = mrd_from_IWineMsiRemoteDatabase( iface );
1083 UINT r = MsiDatabaseOpenViewW(This->database, (LPWSTR)query, view);
1084 return HRESULT_FROM_WIN32(r);
1087 static HRESULT WINAPI mrd_SetMsiHandle( IWineMsiRemoteDatabase *iface, MSIHANDLE handle )
1089 msi_remote_database_impl* This = mrd_from_IWineMsiRemoteDatabase( iface );
1090 This->database = handle;
1094 static const IWineMsiRemoteDatabaseVtbl msi_remote_database_vtbl =
1099 mrd_IsTablePersistent,
1101 mrd_GetSummaryInformation,
1106 HRESULT create_msi_remote_database( IUnknown *pOuter, LPVOID *ppObj )
1108 msi_remote_database_impl *This;
1110 This = msi_alloc( sizeof *This );
1112 return E_OUTOFMEMORY;
1114 This->lpVtbl = &msi_remote_database_vtbl;