mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Cleanup single_get_filesystem()
This commit is contained in:
parent
ffce4908ef
commit
93ee37c872
@ -100,7 +100,7 @@ set_size_property(PyObject *dict, REFPROPERTYKEY key, const char *pykey, const C
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
set_date_property(PyObject *dict, REFPROPERTYKEY key, const char *pykey, const CComPtr<IPortableDeviceValues> &properties) {
|
set_date_property(PyObject *dict, REFPROPERTYKEY key, const char *pykey, const CComPtr<IPortableDeviceValues> &properties) {
|
||||||
PROPVARIANT ts = {0};
|
prop_variant ts;
|
||||||
if (SUCCEEDED(properties->GetValue(key, &ts))) {
|
if (SUCCEEDED(properties->GetValue(key, &ts))) {
|
||||||
SYSTEMTIME st;
|
SYSTEMTIME st;
|
||||||
if (ts.vt == VT_DATE && VariantTimeToSystemTime(ts.date, &st)) {
|
if (ts.vt == VT_DATE && VariantTimeToSystemTime(ts.date, &st)) {
|
||||||
@ -381,7 +381,6 @@ get_object_properties(IPortableDeviceProperties *devprops, IPortableDeviceKeyCol
|
|||||||
static bool
|
static bool
|
||||||
single_get_filesystem(unsigned int level, CComPtr<IPortableDeviceContent> &content, CComPtr<IPortableDevicePropVariantCollection> &object_ids, PyObject *callback, PyObject *ans, PyObject *subfolders) {
|
single_get_filesystem(unsigned int level, CComPtr<IPortableDeviceContent> &content, CComPtr<IPortableDevicePropVariantCollection> &object_ids, PyObject *callback, PyObject *ans, PyObject *subfolders) {
|
||||||
DWORD num;
|
DWORD num;
|
||||||
PROPVARIANT pv;
|
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
CComPtr<IPortableDeviceProperties> devprops;
|
CComPtr<IPortableDeviceProperties> devprops;
|
||||||
|
|
||||||
@ -395,28 +394,20 @@ single_get_filesystem(unsigned int level, CComPtr<IPortableDeviceContent> &conte
|
|||||||
if (FAILED(hr)) { hresult_set_exc("Failed to get object id count", hr); return false; }
|
if (FAILED(hr)) { hresult_set_exc("Failed to get object id count", hr); return false; }
|
||||||
|
|
||||||
for (DWORD i = 0; i < num; i++) {
|
for (DWORD i = 0; i < num; i++) {
|
||||||
bool ok = false;
|
prop_variant pv;
|
||||||
PropVariantInit(&pv);
|
|
||||||
hr = object_ids->GetAt(i, &pv);
|
hr = object_ids->GetAt(i, &pv);
|
||||||
pyobject_raii recurse;
|
pyobject_raii recurse;
|
||||||
if (SUCCEEDED(hr) && pv.pwszVal != NULL) {
|
if (SUCCEEDED(hr) && pv.pwszVal != NULL) {
|
||||||
pyobject_raii item(get_object_properties(devprops, properties, pv.pwszVal));
|
pyobject_raii item(get_object_properties(devprops, properties, pv.pwszVal));
|
||||||
if (item) {
|
if (!item) return false;
|
||||||
PyObject_Print(item.ptr(), stdout, 0);
|
pyobject_raii r(PyObject_CallFunction(callback, "OI", item.ptr(), level));
|
||||||
printf("\n");
|
if (PyDict_SetItem(ans, PyDict_GetItemString(item.ptr(), "id"), item.ptr()) != 0) return false;
|
||||||
pyobject_raii r(PyObject_CallFunction(callback, "OI", item.ptr(), level));
|
if (r && PyObject_IsTrue(r.ptr())) recurse.attach(item.detach());
|
||||||
PyDict_SetItem(ans, PyDict_GetItemString(item.ptr(), "id"), item.ptr());
|
} else { hresult_set_exc("Failed to get item from IPortableDevicePropVariantCollection", hr); return false; }
|
||||||
if (r && PyObject_IsTrue(r.ptr())) recurse.attach(item.detach());
|
|
||||||
ok = true;
|
|
||||||
}
|
|
||||||
} else hresult_set_exc("Failed to get item from IPortableDevicePropVariantCollection", hr);
|
|
||||||
|
|
||||||
PropVariantClear(&pv);
|
|
||||||
if (!ok) return false;
|
|
||||||
if (recurse) {
|
if (recurse) {
|
||||||
if (PyList_Append(subfolders, PyDict_GetItemString(recurse.ptr(), "id")) == -1) ok = false;
|
if (PyList_Append(subfolders, PyDict_GetItemString(recurse.ptr(), "id")) == -1) return false;
|
||||||
}
|
}
|
||||||
if (!ok) return false;
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user