diff --git a/deluge/common.py b/deluge/common.py index c32238f3c..1fd2c652c 100644 --- a/deluge/common.py +++ b/deluge/common.py @@ -718,3 +718,27 @@ class VersionSplit(object): v1 = [self.version, self.suffix or 'z', self.dev] v2 = [ver.version, ver.suffix or 'z', ver.dev] 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)] diff --git a/deluge/main.py b/deluge/main.py index f8953d2a1..01744f4c3 100644 --- a/deluge/main.py +++ b/deluge/main.py @@ -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) # 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 if options.quiet: diff --git a/deluge/ui/gtkui/ipcinterface.py b/deluge/ui/gtkui/ipcinterface.py index 03c281c48..f10345314 100644 --- a/deluge/ui/gtkui/ipcinterface.py +++ b/deluge/ui/gtkui/ipcinterface.py @@ -211,7 +211,7 @@ def process_args(args): log.debug("Attempting to add file (%s) from external source...", arg) if urlparse(arg).scheme == "file": 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): log.error("No such file: %s", path) diff --git a/deluge/ui/ui.py b/deluge/ui/ui.py index 2662543e8..17f08f613 100644 --- a/deluge/ui/ui.py +++ b/deluge/ui/ui.py @@ -99,7 +99,10 @@ class _UI(object): return self.__args 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: self.__options.loglevel = "none"