268
273
Returned value can be unicode or plain string.
269
274
To convert plain string to unicode use
270
s.decode(bzrlib.user_encoding)
275
s.decode(osutils.get_user_encoding())
271
276
(XXX - but see bug 262874, which asserts the correct encoding is 'mbcs')
273
278
local = _get_sh_special_folder_path(CSIDL_LOCAL_APPDATA)
463
467
or appname itself if nothing found.
472
if not os.path.splitext(basename)[1]:
473
basename = appname + '.exe'
467
476
hkey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,
468
r'SOFTWARE\Microsoft\Windows'
469
r'\CurrentVersion\App Paths')
477
'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\' +
470
479
except EnvironmentError:
474
if not os.path.splitext(basename)[1]:
475
basename = appname + '.exe'
478
fullpath = _winreg.QueryValue(hkey, basename)
484
path, type_id = _winreg.QueryValueEx(hkey, '')
479
485
except WindowsError:
482
488
_winreg.CloseKey(hkey)
490
if type_id == REG_SZ:
492
if type_id == REG_EXPAND_SZ and has_win32api:
493
fullpath = win32api.ExpandEnvironmentStrings(path)
494
if len(fullpath) > 1 and fullpath[0] == '"' and fullpath[-1] == '"':
495
fullpath = fullpath[1:-1] # remove quotes around value
487
500
def set_file_attr_hidden(path):
488
501
"""Set file attributes to hidden if possible"""
489
502
if has_win32file:
490
win32file.SetFileAttributes(path, win32file.FILE_ATTRIBUTE_HIDDEN)
503
if winver != 'Windows 98':
504
SetFileAttributes = win32file.SetFileAttributesW
506
SetFileAttributes = win32file.SetFileAttributes
508
SetFileAttributes(path, win32file.FILE_ATTRIBUTE_HIDDEN)
509
except pywintypes.error, e:
510
from bzrlib import trace
511
trace.mutter('Unable to set hidden attribute on %r: %s', path, e)
514
if has_ctypes and winver != 'Windows 98':
515
def get_unicode_argv():
516
LPCWSTR = ctypes.c_wchar_p
518
POINTER = ctypes.POINTER
519
prototype = ctypes.WINFUNCTYPE(LPCWSTR)
520
GetCommandLine = prototype(("GetCommandLineW",
521
ctypes.windll.kernel32))
522
prototype = ctypes.WINFUNCTYPE(POINTER(LPCWSTR), LPCWSTR, POINTER(INT))
523
CommandLineToArgv = prototype(("CommandLineToArgvW",
524
ctypes.windll.shell32))
526
pargv = CommandLineToArgv(GetCommandLine(), ctypes.byref(c))
527
# Skip the first argument, since we only care about parameters
528
argv = [pargv[i] for i in range(1, c.value)]
529
if getattr(sys, 'frozen', None) is None:
530
# Invoked via 'python.exe' which takes the form:
531
# python.exe [PYTHON_OPTIONS] C:\Path\bzr [BZR_OPTIONS]
532
# we need to get only BZR_OPTIONS part,
533
# so let's using sys.argv[1:] as reference to get the tail
535
tail_len = len(sys.argv[1:])
536
ix = len(argv) - tail_len
540
get_unicode_argv = None