mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
MTP: Fix last modified date not getting read correctly on windows
This commit is contained in:
parent
f36feac5ba
commit
f07002fdd2
@ -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']
|
||||
),
|
||||
|
@ -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')
|
||||
|
@ -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); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user