~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/win32utils.py

  • Committer: John Arbash Meinel
  • Date: 2009-07-29 21:35:05 UTC
  • mfrom: (4576 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4577.
  • Revision ID: john@arbash-meinel.com-20090729213505-tkqsvy1zfpocu75w
Merge bzr.dev 4576 in prep for NEWS

Show diffs side-by-side

added added

removed removed

Lines of Context:
66
66
        suffix = 'W'
67
67
try:
68
68
    import win32file
 
69
    import pywintypes
69
70
    has_win32file = True
70
71
except ImportError:
71
72
    has_win32file = False
96
97
UNLEN = 256
97
98
MAX_COMPUTERNAME_LENGTH = 31
98
99
 
 
100
# Registry data type ids
 
101
REG_SZ = 1
 
102
REG_EXPAND_SZ = 2
 
103
 
99
104
 
100
105
def debug_memory_win32api(message='', short=True):
101
106
    """Use trace.note() to dump the running memory info."""
267
272
 
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')
272
277
    """
273
278
    local = _get_sh_special_folder_path(CSIDL_LOCAL_APPDATA)
462
467
                or appname itself if nothing found.
463
468
    """
464
469
    import _winreg
 
470
 
 
471
    basename = appname
 
472
    if not os.path.splitext(basename)[1]:
 
473
        basename = appname + '.exe'
 
474
 
465
475
    try:
466
476
        hkey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,
467
 
                               r'SOFTWARE\Microsoft\Windows'
468
 
                               r'\CurrentVersion\App Paths')
 
477
            'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\' +
 
478
            basename)
469
479
    except EnvironmentError:
470
480
        return appname
471
481
 
472
 
    basename = appname
473
 
    if not os.path.splitext(basename)[1]:
474
 
        basename = appname + '.exe'
475
482
    try:
476
483
        try:
477
 
            fullpath = _winreg.QueryValue(hkey, basename)
 
484
            path, type_id = _winreg.QueryValueEx(hkey, '')
478
485
        except WindowsError:
479
 
            fullpath = appname
 
486
            return appname
480
487
    finally:
481
488
        _winreg.CloseKey(hkey)
482
489
 
483
 
    return fullpath
 
490
    if type_id == REG_SZ:
 
491
        return path
 
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
 
496
        return fullpath
 
497
    return appname
484
498
 
485
499
 
486
500
def set_file_attr_hidden(path):
487
501
    """Set file attributes to hidden if possible"""
488
502
    if has_win32file:
489
 
        win32file.SetFileAttributes(path, win32file.FILE_ATTRIBUTE_HIDDEN)
 
503
        if winver != 'Windows 98':
 
504
            SetFileAttributes = win32file.SetFileAttributesW
 
505
        else:
 
506
            SetFileAttributes = win32file.SetFileAttributes
 
507
        try:
 
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)
490
512
 
491
513
 
492
514
if has_ctypes and winver != 'Windows 98':