mercurial/win32.py
branchstable
changeset 16759 133a7922a900
parent 15095 ec222a29bdf0
child 16761 07741a5d6608
equal deleted inserted replaced
16748:0a730d3c5aae 16759:133a7922a900
     3 # Copyright 2005-2009 Matt Mackall <mpm@selenic.com> and others
     3 # Copyright 2005-2009 Matt Mackall <mpm@selenic.com> and others
     4 #
     4 #
     5 # This software may be used and distributed according to the terms of the
     5 # This software may be used and distributed according to the terms of the
     6 # GNU General Public License version 2 or any later version.
     6 # GNU General Public License version 2 or any later version.
     7 
     7 
     8 import encoding
       
     9 import ctypes, errno, os, struct, subprocess, random
     8 import ctypes, errno, os, struct, subprocess, random
    10 
     9 
    11 _kernel32 = ctypes.windll.kernel32
    10 _kernel32 = ctypes.windll.kernel32
    12 _advapi32 = ctypes.windll.advapi32
    11 _advapi32 = ctypes.windll.advapi32
    13 _user32 = ctypes.windll.user32
    12 _user32 = ctypes.windll.user32
   288             res = _advapi32.RegQueryValueExA(kh.value, valname, None,
   287             res = _advapi32.RegQueryValueExA(kh.value, valname, None,
   289                                        byref(type), buf, byref(size))
   288                                        byref(type), buf, byref(size))
   290             if res != _ERROR_SUCCESS:
   289             if res != _ERROR_SUCCESS:
   291                 continue
   290                 continue
   292             if type.value == _REG_SZ:
   291             if type.value == _REG_SZ:
   293                 # never let a Unicode string escape into the wild
   292                 # string is in ANSI code page, aka local encoding
   294                 return encoding.tolocal(buf.value.encode('UTF-8'))
   293                 return buf.value
   295             elif type.value == _REG_DWORD:
   294             elif type.value == _REG_DWORD:
   296                 fmt = '<L'
   295                 fmt = '<L'
   297                 s = ctypes.string_at(byref(buf), struct.calcsize(fmt))
   296                 s = ctypes.string_at(byref(buf), struct.calcsize(fmt))
   298                 return struct.unpack(fmt, s)[0]
   297                 return struct.unpack(fmt, s)[0]
   299         finally:
   298         finally: