UINT CREATE_CreateView( MSIDATABASE *db, MSIVIEW **view, LPCWSTR table, column_info *col_info, BOOL hold ) { MSICREATEVIEW *cv = NULL; UINT r; column_info *col; BOOL temp = TRUE; BOOL tempprim = FALSE; TRACE("%p\n", cv ); r = check_columns( col_info ); if( r != ERROR_SUCCESS ) return r; cv = msi_alloc_zero( sizeof *cv ); if( !cv ) return ERROR_FUNCTION_FAILED; for( col = col_info; col; col = col->next ) { if (!col->table) col->table = table; if( !col->temporary ) temp = FALSE; else if ( col->type & MSITYPE_KEY ) tempprim = TRUE; } if ( !temp && tempprim ) { msi_free( cv ); return ERROR_FUNCTION_FAILED; } /* fill the structure */ cv->view.ops = &create_ops; msiobj_addref( &db->hdr ); cv->db = db; cv->name = table; cv->col_info = col_info; cv->bIsTemp = temp; cv->hold = hold; *view = (MSIVIEW*) cv; return ERROR_SUCCESS; }
MSIPREVIEW *MSI_EnableUIPreview( MSIDATABASE *db ) { MSIPREVIEW *preview = NULL; MSIPACKAGE *package; package = MSI_CreatePackage( db, NULL ); if( package ) { preview = alloc_msiobject( MSIHANDLETYPE_PREVIEW, sizeof (MSIPREVIEW), MSI_ClosePreview ); if( preview ) { preview->package = package; preview->dialog = 0; msiobj_addref( &package->hdr ); } msiobj_release( &package->hdr ); } return preview; }
MSIHANDLE alloc_msihandle( MSIOBJECTHDR *obj ) { msi_handle_info *entry; MSIHANDLE ret; EnterCriticalSection( &MSI_handle_cs ); ret = alloc_handle_table_entry(); if (ret) { entry = &msihandletable[ ret - 1 ]; msiobj_addref( obj ); entry->u.obj = obj; entry->dwThreadId = GetCurrentThreadId(); entry->remote = FALSE; } LeaveCriticalSection( &MSI_handle_cs ); TRACE("%p -> %d\n", obj, ret ); return ret; }
void *msihandle2msiinfo(MSIHANDLE handle, UINT type) { MSIOBJECTHDR *ret = NULL; EnterCriticalSection( &MSI_handle_cs ); handle--; if( handle >= msihandletable_size ) goto out; if( msihandletable[handle].remote) goto out; if( !msihandletable[handle].u.obj ) goto out; if( msihandletable[handle].u.obj->magic != MSIHANDLE_MAGIC ) goto out; if( type && (msihandletable[handle].u.obj->type != type) ) goto out; ret = msihandletable[handle].u.obj; msiobj_addref( ret ); out: LeaveCriticalSection( &MSI_handle_cs ); return ret; }
UINT MSI_OpenDatabaseW(LPCWSTR szDBPath, LPCWSTR szPersist, MSIDATABASE **pdb) { IStorage *stg = NULL; HRESULT r; MSIDATABASE *db = NULL; UINT ret = ERROR_FUNCTION_FAILED; LPCWSTR szMode; STATSTG stat; TRACE("%s %s\n",debugstr_w(szDBPath),debugstr_w(szPersist) ); if( !pdb ) return ERROR_INVALID_PARAMETER; szMode = szPersist; if( HIWORD( szPersist ) ) { /* UINT len = lstrlenW( szPerist ) + 1; */ FIXME("don't support persist files yet\b"); return ERROR_INVALID_PARAMETER; /* szMode = msi_alloc( len * sizeof (DWORD) ); */ } else if( szPersist == MSIDBOPEN_READONLY ) { r = StgOpenStorage( szDBPath, NULL, STGM_DIRECT|STGM_READ|STGM_SHARE_DENY_WRITE, NULL, 0, &stg); } else if( szPersist == MSIDBOPEN_CREATE || szPersist == MSIDBOPEN_CREATEDIRECT ) { /* FIXME: MSIDBOPEN_CREATE should case STGM_TRANSACTED flag to be * used here: */ r = StgCreateDocfile( szDBPath, STGM_DIRECT|STGM_READWRITE|STGM_SHARE_EXCLUSIVE, 0, &stg); if( r == ERROR_SUCCESS ) { IStorage_SetClass( stg, &CLSID_MsiDatabase ); r = init_string_table( stg ); } } else if( szPersist == MSIDBOPEN_TRANSACT ) { /* FIXME: MSIDBOPEN_TRANSACT should case STGM_TRANSACTED flag to be * used here: */ r = StgOpenStorage( szDBPath, NULL, STGM_DIRECT|STGM_READWRITE|STGM_SHARE_EXCLUSIVE, NULL, 0, &stg); } else if( szPersist == MSIDBOPEN_DIRECT ) { r = StgOpenStorage( szDBPath, NULL, STGM_DIRECT|STGM_READWRITE|STGM_SHARE_EXCLUSIVE, NULL, 0, &stg); } else { ERR("unknown flag %p\n",szPersist); return ERROR_INVALID_PARAMETER; } if( FAILED( r ) ) { FIXME("open failed r = %08lx!\n",r); return ERROR_FUNCTION_FAILED; } r = IStorage_Stat( stg, &stat, STATFLAG_NONAME ); if( FAILED( r ) ) { FIXME("Failed to stat storage\n"); goto end; } if ( !IsEqualGUID( &stat.clsid, &CLSID_MsiDatabase ) && !IsEqualGUID( &stat.clsid, &CLSID_MsiPatch ) ) { ERR("storage GUID is not a MSI database GUID %s\n", debugstr_guid(&stat.clsid) ); goto end; } db = alloc_msiobject( MSIHANDLETYPE_DATABASE, sizeof (MSIDATABASE), MSI_CloseDatabase ); if( !db ) { FIXME("Failed to allocate a handle\n"); goto end; } if( TRACE_ON( msi ) ) enum_stream_names( stg ); db->storage = stg; db->mode = szMode; list_init( &db->tables ); list_init( &db->transforms ); db->strings = load_string_table( stg ); if( !db->strings ) goto end; ret = ERROR_SUCCESS; msiobj_addref( &db->hdr ); IStorage_AddRef( stg ); *pdb = db; end: if( db ) msiobj_release( &db->hdr ); if( stg ) IStorage_Release( stg ); return ret; }