mirror of
https://github.com/arsenetar/send2trash.git
synced 2026-01-25 16:11:39 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7d38de269a | ||
| 5733670fc2 |
@@ -1,6 +1,11 @@
|
|||||||
Changes
|
Changes
|
||||||
=======
|
=======
|
||||||
|
|
||||||
|
Version 1.4.2 -- 2017/11/17
|
||||||
|
---------------------------
|
||||||
|
|
||||||
|
* Fix incompatibility with Python 3.6 on Windows. (#18)
|
||||||
|
|
||||||
Version 1.4.1 -- 2017/08/07
|
Version 1.4.1 -- 2017/08/07
|
||||||
---------------------------
|
---------------------------
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,8 @@
|
|||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from ctypes import windll, Structure, byref, c_uint
|
from ctypes import (windll, Structure, byref, c_uint,
|
||||||
|
create_unicode_buffer, sizeof, addressof)
|
||||||
from ctypes.wintypes import HWND, UINT, LPCWSTR, BOOL
|
from ctypes.wintypes import HWND, UINT, LPCWSTR, BOOL
|
||||||
import os.path as op
|
import os.path as op
|
||||||
|
|
||||||
@@ -46,7 +47,19 @@ def send2trash(path):
|
|||||||
fileop = SHFILEOPSTRUCTW()
|
fileop = SHFILEOPSTRUCTW()
|
||||||
fileop.hwnd = 0
|
fileop.hwnd = 0
|
||||||
fileop.wFunc = FO_DELETE
|
fileop.wFunc = FO_DELETE
|
||||||
fileop.pFrom = LPCWSTR(path + '\0')
|
# FIX: https://github.com/hsoft/send2trash/issues/17
|
||||||
|
# Starting in python 3.6.3 it is no longer possible to use:
|
||||||
|
# LPCWSTR(path + '\0') directly as embedded null characters are no longer
|
||||||
|
# allowed in strings
|
||||||
|
# Workaround
|
||||||
|
# - create buffer of c_wchar[] (LPCWSTR is based on this type)
|
||||||
|
# - buffer is two c_wchar characters longer (double null terminator)
|
||||||
|
# - cast the address of the buffer to a LPCWSTR
|
||||||
|
# NOTE: based on how python allocates memory for these types they should
|
||||||
|
# always be zero, if this is ever not true we can go back to explicitly
|
||||||
|
# setting the last two characters to null using buffer[index] = '\0'.
|
||||||
|
buffer = create_unicode_buffer(path, len(path)+2)
|
||||||
|
fileop.pFrom = LPCWSTR(addressof(buffer))
|
||||||
fileop.pTo = None
|
fileop.pTo = None
|
||||||
fileop.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT
|
fileop.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT
|
||||||
fileop.fAnyOperationsAborted = 0
|
fileop.fAnyOperationsAborted = 0
|
||||||
|
|||||||
2
setup.py
2
setup.py
@@ -19,7 +19,7 @@ LONG_DESCRIPTION = open('README.rst', 'rt').read() + '\n\n' + open('CHANGES.rst'
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='Send2Trash',
|
name='Send2Trash',
|
||||||
version='1.4.1',
|
version='1.4.2',
|
||||||
author='Virgil Dupras',
|
author='Virgil Dupras',
|
||||||
author_email='hsoft@hardcoded.net',
|
author_email='hsoft@hardcoded.net',
|
||||||
packages=['send2trash'],
|
packages=['send2trash'],
|
||||||
|
|||||||
Reference in New Issue
Block a user