Skip to content
This repository was archived by the owner on Sep 2, 2021. It is now read-only.

Commit 9a12246

Browse files
committed
Move AppGetProductVersionString and AppGetChromiumVersionString in appshell_helpers
1 parent 6710571 commit 9a12246

9 files changed

Lines changed: 105 additions & 102 deletions

appshell/appshell_helpers.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,10 @@ CefString AppGetDocumentsDirectory();
3939
// Returns the default CEF cache location
4040
CefString AppGetCachePath();
4141

42+
// Returns a string containing the product and version (e.g. "Brackets/0.19.0.0")
43+
CefString AppGetProductVersionString();
44+
45+
// Returns a string containing "Chrome/" appends with its version (e.g. "Chrome/29.0.1547.65")
46+
CefString AppGetChromiumVersionString();
47+
4248
} // namespace appshell

appshell/appshell_helpers_gtk.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include "appshell/browser/resource.h"
2727
#include "include/cef_base.h"
28+
#include "include/cef_version.h"
2829

2930
#include <gtk/gtk.h>
3031
#include <pwd.h>
@@ -106,4 +107,14 @@ CefString AppGetCachePath() {
106107
return CefString(cachePath);
107108
}
108109

110+
CefString AppGetProductVersionString() {
111+
// TODO
112+
return CefString("");
113+
}
114+
115+
CefString AppGetChromiumVersionString() {
116+
// TODO
117+
return CefString("");
118+
}
119+
109120
} // namespace appshell

appshell/appshell_helpers_mac.mm

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "appshell/appshell_helpers.h"
2525

2626
#include "include/cef_base.h"
27+
#include "include/cef_version.h"
2728
#include "config.h"
2829
#include <Cocoa/Cocoa.h>
2930

@@ -102,4 +103,25 @@ CefString AppGetCachePath() {
102103
return CefString(cachePath);
103104
}
104105

106+
CefString AppGetProductVersionString() {
107+
NSMutableString *s = [NSMutableString stringWithString:APP_NAME];
108+
[s replaceOccurrencesOfString:@" "
109+
withString:@""
110+
options:NSLiteralSearch
111+
range:NSMakeRange(0, [s length])];
112+
[s appendString:@"/"];
113+
[s appendString:(NSString*)[[NSBundle mainBundle]
114+
objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey]];
115+
CefString result = CefString([s UTF8String]);
116+
return result;
117+
}
118+
119+
CefString AppGetChromiumVersionString() {
120+
NSMutableString *s = [NSMutableString stringWithFormat:@"Chrome/%d.%d.%d.%d",
121+
cef_version_info(2), cef_version_info(3),
122+
cef_version_info(4), cef_version_info(5)];
123+
CefString result = CefString([s UTF8String]);
124+
return result;
125+
}
126+
105127
} // namespace appshell

appshell/appshell_helpers_win.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include "appshell/browser/resource.h"
2727
#include "include/cef_base.h"
28+
#include "include/cef_version.h"
2829

