obs-windows.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /******************************************************************************
  2. Copyright (C) 2013 by Hugh Bailey <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #include "util/platform.h"
  15. #include "util/dstr.h"
  16. #include "obs.h"
  17. #include "obs-internal.h"
  18. #include <windows.h>
  19. static inline bool check_path(const char* data, const char *path,
  20. struct dstr * output)
  21. {
  22. dstr_copy(output, path);
  23. dstr_cat(output, data);
  24. blog(LOG_DEBUG, "Attempting path: %s\n", output->array);
  25. return os_file_exists(output->array);
  26. }
  27. static inline bool check_lib_path(const char* data, const char *path,
  28. struct dstr *output)
  29. {
  30. bool result = false;
  31. struct dstr tmp;
  32. dstr_init_copy(&tmp, data);
  33. dstr_cat(&tmp, ".dll");
  34. result = check_path(tmp.array, path, output);
  35. dstr_free(&tmp);
  36. return result;
  37. }
  38. /* on windows, plugin files are located in [base directory]/plugins/[bit] */
  39. char *find_plugin(const char *plugin)
  40. {
  41. struct dstr path;
  42. dstr_init(&path);
  43. #ifdef _WIN64
  44. if (check_lib_path(plugin, "obs-plugins/64bit/", &path))
  45. #else
  46. if (check_lib_path(plugin, "obs-plugins/32bit/", &path))
  47. #endif
  48. return path.array;
  49. #ifdef _WIN64
  50. if (check_lib_path(plugin, "../../obs-plugins/64bit/", &path))
  51. #else
  52. if (check_lib_path(plugin, "../../obs-plugins/32bit/", &path))
  53. #endif
  54. return path.array;
  55. dstr_free(&path);
  56. return NULL;
  57. }
  58. /* on windows, points to [base directory]/libobs */
  59. char *find_libobs_data_file(const char *file)
  60. {
  61. struct dstr path;
  62. dstr_init(&path);
  63. if (check_path(file, "data/libobs/", &path))
  64. return path.array;
  65. if (check_path(file, "../../data/libobs/", &path))
  66. return path.array;
  67. dstr_free(&path);
  68. return NULL;
  69. }
  70. /* on windows, data files should always be in [base directory]/data */
  71. char *obs_find_plugin_file(const char *file)
  72. {
  73. struct dstr path;
  74. dstr_init(&path);
  75. if (check_path(file, "data/obs-plugins/", &path))
  76. return path.array;
  77. if (check_path(file, "../../data/obs-plugins/", &path))
  78. return path.array;
  79. dstr_free(&path);
  80. return NULL;
  81. }
  82. static void log_processor_info(void)
  83. {
  84. HKEY key;
  85. wchar_t data[1024];
  86. char *str = NULL;
  87. DWORD size, speed;
  88. LSTATUS status;
  89. memset(data, 0, 1024);
  90. status = RegOpenKeyW(HKEY_LOCAL_MACHINE,
  91. L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0",
  92. &key);
  93. if (status != ERROR_SUCCESS)
  94. return;
  95. size = 1024;
  96. status = RegQueryValueExW(key, L"ProcessorNameString", NULL, NULL,
  97. (LPBYTE)data, &size);
  98. if (status == ERROR_SUCCESS) {
  99. os_wcs_to_utf8_ptr(data, 0, &str);
  100. blog(LOG_INFO, "CPU Name: %s", str);
  101. bfree(str);
  102. }
  103. size = sizeof(speed);
  104. status = RegQueryValueExW(key, L"~MHz", NULL, NULL, (LPBYTE)&speed,
  105. &size);
  106. if (status == ERROR_SUCCESS)
  107. blog(LOG_INFO, "CPU Speed: %dMHz", speed);
  108. RegCloseKey(key);
  109. }
  110. static DWORD num_logical_cores(ULONG_PTR mask)
  111. {
  112. DWORD left_shift = sizeof(ULONG_PTR) * 8 - 1;
  113. DWORD bit_set_count = 0;
  114. ULONG_PTR bit_test = (ULONG_PTR)1 << left_shift;
  115. for (DWORD i = 0; i <= left_shift; ++i) {
  116. bit_set_count += ((mask & bit_test) ? 1 : 0);
  117. bit_test /= 2;
  118. }
  119. return bit_set_count;
  120. }
  121. static void log_processor_cores(void)
  122. {
  123. PSYSTEM_LOGICAL_PROCESSOR_INFORMATION info = NULL, temp = NULL;
  124. DWORD len = 0;
  125. GetLogicalProcessorInformation(info, &len);
  126. if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
  127. return;
  128. info = malloc(len);
  129. if (GetLogicalProcessorInformation(info, &len)) {
  130. DWORD num = len / sizeof(*info);
  131. int physical_cores = 0;
  132. int logical_cores = 0;
  133. temp = info;
  134. for (DWORD i = 0; i < num; i++) {
  135. if (temp->Relationship == RelationProcessorCore) {
  136. ULONG_PTR mask = temp->ProcessorMask;
  137. physical_cores++;
  138. logical_cores += num_logical_cores(mask);
  139. }
  140. temp++;
  141. }
  142. blog(LOG_INFO, "Physical Cores: %d, Logical Cores: %d",
  143. physical_cores, logical_cores);
  144. }
  145. free(info);
  146. }
  147. static void log_available_memory(void)
  148. {
  149. MEMORYSTATUS ms;
  150. GlobalMemoryStatus(&ms);
  151. #ifdef _WIN64
  152. const char *note = "";
  153. #else
  154. const char *note = " (NOTE: 4 gigs max is normal for 32bit programs)";
  155. #endif
  156. blog(LOG_INFO, "Physical Memory: %ldMB Total, %ldMB Free%s",
  157. ms.dwTotalPhys / 1048576,
  158. ms.dwAvailPhys / 1048576,
  159. note);
  160. }
  161. static void log_windows_version(void)
  162. {
  163. OSVERSIONINFOW osvi;
  164. char *build = NULL;
  165. osvi.dwOSVersionInfoSize = sizeof(osvi);
  166. GetVersionExW(&osvi);
  167. os_wcs_to_utf8_ptr(osvi.szCSDVersion, 0, &build);
  168. blog(LOG_INFO, "Windows Version: %u.%u Build %u %s",
  169. osvi.dwMajorVersion,
  170. osvi.dwMinorVersion,
  171. osvi.dwBuildNumber,
  172. build);
  173. bfree(build);
  174. }
  175. void log_system_info(void)
  176. {
  177. log_processor_info();
  178. log_processor_cores();
  179. log_available_memory();
  180. log_windows_version();
  181. }