[#2093] Backport win32_unicode_argv from develop
* Also includes fix for drag'n'drop non-ascii filepaths by decoding after urlparse.
This commit is contained in:
parent
0260e34189
commit
9f3b2f3167
|
@ -718,3 +718,27 @@ class VersionSplit(object):
|
||||||
v1 = [self.version, self.suffix or 'z', self.dev]
|
v1 = [self.version, self.suffix or 'z', self.dev]
|
||||||
v2 = [ver.version, ver.suffix or 'z', ver.dev]
|
v2 = [ver.version, ver.suffix or 'z', ver.dev]
|
||||||
return cmp(v1, v2)
|
return cmp(v1, v2)
|
||||||
|
|
||||||
|
def win32_unicode_argv():
|
||||||
|
""" Gets sys.argv as list of unicode objects on any platform."""
|
||||||
|
if windows_check():
|
||||||
|
# Versions 2.x of Python don't support Unicode in sys.argv on Windows, with the
|
||||||
|
# underlying Windows API instead replacing multi-byte characters with '?'.
|
||||||
|
from ctypes import POINTER, byref, cdll, c_int, windll
|
||||||
|
from ctypes.wintypes import LPCWSTR, LPWSTR
|
||||||
|
|
||||||
|
get_cmd_linew = cdll.kernel32.GetCommandLineW
|
||||||
|
get_cmd_linew.argtypes = []
|
||||||
|
get_cmd_linew.restype = LPCWSTR
|
||||||
|
|
||||||
|
cmdline_to_argvw = windll.shell32.CommandLineToArgvW
|
||||||
|
cmdline_to_argvw.argtypes = [LPCWSTR, POINTER(c_int)]
|
||||||
|
cmdline_to_argvw.restype = POINTER(LPWSTR)
|
||||||
|
|
||||||
|
cmd = get_cmd_linew()
|
||||||
|
argc = c_int(0)
|
||||||
|
argv = cmdline_to_argvw(cmd, byref(argc))
|
||||||
|
if argc.value > 0:
|
||||||
|
# Remove Python executable and commands if present
|
||||||
|
start = argc.value - len(sys.argv)
|
||||||
|
return [argv[i] for i in xrange(start, argc.value)]
|
||||||
|
|
|
@ -86,7 +86,10 @@ def start_ui():
|
||||||
help="Sets the log level to 'none', this is the same as `-L none`", action="store_true", default=False)
|
help="Sets the log level to 'none', this is the same as `-L none`", action="store_true", default=False)
|
||||||
|
|
||||||
# Get the options and args from the OptionParser
|
# Get the options and args from the OptionParser
|
||||||
(options, args) = parser.parse_args()
|
if deluge.common.windows_check():
|
||||||
|
(options, args) = parser.parse_args(deluge.common.win32_unicode_argv()[1:])
|
||||||
|
else:
|
||||||
|
(options, args) = parser.parse_args()
|
||||||
|
|
||||||
# Setup the logger
|
# Setup the logger
|
||||||
if options.quiet:
|
if options.quiet:
|
||||||
|
|
|
@ -211,7 +211,7 @@ def process_args(args):
|
||||||
log.debug("Attempting to add file (%s) from external source...", arg)
|
log.debug("Attempting to add file (%s) from external source...", arg)
|
||||||
if urlparse(arg).scheme == "file":
|
if urlparse(arg).scheme == "file":
|
||||||
arg = url2pathname(urlparse(arg).path)
|
arg = url2pathname(urlparse(arg).path)
|
||||||
path = os.path.abspath(arg)
|
path = os.path.abspath(deluge.common.decode_string(arg))
|
||||||
|
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
log.error("No such file: %s", path)
|
log.error("No such file: %s", path)
|
||||||
|
|
|
@ -99,7 +99,10 @@ class _UI(object):
|
||||||
return self.__args
|
return self.__args
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
(self.__options, self.__args) = self.__parser.parse_args()
|
if deluge.common.windows_check():
|
||||||
|
(self.__options, self.__args) = self.__parser.parse_args(deluge.common.win32_unicode_argv()[1:])
|
||||||
|
else:
|
||||||
|
(self.__options, self.__args) = self.__parser.parse_args()
|
||||||
|
|
||||||
if self.__options.quiet:
|
if self.__options.quiet:
|
||||||
self.__options.loglevel = "none"
|
self.__options.loglevel = "none"
|
||||||
|
|
Loading…
Reference in New Issue