mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 02:34:06 -04:00
Dont ignore failures reported in OnEnd when doing bulk property queries
This commit is contained in:
parent
f1d2910e73
commit
66cf52e1c6
@ -157,6 +157,7 @@ private:
|
|||||||
HANDLE complete;
|
HANDLE complete;
|
||||||
ULONG self_ref;
|
ULONG self_ref;
|
||||||
PyObject *callback;
|
PyObject *callback;
|
||||||
|
HRESULT end_status;
|
||||||
|
|
||||||
void do_one_object(CComPtr<IPortableDeviceValues> &properties) {
|
void do_one_object(CComPtr<IPortableDeviceValues> &properties) {
|
||||||
com_wchar_raii property;
|
com_wchar_raii property;
|
||||||
@ -200,17 +201,26 @@ public:
|
|||||||
if (complete == NULL || complete == INVALID_HANDLE_VALUE) return false;
|
if (complete == NULL || complete == INVALID_HANDLE_VALUE) return false;
|
||||||
|
|
||||||
this->items = items; this->subfolders = subfolders; this->level = level; this->callback = callback;
|
this->items = items; this->subfolders = subfolders; this->level = level; this->callback = callback;
|
||||||
|
this->end_status = S_OK;
|
||||||
self_ref = 0;
|
self_ref = 0;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
void end_processing() {
|
HRESULT end_processing() {
|
||||||
if (complete != INVALID_HANDLE_VALUE) CloseHandle(complete);
|
if (complete != INVALID_HANDLE_VALUE) CloseHandle(complete);
|
||||||
items = NULL; subfolders = NULL; level = 0; complete = INVALID_HANDLE_VALUE; callback = NULL;
|
items = NULL; subfolders = NULL; level = 0; complete = INVALID_HANDLE_VALUE; callback = NULL;
|
||||||
|
return this->end_status;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool handle_is_valid() const { return complete != INVALID_HANDLE_VALUE; }
|
bool handle_is_valid() const { return complete != INVALID_HANDLE_VALUE; }
|
||||||
|
|
||||||
HRESULT __stdcall OnStart(REFGUID Context) { return S_OK; }
|
HRESULT __stdcall OnStart(REFGUID Context) { return S_OK; }
|
||||||
HRESULT __stdcall OnEnd(REFGUID Context, HRESULT hrStatus) { if (complete != INVALID_HANDLE_VALUE) SetEvent(complete); return S_OK; }
|
|
||||||
|
HRESULT __stdcall OnEnd(REFGUID Context, HRESULT hrStatus) {
|
||||||
|
if (complete != INVALID_HANDLE_VALUE) SetEvent(complete);
|
||||||
|
this->end_status = hrStatus;
|
||||||
|
return S_OK;
|
||||||
|
}
|
||||||
|
|
||||||
ULONG __stdcall AddRef() { InterlockedIncrement((long*) &self_ref); return self_ref; }
|
ULONG __stdcall AddRef() { InterlockedIncrement((long*) &self_ref); return self_ref; }
|
||||||
ULONG __stdcall Release() {
|
ULONG __stdcall Release() {
|
||||||
ULONG refcnt = self_ref - 1;
|
ULONG refcnt = self_ref - 1;
|
||||||
@ -304,13 +314,18 @@ bulk_get_filesystem(
|
|||||||
PyErr_SetExcFromWindowsErrWithFilename(WPDError, 0, buf);
|
PyErr_SetExcFromWindowsErrWithFilename(WPDError, 0, buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bulk_properties_callback->end_processing();
|
hr = bulk_properties_callback->end_processing();
|
||||||
if (PyErr_Occurred()) {
|
if (PyErr_Occurred()) {
|
||||||
bulk_properties->Cancel(guid_context);
|
bulk_properties->Cancel(guid_context);
|
||||||
pump_waiting_messages();
|
pump_waiting_messages();
|
||||||
}
|
}
|
||||||
bulk_properties_callback->Release();
|
bulk_properties_callback->Release();
|
||||||
return PyErr_Occurred() ? false : true;
|
if (PyErr_Occurred()) return false;
|
||||||
|
if (FAILED(hr)) {
|
||||||
|
hresult_set_exc("Bulk get properties failed in OnEnd", hr);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
|
@ -36,7 +36,7 @@ init(Device *self, PyObject *args, PyObject *kwds)
|
|||||||
if (client_information) {
|
if (client_information) {
|
||||||
self->device = open_device(self->pnp_id.ptr(), client_information);
|
self->device = open_device(self->pnp_id.ptr(), client_information);
|
||||||
if (self->device) {
|
if (self->device) {
|
||||||
self->device_information.attach(get_device_information(self->device, self->bulk_properties));
|
self->device_information.attach(get_device_information(self->pnp_id.ptr(), self->device, self->bulk_properties));
|
||||||
if (self->device_information) ret = 0;
|
if (self->device_information) ret = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -50,7 +50,7 @@ static PyObject*
|
|||||||
update_data(Device *self, PyObject *args) {
|
update_data(Device *self, PyObject *args) {
|
||||||
PyObject *di = NULL;
|
PyObject *di = NULL;
|
||||||
CComPtr<IPortableDevicePropertiesBulk> bulk_properties;
|
CComPtr<IPortableDevicePropertiesBulk> bulk_properties;
|
||||||
di = get_device_information(self->device, bulk_properties);
|
di = get_device_information(self->pnp_id.ptr(), self->device, bulk_properties);
|
||||||
if (di == NULL) return NULL;
|
if (di == NULL) return NULL;
|
||||||
self->device_information.attach(di);
|
self->device_information.attach(di);
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
|
@ -151,7 +151,7 @@ get_storage_info(IPortableDevice *device) { // {{{
|
|||||||
} // }}}
|
} // }}}
|
||||||
|
|
||||||
PyObject*
|
PyObject*
|
||||||
get_device_information(CComPtr<IPortableDevice> &device, CComPtr<IPortableDevicePropertiesBulk> &pb) { // {{{
|
get_device_information(const wchar_t *pnp_id, CComPtr<IPortableDevice> &device, CComPtr<IPortableDevicePropertiesBulk> &pb) { // {{{
|
||||||
CComPtr<IPortableDeviceContent> content = NULL;
|
CComPtr<IPortableDeviceContent> content = NULL;
|
||||||
CComPtr<IPortableDeviceProperties> properties = NULL;
|
CComPtr<IPortableDeviceProperties> properties = NULL;
|
||||||
CComPtr<IPortableDeviceKeyCollection> keys = NULL;
|
CComPtr<IPortableDeviceKeyCollection> keys = NULL;
|
||||||
@ -260,6 +260,8 @@ get_device_information(CComPtr<IPortableDevice> &device, CComPtr<IPortableDevice
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
PyDict_SetItemString(ans, "has_storage", has_storage ? Py_True : Py_False);
|
PyDict_SetItemString(ans, "has_storage", has_storage ? Py_True : Py_False);
|
||||||
|
pyobject_raii pid(PyUnicode_FromWideChar(pnp_id, -1));
|
||||||
|
if (pid) PyDict_SetItemString(ans, "pnp_id", pid.ptr());
|
||||||
|
|
||||||
if (has_storage) {
|
if (has_storage) {
|
||||||
pyobject_raii storage(get_storage_info(device));
|
pyobject_raii storage(get_storage_info(device));
|
||||||
|
@ -43,7 +43,7 @@ extern PyTypeObject DeviceType;
|
|||||||
|
|
||||||
extern IPortableDeviceValues* get_client_information();
|
extern IPortableDeviceValues* get_client_information();
|
||||||
extern IPortableDevice* open_device(const wchar_t *pnp_id, CComPtr<IPortableDeviceValues> &client_information);
|
extern IPortableDevice* open_device(const wchar_t *pnp_id, CComPtr<IPortableDeviceValues> &client_information);
|
||||||
extern PyObject* get_device_information(CComPtr<IPortableDevice> &device, CComPtr<IPortableDevicePropertiesBulk> &bulk_properties);
|
extern PyObject* get_device_information(const wchar_t *pnp_id, CComPtr<IPortableDevice> &device, CComPtr<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);
|
||||||
extern PyObject* create_folder(IPortableDevice *device, const wchar_t *parent_id, const wchar_t *name);
|
extern PyObject* create_folder(IPortableDevice *device, const wchar_t *parent_id, const wchar_t *name);
|
||||||
|
@ -185,7 +185,7 @@ wpd_device_info(PyObject *self, PyObject *args) {
|
|||||||
if (client_information) {
|
if (client_information) {
|
||||||
device = open_device(pnp_id.ptr(), client_information);
|
device = open_device(pnp_id.ptr(), client_information);
|
||||||
CComPtr<IPortableDevicePropertiesBulk> properties_bulk;
|
CComPtr<IPortableDevicePropertiesBulk> properties_bulk;
|
||||||
if (device) ans = get_device_information(device, properties_bulk);
|
if (device) ans = get_device_information(pnp_id.ptr(), device, properties_bulk);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (device) device->Close();
|
if (device) device->Close();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user