Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/cpp/iedriver/FileUtilities.cpp
2867 views
1
// Licensed to the Software Freedom Conservancy (SFC) under one
2
// or more contributor license agreements. See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership. The SFC licenses this file
5
// to you under the Apache License, Version 2.0 (the "License");
6
// you may not use this file except in compliance with the License.
7
// You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing, software
12
// distributed under the License is distributed on an "AS IS" BASIS,
13
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
// See the License for the specific language governing permissions and
15
// limitations under the License.
16
17
#include "FileUtilities.h"
18
#include "StringUtilities.h"
19
20
#define FILE_LANGUAGE_INFO L"\\VarFileInfo\\Translation"
21
#define FILE_VERSION_INFO L"\\StringFileInfo\\%04x%04x\\FileVersion"
22
23
namespace webdriver {
24
25
FileUtilities::FileUtilities(void) {
26
}
27
28
FileUtilities::~FileUtilities(void) {
29
}
30
31
std::string FileUtilities::GetFileVersion(const std::string& file_name) {
32
return GetFileVersion(StringUtilities::ToWString(file_name));
33
}
34
35
std::string FileUtilities::GetFileVersion(const std::wstring& file_name) {
36
struct LANGANDCODEPAGE {
37
WORD language;
38
WORD code_page;
39
} *language_info;
40
41
DWORD dummy = 0;
42
DWORD length = ::GetFileVersionInfoSize(file_name.c_str(), &dummy);
43
if (length == 0) {
44
return "";
45
}
46
47
std::vector<char> version_buffer(length);
48
::GetFileVersionInfo(file_name.c_str(),
49
0, /* ignored */
50
length,
51
&version_buffer[0]);
52
53
UINT page_count;
54
BOOL query_result = ::VerQueryValue(&version_buffer[0],
55
FILE_LANGUAGE_INFO,
56
reinterpret_cast<void**>(&language_info),
57
&page_count);
58
59
std::vector<wchar_t> sub_block(MAX_PATH);
60
_snwprintf_s(&sub_block[0],
61
MAX_PATH,
62
MAX_PATH,
63
FILE_VERSION_INFO,
64
language_info->language,
65
language_info->code_page);
66
std::wstring sub_block_string = &sub_block[0];
67
68
void* value = NULL;
69
unsigned int size;
70
query_result = ::VerQueryValue(&version_buffer[0],
71
sub_block_string.c_str(),
72
&value,
73
&size);
74
std::wstring wide_version;
75
wide_version.assign(static_cast<wchar_t*>(value));
76
std::string version = StringUtilities::ToString(wide_version);
77
return version;
78
}
79
80
} // namespace webdriver
81