From f07002fdd226fc735e93a6b5979ed0849e1cd89f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 3 Sep 2012 21:42:31 +0530 Subject: [PATCH] MTP: Fix last modified date not getting read correctly on windows --- setup/extensions.py | 2 +- src/calibre/devices/mtp/filesystem_cache.py | 5 ++++- .../mtp/windows/content_enumeration.cpp | 12 +++++++++-- src/calibre/devices/mtp/windows/remote.py | 20 +++++++++---------- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/setup/extensions.py b/setup/extensions.py index f4ed22687b..f7d40ca72c 100644 --- a/setup/extensions.py +++ b/setup/extensions.py @@ -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'] ), diff --git a/src/calibre/devices/mtp/filesystem_cache.py b/src/calibre/devices/mtp/filesystem_cache.py index d8c5170e59..8f4d20ae18 100644 --- a/src/calibre/devices/mtp/filesystem_cache.py +++ b/src/calibre/devices/mtp/filesystem_cache.py @@ -37,7 +37,10 @@ class FileOrFolder(object): self.size = entry.get('size', 0) md = entry.get('modified', 0) try: - self.last_modified = datetime.fromtimestamp(md, local_tz) + 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) self.last_mod_string = self.last_modified.strftime('%Y/%m/%d %H:%M') diff --git a/src/calibre/devices/mtp/windows/content_enumeration.cpp b/src/calibre/devices/mtp/windows/content_enumeration.cpp index 7186bbdcdb..580f77f9b0 100644 --- a/src/calibre/devices/mtp/windows/content_enumeration.cpp +++ b/src/calibre/devices/mtp/windows/content_enumeration.cpp @@ -84,11 +84,19 @@ 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 (t != NULL) { PyDict_SetItemString(dict, pykey, t); Py_DECREF(t); } + 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); } + } } } diff --git a/src/calibre/devices/mtp/windows/remote.py b/src/calibre/devices/mtp/windows/remote.py index cbc23978d2..f1dfa92767 100644 --- a/src/calibre/devices/mtp/windows/remote.py +++ b/src/calibre/devices/mtp/windows/remote.py @@ -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()