273
268
Returned value can be unicode or plain string.
274
269
To convert plain string to unicode use
275
s.decode(osutils.get_user_encoding())
270
s.decode(bzrlib.user_encoding)
276
271
(XXX - but see bug 262874, which asserts the correct encoding is 'mbcs')
278
273
local = _get_sh_special_folder_path(CSIDL_LOCAL_APPDATA)
467
463
or appname itself if nothing found.
467
hkey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,
468
r'SOFTWARE\Microsoft\Windows'
469
r'\CurrentVersion\App Paths')
470
except EnvironmentError:
471
473
basename = appname
472
474
if not os.path.splitext(basename)[1]:
473
475
basename = appname + '.exe'
476
hkey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,
477
'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\' +
479
except EnvironmentError:
484
path, type_id = _winreg.QueryValueEx(hkey, '')
478
fullpath = _winreg.QueryValue(hkey, basename)
485
479
except WindowsError:
488
482
_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
500
487
def set_file_attr_hidden(path):
501
488
"""Set file attributes to hidden if possible"""
502
489
if has_win32file:
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
490
win32file.SetFileAttributes(path, win32file.FILE_ATTRIBUTE_HIDDEN)