add skeleton for variant type support
[pywinlite.git] / version.py
blob2c8fd27005b76528d52c1219f3f45c9abfa904f2
1 #Copyright (c) 2008 Vincent Povirk
3 #Permission is hereby granted, free of charge, to any person
4 #obtaining a copy of this software and associated documentation
5 #files (the "Software"), to deal in the Software without
6 #restriction, including without limitation the rights to use,
7 #copy, modify, merge, publish, distribute, sublicense, and/or sell
8 #copies of the Software, and to permit persons to whom the
9 #Software is furnished to do so, subject to the following
10 #conditions:
12 #The above copyright notice and this permission notice shall be
13 #included in all copies or substantial portions of the Software.
15 #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 #EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17 #OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 #NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 #HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 #WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 #FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 #OTHER DEALINGS IN THE SOFTWARE.
24 # Version Information definitions
25 # see http://msdn.microsoft.com/en-us/library/ms646981(VS.85).aspx
27 from ctypes import windll, byref, create_string_buffer
28 from winlitecfg import get_aw_symbols
29 from winliteutils import NONZERO, get_symbols, ERRFLAGS
30 from windef import LPCTSTR, DWORD, LPVOID, LPCTSTR, LPCSTR, LPTSTR, PUINT, MAX_PATH, create_tchar_buffer, LPDWORD, LPCVOID, UINT
32 _version = windll.version
33 _kernel32 = windll.kernel32
35 FILE_VER_GET_LOCALISED = 1
36 FILE_VER_GET_NEUTRAL = 2
38 VIF_TEMPFILE = 0x00000001
39 VIF_MISMATCH = 0x00000002
40 VIF_SRCOLD = 0x00000004
41 VIF_DIFFLANG = 0x00000008
42 VIF_DIFFCODEPG = 0x00000010
43 VIF_DIFFTYPE = 0x00000020
44 VIF_WRITEPROT = 0x00000040
45 VIF_FILEINUSE = 0x00000080
46 VIF_OUTOFSPACE = 0x00000100
47 VIF_ACCESSVIOLATION = 0x00000200
48 VIF_SHARINGVIOLATION = 0x00000400
49 VIF_CANNOTCREATE = 0x00000800
50 VIF_CANNOTDELETE = 0x00001000
51 VIF_CANNOTRENAME = 0x00002000
52 VIF_CANNOTDELETECUR = 0x00004000
53 VIF_OUTOFMEMORY = 0x00008000
54 VIF_CANNOTREADSRC = 0x00010000
55 VIF_CANNOTREADDST = 0x00020000
56 VIF_BUFFTOOSMALL = 0x00040000
58 VIFF_FORCEINSTALL = 1
59 VIFF_DONTDELETEOLD = 1
61 VFF_CURNEDEST = 1
62 VFF_FILEINUSE = 2
63 VFF_BUFFTOOSMALL = 4
65 VFFF_ISSHAREDFILE = 1
67 get_aw_symbols(globals(), _version, ['GetFileVersionInfo', 'GetFileVersionInfoSize', 'VerFindFile', 'VerInstallFile', 'VerQueryValue'])
69 GetFileVersionInfoSize.argtypes = [LPCTSTR, LPDWORD]
70 GetFileVersionInfoSize.restype = NONZERO
71 _GetFileVersionInfoSize = GetFileVersionInfoSize
72 def GetFileVersionInfoSize(filename):
73 handle = DWORD()
74 return _GetFileVersionInfoSize(filename, byref(handle))
76 GetFileVersionInfo.argtypes = [LPCTSTR, DWORD, DWORD, LPVOID]
77 GetFileVersionInfo.restype = NONZERO
78 _GetFileVersionInfo = GetFileVersionInfo
79 def GetFileVersionInfo(filename, bytes=None):
80 if bytes is None:
81 bytes = GetFileVersionInfoSize(filename)
82 result = create_string_buffer(bytes)
83 _GetFileVersionInfo(filename, 0, bytes, result)
84 return result
86 VerFindFile.argtypes = [DWORD, LPCTSTR, LPCTSTR, LPCTSTR, LPCSTR, PUINT, LPTSTR, PUINT]
87 _VerFindFile = VerFindFile
88 def VerFindFile(flags, filename, windir, appdir, curdirlen=MAX_PATH, destdirlen=MAX_PATH):
89 curdir = create_string_buffer(curdirlen)
90 destdir = create_tchar_buffer(destdirlen)
91 curdirlen = UINT(curdirlen)
92 destdirlen = UINT(destdirlen)
93 ret = _VerFindFile(flags, filename, windir, appdir, curdir, byref(curdirlen), destdir, byref(destdirlen))
94 return ret, curdir.value, destdir.value
96 VerInstallFile.argtypes = [DWORD, LPCTSTR, LPCTSTR, LPCTSTR, LPCTSTR, LPCTSTR, LPTSTR, PUINT]
97 VerInstallFile.restype = ERRFLAGS(globals(), 'VIF_')
98 _VerInstallFile = VerInstallFile
99 def VerInstallFile(flags, srcfilename, destfilename, srcdir, destdir, curdir, tmpfilelen=MAX_PATH):
100 tmpfile = create_tchar_buffer(tmpfilelen)
101 tmpfilelen = UINT(tmpfilelen)
102 _VerInstallFile(flags, srcfilename, destfilename, srcdir, destdir, curdir, tmpfile, byref(tmpfilelen))
103 return tmpfile.value
105 VerQueryValue.argtypes = [LPCVOID, LPCTSTR, LPVOID, PUINT]
106 _VerQueryValue = VerQueryValue
107 def VerQueryValue(block, subblock):
108 ppbuffer = LPVOID()
109 len = UINT()
110 _VerQueryValue(block, subblock, byref(ppbuffer), byref(len))
111 return ppbuffer.value, len.value
113 get_aw_symbols(globals(), _kernel32, ['VerLanguageName'])
115 VerLanguageName.argtypes = [DWORD, LPTSTR, DWORD]
116 VerLanguageName.restype = NONZERO
117 _VerLanguageName = VerLanguageName
118 def VerLanguageName(langid, langsize=None):
119 if langsize is None:
120 langsize = _VerLanguageName(langid, 0, 0)
121 lang = create_tchar_buffer(langsize)
122 _VerLanguageName(langid, lang, langsize)
123 return lang.value
125 try:
126 #requires windows vista
127 get_symbols(globals(), _version, ['GetFileVersionInfoEx', 'GetFileVersionInfoSizeEx'])
128 except AttributeError:
129 pass
130 else:
131 GetFileVersionInfoSizeEx.argtypes = [DWORD, LPCTSTR, LPDWORD]
132 GetFileVersionInfoSizeEx.restype = NONZERO
133 _GetFileVersionInfoSizeEx = GetFileVersionInfoSizeEx
134 def GetFileVersionInfoSizeEx(flags, filename):
135 handle = DWORD()
136 return _GetFileVersionInfoSizeEx(flags, filename, byref(handle))
138 GetFileVersionInfoEx.argtypes = [DWORD, LPCTSTR, DWORD, DWORD, LPVOID]
139 GetFileVersionInfoEx.restype = NONZERO
140 _GetFileVersionInfoEx = GetFileVersionInfoEx
141 def GetFileVersionInfoEx(flags, filename, bytes=None):
142 if bytes is None:
143 bytes = GetFileVersionInfoSizeEx(flags, filename)
144 result = create_string_buffer(bytes)
145 _GetFileVersionInfoEx(flags, filename, 0, bytes, result)
146 return result