ReactOS  0.4.13-dev-563-g0561610
rosddt.c File Reference
#include <stdio.h>
#include <windows.h>
#include <setupapi.h>
#include "http.h"
Include dependency graph for rosddt.c:

Go to the source code of this file.

Macros

#define ST_NEUTRAL   0
 
#define ST_ROS_CRASH   1
 
#define ST_DEV_NOTWORK   2
 
#define ST_DEV_OK   3
 
#define ST_ERROR   4
 
#define ST_LAST_STATUS   ST_ERROR
 

Functions

static int hw_check_ini (wchar_t *name)
 
static int hw_check_base (wchar_t *hw_id, wchar_t *hw_name)
 
static void trim (wchar_t *s)
 
static int hw_check_device (HDEVINFO h_info, SP_DEVINFO_DATA *d_inf)
 
static void do_update_base ()
 
static void do_send_report (wchar_t *report)
 
int wmain (int argc, wchar_t *argv[])
 

Variables

static int is_show_hw
 
static int is_check_hw
 
static wchar_t gl_ini_file [MAX_PATH]
 
static wchar_tgl_report
 

Macro Definition Documentation

◆ ST_DEV_NOTWORK

#define ST_DEV_NOTWORK   2

Definition at line 8 of file rosddt.c.

◆ ST_DEV_OK

#define ST_DEV_OK   3

Definition at line 9 of file rosddt.c.

◆ ST_ERROR

#define ST_ERROR   4

Definition at line 10 of file rosddt.c.

◆ ST_LAST_STATUS

#define ST_LAST_STATUS   ST_ERROR

Definition at line 11 of file rosddt.c.

◆ ST_NEUTRAL

#define ST_NEUTRAL   0

Definition at line 6 of file rosddt.c.

◆ ST_ROS_CRASH

#define ST_ROS_CRASH   1

Definition at line 7 of file rosddt.c.

Function Documentation

◆ do_send_report()

static void do_send_report ( wchar_t report)
static

Definition at line 173 of file rosddt.c.

174 {
175  wchar_t up_url[MAX_PATH];
176  int utf_sz;
177  char *utf;
178  char *p = NULL;
179 
180  if (GetPrivateProfileString(L"URL", L"report", NULL, up_url, MAX_PATH, gl_ini_file) == 0) {
181  wprintf(L"Report URL not found in rosddt.ini\n"); return;
182  }
183 
184  utf_sz = WideCharToMultiByte(CP_UTF8, 0, report, -1, NULL, 0, NULL, NULL);
185  utf = malloc(utf_sz);
186  utf_sz = WideCharToMultiByte(CP_UTF8, 0, report, -1, utf, utf_sz, NULL, NULL);
187 
188  wprintf(L"Sending report...\n");
189 
190  if (p == http_post(up_url, utf, utf_sz-1, NULL)) {
191  wprintf(L"%S\n", p); free(p);
192  } else {
193  wprintf(L"Report can not be sended, connection error\n");
194  }
195 }
void * http_post(wchar_t *url, void *data, int size, u_long *d_size)
Definition: http.c:69
#define WideCharToMultiByte
Definition: compat.h:101
#define free
Definition: debug_ros.c:5
#define wprintf(...)
Definition: whoami.c:18
static wchar_t gl_ini_file[MAX_PATH]
Definition: rosddt.c:15
#define CP_UTF8
Definition: nls.h:20
smooth NULL
Definition: ftsmooth.c:416
static void report(const DATA_BLOB *pDataIn, const DATA_BLOB *pOptionalEntropy, CRYPTPROTECT_PROMPTSTRUCT *pPromptStruct, DWORD dwFlags)
Definition: protectdata.c:769
#define MAX_PATH
Definition: compat.h:26
static const WCHAR L[]
Definition: oid.c:1250
#define GetPrivateProfileString
Definition: winbase.h:3649
#define malloc
Definition: debug_ros.c:4
GLfloat GLfloat p
Definition: glext.h:8902

