forked from obsproject/obs-studio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplatform-windows.cpp
205 lines (159 loc) · 4.57 KB
/
platform-windows.cpp
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/******************************************************************************
Copyright (C) 2013 by Hugh Bailey <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
#include <algorithm>
#include <sstream>
#include "obs-config.h"
#include "obs-app.hpp"
#include "platform.hpp"
using namespace std;
#include <util/platform.h>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <shellapi.h>
#include <shlobj.h>
#include <Dwmapi.h>
static inline bool check_path(const char* data, const char *path,
string &output)
{
ostringstream str;
str << path << data;
output = str.str();
printf("Attempted path: %s\n", output.c_str());
return os_file_exists(output.c_str());
}
bool GetDataFilePath(const char *data, string &output)
{
if (check_path(data, "data/obs-studio/", output))
return true;
return check_path(data, OBS_DATA_PATH "/obs-studio/", output);
}
static BOOL CALLBACK OBSMonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor,
LPRECT rect, LPARAM param)
{
vector<MonitorInfo> &monitors = *(vector<MonitorInfo> *)param;
monitors.emplace_back(
rect->left,
rect->top,
rect->right - rect->left,
rect->bottom - rect->top);
UNUSED_PARAMETER(hMonitor);
UNUSED_PARAMETER(hdcMonitor);
return true;
}
void GetMonitors(vector<MonitorInfo> &monitors)
{
monitors.clear();
EnumDisplayMonitors(NULL, NULL, OBSMonitorEnumProc, (LPARAM)&monitors);
}
bool InitApplicationBundle()
{
return true;
}
string GetDefaultVideoSavePath()
{
wchar_t path_utf16[MAX_PATH];
char path_utf8[MAX_PATH] = {};
SHGetFolderPathW(NULL, CSIDL_MYVIDEO, NULL, SHGFP_TYPE_CURRENT,
path_utf16);
os_wcs_to_utf8(path_utf16, wcslen(path_utf16), path_utf8, MAX_PATH);
return string(path_utf8);
}
static vector<string> GetUserPreferredLocales()
{
vector<string> result;
ULONG num, length = 0;
if (!GetUserPreferredUILanguages(MUI_LANGUAGE_NAME, &num,
nullptr, &length))
return result;
vector<wchar_t> buffer(length);
if (!GetUserPreferredUILanguages(MUI_LANGUAGE_NAME, &num,
&buffer.front(), &length))
return result;
result.reserve(num);
auto start = begin(buffer);
auto end_ = end(buffer);
decltype(start) separator;
while ((separator = find(start, end_, 0)) != end_) {
if (result.size() == num)
break;
char conv[MAX_PATH] = {};
os_wcs_to_utf8(&*start, separator - start, conv, MAX_PATH);
result.emplace_back(conv);
start = separator + 1;
}
return result;
}
vector<string> GetPreferredLocales()
{
vector<string> windows_locales = GetUserPreferredLocales();
auto obs_locales = GetLocaleNames();
auto windows_to_obs = [&obs_locales](string windows) {
string lang_match;
for (auto &locale_pair : obs_locales) {
auto &locale = locale_pair.first;
if (locale == windows.substr(0, locale.size()))
return locale;
if (lang_match.size())
continue;
if (locale.substr(0, 2) == windows.substr(0, 2))
lang_match = locale;
}
return lang_match;
};
vector<string> result;
result.reserve(obs_locales.size());
for (const string &locale : windows_locales) {
string match = windows_to_obs(locale);
if (!match.size())
continue;
if (find(begin(result), end(result), match) != end(result))
continue;
result.emplace_back(match);
}
return result;
}
uint32_t GetWindowsVersion()
{
static uint32_t ver = 0;
if (ver == 0) {
OSVERSIONINFOW osvi = {};
osvi.dwOSVersionInfoSize = sizeof(osvi);
if (GetVersionExW(&osvi)) {
ver = osvi.dwMajorVersion << 8 | osvi.dwMinorVersion;
}
}
return ver;
}
void SetAeroEnabled(bool enable)
{
static HRESULT (WINAPI *func)(UINT) = nullptr;
static bool failed = false;
if (!func) {
if (failed) {
return;
}
HMODULE dwm = LoadLibraryW(L"dwmapi");
if (!dwm) {
failed = true;
return;
}
func = reinterpret_cast<decltype(func)>(GetProcAddress(dwm,
"DwmEnableComposition"));
if (!func) {
failed = true;
return;
}
}
func(enable ? DWM_EC_ENABLECOMPOSITION : DWM_EC_DISABLECOMPOSITION);
}