]> git.sesse.net Git - casparcg/blob - common/os/windows/system_info.cpp
* Fixed problem where the base path of CLS, CINF, TLS, DATA LIST and THUMBNAIL LIST...
[casparcg] / common / os / windows / system_info.cpp
1 /*
2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
3 *
4 * This file is part of CasparCG (www.casparcg.com).
5 *
6 * CasparCG is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * CasparCG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * Author: Robert Nagy, ronag89@gmail.com
20 */
21
22 #include "../../stdafx.h"
23
24 #include "../system_info.h"
25 #include "current_version.h"
26
27 #include "windows.h"
28
29 #include <sstream>
30 #include <map>
31
32 namespace caspar {
33         
34 std::wstring cpu_info()
35 {
36         std::wstring cpu_name = L"Unknown CPU";
37         HKEY hkey; 
38         DWORD dwType, dwSize;
39         if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0"), 0, KEY_QUERY_VALUE, &hkey) == ERROR_SUCCESS)
40         {
41                 wchar_t p_name_str[1024];
42
43                 dwType = REG_SZ;
44                 dwSize = sizeof(p_name_str);
45
46                 if(RegQueryValueEx(hkey, TEXT("ProcessorNameString"), NULL, &dwType, (PBYTE)&p_name_str, &dwSize) == ERROR_SUCCESS)             
47                         cpu_name = p_name_str;          
48                  
49                 RegCloseKey(hkey);
50         }
51
52
53         SYSTEM_INFO sysinfo;
54         GetSystemInfo(&sysinfo);
55
56         std::wstringstream s;
57
58         s << cpu_name << L" Physical Threads: " << sysinfo.dwNumberOfProcessors;
59
60         return s.str();
61 }
62
63 std::wstring system_product_name()
64 {
65         std::wstring system_product_name = L"Unknown System";
66         HKEY hkey; 
67         DWORD dwType, dwSize;
68         if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("HARDWARE\\DESCRIPTION\\System\\BIOS"), 0, KEY_QUERY_VALUE, &hkey) == ERROR_SUCCESS)
69         {
70                 wchar_t p_name_str[1024];
71
72                 dwType = REG_SZ;
73                 dwSize = sizeof(p_name_str);
74
75                 if(RegQueryValueEx(hkey, TEXT("SystemProductName"), NULL, &dwType, (PBYTE)&p_name_str, &dwSize) == ERROR_SUCCESS)               
76                         system_product_name = p_name_str;               
77                  
78                 RegCloseKey(hkey);
79         }
80
81         return system_product_name;
82 }
83
84 std::wstring os_description()
85 {
86         return win_product_name() + L" " + win_sp_version();
87 }
88
89
90 /*static std::map<std::wstring, std::wstring> enumerate_fonts()
91 {
92         std::map<std::wstring, std::wstring> result;
93         const DWORD max_str_length = 32766;
94
95         HKEY hkey; 
96         if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts"), 0, KEY_QUERY_VALUE, &hkey) == ERROR_SUCCESS)
97         {
98                 int index = 0;
99                 do
100                 {
101                         DWORD name_length = max_str_length;
102                         wchar_t name[max_str_length];
103
104                         DWORD value_length = max_str_length;
105                         wchar_t value[max_str_length];
106
107                         long code = RegEnumValueW(hkey, index, name, &name_length, NULL, NULL, (PBYTE)value, &value_length);
108                         if(code == ERROR_SUCCESS)
109                         {
110                                 std::wstring name_str(name);
111                                 name_str = name_str.substr(0, name_str.find_last_of(L' '));     //the font names are formated like this: "AGaramondPro-Italic (OpenType)". We need to strip away the '(OpenType)'-part
112                                 result.insert(std::pair<std::wstring, std::wstring>(name_str, std::wstring(value)));
113                         }
114                         else if(code == ERROR_NO_MORE_ITEMS)
115                                 break;
116                 }
117                 while(++index);
118                 //if(RegQueryValueEx(hkey, TEXT("SystemProductName"), NULL, &dwType, (PBYTE)&p_name_str, &dwSize) == ERROR_SUCCESS)             
119                 //      system_product_name = p_name_str;               
120                  
121                 RegCloseKey(hkey);
122         }
123
124         return result;
125 }*/
126
127 }