Index: src/installer-ca/dutil/fileutil.cpp |
=================================================================== |
new file mode 100644 |
--- /dev/null |
+++ b/src/installer-ca/dutil/fileutil.cpp |
@@ -0,0 +1,61 @@ |
+//------------------------------------------------------------------------------------------------- |
+// <copyright file="fileutil.cpp" company="Outercurve Foundation"> |
+// Copyright (c) 2004, Outercurve Foundation. |
+// This software is released under Microsoft Reciprocal License (MS-RL). |
+// The license and further copyright text can be found in the file |
+// LICENSE.TXT at the root directory of the distribution. |
+// </copyright> |
+// |
+// <summary> |
+// File helper functions. |
+// </summary> |
+//------------------------------------------------------------------------------------------------- |
+ |
+#include "../precomp.h" |
+ |
+/******************************************************************* |
+ FileVersion |
+ |
+********************************************************************/ |
+extern "C" HRESULT DAPI FileVersion( |
+ __in LPCWSTR wzFilename, |
+ __out DWORD *pdwVerMajor, |
+ __out DWORD* pdwVerMinor |
+ ) |
+{ |
+ HRESULT hr = S_OK; |
+ |
+ DWORD dwHandle = 0; |
+ UINT cbVerBuffer = 0; |
+ LPVOID pVerBuffer = NULL; |
+ VS_FIXEDFILEINFO* pvsFileInfo = NULL; |
+ UINT cbFileInfo = 0; |
+ |
+ if (0 == (cbVerBuffer = ::GetFileVersionInfoSizeW(wzFilename, &dwHandle))) |
+ { |
+ ExitOnLastErrorDebugTrace1(hr, "failed to get version info for file: %ls", wzFilename); |
+ } |
+ |
+ pVerBuffer = ::GlobalAlloc(GMEM_FIXED, cbVerBuffer); |
+ ExitOnNullDebugTrace1(pVerBuffer, hr, E_OUTOFMEMORY, "failed to allocate version info for file: %ls", wzFilename); |
+ |
+ if (!::GetFileVersionInfoW(wzFilename, dwHandle, cbVerBuffer, pVerBuffer)) |
+ { |
+ ExitOnLastErrorDebugTrace1(hr, "failed to get version info for file: %ls", wzFilename); |
+ } |
+ |
+ if (!::VerQueryValueW(pVerBuffer, L"\\", (void**)&pvsFileInfo, &cbFileInfo)) |
+ { |
+ ExitOnLastErrorDebugTrace1(hr, "failed to get version value for file: %ls", wzFilename); |
+ } |
+ |
+ *pdwVerMajor = pvsFileInfo->dwFileVersionMS; |
+ *pdwVerMinor = pvsFileInfo->dwFileVersionLS; |
+ |
+LExit: |
+ if (pVerBuffer) |
+ { |
+ ::GlobalFree(pVerBuffer); |
+ } |
+ return hr; |
+} |