@@ -196,7 +196,10 @@ static PyObject *find_all_instances()
196196
197197PyDoc_STRVAR (findvs_findall_doc, " findall()\
198198\
199- Finds all installed versions of Visual Studio." );
199+ Finds all installed versions of Visual Studio.\
200+ \
201+ This function will initialize COM temporarily. To avoid impact on other parts\
202+ of your application, use a new thread to make this call." );
200203
201204static PyObject *findvs_findall (PyObject *self, PyObject *args, PyObject *kwargs)
202205{
@@ -210,67 +213,9 @@ static PyObject *findvs_findall(PyObject *self, PyObject *args, PyObject *kwargs
210213 return res;
211214}
212215
213- PyDoc_STRVAR (findvs_getversion_doc, " getversion(path)\
214- \
215- Reads the product version from the specified file." );
216-
217- static PyObject *findvs_getversion (PyObject *self, PyObject *args, PyObject *kwargs)
218- {
219- LPVOID verblock;
220- DWORD verblock_size;
221-
222- PyObject *res = NULL ;
223-
224- PyObject *path_obj;
225- const wchar_t *path;
226- Py_ssize_t path_len;
227-
228- static const char * keywords[] = { " path" , NULL };
229- if (!PyArg_ParseTupleAndKeywords (args, kwargs, " O&:getversion" ,
230- (char **)keywords, PyUnicode_FSDecoder, &path_obj))
231- return NULL ;
232-
233- path = PyUnicode_AsWideCharString (path_obj, &path_len);
234- Py_DECREF (path_obj);
235- if (!path) {
236- return NULL ;
237- }
238-
239- if ((verblock_size = GetFileVersionInfoSizeW (path, NULL )) &&
240- (verblock = malloc (verblock_size))) {
241- WORD *langinfo;
242- wchar_t *verstr;
243- UINT langinfo_size, ver_size;
244-
245- if (GetFileVersionInfoW (path, 0 , verblock_size, verblock) &&
246- VerQueryValueW (verblock, L" \\ VarFileInfo\\ Translation" ,
247- (LPVOID*)&langinfo, &langinfo_size)) {
248- wchar_t rsrc_name[256 ];
249- StringCchPrintfW (rsrc_name, 256 ,
250- L" \\ StringFileInfo\\ %04x%04x\\ ProductVersion" ,
251- langinfo[0 ], langinfo[1 ]);
252- if (VerQueryValueW (verblock, rsrc_name, (LPVOID*)&verstr, &ver_size)) {
253- while (ver_size > 0 && !verstr[ver_size]) {
254- ver_size -= 1 ;
255- }
256- res = PyUnicode_FromWideChar (verstr, ver_size - 1 );
257- }
258- }
259- free (verblock);
260- }
261-
262- PyMem_Free ((void *)path);
263- if (!res) {
264- Py_RETURN_NONE;
265- }
266- return res;
267- }
268-
269-
270216// List of functions to add to findvs in exec_findvs().
271217static PyMethodDef findvs_functions[] = {
272218 { " findall" , (PyCFunction)findvs_findall, METH_VARARGS | METH_KEYWORDS, findvs_findall_doc },
273- { " getversion" , (PyCFunction)findvs_getversion, METH_VARARGS | METH_KEYWORDS, findvs_getversion_doc },
274219 { NULL , NULL , 0 , NULL }
275220};
276221
0 commit comments