Referenced by wmain().

◆ do_update_base()

static void do_update_base ( )
static

Definition at line 144 of file rosddt.c.

145 {
146  wchar_t up_url[MAX_PATH];
147  void *data = NULL;
148  u_long size;
149  FILE *f;
150 
151  if (GetPrivateProfileString(L"URL", L"udpate", NULL, up_url, MAX_PATH, gl_ini_file) == 0) {
152  wprintf(L"Update URL not found in rosddt.ini\n"); return;
153  }
154 
155  wprintf(L"Downloading new rosddt.ini...\n");
156 
157  if (data == http_get(up_url, &size))
158  {
159  f = _wfopen(gl_ini_file, L"wb");
160  if (f) {
161  fwrite(data, 1, size, f);
162  fclose(f);
163  wprintf(L"Update completed\n");
164  } else {
165  wprintf(L"Can not open rosddt.ini for writing\n");
166  }
167  free(data);
168  } else {
169  wprintf(L"Error, rosddt.ini can not be loaded\n");
170  }
171 }
unsigned long u_long
Definition: linux.h:269
_Check_return_ _CRTIMP FILE *__cdecl _wfopen(_In_z_ const wchar_t *_Filename, _In_z_ const wchar_t *_Mode)
#define free
Definition: debug_ros.c:5
#define wprintf(...)
Definition: whoami.c:18
static wchar_t gl_ini_file[MAX_PATH]
Definition: rosddt.c:15
_Check_return_opt_ _CRTIMP size_t __cdecl fwrite(_In_reads_bytes_(_Size *_Count) const void *_Str, _In_ size_t _Size, _In_ size_t _Count, _Inout_ FILE *_File)
smooth NULL
Definition: ftsmooth.c:416
void * http_get(wchar_t *url, u_long *d_size)
Definition: http.c:43
GLfloat f
Definition: glext.h:7540
GLsizeiptr size
Definition: glext.h:5919
#define MAX_PATH
Definition: compat.h:26
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
static const WCHAR L[]
Definition: oid.c:1250
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
#define GetPrivateProfileString
Definition: winbase.h:3649
#define f
Definition: ke_i.h:83

Referenced by wmain().

◆ hw_check_base()

static int hw_check_base ( wchar_t hw_id,
wchar_t hw_name 
)
static

Definition at line 31 of file rosddt.c.

32 {
33  wchar_t buff[MAX_PATH];
34  wchar_t *p = NULL;
35  int status;
36 
37  if ( (status = hw_check_ini(hw_id)) != ST_NEUTRAL ) {
38  return status;
39  }
40  if ( (status = hw_check_ini(hw_name)) != ST_NEUTRAL ) {
41  return status;
42  }
43 
44  if (wcsncmp(hw_id, L"PCI\\VEN_", 8) == 0)
45  {
46  wcsncpy(buff, hw_id, 21); buff[21] = 0;
47 
48  if ( (status = hw_check_ini(buff)) != ST_NEUTRAL ) {
49  return status;
50  }
51 
52  if (p == wcsstr(hw_id, L"&REV_")) {
54  }
55  } else if ( (wcsncmp(hw_id, L"USB\\", 4) == 0) && (p = wcsstr(hw_id, L"&VID")) )
56  {
57  wsprintf(buff, L"USB\\%s", p+1);
58 
59  if ( (status = hw_check_ini(buff)) != ST_NEUTRAL ) {
60  return status;
61  }
62 
63  if (p == wcsstr(buff, L"&REV")) {
64  *p = 0; status = hw_check_ini(buff);
65  }
66  }
67  return status;
68 }
_CONST_RETURN wchar_t *__cdecl wcsstr(_In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_SubStr)
smooth NULL
Definition: ftsmooth.c:416
static int hw_check_ini(wchar_t *name)
Definition: rosddt.c:18
#define MAX_PATH
Definition: compat.h:26
_Check_return_ _CRTIMP int __cdecl wcsncmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
static const WCHAR L[]
Definition: oid.c:1250
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
GLfloat GLfloat p
Definition: glext.h:8902
#define wsprintf
Definition: winuser.h:5731
static SERVICE_STATUS status
Definition: service.c:31
#define ST_NEUTRAL
Definition: rosddt.c:6
static unsigned char buff[32768]
Definition: fatten.c:17
Definition: ps.c:97

