1 // VersionInfo.cpp: implementation of the CVersionInfo class.
3 //////////////////////////////////////////////////////////////////////
6 #include "bindinstall.h"
7 #include "VersionInfo.h"
12 static char THIS_FILE
[]=__FILE__
;
16 //////////////////////////////////////////////////////////////////////
17 // Construction/Destruction
18 //////////////////////////////////////////////////////////////////////
20 CVersionInfo::CVersionInfo(CString filename
)
24 memset(&fd
, 0, sizeof(WIN32_FIND_DATA
));
26 m_status
= ERROR_SUCCESS
;
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
;
40 // Extract the file info
42 DWORD viSize
= GetFileVersionInfoSize((LPTSTR
)(LPCTSTR
)filename
, &handle
);
47 m_status
= GetLastError();
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
))
58 delete [] m_versionInfo
;
64 // Now extract the sub block we are interested in
67 if(!VerQueryValue(m_versionInfo
, "\\", &viBlob
, &versionLen
))
71 delete [] m_versionInfo
;
77 // And finally the version info is ours
78 m_fixedInfo
= (VS_FIXEDFILEINFO
*)viBlob
;
82 // If we got here, all is good
87 CVersionInfo::~CVersionInfo()
92 delete [] m_versionInfo
;
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"));
158 BOOL
CVersionInfo::CopyFileCheckVersion(CVersionInfo
&originalFile
)
160 _int64 myVer
= GetFileVersion();
161 _int64 origVer
= originalFile
.GetFileVersion();
166 msg
.Format(IDS_EXISTING_NEWER
, m_filename
);
167 DWORD query
= AfxMessageBox(msg
, MB_YESNO
);
172 return(CopyFileNoVersion(originalFile
));
176 BOOL
CVersionInfo::CopyFileNoVersion(CVersionInfo
&originalFile
)
179 return(CopyFile(originalFile
.GetFilename(), m_filename
, FALSE
));
183 _int64
CVersionInfo::GetFileVersion()
189 ver
= m_fixedInfo
->dwFileVersionMS
;
191 ver
+= m_fixedInfo
->dwFileVersionLS
;
196 _int64
CVersionInfo::GetProductVersion()
202 ver
= m_fixedInfo
->dwProductVersionMS
;
204 ver
+= m_fixedInfo
->dwProductVersionLS
;
209 _int64
CVersionInfo::GetFileDate()
215 fDate
= m_fixedInfo
->dwFileDateMS
;
217 fDate
+= m_fixedInfo
->dwFileDateLS
;
222 DWORD
CVersionInfo::GetFileFlagMask()
226 return(m_fixedInfo
->dwFileFlagsMask
);
231 DWORD
CVersionInfo::GetFileFlags()
235 return(m_fixedInfo
->dwFileFlags
);
240 DWORD
CVersionInfo::GetFileOS()
244 return(m_fixedInfo
->dwFileOS
);
249 DWORD
CVersionInfo::GetFileType()
253 return(m_fixedInfo
->dwFileType
);
258 DWORD
CVersionInfo::GetFileSubType()
262 return(m_fixedInfo
->dwFileSubtype
);
264 return(VFT2_UNKNOWN
);
267 CString
CVersionInfo::QueryStringValue(CString value
)
270 LPVOID viBlob
= NULL
;
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");