obs-windows.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. const char *get_module_extension(void)
  20. {
  21. return ".dll";
  22. }
  23. #ifdef _WIN64
  24. #define BIT_STRING "64bit"
  25. #else
  26. #define BIT_STRING "32bit"
  27. #endif
  28. static const char *module_bin[] = {
  29. "obs-plugins/" BIT_STRING,
  30. "../../obs-plugins/" BIT_STRING,
  31. };
  32. static const char *module_data[] = {
  33. "data/%module%",
  34. "../../data/obs-plugins/%module%"
  35. };
  36. static const int module_patterns_size =
  37. sizeof(module_bin)/sizeof(module_bin[0]);
  38. void add_default_module_paths(void)
  39. {
  40. char bin[512];
  41. char data[512];
  42. int ret;
  43. for (int i = 0; i < module_patterns_size; i++)
  44. obs_add_module_path(module_bin[i], module_data[i]);
  45. ret = os_get_config_path(bin, sizeof(bin), "obs-plugins/%module%");
  46. if (ret <= 0)
  47. return;
  48. strcpy(data, bin);
  49. strcat(data, "/data");
  50. strcat(bin, "/bin/" BIT_STRING);
  51. obs_add_module_path(bin, data);
  52. }
  53. /* on windows, points to [base directory]/data/libobs */
  54. char *find_libobs_data_file(const char *file)
  55. {
  56. struct dstr path;
  57. dstr_init(&path);
  58. if (check_path(file, "data/libobs/", &path))
  59. return path.array;
  60. if (check_path(file, "../../data/libobs/", &path))
  61. return path.array;
  62. dstr_free(&path);
  63. return NULL;
  64. }
  65. static void log_processor_info(void)
  66. {
  67. HKEY key;
  68. wchar_t data[1024];
  69. char *str = NULL;
  70. DWORD size, speed;
  71. LSTATUS status;
  72. memset(data, 0, 1024);
  73. status = RegOpenKeyW(HKEY_LOCAL_MACHINE,
  74. L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0",
  75. &key);
  76. if (status != ERROR_SUCCESS)
  77. return;
  78. size = 1024;
  79. status = RegQueryValueExW(key, L"ProcessorNameString", NULL, NULL,
  80. (LPBYTE)data, &size);
  81. if (status == ERROR_SUCCESS) {
  82. os_wcs_to_utf8_ptr(data, 0, &str);
  83. blog(LOG_INFO, "CPU Name: %s", str);
  84. bfree(str);
  85. }
  86. size = sizeof(speed);
  87. status = RegQueryValueExW(key, L"~MHz", NULL, NULL, (LPBYTE)&speed,
  88. &size);
  89. if (status == ERROR_SUCCESS)
  90. blog(LOG_INFO, "CPU Speed: %dMHz", speed);
  91. RegCloseKey(key);
  92. }
  93. static DWORD num_logical_cores(ULONG_PTR mask)
  94. {
  95. DWORD left_shift = sizeof(ULONG_PTR) * 8 - 1;
  96. DWORD bit_set_count = 0;
  97. ULONG_PTR bit_test = (ULONG_PTR)1 << left_shift;
  98. for (DWORD i = 0; i <= left_shift; ++i) {
  99. bit_set_count += ((mask & bit_test) ? 1 : 0);
  100. bit_test /= 2;
  101. }
  102. return bit_set_count;
  103. }
  104. static void log_processor_cores(void)
  105. {
  106. PSYSTEM_LOGICAL_PROCESSOR_INFORMATION info = NULL, temp = NULL;
  107. DWORD len = 0;
  108. GetLogicalProcessorInformation(info, &len);
  109. if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
  110. return;
  111. info = malloc(len);
  112. if (GetLogicalProcessorInformation(info, &len)) {
  113. DWORD num = len / sizeof(*info);
  114. int physical_cores = 0;
  115. int logical_cores = 0;
  116. temp = info;
  117. for (DWORD i = 0; i < num; i++) {
  118. if (temp->Relationship == RelationProcessorCore) {
  119. ULONG_PTR mask = temp->ProcessorMask;
  120. physical_cores++;
  121. logical_cores += num_logical_cores(mask);
  122. }
  123. temp++;
  124. }
  125. blog(LOG_INFO, "Physical Cores: %d, Logical Cores: %d",
  126. physical_cores, logical_cores);
  127. }
  128. free(info);
  129. }
  130. static void log_available_memory(void)
  131. {
  132. MEMORYSTATUS ms;
  133. GlobalMemoryStatus(&ms);
  134. #ifdef _WIN64
  135. const char *note = "";
  136. #else
  137. const char *note = " (NOTE: 4 gigs max is normal for 32bit programs)";
  138. #endif
  139. blog(LOG_INFO, "Physical Memory: %luMB Total, %luMB Free%s",
  140. (DWORD)(ms.dwTotalPhys / 1048576),
  141. (DWORD)(ms.dwAvailPhys / 1048576),
  142. note);
  143. }
  144. static void log_windows_version(void)
  145. {
  146. OSVERSIONINFOW osvi;
  147. char *build = NULL;
  148. osvi.dwOSVersionInfoSize = sizeof(osvi);
  149. GetVersionExW(&osvi);
  150. os_wcs_to_utf8_ptr(osvi.szCSDVersion, 0, &build);
  151. blog(LOG_INFO, "Windows Version: %u.%u Build %u %s",
  152. osvi.dwMajorVersion,
  153. osvi.dwMinorVersion,
  154. osvi.dwBuildNumber,
  155. build);
  156. bfree(build);
  157. }
  158. void log_system_info(void)
  159. {
  160. log_processor_info();
  161. log_processor_cores();
  162. log_available_memory();
  163. log_windows_version();
  164. }