Referenced by hw_check_device().

◆ hw_check_device()

static int hw_check_device ( HDEVINFO  h_info,
SP_DEVINFO_DATA d_inf 
)
static

Definition at line 76 of file rosddt.c.

77 {
78  wchar_t *hw_id = NULL;
79  wchar_t *hw_name = NULL;
80  u_long type, bytes;
81  int status;
82  char name[MAX_PATH];
83  wchar_t w_name[MAX_PATH];
84 
85  do
86  {
87  if ( (hw_id = malloc(4096)) == NULL ) {
88  status = ST_ERROR; break;
89  }
90  if ( (hw_name = malloc(4096)) == NULL ) {
91  status = ST_ERROR; break;
92  }
93  hw_id[0] = 0, hw_name[0] = 0;
94 
95  SetupDiGetDeviceRegistryProperty(h_info, d_inf, SPDRP_HARDWAREID, &type, (void*)hw_id, 4096, &bytes);
96  SetupDiGetDeviceRegistryProperty(h_info, d_inf, SPDRP_DEVICEDESC, &type, (void*)hw_name, 4096, &bytes);
97 
98  if (hw_id[0] == 0 || hw_name[0] == 0) {
99  status = ST_NEUTRAL; break;
100  }
101  /* trim strings */
102  trim(hw_id); trim(hw_name);
103 
104  if ( (wcschr(hw_id, L'\\') == NULL) || (_wcsnicmp(hw_id, L"ROOT\\", 5) == 0) ||
105  (_wcsicmp(hw_id, L"STORAGE\\Volume") == 0) || (_wcsicmp(hw_id, L"UMB\\UMBUS") == 0) ||
106  (_wcsnicmp(hw_id, L"SW\\", 3) == 0) )
107  {
108  status = ST_NEUTRAL; break;
109  }
110 
111  if (is_show_hw != 0) {
112  CharToOem(hw_name, name);
113  wprintf(L"%s - [%S]\n", hw_id, name);
114  }
115 
116  if (gl_report != NULL) {
117  wsprintf(w_name, L"%s - [%s]\n", hw_id, hw_name);
118  wcscat(gl_report, w_name);
119  }
120 
121  if (is_check_hw != 0)
122  {
123  status = hw_check_base(hw_id, hw_name);
124 
125  if (status == ST_DEV_NOTWORK) {
126  CharToOem(hw_name, name);
127  wprintf(L"Device \"%S\" does not work in ReactOS\n", name);
128  }
129  if (status == ST_ROS_CRASH) {
130  CharToOem(hw_name, name);
131  wprintf(L"ReactOS does not work with device \"%S\"\n", name);
132  }
133  } else {
134  status = ST_NEUTRAL;
135  }
136  } while (0);
137 
138  if (hw_id != NULL) free(hw_id);
139  if (hw_name != NULL) free(hw_name);
140 
141  return status;
142 }
unsigned long u_long
Definition: linux.h:269
#define free
Definition: debug_ros.c:5
_Check_return_ _CRTIMP int __cdecl _wcsnicmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
#define ST_ROS_CRASH
Definition: rosddt.c:7
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define SetupDiGetDeviceRegistryProperty
Definition: setupapi.h:2598
#define wprintf(...)
Definition: whoami.c:18
static unsigned char bytes[4]
Definition: adnsresfilter.c:74
#define ST_ERROR
Definition: rosddt.c:10
smooth NULL
Definition: ftsmooth.c:416
static wchar_t * gl_report
Definition: rosddt.c:16
_CONST_RETURN wchar_t *__cdecl wcschr(_In_z_ const wchar_t *_Str, wchar_t _Ch)
#define MAX_PATH
Definition: compat.h:26
#define SPDRP_HARDWAREID
Definition: setupapi.h:503
static const WCHAR L[]
Definition: oid.c:1250
#define ST_DEV_NOTWORK
Definition: rosddt.c:8
#define SPDRP_DEVICEDESC
Definition: setupapi.h:502
static int is_check_hw
Definition: rosddt.c:14
static int is_show_hw
Definition: rosddt.c:13
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define CharToOem
Definition: winuser.h:5609
static void trim(wchar_t *s)
Definition: rosddt.c:70
Definition: name.c:36
#define malloc
Definition: debug_ros.c:4
#define wsprintf
Definition: winuser.h:5731
static SERVICE_STATUS status
Definition: service.c:31
#define ST_NEUTRAL
Definition: rosddt.c:6
static int hw_check_base(wchar_t *hw_id, wchar_t *hw_name)
Definition: rosddt.c:31
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
Definition: ps.c:97

