UINT WINAPI MsiDatabaseImportA( MSIHANDLE handle, LPCSTR szFolder, LPCSTR szFilename ) { LPWSTR path = NULL, file = NULL; UINT r = ERROR_OUTOFMEMORY; TRACE("%lx %s %s\n", handle, debugstr_a(szFolder), debugstr_a(szFilename)); if( szFolder ) { path = strdupAtoW( szFolder ); if( !path ) goto end; } if( szFilename ) { file = strdupAtoW( szFilename ); if( !file ) goto end; } r = MsiDatabaseImportW( handle, path, file ); end: msi_free( path ); msi_free( file ); return r; }
/*********************************************************************** * msidbImportTables * * Takes a list of tables or '*' (for all) to import from text archive * files in specified folder * * For each table, a file called <tablename>.idt is imported containing * tab separated ASCII. * * Examples (note wildcard escape for *nix/bash): * msidb -d <pathtomsi>.msi -f <workdir> -i \* * msidb -d <pathtomsi>.msi -f <workdir> -i File Directory Binary **********************************************************************/ static BOOL msidbImportTables(LPCWSTR dbfile, LPCWSTR wdir, LPWSTR tables[], BOOL create) { static const WCHAR ext[] = {'.', 'i', 'd', 't', 0}; static const WCHAR all[] = {'*', 0}; UINT r, len; char *dirNameA; char *fileName; DIR *dir; struct dirent *ent; int i = 0; MSIHANDLE dbhandle; LPWSTR tableFile = 0; LPCWSTR oFlag = (LPCWSTR) MSIDBOPEN_TRANSACT; if (create == TRUE) oFlag = (LPCWSTR) MSIDBOPEN_CREATE; r = MsiOpenDatabaseW(dbfile, oFlag, &dbhandle); if (r != ERROR_SUCCESS) { return FALSE; } if (strcmpW(tables[0], all) == 0) { dirNameA = strdupWtoA(CP_ACP, wdir); dir = opendir(dirNameA); if (dir) { while ((ent = readdir(dir)) != NULL) { if (ent->d_type != DT_REG) continue; fileName = ent->d_name; if (strcmp(fileName+strlen(fileName)-4*sizeof(fileName[0]), ".idt") != 0) continue; if (strcmp(fileName, ".") == 0 || strcmp(fileName, "..") == 0) continue; tableFile = strdupAtoW(CP_ACP, fileName); r = MsiDatabaseImportW(dbhandle, wdir, tableFile); free(tableFile); } } else return FALSE; closedir(dir); free(dirNameA); } else { for (i = 0; i < MAX_TABLES && tables[i] != 0; ++i) { len = lstrlenW(tables[i]) + 5; tableFile = malloc(len * sizeof (WCHAR)); if (tableFile == NULL) return FALSE; lstrcpyW(tableFile, tables[i]); lstrcatW(tableFile, ext); r = MsiDatabaseImportW(dbhandle, wdir, tableFile); free(tableFile); if (r != ERROR_SUCCESS) { return FALSE; } } } MsiDatabaseCommit(dbhandle); MsiCloseHandle(dbhandle); return TRUE; }