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=[ headers=[
'calibre/devices/mtp/windows/global.h', 'calibre/devices/mtp/windows/global.h',
], ],
libraries=['ole32', 'portabledeviceguids', 'user32'], libraries=['ole32', 'oleaut32', 'portabledeviceguids', 'user32'],
# needs_ddk=True, # needs_ddk=True,
cflags=['/X'] cflags=['/X']
), ),

View File

@ -37,7 +37,10 @@ class FileOrFolder(object):
self.size = entry.get('size', 0) self.size = entry.get('size', 0)
md = entry.get('modified', 0) md = entry.get('modified', 0)
try: 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: except:
self.last_modified = datetime.fromtimestamp(0, local_tz) self.last_modified = datetime.fromtimestamp(0, local_tz)
self.last_mod_string = self.last_modified.strftime('%Y/%m/%d %H:%M') self.last_mod_string = self.last_modified.strftime('%Y/%m/%d %H:%M')

View File

@ -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) { static void set_date_property(PyObject *dict, REFPROPERTYKEY key, const char *pykey, IPortableDeviceValues *properties) {
FLOAT val = 0; FLOAT val = 0;
SYSTEMTIME st;
unsigned int microseconds;
PyObject *t; PyObject *t;
if (SUCCEEDED(properties->GetFloatValue(key, &val))) { if (SUCCEEDED(properties->GetFloatValue(key, &val))) {
t = Py_BuildValue("d", (double)val); if (VariantTimeToSystemTime(val, &st)) {
if (t != NULL) { PyDict_SetItemString(dict, pykey, t); Py_DECREF(t); } 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); }
}
} }
} }

View File

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