Referenced by wmain().

◆ hw_check_ini()

static int hw_check_ini ( wchar_t name)
static

Definition at line 18 of file rosddt.c.

19 {
20  wchar_t buff[MAX_PATH];
21 
23  return ST_NEUTRAL;
24  }
25  if (_wcsicmp(buff, L"ok") == 0) return ST_DEV_OK;
26  if (_wcsicmp(buff, L"notwork") == 0) return ST_DEV_NOTWORK;
27  if (_wcsicmp(buff, L"crash") == 0) return ST_ROS_CRASH;
28  return ST_NEUTRAL;
29 }
#define ST_ROS_CRASH
Definition: rosddt.c:7
static wchar_t gl_ini_file[MAX_PATH]
Definition: rosddt.c:15
smooth NULL
Definition: ftsmooth.c:416
#define ST_DEV_OK
Definition: rosddt.c:9
#define MAX_PATH
Definition: compat.h:26
static const WCHAR L[]
Definition: oid.c:1250
#define ST_DEV_NOTWORK
Definition: rosddt.c:8
#define GetPrivateProfileString
Definition: winbase.h:3649
Definition: name.c:36
#define ST_NEUTRAL
Definition: rosddt.c:6
static unsigned char buff[32768]
Definition: fatten.c:17
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)

Referenced by hw_check_base().

◆ trim()

static void trim ( wchar_t s)
static

Definition at line 70 of file rosddt.c.

71 {
72  wchar_t *p;
73  for (p = s + wcslen(s) - 1; (p > s) && (*p == L' '); *p-- = 0);
74 }
static const WCHAR L[]
Definition: oid.c:1250
GLdouble s
Definition: gl.h:2039
GLfloat GLfloat p
Definition: glext.h:8902
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

Referenced by hw_check_device().

◆ wmain()

int wmain ( int  argc,
wchar_t argv[] 
)

Definition at line 197 of file rosddt.c.

