mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -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=[
|
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']
|
||||||
),
|
),
|
||||||
|
@ -37,6 +37,9 @@ 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:
|
||||||
|
if isinstance(md, tuple):
|
||||||
|
self.last_modified = datetime(*(list(md)+[local_tz]))
|
||||||
|
else:
|
||||||
self.last_modified = datetime.fromtimestamp(md, local_tz)
|
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)
|
||||||
|
@ -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) {
|
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)) {
|
||||||
|
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); }
|
if (t != NULL) { PyDict_SetItemString(dict, pykey, t); Py_DECREF(t); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void set_content_type_property(PyObject *dict, IPortableDeviceValues *properties) {
|
static void set_content_type_property(PyObject *dict, IPortableDeviceValues *properties) {
|
||||||
GUID guid = GUID_NULL;
|
GUID guid = GUID_NULL;
|
||||||
|
@ -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()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user