MTP: Fix last modified date not getting read correctly on windows

This commit is contained in:
Kovid Goyal 2012-09-03 21:42:31 +05:30
parent f36feac5ba
commit f07002fdd2
4 changed files with 25 additions and 14 deletions

View File

@ -187,7 +187,7 @@ if iswindows:
headers=[
'calibre/devices/mtp/windows/global.h',
],
libraries=['ole32', 'portabledeviceguids', 'user32'],
libraries=['ole32', 'oleaut32', 'portabledeviceguids', 'user32'],
# needs_ddk=True,
cflags=['/X']
),

View File

@ -37,6 +37,9 @@ class FileOrFolder(object):
self.size = entry.get('size', 0)
md = entry.get('modified', 0)
try:
if isinstance(md, tuple):
self.last_modified = datetime(*(list(md)+[local_tz]))
else:
self.last_modified = datetime.fromtimestamp(md, local_tz)
except:
self.last_modified = datetime.fromtimestamp(0, local_tz)

View File

@ -84,13 +84,21 @@ static void set_size_property(PyObject *dict, REFPROPERTYKEY key, const char *py
static void set_date_property(PyObject *dict, REFPROPERTYKEY key, const char *pykey, IPortableDeviceValues *properties) {
FLOAT val = 0;
SYSTEMTIME st;
unsigned int microseconds;
PyObject *t;
if (SUCCEEDED(properties->GetFloatValue(key, &val))) {
t = Py_BuildValue("d", (double)val);
if (VariantTimeToSystemTime(val, &st)) {
microseconds = 1000 * st.wMilliseconds;
t = Py_BuildValue("H H H H H H I", (unsigned short)st.wYear,
(unsigned short)st.wMonth, (unsigned short)st.wDay,
(unsigned short)st.wHour, (unsigned short)st.wMinute,
(unsigned short)st.wSecond, microseconds);
if (t != NULL) { PyDict_SetItemString(dict, pykey, t); Py_DECREF(t); }
}
}
}
static void set_content_type_property(PyObject *dict, IPortableDeviceValues *properties) {
GUID guid = GUID_NULL;

View File

@ -54,9 +54,9 @@ def main():
plugins._plugins['wpd'] = (wpd, '')
sys.path.pop(0)
from calibre.devices.mtp.test import run
run()
return
# from calibre.devices.mtp.test import run
# run()
# return
from calibre.devices.scanner import win_scanner
from calibre.devices.mtp.windows.driver import MTP_DEVICE
@ -81,13 +81,13 @@ def main():
# print ('Fetching file: oFF (198214 bytes)')
# stream = dev.get_file('oFF')
# print ("Fetched size: ", stream.tell())
size = 4
stream = io.BytesIO(b'a'*size)
name = 'zzz-test-file.txt'
stream.seek(0)
f = dev.put_file(dev.filesystem_cache.entries[0], name, stream, size)
print ('Put file:', f)
# dev.filesystem_cache.dump()
# size = 4
# stream = io.BytesIO(b'a'*size)
# name = 'zzz-test-file.txt'
# stream.seek(0)
# f = dev.put_file(dev.filesystem_cache.entries[0], name, stream, size)
# print ('Put file:', f)
dev.filesystem_cache.dump()
finally:
dev.shutdown()