198 {
199  HDEVINFO h_info;
200  SP_DEVINFO_DATA d_inf;
201  int codes[ST_LAST_STATUS + 1] = {0};
202  int i;
203  wchar_t *p;
204 
205  if (argc != 2)
206  {
207  wprintf(
208  L"rosddt [parameters]\n"
209  L" -enum enumerate all installed hardware\n"
210  L" -check check hardware compatibility with ReactOS\n"
211  L" -update update hardware compatibility database\n"
212  L" -report send your hardware configuration to ReactOS team\n"
213  );
214  return 0;
215  }
216 
217  /* get path to ini file */
219  for (p = gl_ini_file + wcslen(gl_ini_file); *p != L'\\'; *p-- = 0);
220  wcscat(gl_ini_file, L"rosddt.ini");
221 
222  if (_wcsicmp(argv[1], L"-update") == 0) {
223  do_update_base(); return 0;
224  }
225  if (_wcsicmp(argv[1], L"-enum") == 0) {
226  is_show_hw = 1; is_check_hw = 0;
227  }
228  if (_wcsicmp(argv[1], L"-check") == 0) {
229  is_show_hw = 0; is_check_hw = 1;
230  }
231  if (_wcsicmp(argv[1], L"-report") == 0) {
232  is_show_hw = 0; is_check_hw = 0;
233  gl_report = malloc(65536); gl_report[0] = 0;
234  }
235 
237 
238  if (h_info == INVALID_HANDLE_VALUE) {
239  wprintf(L"SetupDiGetClassDevs error\n"); return 1;
240  }
241 
242  d_inf.cbSize = sizeof(d_inf); i = 0;
243 
244  while (SetupDiEnumDeviceInfo(h_info, i++, &d_inf) != 0) {
245  codes[hw_check_device(h_info, &d_inf)]++;
246  }
247 
248  if (is_check_hw != 0)
249  {
250  wprintf(
251  L"Checking completed.\nFound %d supported devices, %d unsupported devices and %d incompatible devices\n",
252  codes[ST_DEV_OK], codes[ST_DEV_NOTWORK], codes[ST_ROS_CRASH]);
253 
254  if (codes[ST_ROS_CRASH] == 0) {
255  wprintf(L"ReactOS can be installed on your computer\n");
256  } else {
257  wprintf(L"ReactOS can not be installed on your computer\n");
258  }
259  }
260 
261  if (gl_report != NULL) {
263  }
264 
265  return 0;
266 }
BOOL WINAPI SetupDiEnumDeviceInfo(HDEVINFO devinfo, DWORD index, PSP_DEVINFO_DATA info)
Definition: devinst.c:1792
static int argc
Definition: ServiceArgs.c:12
#define ST_ROS_CRASH
Definition: rosddt.c:7
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
#define wprintf(...)
Definition: whoami.c:18
static wchar_t gl_ini_file[MAX_PATH]
Definition: rosddt.c:15
#define argv
Definition: mplay32.c:18
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
smooth NULL
Definition: ftsmooth.c:416
static wchar_t * gl_report
Definition: rosddt.c:16
static void do_update_base()
Definition: rosddt.c:144
#define ST_DEV_OK
Definition: rosddt.c:9
#define MAX_PATH
Definition: compat.h:26
#define ST_LAST_STATUS
Definition: rosddt.c:11
#define GetModuleFileName
Definition: winbase.h:3645
#define DIGCF_ALLCLASSES
Definition: setupapi.h:172
static const WCHAR L[]
Definition: oid.c:1250
#define ST_DEV_NOTWORK
Definition: rosddt.c:8
#define SetupDiGetClassDevs
Definition: setupapi.h:2588
static int is_check_hw
Definition: rosddt.c:14
static int hw_check_device(HDEVINFO h_info, SP_DEVINFO_DATA *d_inf)
Definition: rosddt.c:76
static void do_send_report(wchar_t *report)
Definition: rosddt.c:173
static int is_show_hw
Definition: rosddt.c:13
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define malloc
Definition: debug_ros.c:4
GLfloat GLfloat p
Definition: glext.h:8902
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define DIGCF_PRESENT
Definition: setupapi.h:171

Variable Documentation

◆ gl_ini_file

wchar_t gl_ini_file[MAX_PATH]
static

Definition at line 15 of file rosddt.c.

Referenced by do_send_report(), do_update_base(), hw_check_ini(), and wmain().

◆ gl_report

wchar_t* gl_report
static

Definition at line 16 of file rosddt.c.

Referenced by hw_check_device(), and wmain().

◆ is_check_hw

int is_check_hw
static

Definition at line 14 of file rosddt.c.

Referenced by hw_check_device(), and wmain().

◆ is_show_hw

int is_show_hw
static

Definition at line 13 of file rosddt.c.

Referenced by hw_check_device(), and wmain().