mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Use CComPtr for client information
This commit is contained in:
parent
96af51a318
commit
06d82ad1c3
@ -7,10 +7,6 @@
|
|||||||
|
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
|
|
||||||
extern IPortableDevice* wpd::open_device(const wchar_t *pnp_id, IPortableDeviceValues *client_information);
|
|
||||||
extern IPortableDeviceValues* wpd::get_client_information();
|
|
||||||
extern PyObject* wpd::get_device_information(IPortableDevice *device, IPortableDevicePropertiesBulk **pb);
|
|
||||||
|
|
||||||
using namespace wpd;
|
using namespace wpd;
|
||||||
// Device.__init__() {{{
|
// Device.__init__() {{{
|
||||||
static void
|
static void
|
||||||
@ -28,8 +24,6 @@ dealloc(Device* self)
|
|||||||
Py_END_ALLOW_THREADS;
|
Py_END_ALLOW_THREADS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self->client_information != NULL) { self->client_information->Release(); self->client_information = NULL; }
|
|
||||||
|
|
||||||
Py_XDECREF(self->device_information); self->device_information = NULL;
|
Py_XDECREF(self->device_information); self->device_information = NULL;
|
||||||
|
|
||||||
Py_TYPE(self)->tp_free((PyObject*)self);
|
Py_TYPE(self)->tp_free((PyObject*)self);
|
||||||
@ -48,9 +42,9 @@ init(Device *self, PyObject *args, PyObject *kwds)
|
|||||||
|
|
||||||
self->bulk_properties = NULL;
|
self->bulk_properties = NULL;
|
||||||
|
|
||||||
self->client_information = get_client_information();
|
CComPtr<IPortableDeviceValues> client_information = get_client_information();
|
||||||
if (self->client_information != NULL) {
|
if (client_information) {
|
||||||
self->device = open_device(self->pnp_id, self->client_information);
|
self->device = open_device(self->pnp_id, client_information);
|
||||||
if (self->device != NULL) {
|
if (self->device != NULL) {
|
||||||
self->device_information = get_device_information(self->device, &(self->bulk_properties));
|
self->device_information = get_device_information(self->device, &(self->bulk_properties));
|
||||||
if (self->device_information != NULL) {
|
if (self->device_information != NULL) {
|
||||||
|
@ -46,7 +46,7 @@ IPortableDeviceValues *get_client_information() { // {{{
|
|||||||
return client_information;
|
return client_information;
|
||||||
} // }}}
|
} // }}}
|
||||||
|
|
||||||
IPortableDevice *open_device(const wchar_t *pnp_id, IPortableDeviceValues *client_information) { // {{{
|
IPortableDevice *open_device(const wchar_t *pnp_id, CComPtr<IPortableDeviceValues> &client_information) { // {{{
|
||||||
IPortableDevice *device = NULL;
|
IPortableDevice *device = NULL;
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#define UNICODE
|
#define UNICODE
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
#include <atlbase.h>
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
|
|
||||||
#include <Objbase.h>
|
#include <Objbase.h>
|
||||||
@ -40,7 +41,6 @@ typedef struct {
|
|||||||
PyObject_HEAD
|
PyObject_HEAD
|
||||||
// Type-specific fields go here.
|
// Type-specific fields go here.
|
||||||
wchar_t *pnp_id;
|
wchar_t *pnp_id;
|
||||||
IPortableDeviceValues *client_information;
|
|
||||||
IPortableDevice *device;
|
IPortableDevice *device;
|
||||||
PyObject *device_information;
|
PyObject *device_information;
|
||||||
IPortableDevicePropertiesBulk *bulk_properties;
|
IPortableDevicePropertiesBulk *bulk_properties;
|
||||||
@ -55,7 +55,7 @@ PyObject *wchar_to_unicode(const wchar_t *o);
|
|||||||
int pump_waiting_messages();
|
int pump_waiting_messages();
|
||||||
|
|
||||||
extern IPortableDeviceValues* get_client_information();
|
extern IPortableDeviceValues* get_client_information();
|
||||||
extern IPortableDevice* open_device(const wchar_t *pnp_id, IPortableDeviceValues *client_information);
|
extern IPortableDevice* open_device(const wchar_t *pnp_id, CComPtr<IPortableDeviceValues> &client_information);
|
||||||
extern PyObject* get_device_information(IPortableDevice *device, IPortableDevicePropertiesBulk **bulk_properties);
|
extern PyObject* get_device_information(IPortableDevice *device, IPortableDevicePropertiesBulk **bulk_properties);
|
||||||
extern PyObject* get_filesystem(IPortableDevice *device, const wchar_t *storage_id, IPortableDevicePropertiesBulk *bulk_properties, PyObject *callback);
|
extern PyObject* get_filesystem(IPortableDevice *device, const wchar_t *storage_id, IPortableDevicePropertiesBulk *bulk_properties, PyObject *callback);
|
||||||
extern PyObject* get_file(IPortableDevice *device, const wchar_t *object_id, PyObject *dest, PyObject *callback);
|
extern PyObject* get_file(IPortableDevice *device, const wchar_t *object_id, PyObject *dest, PyObject *callback);
|
||||||
|
@ -20,10 +20,6 @@ static int _com_initialized = 0;
|
|||||||
// Application Info
|
// Application Info
|
||||||
wpd::ClientInfo wpd::client_info = {0};
|
wpd::ClientInfo wpd::client_info = {0};
|
||||||
|
|
||||||
extern IPortableDeviceValues* wpd::get_client_information();
|
|
||||||
extern IPortableDevice* wpd::open_device(const wchar_t *pnp_id, IPortableDeviceValues *client_information);
|
|
||||||
extern PyObject* wpd::get_device_information(IPortableDevice *device, IPortableDevicePropertiesBulk **bulk_properties);
|
|
||||||
|
|
||||||
// Module startup/shutdown {{{
|
// Module startup/shutdown {{{
|
||||||
static PyObject *
|
static PyObject *
|
||||||
wpd_init(PyObject *self, PyObject *args) {
|
wpd_init(PyObject *self, PyObject *args) {
|
||||||
@ -135,7 +131,6 @@ wpd_enumerate_devices(PyObject *self, PyObject *args) {
|
|||||||
static PyObject *
|
static PyObject *
|
||||||
wpd_device_info(PyObject *self, PyObject *args) {
|
wpd_device_info(PyObject *self, PyObject *args) {
|
||||||
PyObject *ans = NULL;
|
PyObject *ans = NULL;
|
||||||
IPortableDeviceValues *client_information = NULL;
|
|
||||||
IPortableDevice *device = NULL;
|
IPortableDevice *device = NULL;
|
||||||
|
|
||||||
ENSURE_WPD(NULL);
|
ENSURE_WPD(NULL);
|
||||||
@ -144,15 +139,14 @@ wpd_device_info(PyObject *self, PyObject *args) {
|
|||||||
if (!PyArg_ParseTuple(args, "O&", py_to_wchar_no_none, &pnp_id)) return NULL;
|
if (!PyArg_ParseTuple(args, "O&", py_to_wchar_no_none, &pnp_id)) return NULL;
|
||||||
if (wcslen(pnp_id.ptr()) < 1) { PyErr_SetString(WPDError, "The PNP id must not be empty."); return NULL; }
|
if (wcslen(pnp_id.ptr()) < 1) { PyErr_SetString(WPDError, "The PNP id must not be empty."); return NULL; }
|
||||||
|
|
||||||
client_information = get_client_information();
|
CComPtr<IPortableDeviceValues> client_information = get_client_information();
|
||||||
if (client_information != NULL) {
|
if (client_information) {
|
||||||
device = open_device(pnp_id.ptr(), client_information);
|
device = open_device(pnp_id.ptr(), client_information);
|
||||||
if (device != NULL) {
|
if (device != NULL) {
|
||||||
ans = get_device_information(device, NULL);
|
ans = get_device_information(device, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (client_information != NULL) client_information->Release();
|
|
||||||
if (device != NULL) {device->Close(); device->Release();}
|
if (device != NULL) {device->Close(); device->Release();}
|
||||||
return ans;
|
return ans;
|
||||||
} // }}}
|
} // }}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user