mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-05-09 08:03:12 +02:00
add function to winutil to check for an active internet connection
This commit is contained in:
parent
833c54c5d2
commit
9d61fbe0d9
2 changed files with 18 additions and 1 deletions
|
|
@ -143,7 +143,7 @@ def __init__(self, name, sources, **kwargs):
|
|||
if iswindows:
|
||||
extensions.append(Extension('winutil',
|
||||
['calibre/utils/windows/winutil.c'],
|
||||
libraries=['shell32', 'setupapi'],
|
||||
libraries=['shell32', 'setupapi', 'wininet'],
|
||||
cflags=['/X']
|
||||
))
|
||||
|
||||
|
|
|
|||
|
|
@ -51,11 +51,15 @@ wherever possible in this module.
|
|||
script being run. So to replace sys.argv, you should use
|
||||
`if len(sys.argv) > 1: sys.argv[1:] = winutil.argv()[1-len(sys.argv):]`
|
||||
|
||||
.. function:: internet_connected() -> Return True if there is an active
|
||||
internet connection.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#define UNICODE
|
||||
#include <Windows.h>
|
||||
#include <Wininet.h>
|
||||
#include <Python.h>
|
||||
#include <structseq.h>
|
||||
#include <timefuncs.h>
|
||||
|
|
@ -771,6 +775,15 @@ gettmarg(PyObject *args, struct tm *p)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
winutil_internet_connected(PyObject *self, PyObject *args) {
|
||||
DWORD flags;
|
||||
BOOL ans = InternetGetConnectedState(&flags, 0);
|
||||
if (ans) Py_RETURN_TRUE;
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
|
||||
static PyObject *
|
||||
winutil_strftime(PyObject *self, PyObject *args)
|
||||
{
|
||||
|
|
@ -919,6 +932,10 @@ be a unicode string. Returns unicode strings."
|
|||
"eject_drive(drive_letter)\n\nEject a drive. Raises an exception on failure."
|
||||
},
|
||||
|
||||
{"internet_connected", winutil_internet_connected, METH_VARARGS,
|
||||
"internet_connected()\n\nReturn True if there is an active internet connection"
|
||||
},
|
||||
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue