/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/win32utils.py

  • Committer: John Arbash Meinel
  • Date: 2009-07-08 14:37:25 UTC
  • mfrom: (4516 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4517.
  • Revision ID: john@arbash-meinel.com-20090708143725-sc9sjy3mz4cxwxzz
Merge bzr.dev 4516

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."""
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':