2930
#include <algorithm>
3031
#include <MMSystem.h>
@@ -122,5 +123,67 @@ CefString AppGetCachePath() {
122123

123124
return CefString(cachePath);
124125
}
126+
// Helper function for AppGetProductVersionString. Reads version info from
127+
// VERSIONINFO and writes it into the passed in std::wstring.
128+
void GetFileVersionString(std::wstring &retVersion) {
129+
DWORD dwSize = 0;
130+
BYTE *pVersionInfo = NULL;
131+
VS_FIXEDFILEINFO *pFileInfo = NULL;
132+
UINT pLenFileInfo = 0;
133+
134+
HMODULE module = GetModuleHandle(NULL);
135+
TCHAR executablePath[MAX_UNC_PATH];
136+
GetModuleFileName(module, executablePath, MAX_UNC_PATH);
137+
138+
dwSize = GetFileVersionInfoSize(executablePath, NULL);
139+
if (dwSize == 0) {
140+
return;
141+
}
142+
143+
pVersionInfo = new BYTE[dwSize];
144+
145+
if (!GetFileVersionInfo(executablePath, 0, dwSize, pVersionInfo)) {
146+
delete[] pVersionInfo;
147+
return;
148+
}
149+
150+
if (!VerQueryValue(pVersionInfo, TEXT("\\"), (LPVOID*) &pFileInfo, &pLenFileInfo)) {
151+
delete[] pVersionInfo;
152+
return;
153+
}
154+
155+
int major = (pFileInfo->dwFileVersionMS >> 16) & 0xffff ;
156+
int minor = (pFileInfo->dwFileVersionMS) & 0xffff;
157+
int hotfix = (pFileInfo->dwFileVersionLS >> 16) & 0xffff;
158+
int other = (pFileInfo->dwFileVersionLS) & 0xffff;
159+
160+
delete[] pVersionInfo;
161+
162+
std::wostringstream versionStream(L"");
163+
versionStream << major << L"." << minor << L"." << hotfix << L"." << other;
164+
retVersion = versionStream.str();
165+
}
166+
167+
CefString AppGetProductVersionString() {
168+
std::wstring s(APP_NAME);
169+
size_t i = s.find(L" ");
170+
while (i != std::wstring::npos) {
171+
s.erase(i, 1);
172+
i = s.find(L" ");
173+
}
174+
std::wstring version(L"");
175+
GetFileVersionString(version);
176+
s.append(L"/");
177+
s.append(version);
178+
return CefString(s);
179+
}
180+
181+
CefString AppGetChromiumVersionString() {
182+
std::wostringstream versionStream(L"");
183+
versionStream << L"Chrome/" << cef_version_info(2) << L"." << cef_version_info(3)
184+
<< L"." << cef_version_info(4) << L"." << cef_version_info(5);
185+
186+
return CefString(versionStream.str());
187+
}
125188

126189
} // namespace appshell

appshell/cefclient.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "include/base/cef_logging.h"
1717
#include "client_handler.h"
1818
#include "appshell/common/client_switches.h"
19+
#include "appshell/appshell_helpers.h"
1920
#include "config.h"
2021

