From b3a6f25c1c486f02e22373b1cc53df57fc2d5c2b Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Sun, 10 Jan 2021 11:01:30 -0500 Subject: [PATCH] Python 2 gets an old version with no CommandLineToArgv Thanks. --- src/allmydata/windows/fixups.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/allmydata/windows/fixups.py b/src/allmydata/windows/fixups.py index 9fb81bdff..2cdb1ad93 100644 --- a/src/allmydata/windows/fixups.py +++ b/src/allmydata/windows/fixups.py @@ -13,12 +13,30 @@ def get_argv(): shape. """ # - from win32api import ( + from win32ui import ( GetCommandLine, - CommandLineToArgv, ) - return CommandLineToArgv(GetCommandLine()) + from ctypes import WINFUNCTYPE, WinError, windll, POINTER, byref, c_int, get_last_error + from ctypes.wintypes import LPWSTR, LPCWSTR + + # + CommandLineToArgvW = WINFUNCTYPE( + POINTER(LPWSTR), LPCWSTR, POINTER(c_int), + use_last_error=True + )(("CommandLineToArgvW", windll.shell32)) + + argc = c_int(0) + argv_unicode = CommandLineToArgvW(GetCommandLine(), byref(argc)) + if argv_unicode is None: + raise WinError(get_last_error()) + + # Convert it to a normal Python list + return list( + argv_unicode[i] + for i + in range(argc.value) + ) def initialize():