~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/win32utils.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-06-27 00:29:53 UTC
  • mfrom: (4487.1.1 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20090627002953-q4333x7hfvw1q3wz
(igc) Teach get_app_path to read wordpad.exe (Alexander Belchenko)

Show diffs side-by-side

added added

removed removed

Lines of Context:
96
96
UNLEN = 256
97
97
MAX_COMPUTERNAME_LENGTH = 31
98
98
 
 
99
# Registry data type ids
 
100
REG_SZ = 1
 
101
REG_EXPAND_SZ = 2
 
102
 
99
103
 
100
104
def debug_memory_win32api(message='', short=True):
101
105
    """Use trace.note() to dump the running memory info."""
462
466
                or appname itself if nothing found.
463
467
    """
464
468
    import _winreg
 
469
 
 
470
    basename = appname
 
471
    if not os.path.splitext(basename)[1]:
 
472
        basename = appname + '.exe'
 
473
 
465
474
    try:
466
475
        hkey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,
467
 
                               r'SOFTWARE\Microsoft\Windows'
468
 
                               r'\CurrentVersion\App Paths')
 
476
            'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\' +
 
477
            basename)
469
478
    except EnvironmentError:
470
479
        return appname
471
480
 
472
 
    basename = appname
473
 
    if not os.path.splitext(basename)[1]:
474
 
        basename = appname + '.exe'
475
481
    try:
476
482
        try:
477
 
            fullpath = _winreg.QueryValue(hkey, basename)
 
483
            path, type_id = _winreg.QueryValueEx(hkey, '')
478
484
        except WindowsError:
479
 
            fullpath = appname
 
485
            return appname
480
486
    finally:
481
487
        _winreg.CloseKey(hkey)
482
488
 
483
 
    return fullpath
 
489
    if type_id == REG_SZ:
 
490
        return path
 
491
    if type_id == REG_EXPAND_SZ and has_win32api:
 
492
        fullpath = win32api.ExpandEnvironmentStrings(path)
 
493
        if len(fullpath) > 1 and fullpath[0] == '"' and fullpath[-1] == '"':
 
494
            fullpath = fullpath[1:-1]   # remove quotes around value
 
495
        return fullpath
 
496
    return appname
484
497
 
485
498
 
486
499
def set_file_attr_hidden(path):