2122
CefRefPtr<ClientHandler> g_handler;
@@ -95,14 +96,14 @@ void AppGetSettings(CefSettings& settings, CefRefPtr<ClientApp> app) {
9596
// Enable dev tools
9697
settings.remote_debugging_port = REMOTE_DEBUGGING_PORT;
9798

98-
std::wstring versionStr = AppGetProductVersionString();
99+
std::wstring versionStr = appshell::AppGetProductVersionString();
99100

100101
if (!versionStr.empty()) {
101102
// Explicitly append the Chromium version to our own product version string
102103
// since assigning product version always replaces the Chromium version in
103104
// the User Agent string.
104105
versionStr.append(L" ");
105-
versionStr.append(AppGetChromiumVersionString());
106+
versionStr.append(appshell::AppGetChromiumVersionString());
106107

107108
// Set product version, which gets added to the User Agent string
108109
CefString(&settings.product_version) = versionStr;

appshell/cefclient.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,6 @@ std::string AppGetWorkingDirectory();
2626
// Returns the starting URL
2727
CefString AppGetInitialURL();
2828

29-
// Returns a string containing the product and version (e.g. "Brackets/0.19.0.0")
30-
CefString AppGetProductVersionString();
31-
32-
// Returns a string containing "Chrome/" appends with its version (e.g. "Chrome/29.0.1547.65")
33-
CefString AppGetChromiumVersionString();
34-
3529
// Initialize the application command line.
3630
void AppInitCommandLine(int argc, const char* const* argv);
3731

appshell/cefclient_gtk.cc

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,3 @@ int main(int argc, char* argv[]) {
266266

267267
return 0;
268268
}
269-
270-
CefString AppGetProductVersionString() {
271-
// TODO
272-
return CefString("");
273-
}
274-
275-
CefString AppGetChromiumVersionString() {
276-
// TODO
277-
return CefString("");
278-
}

appshell/cefclient_mac.mm

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -920,24 +920,3 @@ int main(int argc, char* argv[]) {
920920
std::string AppGetWorkingDirectory() {
921921
return szWorkingDir;
922922
}
923-
924-
CefString AppGetProductVersionString() {
925-
NSMutableString *s = [NSMutableString stringWithString:APP_NAME];
926-
[s replaceOccurrencesOfString:@" "
927-
withString:@""
928-
options:NSLiteralSearch
929-
range:NSMakeRange(0, [s length])];
930-
[s appendString:@"/"];
931-
[s appendString:(NSString*)[[NSBundle mainBundle]
932-
objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey]];
933-
CefString result = CefString([s UTF8String]);
934-
return result;
935-
}
936-
937-
CefString AppGetChromiumVersionString() {
938-
NSMutableString *s = [NSMutableString stringWithFormat:@"Chrome/%d.%d.%d.%d",
939-
cef_version_info(2), cef_version_info(3),
940-
cef_version_info(4), cef_version_info(5)];
941-
CefString result = CefString([s UTF8String]);
942-
return result;
943-
}

appshell/cefclient_win.cpp

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -358,66 +358,3 @@ std::string AppGetWorkingDirectory() {
358358
CefString AppGetInitialURL() {
359359
return szInitialUrl;
360360
}
361-
362-
// Helper function for AppGetProductVersionString. Reads version info from
363-
// VERSIONINFO and writes it into the passed in std::wstring.
364-
void GetFileVersionString(std::wstring &retVersion) {
365-
DWORD dwSize = 0;
366-
BYTE *pVersionInfo = NULL;
367-
VS_FIXEDFILEINFO *pFileInfo = NULL;
368-
UINT pLenFileInfo = 0;
369-
370-
HMODULE module = GetModuleHandle(NULL);
371-
TCHAR executablePath[MAX_UNC_PATH];
372-
GetModuleFileName(module, executablePath, MAX_UNC_PATH);
373-
374-
dwSize = GetFileVersionInfoSize(executablePath, NULL);
375-
if (dwSize == 0) {
376-
return;
377-
}
378-
379-
pVersionInfo = new BYTE[dwSize];
380-
381-
if (!GetFileVersionInfo(executablePath, 0, dwSize, pVersionInfo)) {
382-
delete[] pVersionInfo;
383-
return;
384-
}
385-
386-
if (!VerQueryValue(pVersionInfo, TEXT("\\"), (LPVOID*) &pFileInfo, &pLenFileInfo)) {
387-
delete[] pVersionInfo;
388-
return;
389-
}
390-
391-
int major = (pFileInfo->dwFileVersionMS >> 16) & 0xffff ;
392-
int minor = (pFileInfo->dwFileVersionMS) & 0xffff;
393-
int hotfix = (pFileInfo->dwFileVersionLS >> 16) & 0xffff;
394-
int other = (pFileInfo->dwFileVersionLS) & 0xffff;
395-
396-
delete[] pVersionInfo;
397-
398-
std::wostringstream versionStream(L"");
399-
versionStream << major << L"." << minor << L"." << hotfix << L"." << other;
400-
retVersion = versionStream.str();
401-
}
402-
403-
CefString AppGetProductVersionString() {
404-
std::wstring s(APP_NAME);
405-
size_t i = s.find(L" ");
406-
while (i != std::wstring::npos) {
407-
s.erase(i, 1);
408-
i = s.find(L" ");
409-
}
410-
std::wstring version(L"");
411-
GetFileVersionString(version);
412-
s.append(L"/");
413-
s.append(version);
414-
return CefString(s);
415-
}
416-
417-
CefString AppGetChromiumVersionString() {
418-
std::wostringstream versionStream(L"");
419-
versionStream << L"Chrome/" << cef_version_info(2) << L"." << cef_version_info(3)
420-
<< L"." << cef_version_info(4) << L"." << cef_version_info(5);
421-
422-
return CefString(versionStream.str());
423-
}

0 commit comments

Comments
 (0)