Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1 | /* Helper library for MSI creation with Python. |
Florent Xicluna | c934f32 | 2010-09-03 23:47:32 +0000 | [diff] [blame] | 2 | * Copyright (C) 2005 Martin v. Löwis |
Martin v. Löwis | dd860ca | 2006-03-05 13:39:10 +0000 | [diff] [blame] | 3 | * Licensed to PSF under a contributor agreement. |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <Python.h> |
| 7 | #include <fci.h> |
| 8 | #include <fcntl.h> |
| 9 | #include <windows.h> |
| 10 | #include <msi.h> |
| 11 | #include <msiquery.h> |
| 12 | #include <msidefs.h> |
| 13 | #include <rpc.h> |
| 14 | |
| 15 | static PyObject *MSIError; |
| 16 | |
| 17 | static PyObject* |
| 18 | uuidcreate(PyObject* obj, PyObject*args) |
| 19 | { |
| 20 | UUID result; |
Hirokazu Yamamoto | ab058ed | 2008-08-17 07:26:26 +0000 | [diff] [blame] | 21 | unsigned short *cresult; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 22 | PyObject *oresult; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 23 | |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 24 | /* May return ok, local only, and no address. |
| 25 | For local only, the documentation says we still get a uuid. |
| 26 | For RPC_S_UUID_NO_ADDRESS, it's not clear whether we can |
| 27 | use the result. */ |
| 28 | if (UuidCreate(&result) == RPC_S_UUID_NO_ADDRESS) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 29 | PyErr_SetString(PyExc_NotImplementedError, "processing 'no address' result"); |
| 30 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 31 | } |
| 32 | |
Martin v. Löwis | 371bb50 | 2008-08-16 13:02:57 +0000 | [diff] [blame] | 33 | if (UuidToStringW(&result, &cresult) == RPC_S_OUT_OF_MEMORY) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 34 | PyErr_SetString(PyExc_MemoryError, "out of memory in uuidgen"); |
| 35 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 36 | } |
| 37 | |
Martin v. Löwis | 371bb50 | 2008-08-16 13:02:57 +0000 | [diff] [blame] | 38 | oresult = PyUnicode_FromUnicode(cresult, wcslen(cresult)); |
| 39 | RpcStringFreeW(&cresult); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 40 | return oresult; |
| 41 | |
| 42 | } |
| 43 | |
| 44 | /* FCI callback functions */ |
| 45 | |
| 46 | static FNFCIALLOC(cb_alloc) |
| 47 | { |
| 48 | return malloc(cb); |
| 49 | } |
| 50 | |
| 51 | static FNFCIFREE(cb_free) |
| 52 | { |
| 53 | free(memory); |
| 54 | } |
| 55 | |
| 56 | static FNFCIOPEN(cb_open) |
| 57 | { |
| 58 | int result = _open(pszFile, oflag, pmode); |
| 59 | if (result == -1) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 60 | *err = errno; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 61 | return result; |
| 62 | } |
| 63 | |
| 64 | static FNFCIREAD(cb_read) |
| 65 | { |
| 66 | UINT result = (UINT)_read(hf, memory, cb); |
| 67 | if (result != cb) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 68 | *err = errno; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 69 | return result; |
| 70 | } |
| 71 | |
| 72 | static FNFCIWRITE(cb_write) |
| 73 | { |
| 74 | UINT result = (UINT)_write(hf, memory, cb); |
| 75 | if (result != cb) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 76 | *err = errno; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 77 | return result; |
| 78 | } |
| 79 | |
| 80 | static FNFCICLOSE(cb_close) |
| 81 | { |
| 82 | int result = _close(hf); |
| 83 | if (result != 0) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 84 | *err = errno; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 85 | return result; |
| 86 | } |
| 87 | |
| 88 | static FNFCISEEK(cb_seek) |
| 89 | { |
| 90 | long result = (long)_lseek(hf, dist, seektype); |
| 91 | if (result == -1) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 92 | *err = errno; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 93 | return result; |
| 94 | } |
| 95 | |
| 96 | static FNFCIDELETE(cb_delete) |
| 97 | { |
| 98 | int result = remove(pszFile); |
| 99 | if (result != 0) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 100 | *err = errno; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 101 | return result; |
| 102 | } |
| 103 | |
| 104 | static FNFCIFILEPLACED(cb_fileplaced) |
| 105 | { |
| 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | static FNFCIGETTEMPFILE(cb_gettempfile) |
| 110 | { |
| 111 | char *name = _tempnam("", "tmp"); |
| 112 | if ((name != NULL) && ((int)strlen(name) < cbTempName)) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 113 | strcpy(pszTempName, name); |
| 114 | free(name); |
| 115 | return TRUE; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | if (name) free(name); |
| 119 | return FALSE; |
| 120 | } |
| 121 | |
| 122 | static FNFCISTATUS(cb_status) |
| 123 | { |
| 124 | if (pv) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 125 | PyObject *result = PyObject_CallMethod(pv, "status", "iii", typeStatus, cb1, cb2); |
| 126 | if (result == NULL) |
| 127 | return -1; |
| 128 | Py_DECREF(result); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 129 | } |
| 130 | return 0; |
| 131 | } |
| 132 | |
| 133 | static FNFCIGETNEXTCABINET(cb_getnextcabinet) |
| 134 | { |
| 135 | if (pv) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 136 | PyObject *result = PyObject_CallMethod(pv, "getnextcabinet", "i", pccab->iCab); |
| 137 | if (result == NULL) |
| 138 | return -1; |
| 139 | if (!PyBytes_Check(result)) { |
| 140 | PyErr_Format(PyExc_TypeError, |
| 141 | "Incorrect return type %s from getnextcabinet", |
| 142 | result->ob_type->tp_name); |
| 143 | Py_DECREF(result); |
| 144 | return FALSE; |
| 145 | } |
| 146 | strncpy(pccab->szCab, PyBytes_AsString(result), sizeof(pccab->szCab)); |
| 147 | return TRUE; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 148 | } |
| 149 | return FALSE; |
| 150 | } |
| 151 | |
| 152 | static FNFCIGETOPENINFO(cb_getopeninfo) |
| 153 | { |
| 154 | BY_HANDLE_FILE_INFORMATION bhfi; |
| 155 | FILETIME filetime; |
| 156 | HANDLE handle; |
| 157 | |
| 158 | /* Need Win32 handle to get time stamps */ |
| 159 | handle = CreateFile(pszName, GENERIC_READ, FILE_SHARE_READ, NULL, |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 160 | OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 161 | if (handle == INVALID_HANDLE_VALUE) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 162 | return -1; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 163 | |
| 164 | if (GetFileInformationByHandle(handle, &bhfi) == FALSE) |
| 165 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 166 | CloseHandle(handle); |
| 167 | return -1; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | FileTimeToLocalFileTime(&bhfi.ftLastWriteTime, &filetime); |
| 171 | FileTimeToDosDateTime(&filetime, pdate, ptime); |
| 172 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 173 | *pattribs = (int)(bhfi.dwFileAttributes & |
| 174 | (_A_RDONLY | _A_SYSTEM | _A_HIDDEN | _A_ARCH)); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 175 | |
| 176 | CloseHandle(handle); |
| 177 | |
| 178 | return _open(pszName, _O_RDONLY | _O_BINARY); |
| 179 | } |
| 180 | |
| 181 | static PyObject* fcicreate(PyObject* obj, PyObject* args) |
| 182 | { |
Christian Heimes | 0bd4e11 | 2008-02-12 22:59:25 +0000 | [diff] [blame] | 183 | char *cabname, *p; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 184 | PyObject *files; |
| 185 | CCAB ccab; |
| 186 | HFCI hfci; |
| 187 | ERF erf; |
Christian Heimes | 0bd4e11 | 2008-02-12 22:59:25 +0000 | [diff] [blame] | 188 | Py_ssize_t i; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 189 | |
| 190 | |
| 191 | if (!PyArg_ParseTuple(args, "sO:FCICreate", &cabname, &files)) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 192 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 193 | |
| 194 | if (!PyList_Check(files)) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 195 | PyErr_SetString(PyExc_TypeError, "FCICreate expects a list"); |
| 196 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | ccab.cb = INT_MAX; /* no need to split CAB into multiple media */ |
| 200 | ccab.cbFolderThresh = 1000000; /* flush directory after this many bytes */ |
| 201 | ccab.cbReserveCFData = 0; |
| 202 | ccab.cbReserveCFFolder = 0; |
| 203 | ccab.cbReserveCFHeader = 0; |
| 204 | |
| 205 | ccab.iCab = 1; |
| 206 | ccab.iDisk = 1; |
| 207 | |
| 208 | ccab.setID = 0; |
| 209 | ccab.szDisk[0] = '\0'; |
| 210 | |
Christian Heimes | 0bd4e11 | 2008-02-12 22:59:25 +0000 | [diff] [blame] | 211 | for (i = 0, p = cabname; *p; p = CharNext(p)) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 212 | if (*p == '\\' || *p == '/') |
| 213 | i = p - cabname + 1; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 214 | |
Christian Heimes | 0bd4e11 | 2008-02-12 22:59:25 +0000 | [diff] [blame] | 215 | if (i >= sizeof(ccab.szCabPath) || |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 216 | strlen(cabname+i) >= sizeof(ccab.szCab)) { |
| 217 | PyErr_SetString(PyExc_ValueError, "path name too long"); |
| 218 | return 0; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 219 | } |
| 220 | |
Christian Heimes | 0bd4e11 | 2008-02-12 22:59:25 +0000 | [diff] [blame] | 221 | if (i > 0) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 222 | memcpy(ccab.szCabPath, cabname, i); |
| 223 | ccab.szCabPath[i] = '\0'; |
| 224 | strcpy(ccab.szCab, cabname+i); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 225 | } else { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 226 | strcpy(ccab.szCabPath, ".\\"); |
| 227 | strcpy(ccab.szCab, cabname); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | hfci = FCICreate(&erf, cb_fileplaced, cb_alloc, cb_free, |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 231 | cb_open, cb_read, cb_write, cb_close, cb_seek, cb_delete, |
| 232 | cb_gettempfile, &ccab, NULL); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 233 | |
| 234 | if (hfci == NULL) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 235 | PyErr_Format(PyExc_ValueError, "FCI error %d", erf.erfOper); |
| 236 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | for (i=0; i < PyList_GET_SIZE(files); i++) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 240 | PyObject *item = PyList_GET_ITEM(files, i); |
| 241 | char *filename, *cabname; |
| 242 | if (!PyArg_ParseTuple(item, "ss", &filename, &cabname)) |
| 243 | goto err; |
| 244 | if (!FCIAddFile(hfci, filename, cabname, FALSE, |
| 245 | cb_getnextcabinet, cb_status, cb_getopeninfo, |
| 246 | tcompTYPE_MSZIP)) |
| 247 | goto err; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | if (!FCIFlushCabinet(hfci, FALSE, cb_getnextcabinet, cb_status)) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 251 | goto err; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 252 | |
| 253 | if (!FCIDestroy(hfci)) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 254 | goto err; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 255 | |
| 256 | Py_INCREF(Py_None); |
| 257 | return Py_None; |
| 258 | err: |
| 259 | PyErr_Format(PyExc_ValueError, "FCI error %d", erf.erfOper); /* XXX better error type */ |
| 260 | FCIDestroy(hfci); |
| 261 | return NULL; |
| 262 | } |
| 263 | |
| 264 | typedef struct msiobj{ |
| 265 | PyObject_HEAD |
| 266 | MSIHANDLE h; |
| 267 | }msiobj; |
| 268 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 269 | static void |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 270 | msiobj_dealloc(msiobj* msidb) |
| 271 | { |
| 272 | MsiCloseHandle(msidb->h); |
| 273 | msidb->h = 0; |
| 274 | } |
| 275 | |
| 276 | static PyObject* |
| 277 | msiobj_close(msiobj* msidb, PyObject *args) |
| 278 | { |
| 279 | MsiCloseHandle(msidb->h); |
| 280 | msidb->h = 0; |
| 281 | Py_INCREF(Py_None); |
| 282 | return Py_None; |
| 283 | } |
| 284 | |
| 285 | static PyObject* |
| 286 | msierror(int status) |
| 287 | { |
| 288 | int code; |
| 289 | char buf[2000]; |
| 290 | char *res = buf; |
| 291 | DWORD size = sizeof(buf); |
| 292 | MSIHANDLE err = MsiGetLastErrorRecord(); |
| 293 | |
| 294 | if (err == 0) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 295 | switch(status) { |
| 296 | case ERROR_ACCESS_DENIED: |
| 297 | PyErr_SetString(MSIError, "access denied"); |
| 298 | return NULL; |
| 299 | case ERROR_FUNCTION_FAILED: |
| 300 | PyErr_SetString(MSIError, "function failed"); |
| 301 | return NULL; |
| 302 | case ERROR_INVALID_DATA: |
| 303 | PyErr_SetString(MSIError, "invalid data"); |
| 304 | return NULL; |
| 305 | case ERROR_INVALID_HANDLE: |
| 306 | PyErr_SetString(MSIError, "invalid handle"); |
| 307 | return NULL; |
| 308 | case ERROR_INVALID_STATE: |
| 309 | PyErr_SetString(MSIError, "invalid state"); |
| 310 | return NULL; |
| 311 | case ERROR_INVALID_PARAMETER: |
| 312 | PyErr_SetString(MSIError, "invalid parameter"); |
| 313 | return NULL; |
| 314 | default: |
| 315 | PyErr_Format(MSIError, "unknown error %x", status); |
| 316 | return NULL; |
| 317 | } |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | code = MsiRecordGetInteger(err, 1); /* XXX code */ |
| 321 | if (MsiFormatRecord(0, err, res, &size) == ERROR_MORE_DATA) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 322 | res = malloc(size+1); |
| 323 | MsiFormatRecord(0, err, res, &size); |
| 324 | res[size]='\0'; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 325 | } |
| 326 | MsiCloseHandle(err); |
| 327 | PyErr_SetString(MSIError, res); |
| 328 | if (res != buf) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 329 | free(res); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 330 | return NULL; |
| 331 | } |
| 332 | |
| 333 | /*************************** Record objects **********************/ |
| 334 | |
| 335 | static PyObject* |
| 336 | record_getfieldcount(msiobj* record, PyObject* args) |
| 337 | { |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 338 | return PyLong_FromLong(MsiRecordGetFieldCount(record->h)); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | static PyObject* |
Martin v. Löwis | e95593e | 2008-06-02 10:08:54 +0000 | [diff] [blame] | 342 | record_getinteger(msiobj* record, PyObject* args) |
| 343 | { |
| 344 | unsigned int field; |
| 345 | int status; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 346 | |
Martin v. Löwis | e95593e | 2008-06-02 10:08:54 +0000 | [diff] [blame] | 347 | if (!PyArg_ParseTuple(args, "I:GetInteger", &field)) |
| 348 | return NULL; |
| 349 | status = MsiRecordGetInteger(record->h, field); |
| 350 | if (status == MSI_NULL_INTEGER){ |
| 351 | PyErr_SetString(MSIError, "could not convert record field to integer"); |
| 352 | return NULL; |
| 353 | } |
Martin v. Löwis | 704d8b1 | 2008-06-02 11:32:23 +0000 | [diff] [blame] | 354 | return PyLong_FromLong((long) status); |
Martin v. Löwis | e95593e | 2008-06-02 10:08:54 +0000 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | static PyObject* |
| 358 | record_getstring(msiobj* record, PyObject* args) |
| 359 | { |
| 360 | unsigned int field; |
| 361 | unsigned int status; |
Martin v. Löwis | 371bb50 | 2008-08-16 13:02:57 +0000 | [diff] [blame] | 362 | WCHAR buf[2000]; |
| 363 | WCHAR *res = buf; |
Martin v. Löwis | e95593e | 2008-06-02 10:08:54 +0000 | [diff] [blame] | 364 | DWORD size = sizeof(buf); |
| 365 | PyObject* string; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 366 | |
Martin v. Löwis | e95593e | 2008-06-02 10:08:54 +0000 | [diff] [blame] | 367 | if (!PyArg_ParseTuple(args, "I:GetString", &field)) |
| 368 | return NULL; |
Martin v. Löwis | 371bb50 | 2008-08-16 13:02:57 +0000 | [diff] [blame] | 369 | status = MsiRecordGetStringW(record->h, field, res, &size); |
Martin v. Löwis | e95593e | 2008-06-02 10:08:54 +0000 | [diff] [blame] | 370 | if (status == ERROR_MORE_DATA) { |
Martin v. Löwis | 371bb50 | 2008-08-16 13:02:57 +0000 | [diff] [blame] | 371 | res = (WCHAR*) malloc((size + 1)*sizeof(WCHAR)); |
Martin v. Löwis | e95593e | 2008-06-02 10:08:54 +0000 | [diff] [blame] | 372 | if (res == NULL) |
| 373 | return PyErr_NoMemory(); |
Martin v. Löwis | 371bb50 | 2008-08-16 13:02:57 +0000 | [diff] [blame] | 374 | status = MsiRecordGetStringW(record->h, field, res, &size); |
Martin v. Löwis | e95593e | 2008-06-02 10:08:54 +0000 | [diff] [blame] | 375 | } |
| 376 | if (status != ERROR_SUCCESS) |
| 377 | return msierror((int) status); |
Martin v. Löwis | 371bb50 | 2008-08-16 13:02:57 +0000 | [diff] [blame] | 378 | string = PyUnicode_FromUnicode(res, size); |
Martin v. Löwis | e95593e | 2008-06-02 10:08:54 +0000 | [diff] [blame] | 379 | if (buf != res) |
| 380 | free(res); |
| 381 | return string; |
| 382 | } |
| 383 | |
| 384 | static PyObject* |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 385 | record_cleardata(msiobj* record, PyObject *args) |
| 386 | { |
| 387 | int status = MsiRecordClearData(record->h); |
| 388 | if (status != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 389 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 390 | |
| 391 | Py_INCREF(Py_None); |
| 392 | return Py_None; |
| 393 | } |
| 394 | |
| 395 | static PyObject* |
| 396 | record_setstring(msiobj* record, PyObject *args) |
| 397 | { |
| 398 | int status; |
| 399 | int field; |
Martin v. Löwis | 371bb50 | 2008-08-16 13:02:57 +0000 | [diff] [blame] | 400 | Py_UNICODE *data; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 401 | |
Martin v. Löwis | 371bb50 | 2008-08-16 13:02:57 +0000 | [diff] [blame] | 402 | if (!PyArg_ParseTuple(args, "iu:SetString", &field, &data)) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 403 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 404 | |
Martin v. Löwis | 371bb50 | 2008-08-16 13:02:57 +0000 | [diff] [blame] | 405 | if ((status = MsiRecordSetStringW(record->h, field, data)) != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 406 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 407 | |
| 408 | Py_INCREF(Py_None); |
| 409 | return Py_None; |
| 410 | } |
| 411 | |
| 412 | static PyObject* |
| 413 | record_setstream(msiobj* record, PyObject *args) |
| 414 | { |
| 415 | int status; |
| 416 | int field; |
Martin v. Löwis | 371bb50 | 2008-08-16 13:02:57 +0000 | [diff] [blame] | 417 | Py_UNICODE *data; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 418 | |
Martin v. Löwis | 371bb50 | 2008-08-16 13:02:57 +0000 | [diff] [blame] | 419 | if (!PyArg_ParseTuple(args, "iu:SetStream", &field, &data)) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 420 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 421 | |
Martin v. Löwis | 371bb50 | 2008-08-16 13:02:57 +0000 | [diff] [blame] | 422 | if ((status = MsiRecordSetStreamW(record->h, field, data)) != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 423 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 424 | |
| 425 | Py_INCREF(Py_None); |
| 426 | return Py_None; |
| 427 | } |
| 428 | |
| 429 | static PyObject* |
| 430 | record_setinteger(msiobj* record, PyObject *args) |
| 431 | { |
| 432 | int status; |
| 433 | int field; |
| 434 | int data; |
| 435 | |
| 436 | if (!PyArg_ParseTuple(args, "ii:SetInteger", &field, &data)) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 437 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 438 | |
| 439 | if ((status = MsiRecordSetInteger(record->h, field, data)) != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 440 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 441 | |
| 442 | Py_INCREF(Py_None); |
| 443 | return Py_None; |
| 444 | } |
| 445 | |
| 446 | |
| 447 | |
| 448 | static PyMethodDef record_methods[] = { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 449 | { "GetFieldCount", (PyCFunction)record_getfieldcount, METH_NOARGS, |
| 450 | PyDoc_STR("GetFieldCount() -> int\nWraps MsiRecordGetFieldCount")}, |
Martin v. Löwis | e95593e | 2008-06-02 10:08:54 +0000 | [diff] [blame] | 451 | { "GetInteger", (PyCFunction)record_getinteger, METH_VARARGS, |
| 452 | PyDoc_STR("GetInteger(field) -> int\nWraps MsiRecordGetInteger")}, |
| 453 | { "GetString", (PyCFunction)record_getstring, METH_VARARGS, |
| 454 | PyDoc_STR("GetString(field) -> string\nWraps MsiRecordGetString")}, |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 455 | { "SetString", (PyCFunction)record_setstring, METH_VARARGS, |
| 456 | PyDoc_STR("SetString(field,str) -> None\nWraps MsiRecordSetString")}, |
| 457 | { "SetStream", (PyCFunction)record_setstream, METH_VARARGS, |
| 458 | PyDoc_STR("SetStream(field,filename) -> None\nWraps MsiRecordSetInteger")}, |
| 459 | { "SetInteger", (PyCFunction)record_setinteger, METH_VARARGS, |
| 460 | PyDoc_STR("SetInteger(field,int) -> None\nWraps MsiRecordSetInteger")}, |
| 461 | { "ClearData", (PyCFunction)record_cleardata, METH_NOARGS, |
| 462 | PyDoc_STR("ClearData() -> int\nWraps MsiRecordGClearData")}, |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 463 | { NULL, NULL } |
| 464 | }; |
| 465 | |
| 466 | static PyTypeObject record_Type = { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 467 | PyVarObject_HEAD_INIT(NULL, 0) |
| 468 | "_msi.Record", /*tp_name*/ |
| 469 | sizeof(msiobj), /*tp_basicsize*/ |
| 470 | 0, /*tp_itemsize*/ |
| 471 | /* methods */ |
| 472 | (destructor)msiobj_dealloc, /*tp_dealloc*/ |
| 473 | 0, /*tp_print*/ |
| 474 | 0, /*tp_getattr*/ |
| 475 | 0, /*tp_setattr*/ |
| 476 | 0, /*tp_reserved*/ |
| 477 | 0, /*tp_repr*/ |
| 478 | 0, /*tp_as_number*/ |
| 479 | 0, /*tp_as_sequence*/ |
| 480 | 0, /*tp_as_mapping*/ |
| 481 | 0, /*tp_hash*/ |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 482 | 0, /*tp_call*/ |
| 483 | 0, /*tp_str*/ |
| 484 | PyObject_GenericGetAttr,/*tp_getattro*/ |
| 485 | PyObject_GenericSetAttr,/*tp_setattro*/ |
| 486 | 0, /*tp_as_buffer*/ |
| 487 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 488 | 0, /*tp_doc*/ |
| 489 | 0, /*tp_traverse*/ |
| 490 | 0, /*tp_clear*/ |
| 491 | 0, /*tp_richcompare*/ |
| 492 | 0, /*tp_weaklistoffset*/ |
| 493 | 0, /*tp_iter*/ |
| 494 | 0, /*tp_iternext*/ |
| 495 | record_methods, /*tp_methods*/ |
| 496 | 0, /*tp_members*/ |
| 497 | 0, /*tp_getset*/ |
| 498 | 0, /*tp_base*/ |
| 499 | 0, /*tp_dict*/ |
| 500 | 0, /*tp_descr_get*/ |
| 501 | 0, /*tp_descr_set*/ |
| 502 | 0, /*tp_dictoffset*/ |
| 503 | 0, /*tp_init*/ |
| 504 | 0, /*tp_alloc*/ |
| 505 | 0, /*tp_new*/ |
| 506 | 0, /*tp_free*/ |
| 507 | 0, /*tp_is_gc*/ |
| 508 | }; |
| 509 | |
| 510 | static PyObject* |
| 511 | record_new(MSIHANDLE h) |
| 512 | { |
| 513 | msiobj *result = PyObject_NEW(struct msiobj, &record_Type); |
| 514 | |
| 515 | if (!result) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 516 | MsiCloseHandle(h); |
| 517 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | result->h = h; |
| 521 | return (PyObject*)result; |
| 522 | } |
| 523 | |
| 524 | /*************************** SummaryInformation objects **************/ |
| 525 | |
| 526 | static PyObject* |
| 527 | summary_getproperty(msiobj* si, PyObject *args) |
| 528 | { |
| 529 | int status; |
| 530 | int field; |
| 531 | PyObject *result; |
| 532 | UINT type; |
| 533 | INT ival; |
| 534 | FILETIME fval; |
| 535 | char sbuf[1000]; |
| 536 | char *sval = sbuf; |
| 537 | DWORD ssize = sizeof(sval); |
| 538 | |
| 539 | if (!PyArg_ParseTuple(args, "i:GetProperty", &field)) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 540 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 541 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 542 | status = MsiSummaryInfoGetProperty(si->h, field, &type, &ival, |
| 543 | &fval, sval, &ssize); |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 544 | if (status == ERROR_MORE_DATA) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 545 | sval = malloc(ssize); |
| 546 | status = MsiSummaryInfoGetProperty(si->h, field, &type, &ival, |
| 547 | &fval, sval, &ssize); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | switch(type) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 551 | case VT_I2: case VT_I4: |
| 552 | return PyLong_FromLong(ival); |
| 553 | case VT_FILETIME: |
| 554 | PyErr_SetString(PyExc_NotImplementedError, "FILETIME result"); |
| 555 | return NULL; |
| 556 | case VT_LPSTR: |
| 557 | result = PyBytes_FromStringAndSize(sval, ssize); |
| 558 | if (sval != sbuf) |
| 559 | free(sval); |
| 560 | return result; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 561 | } |
| 562 | PyErr_Format(PyExc_NotImplementedError, "result of type %d", type); |
| 563 | return NULL; |
| 564 | } |
| 565 | |
| 566 | static PyObject* |
| 567 | summary_getpropertycount(msiobj* si, PyObject *args) |
| 568 | { |
| 569 | int status; |
| 570 | UINT result; |
| 571 | |
| 572 | status = MsiSummaryInfoGetPropertyCount(si->h, &result); |
| 573 | if (status != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 574 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 575 | |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 576 | return PyLong_FromLong(result); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | static PyObject* |
| 580 | summary_setproperty(msiobj* si, PyObject *args) |
| 581 | { |
| 582 | int status; |
| 583 | int field; |
| 584 | PyObject* data; |
| 585 | |
| 586 | if (!PyArg_ParseTuple(args, "iO:SetProperty", &field, &data)) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 587 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 588 | |
Martin v. Löwis | 371bb50 | 2008-08-16 13:02:57 +0000 | [diff] [blame] | 589 | if (PyUnicode_Check(data)) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 590 | status = MsiSummaryInfoSetPropertyW(si->h, field, VT_LPSTR, |
| 591 | 0, NULL, PyUnicode_AsUnicode(data)); |
Martin v. Löwis | d1a1d1e | 2007-12-04 22:10:37 +0000 | [diff] [blame] | 592 | } else if (PyLong_CheckExact(data)) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 593 | long value = PyLong_AsLong(data); |
| 594 | if (value == -1 && PyErr_Occurred()) { |
| 595 | return NULL; |
| 596 | } |
| 597 | status = MsiSummaryInfoSetProperty(si->h, field, VT_I4, |
| 598 | value, NULL, NULL); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 599 | } else { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 600 | PyErr_SetString(PyExc_TypeError, "unsupported type"); |
| 601 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 602 | } |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 603 | |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 604 | if (status != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 605 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 606 | |
| 607 | Py_INCREF(Py_None); |
| 608 | return Py_None; |
| 609 | } |
| 610 | |
| 611 | |
| 612 | static PyObject* |
| 613 | summary_persist(msiobj* si, PyObject *args) |
| 614 | { |
| 615 | int status; |
| 616 | |
| 617 | status = MsiSummaryInfoPersist(si->h); |
| 618 | if (status != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 619 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 620 | Py_INCREF(Py_None); |
| 621 | return Py_None; |
| 622 | } |
| 623 | |
| 624 | static PyMethodDef summary_methods[] = { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 625 | { "GetProperty", (PyCFunction)summary_getproperty, METH_VARARGS, |
| 626 | PyDoc_STR("GetProperty(propid) -> value\nWraps MsiSummaryInfoGetProperty")}, |
| 627 | { "GetPropertyCount", (PyCFunction)summary_getpropertycount, METH_NOARGS, |
| 628 | PyDoc_STR("GetProperty() -> int\nWraps MsiSummaryInfoGetPropertyCount")}, |
| 629 | { "SetProperty", (PyCFunction)summary_setproperty, METH_VARARGS, |
| 630 | PyDoc_STR("SetProperty(value) -> None\nWraps MsiSummaryInfoProperty")}, |
| 631 | { "Persist", (PyCFunction)summary_persist, METH_NOARGS, |
| 632 | PyDoc_STR("Persist() -> None\nWraps MsiSummaryInfoPersist")}, |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 633 | { NULL, NULL } |
| 634 | }; |
| 635 | |
| 636 | static PyTypeObject summary_Type = { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 637 | PyVarObject_HEAD_INIT(NULL, 0) |
| 638 | "_msi.SummaryInformation", /*tp_name*/ |
| 639 | sizeof(msiobj), /*tp_basicsize*/ |
| 640 | 0, /*tp_itemsize*/ |
| 641 | /* methods */ |
| 642 | (destructor)msiobj_dealloc, /*tp_dealloc*/ |
| 643 | 0, /*tp_print*/ |
| 644 | 0, /*tp_getattr*/ |
| 645 | 0, /*tp_setattr*/ |
| 646 | 0, /*tp_reserved*/ |
| 647 | 0, /*tp_repr*/ |
| 648 | 0, /*tp_as_number*/ |
| 649 | 0, /*tp_as_sequence*/ |
| 650 | 0, /*tp_as_mapping*/ |
| 651 | 0, /*tp_hash*/ |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 652 | 0, /*tp_call*/ |
| 653 | 0, /*tp_str*/ |
| 654 | PyObject_GenericGetAttr,/*tp_getattro*/ |
| 655 | PyObject_GenericSetAttr,/*tp_setattro*/ |
| 656 | 0, /*tp_as_buffer*/ |
| 657 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 658 | 0, /*tp_doc*/ |
| 659 | 0, /*tp_traverse*/ |
| 660 | 0, /*tp_clear*/ |
| 661 | 0, /*tp_richcompare*/ |
| 662 | 0, /*tp_weaklistoffset*/ |
| 663 | 0, /*tp_iter*/ |
| 664 | 0, /*tp_iternext*/ |
| 665 | summary_methods, /*tp_methods*/ |
| 666 | 0, /*tp_members*/ |
| 667 | 0, /*tp_getset*/ |
| 668 | 0, /*tp_base*/ |
| 669 | 0, /*tp_dict*/ |
| 670 | 0, /*tp_descr_get*/ |
| 671 | 0, /*tp_descr_set*/ |
| 672 | 0, /*tp_dictoffset*/ |
| 673 | 0, /*tp_init*/ |
| 674 | 0, /*tp_alloc*/ |
| 675 | 0, /*tp_new*/ |
| 676 | 0, /*tp_free*/ |
| 677 | 0, /*tp_is_gc*/ |
| 678 | }; |
| 679 | |
| 680 | /*************************** View objects **************/ |
| 681 | |
| 682 | static PyObject* |
| 683 | view_execute(msiobj *view, PyObject*args) |
| 684 | { |
| 685 | int status; |
| 686 | MSIHANDLE params = 0; |
| 687 | PyObject *oparams = Py_None; |
| 688 | |
| 689 | if (!PyArg_ParseTuple(args, "O:Execute", &oparams)) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 690 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 691 | |
| 692 | if (oparams != Py_None) { |
| 693 | if (oparams->ob_type != &record_Type) { |
| 694 | PyErr_SetString(PyExc_TypeError, "Execute argument must be a record"); |
| 695 | return NULL; |
| 696 | } |
| 697 | params = ((msiobj*)oparams)->h; |
| 698 | } |
| 699 | |
| 700 | status = MsiViewExecute(view->h, params); |
| 701 | if (status != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 702 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 703 | |
| 704 | Py_INCREF(Py_None); |
| 705 | return Py_None; |
| 706 | } |
| 707 | |
| 708 | static PyObject* |
| 709 | view_fetch(msiobj *view, PyObject*args) |
| 710 | { |
| 711 | int status; |
| 712 | MSIHANDLE result; |
| 713 | |
| 714 | if ((status = MsiViewFetch(view->h, &result)) != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 715 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 716 | |
| 717 | return record_new(result); |
| 718 | } |
| 719 | |
| 720 | static PyObject* |
| 721 | view_getcolumninfo(msiobj *view, PyObject *args) |
| 722 | { |
| 723 | int status; |
| 724 | int kind; |
| 725 | MSIHANDLE result; |
| 726 | |
| 727 | if (!PyArg_ParseTuple(args, "i:GetColumnInfo", &kind)) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 728 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 729 | |
| 730 | if ((status = MsiViewGetColumnInfo(view->h, kind, &result)) != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 731 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 732 | |
| 733 | return record_new(result); |
| 734 | } |
| 735 | |
| 736 | static PyObject* |
| 737 | view_modify(msiobj *view, PyObject *args) |
| 738 | { |
| 739 | int kind; |
| 740 | PyObject *data; |
| 741 | int status; |
| 742 | |
| 743 | if (!PyArg_ParseTuple(args, "iO:Modify", &kind, &data)) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 744 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 745 | |
| 746 | if (data->ob_type != &record_Type) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 747 | PyErr_SetString(PyExc_TypeError, "Modify expects a record object"); |
| 748 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | if ((status = MsiViewModify(view->h, kind, ((msiobj*)data)->h)) != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 752 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 753 | |
| 754 | Py_INCREF(Py_None); |
| 755 | return Py_None; |
| 756 | } |
| 757 | |
| 758 | static PyObject* |
| 759 | view_close(msiobj *view, PyObject*args) |
| 760 | { |
| 761 | int status; |
| 762 | |
| 763 | if ((status = MsiViewClose(view->h)) != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 764 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 765 | |
| 766 | Py_INCREF(Py_None); |
| 767 | return Py_None; |
| 768 | } |
| 769 | |
| 770 | static PyMethodDef view_methods[] = { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 771 | { "Execute", (PyCFunction)view_execute, METH_VARARGS, |
| 772 | PyDoc_STR("Execute(params=None) -> None\nWraps MsiViewExecute")}, |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 773 | { "GetColumnInfo", (PyCFunction)view_getcolumninfo, METH_VARARGS, |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 774 | PyDoc_STR("GetColumnInfo() -> result\nWraps MsiGetColumnInfo")}, |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 775 | { "Fetch", (PyCFunction)view_fetch, METH_NOARGS, |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 776 | PyDoc_STR("Fetch() -> result\nWraps MsiViewFetch")}, |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 777 | { "Modify", (PyCFunction)view_modify, METH_VARARGS, |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 778 | PyDoc_STR("Modify(mode,record) -> None\nWraps MsiViewModify")}, |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 779 | { "Close", (PyCFunction)view_close, METH_NOARGS, |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 780 | PyDoc_STR("Close() -> result\nWraps MsiViewClose")}, |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 781 | { NULL, NULL } |
| 782 | }; |
| 783 | |
| 784 | static PyTypeObject msiview_Type = { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 785 | PyVarObject_HEAD_INIT(NULL, 0) |
| 786 | "_msi.View", /*tp_name*/ |
| 787 | sizeof(msiobj), /*tp_basicsize*/ |
| 788 | 0, /*tp_itemsize*/ |
| 789 | /* methods */ |
| 790 | (destructor)msiobj_dealloc, /*tp_dealloc*/ |
| 791 | 0, /*tp_print*/ |
| 792 | 0, /*tp_getattr*/ |
| 793 | 0, /*tp_setattr*/ |
| 794 | 0, /*tp_reserved*/ |
| 795 | 0, /*tp_repr*/ |
| 796 | 0, /*tp_as_number*/ |
| 797 | 0, /*tp_as_sequence*/ |
| 798 | 0, /*tp_as_mapping*/ |
| 799 | 0, /*tp_hash*/ |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 800 | 0, /*tp_call*/ |
| 801 | 0, /*tp_str*/ |
| 802 | PyObject_GenericGetAttr,/*tp_getattro*/ |
| 803 | PyObject_GenericSetAttr,/*tp_setattro*/ |
| 804 | 0, /*tp_as_buffer*/ |
| 805 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 806 | 0, /*tp_doc*/ |
| 807 | 0, /*tp_traverse*/ |
| 808 | 0, /*tp_clear*/ |
| 809 | 0, /*tp_richcompare*/ |
| 810 | 0, /*tp_weaklistoffset*/ |
| 811 | 0, /*tp_iter*/ |
| 812 | 0, /*tp_iternext*/ |
| 813 | view_methods, /*tp_methods*/ |
| 814 | 0, /*tp_members*/ |
| 815 | 0, /*tp_getset*/ |
| 816 | 0, /*tp_base*/ |
| 817 | 0, /*tp_dict*/ |
| 818 | 0, /*tp_descr_get*/ |
| 819 | 0, /*tp_descr_set*/ |
| 820 | 0, /*tp_dictoffset*/ |
| 821 | 0, /*tp_init*/ |
| 822 | 0, /*tp_alloc*/ |
| 823 | 0, /*tp_new*/ |
| 824 | 0, /*tp_free*/ |
| 825 | 0, /*tp_is_gc*/ |
| 826 | }; |
| 827 | |
| 828 | /*************************** Database objects **************/ |
| 829 | |
| 830 | static PyObject* |
| 831 | msidb_openview(msiobj *msidb, PyObject *args) |
| 832 | { |
| 833 | int status; |
| 834 | char *sql; |
| 835 | MSIHANDLE hView; |
| 836 | msiobj *result; |
| 837 | |
| 838 | if (!PyArg_ParseTuple(args, "s:OpenView", &sql)) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 839 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 840 | |
| 841 | if ((status = MsiDatabaseOpenView(msidb->h, sql, &hView)) != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 842 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 843 | |
| 844 | result = PyObject_NEW(struct msiobj, &msiview_Type); |
| 845 | if (!result) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 846 | MsiCloseHandle(hView); |
| 847 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 848 | } |
| 849 | |
| 850 | result->h = hView; |
| 851 | return (PyObject*)result; |
| 852 | } |
| 853 | |
| 854 | static PyObject* |
| 855 | msidb_commit(msiobj *msidb, PyObject *args) |
| 856 | { |
| 857 | int status; |
| 858 | |
| 859 | if ((status = MsiDatabaseCommit(msidb->h)) != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 860 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 861 | |
| 862 | Py_INCREF(Py_None); |
| 863 | return Py_None; |
| 864 | } |
| 865 | |
| 866 | static PyObject* |
| 867 | msidb_getsummaryinformation(msiobj *db, PyObject *args) |
| 868 | { |
| 869 | int status; |
| 870 | int count; |
| 871 | MSIHANDLE result; |
| 872 | msiobj *oresult; |
| 873 | |
| 874 | if (!PyArg_ParseTuple(args, "i:GetSummaryInformation", &count)) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 875 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 876 | |
| 877 | status = MsiGetSummaryInformation(db->h, NULL, count, &result); |
| 878 | if (status != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 879 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 880 | |
| 881 | oresult = PyObject_NEW(struct msiobj, &summary_Type); |
| 882 | if (!result) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 883 | MsiCloseHandle(result); |
| 884 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | oresult->h = result; |
| 888 | return (PyObject*)oresult; |
| 889 | } |
| 890 | |
| 891 | static PyMethodDef db_methods[] = { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 892 | { "OpenView", (PyCFunction)msidb_openview, METH_VARARGS, |
| 893 | PyDoc_STR("OpenView(sql) -> viewobj\nWraps MsiDatabaseOpenView")}, |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 894 | { "Commit", (PyCFunction)msidb_commit, METH_NOARGS, |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 895 | PyDoc_STR("Commit() -> None\nWraps MsiDatabaseCommit")}, |
| 896 | { "GetSummaryInformation", (PyCFunction)msidb_getsummaryinformation, METH_VARARGS, |
| 897 | PyDoc_STR("GetSummaryInformation(updateCount) -> viewobj\nWraps MsiGetSummaryInformation")}, |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 898 | { NULL, NULL } |
| 899 | }; |
| 900 | |
| 901 | static PyTypeObject msidb_Type = { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 902 | PyVarObject_HEAD_INIT(NULL, 0) |
| 903 | "_msi.Database", /*tp_name*/ |
| 904 | sizeof(msiobj), /*tp_basicsize*/ |
| 905 | 0, /*tp_itemsize*/ |
| 906 | /* methods */ |
| 907 | (destructor)msiobj_dealloc, /*tp_dealloc*/ |
| 908 | 0, /*tp_print*/ |
| 909 | 0, /*tp_getattr*/ |
| 910 | 0, /*tp_setattr*/ |
| 911 | 0, /*tp_reserved*/ |
| 912 | 0, /*tp_repr*/ |
| 913 | 0, /*tp_as_number*/ |
| 914 | 0, /*tp_as_sequence*/ |
| 915 | 0, /*tp_as_mapping*/ |
| 916 | 0, /*tp_hash*/ |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 917 | 0, /*tp_call*/ |
| 918 | 0, /*tp_str*/ |
| 919 | PyObject_GenericGetAttr,/*tp_getattro*/ |
| 920 | PyObject_GenericSetAttr,/*tp_setattro*/ |
| 921 | 0, /*tp_as_buffer*/ |
| 922 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 923 | 0, /*tp_doc*/ |
| 924 | 0, /*tp_traverse*/ |
| 925 | 0, /*tp_clear*/ |
| 926 | 0, /*tp_richcompare*/ |
| 927 | 0, /*tp_weaklistoffset*/ |
| 928 | 0, /*tp_iter*/ |
| 929 | 0, /*tp_iternext*/ |
| 930 | db_methods, /*tp_methods*/ |
| 931 | 0, /*tp_members*/ |
| 932 | 0, /*tp_getset*/ |
| 933 | 0, /*tp_base*/ |
| 934 | 0, /*tp_dict*/ |
| 935 | 0, /*tp_descr_get*/ |
| 936 | 0, /*tp_descr_set*/ |
| 937 | 0, /*tp_dictoffset*/ |
| 938 | 0, /*tp_init*/ |
| 939 | 0, /*tp_alloc*/ |
| 940 | 0, /*tp_new*/ |
| 941 | 0, /*tp_free*/ |
| 942 | 0, /*tp_is_gc*/ |
| 943 | }; |
| 944 | |
| 945 | static PyObject* msiopendb(PyObject *obj, PyObject *args) |
| 946 | { |
| 947 | int status; |
| 948 | char *path; |
| 949 | int persist; |
| 950 | MSIHANDLE h; |
| 951 | msiobj *result; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 952 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 953 | if (!PyArg_ParseTuple(args, "si:MSIOpenDatabase", &path, &persist)) |
| 954 | return NULL; |
| 955 | |
| 956 | status = MsiOpenDatabase(path, (LPCSTR)persist, &h); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 957 | if (status != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 958 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 959 | |
| 960 | result = PyObject_NEW(struct msiobj, &msidb_Type); |
| 961 | if (!result) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 962 | MsiCloseHandle(h); |
| 963 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 964 | } |
| 965 | result->h = h; |
| 966 | return (PyObject*)result; |
| 967 | } |
| 968 | |
| 969 | static PyObject* |
| 970 | createrecord(PyObject *o, PyObject *args) |
| 971 | { |
| 972 | int count; |
| 973 | MSIHANDLE h; |
| 974 | |
| 975 | if (!PyArg_ParseTuple(args, "i:CreateRecord", &count)) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 976 | return NULL; |
| 977 | |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 978 | h = MsiCreateRecord(count); |
| 979 | if (h == 0) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 980 | return msierror(0); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 981 | |
| 982 | return record_new(h); |
| 983 | } |
| 984 | |
| 985 | |
| 986 | static PyMethodDef msi_methods[] = { |
| 987 | {"UuidCreate", (PyCFunction)uuidcreate, METH_NOARGS, |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 988 | PyDoc_STR("UuidCreate() -> string")}, |
| 989 | {"FCICreate", (PyCFunction)fcicreate, METH_VARARGS, |
| 990 | PyDoc_STR("fcicreate(cabname,files) -> None")}, |
| 991 | {"OpenDatabase", (PyCFunction)msiopendb, METH_VARARGS, |
| 992 | PyDoc_STR("OpenDatabase(name, flags) -> dbobj\nWraps MsiOpenDatabase")}, |
| 993 | {"CreateRecord", (PyCFunction)createrecord, METH_VARARGS, |
| 994 | PyDoc_STR("OpenDatabase(name, flags) -> dbobj\nWraps MsiCreateRecord")}, |
| 995 | {NULL, NULL} /* sentinel */ |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 996 | }; |
| 997 | |
| 998 | static char msi_doc[] = "Documentation"; |
| 999 | |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 1000 | |
| 1001 | static struct PyModuleDef _msimodule = { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1002 | PyModuleDef_HEAD_INIT, |
| 1003 | "_msi", |
| 1004 | msi_doc, |
| 1005 | -1, |
| 1006 | msi_methods, |
| 1007 | NULL, |
| 1008 | NULL, |
| 1009 | NULL, |
| 1010 | NULL |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 1011 | }; |
| 1012 | |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1013 | PyMODINIT_FUNC |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 1014 | PyInit__msi(void) |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1015 | { |
| 1016 | PyObject *m; |
| 1017 | |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 1018 | m = PyModule_Create(&_msimodule); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1019 | if (m == NULL) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1020 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1021 | |
| 1022 | PyModule_AddIntConstant(m, "MSIDBOPEN_CREATEDIRECT", (int)MSIDBOPEN_CREATEDIRECT); |
| 1023 | PyModule_AddIntConstant(m, "MSIDBOPEN_CREATE", (int)MSIDBOPEN_CREATE); |
| 1024 | PyModule_AddIntConstant(m, "MSIDBOPEN_DIRECT", (int)MSIDBOPEN_DIRECT); |
| 1025 | PyModule_AddIntConstant(m, "MSIDBOPEN_READONLY", (int)MSIDBOPEN_READONLY); |
| 1026 | PyModule_AddIntConstant(m, "MSIDBOPEN_TRANSACT", (int)MSIDBOPEN_TRANSACT); |
| 1027 | PyModule_AddIntConstant(m, "MSIDBOPEN_PATCHFILE", (int)MSIDBOPEN_PATCHFILE); |
| 1028 | |
| 1029 | PyModule_AddIntConstant(m, "MSICOLINFO_NAMES", MSICOLINFO_NAMES); |
| 1030 | PyModule_AddIntConstant(m, "MSICOLINFO_TYPES", MSICOLINFO_TYPES); |
| 1031 | |
| 1032 | PyModule_AddIntConstant(m, "MSIMODIFY_SEEK", MSIMODIFY_SEEK); |
| 1033 | PyModule_AddIntConstant(m, "MSIMODIFY_REFRESH", MSIMODIFY_REFRESH); |
| 1034 | PyModule_AddIntConstant(m, "MSIMODIFY_INSERT", MSIMODIFY_INSERT); |
| 1035 | PyModule_AddIntConstant(m, "MSIMODIFY_UPDATE", MSIMODIFY_UPDATE); |
| 1036 | PyModule_AddIntConstant(m, "MSIMODIFY_ASSIGN", MSIMODIFY_ASSIGN); |
| 1037 | PyModule_AddIntConstant(m, "MSIMODIFY_REPLACE", MSIMODIFY_REPLACE); |
| 1038 | PyModule_AddIntConstant(m, "MSIMODIFY_MERGE", MSIMODIFY_MERGE); |
| 1039 | PyModule_AddIntConstant(m, "MSIMODIFY_DELETE", MSIMODIFY_DELETE); |
| 1040 | PyModule_AddIntConstant(m, "MSIMODIFY_INSERT_TEMPORARY", MSIMODIFY_INSERT_TEMPORARY); |
| 1041 | PyModule_AddIntConstant(m, "MSIMODIFY_VALIDATE", MSIMODIFY_VALIDATE); |
| 1042 | PyModule_AddIntConstant(m, "MSIMODIFY_VALIDATE_NEW", MSIMODIFY_VALIDATE_NEW); |
| 1043 | PyModule_AddIntConstant(m, "MSIMODIFY_VALIDATE_FIELD", MSIMODIFY_VALIDATE_FIELD); |
| 1044 | PyModule_AddIntConstant(m, "MSIMODIFY_VALIDATE_DELETE", MSIMODIFY_VALIDATE_DELETE); |
| 1045 | |
| 1046 | PyModule_AddIntConstant(m, "PID_CODEPAGE", PID_CODEPAGE); |
| 1047 | PyModule_AddIntConstant(m, "PID_TITLE", PID_TITLE); |
| 1048 | PyModule_AddIntConstant(m, "PID_SUBJECT", PID_SUBJECT); |
| 1049 | PyModule_AddIntConstant(m, "PID_AUTHOR", PID_AUTHOR); |
| 1050 | PyModule_AddIntConstant(m, "PID_KEYWORDS", PID_KEYWORDS); |
| 1051 | PyModule_AddIntConstant(m, "PID_COMMENTS", PID_COMMENTS); |
| 1052 | PyModule_AddIntConstant(m, "PID_TEMPLATE", PID_TEMPLATE); |
| 1053 | PyModule_AddIntConstant(m, "PID_LASTAUTHOR", PID_LASTAUTHOR); |
| 1054 | PyModule_AddIntConstant(m, "PID_REVNUMBER", PID_REVNUMBER); |
| 1055 | PyModule_AddIntConstant(m, "PID_LASTPRINTED", PID_LASTPRINTED); |
| 1056 | PyModule_AddIntConstant(m, "PID_CREATE_DTM", PID_CREATE_DTM); |
| 1057 | PyModule_AddIntConstant(m, "PID_LASTSAVE_DTM", PID_LASTSAVE_DTM); |
| 1058 | PyModule_AddIntConstant(m, "PID_PAGECOUNT", PID_PAGECOUNT); |
| 1059 | PyModule_AddIntConstant(m, "PID_WORDCOUNT", PID_WORDCOUNT); |
| 1060 | PyModule_AddIntConstant(m, "PID_CHARCOUNT", PID_CHARCOUNT); |
| 1061 | PyModule_AddIntConstant(m, "PID_APPNAME", PID_APPNAME); |
| 1062 | PyModule_AddIntConstant(m, "PID_SECURITY", PID_SECURITY); |
| 1063 | |
| 1064 | MSIError = PyErr_NewException ("_msi.MSIError", NULL, NULL); |
| 1065 | if (!MSIError) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1066 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1067 | PyModule_AddObject(m, "MSIError", MSIError); |
Amaury Forgeot d'Arc | bf9e966 | 2008-06-17 21:39:46 +0000 | [diff] [blame] | 1068 | return m; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1069 | } |