forked from adobe/brackets-shell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_app_win.cpp
More file actions
119 lines (94 loc) · 3.54 KB
/
client_app_win.cpp
File metadata and controls
119 lines (94 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
* Copyright (c) 2012 - present Adobe Systems Incorporated. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
#include "client_app.h"
#include "appshell/browser/resource.h"
#include "include/cef_base.h"
#include "config.h"
#include <algorithm>
#include <MMSystem.h>
#include <ShlObj.h>
#include <string>
extern DWORD g_appStartupTime;
CefString ClientApp::GetCurrentLanguage()
{
// Get the user's selected language
// Defaults to the system installed language if not using MUI.
LANGID langID = GetUserDefaultUILanguage();
// Convert LANGID to a RFC 4646 language tag (per navigator.language)
int langSize = GetLocaleInfo(langID, LOCALE_SISO639LANGNAME, NULL, 0);
int countrySize = GetLocaleInfo(langID, LOCALE_SISO3166CTRYNAME, NULL, 0);
wchar_t *lang = new wchar_t[langSize + countrySize + 1];
wchar_t *country = new wchar_t[countrySize];
GetLocaleInfo(langID, LOCALE_SISO639LANGNAME, lang, langSize);
GetLocaleInfo(langID, LOCALE_SISO3166CTRYNAME, country, countrySize);
// add hyphen
wcscat(wcscat(lang, L"-"), country);
std::wstring locale(lang);
delete [] lang;
delete [] country;
return CefString(locale);
}
std::string ClientApp::GetExtensionJSSource()
{
extern HINSTANCE hInst;
HRSRC hRes = FindResource(hInst, MAKEINTRESOURCE(IDS_APPSHELL_EXTENSIONS), MAKEINTRESOURCE(256));
DWORD dwSize;
LPBYTE pBytes = NULL;
if(hRes)
{
HGLOBAL hGlob = LoadResource(hInst, hRes);
if(hGlob)
{
dwSize = SizeofResource(hInst, hRes);
pBytes = (LPBYTE)LockResource(hGlob);
}
}
if (pBytes) {
std::string result((const char *)pBytes, dwSize);
return result;
}
return "";
}
double ClientApp::GetElapsedMilliseconds()
{
return (timeGetTime() - g_appStartupTime);
}
CefString ClientApp::AppGetSupportDirectory()
{
wchar_t dataPath[MAX_UNC_PATH];
SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, dataPath);
std::wstring appSupportPath = dataPath;
appSupportPath += L"\\" GROUP_NAME APP_NAME;
// Convert '\\' to '/'
replace(appSupportPath.begin(), appSupportPath.end(), '\\', '/');
return CefString(appSupportPath);
}
CefString ClientApp::AppGetDocumentsDirectory()
{
wchar_t dataPath[MAX_UNC_PATH] = {0};
SHGetFolderPath(NULL, CSIDL_MYDOCUMENTS, NULL, SHGFP_TYPE_CURRENT, dataPath);
std::wstring appUserDocuments = dataPath;
// Convert '\\' to '/'
replace(appUserDocuments.begin(), appUserDocuments.end(), '\\', '/');
return CefString(appUserDocuments);
}