Remove building with NOCRYPTO option
[minix.git] / external / bsd / bind / dist / bin / win32 / BINDInstall / VersionInfo.cpp
blobe940e9e042291c25decd0e68d85a1cba25e62fce
1 // VersionInfo.cpp: implementation of the CVersionInfo class.
2 //
3 //////////////////////////////////////////////////////////////////////
5 #include "stdafx.h"
6 #include "bindinstall.h"
7 #include "VersionInfo.h"
8 #include <winver.h>
10 #ifdef _DEBUG
11 #undef THIS_FILE
12 static char THIS_FILE[]=__FILE__;
13 #define new DEBUG_NEW
14 #endif
16 //////////////////////////////////////////////////////////////////////
17 // Construction/Destruction
18 //////////////////////////////////////////////////////////////////////
20 CVersionInfo::CVersionInfo(CString filename)
22 HANDLE hFile;
23 WIN32_FIND_DATA fd;
24 memset(&fd, 0, sizeof(WIN32_FIND_DATA));
26 m_status = ERROR_SUCCESS;
27 m_isValid = FALSE;
28 m_filename = filename;
30 // See if the given file exists
31 hFile = FindFirstFile(filename, &fd);
32 if(hFile == INVALID_HANDLE_VALUE)
34 m_status = ERROR_FILE_NOT_FOUND;
35 m_versionInfo = NULL;
36 return;
38 FindClose(hFile);
40 // Extract the file info
41 DWORD handle;
42 DWORD viSize = GetFileVersionInfoSize((LPTSTR)(LPCTSTR)filename, &handle);
43 m_versionInfo = NULL;
45 if(viSize == 0)
47 m_status = GetLastError();
49 else
51 m_versionInfo = new char[viSize];
53 // Get the block of version info from the file
54 if(!GetFileVersionInfo((LPTSTR)(LPCTSTR)filename, handle, viSize, m_versionInfo))
56 if(m_versionInfo)
58 delete [] m_versionInfo;
59 m_versionInfo = NULL;
61 return;
64 // Now extract the sub block we are interested in
65 UINT versionLen = 0;
66 LPVOID viBlob = NULL;
67 if(!VerQueryValue(m_versionInfo, "\\", &viBlob, &versionLen))
69 if(m_versionInfo)
71 delete [] m_versionInfo;
72 m_versionInfo = NULL;
74 return;
77 // And finally the version info is ours
78 m_fixedInfo = (VS_FIXEDFILEINFO *)viBlob;
80 UINT blobLen = 0;
82 // If we got here, all is good
84 m_isValid = TRUE;
87 CVersionInfo::~CVersionInfo()
89 m_fixedInfo = NULL;
90 if(m_versionInfo)
92 delete [] m_versionInfo;
93 m_versionInfo = NULL;
97 CString CVersionInfo::GetFileVersionString()
99 return(QueryStringValue("FileVersion"));
102 CString CVersionInfo::GetProductVersionString()
104 return(QueryStringValue("ProductVersion"));
107 CString CVersionInfo::GetComments()
109 return(QueryStringValue("Comments"));
112 CString CVersionInfo::GetFileDescription()
114 return(QueryStringValue("FileDescription"));
117 CString CVersionInfo::GetInternalName()
119 return(QueryStringValue("InternalName"));
122 CString CVersionInfo::GetLegalCopyright()
124 return(QueryStringValue("LegalCopyright"));
127 CString CVersionInfo::GetLegalTrademarks()
129 return(QueryStringValue("LegalTrademarks"));
132 CString CVersionInfo::GetOriginalFileName()
134 return(QueryStringValue("OriginalFilename"));
137 CString CVersionInfo::GetProductName()
139 return(QueryStringValue("ProductName"));
142 CString CVersionInfo::GetSpecialBuildString()
144 return(QueryStringValue("SpecialBuild"));
147 CString CVersionInfo::GetPrivateBuildString()
149 return(QueryStringValue("PrivateBuild"));
152 CString CVersionInfo::GetCompanyName()
154 return(QueryStringValue("CompanyName"));
157 #ifdef NOTUSED
158 BOOL CVersionInfo::CopyFileCheckVersion(CVersionInfo &originalFile)
160 _int64 myVer = GetFileVersion();
161 _int64 origVer = originalFile.GetFileVersion();
163 if(origVer > myVer)
165 CString msg;
166 msg.Format(IDS_EXISTING_NEWER, m_filename);
167 DWORD query = AfxMessageBox(msg, MB_YESNO);
168 if(query == IDNO)
169 return(TRUE);
172 return(CopyFileNoVersion(originalFile));
174 #endif
176 BOOL CVersionInfo::CopyFileNoVersion(CVersionInfo &originalFile)
178 int x = 7;
179 return(CopyFile(originalFile.GetFilename(), m_filename, FALSE));
183 _int64 CVersionInfo::GetFileVersion()
185 _int64 ver = 0;
187 if(m_versionInfo)
189 ver = m_fixedInfo->dwFileVersionMS;
190 ver <<= 32;
191 ver += m_fixedInfo->dwFileVersionLS;
193 return(ver);
196 _int64 CVersionInfo::GetProductVersion()
198 _int64 ver = 0;
200 if(m_versionInfo)
202 ver = m_fixedInfo->dwProductVersionMS;
203 ver <<= 32;
204 ver += m_fixedInfo->dwProductVersionLS;
206 return(ver);
209 _int64 CVersionInfo::GetFileDate()
211 _int64 fDate = 0;
213 if(m_versionInfo)
215 fDate = m_fixedInfo->dwFileDateMS;
216 fDate <<= 32;
217 fDate += m_fixedInfo->dwFileDateLS;
219 return(fDate);
222 DWORD CVersionInfo::GetFileFlagMask()
224 if(m_versionInfo)
226 return(m_fixedInfo->dwFileFlagsMask);
228 return(0);
231 DWORD CVersionInfo::GetFileFlags()
233 if(m_versionInfo)
235 return(m_fixedInfo->dwFileFlags);
237 return(0);
240 DWORD CVersionInfo::GetFileOS()
242 if(m_versionInfo)
244 return(m_fixedInfo->dwFileOS);
246 return(VOS_UNKNOWN);
249 DWORD CVersionInfo::GetFileType()
251 if(m_versionInfo)
253 return(m_fixedInfo->dwFileType);
255 return(VFT_UNKNOWN);
258 DWORD CVersionInfo::GetFileSubType()
260 if(m_versionInfo)
262 return(m_fixedInfo->dwFileSubtype);
264 return(VFT2_UNKNOWN);
267 CString CVersionInfo::QueryStringValue(CString value)
269 UINT blobLen = 0;
270 LPVOID viBlob = NULL;
272 if(m_versionInfo)
274 char queryString[256];
276 // This code page value is for American English. If you change the resources to be other than that
277 // You probably should change this to match it.
278 DWORD codePage = 0x040904B0;
280 sprintf(queryString, "\\StringFileInfo\\%08X\\%s", codePage, value);
282 if(VerQueryValue(m_versionInfo, queryString, &viBlob, &blobLen))
283 return((char *)viBlob);
285 return("Not Available");