ReactOS  0.4.15-dev-425-gc40b086
CConfiguration.cpp
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Automatic Testing Utility
3  * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4  * PURPOSE: Class for managing all the configuration parameters
5  * COPYRIGHT: Copyright 2009-2011 Colin Finck (colin@reactos.org)
6  */
7 
8 #include "precomp.h"
9 
10 #define CONFIGURATION_FILENAMEA "rosautotest.ini"
11 #define CONFIGURATION_FILENAMEW L"rosautotest.ini"
12 
14 
19  : m_CrashRecovery(false),
20  m_IsInteractive(false),
21  m_PrintToConsole(true),
22  m_RepeatCount(1),
23  m_Shutdown(false),
24  m_Submit(false)
25 {
26  WCHAR WindowsDirectory[MAX_PATH];
27  WCHAR Interactive[32];
28 
29  /* Check if we are running under ReactOS from the SystemRoot directory */
30  if(!GetWindowsDirectoryW(WindowsDirectory, MAX_PATH))
31  FATAL("GetWindowsDirectoryW failed\n");
32 
33  m_IsReactOS = !_wcsnicmp(&WindowsDirectory[3], L"reactos", 7);
34 
35  if(GetEnvironmentVariableW(L"WINETEST_INTERACTIVE", Interactive, _countof(Interactive)))
37 }
38 
48 void
50 {
51  /* Parse the command line arguments */
52  for(int i = 1; i < argc; i++)
53  {
54  if(argv[i][0] == '-' || argv[i][0] == '/')
55  {
56  unsigned long tmp_RepeatCount;
57 
58  switch(argv[i][1])
59  {
60  case 'c':
61  ++i;
62  if (i >= argc)
63  {
65  }
66 
68  break;
69 
70  case 'n':
71  m_PrintToConsole = false;
72  break;
73 
74  case 'r':
75  m_CrashRecovery = true;
76  break;
77 
78  case 's':
79  m_Shutdown = true;
80  break;
81 
82  case 'w':
83  m_Submit = true;
84  break;
85 
86  case 't':
87  ++i;
88  if (i >= argc)
89  {
91  }
92 
93  tmp_RepeatCount = wcstoul(argv[i], NULL, 10);
94 
95  if (tmp_RepeatCount == 0 || tmp_RepeatCount > 10000)
96  {
98  }
99 
100  m_RepeatCount = tmp_RepeatCount;
101  break;
102 
103  default:
105  }
106  }
107  else
108  {
109  /* Which parameter is this? */
110  if(m_Module.empty())
111  {
112  /* Copy the parameter */
113  m_Module = argv[i];
114  }
115  else if(m_Test.empty())
116  {
117  /* Copy the parameter converted to ASCII */
119  }
120  else
121  {
123  }
124  }
125  }
126 
127  /* The /r and /w options shouldn't be used in conjunction */
130 }
131 
135 void
137 {
138  char ProductType;
139  GETSYSINFO GetSysInfo;
140  HMODULE hKernel32;
141  OSVERSIONINFOEXW os;
143  SYSTEM_INFO si;
144 
145  /* Get the build from the define */
146  ss << "&revision=";
147  ss << KERNEL_VERSION_COMMIT_HASH;
148 
149  ss << "&platform=";
150 
151  if(m_IsReactOS)
152  {
153  ss << "reactos";
154  }
155  else
156  {
157  /* No, then use the info from GetVersionExW */
158  os.dwOSVersionInfoSize = sizeof(os);
159 
161  FATAL("GetVersionExW failed\n");
162 
163  if(os.dwMajorVersion < 5)
164  EXCEPTION("Application requires at least Windows 2000!\n");
165 
166  if(os.wProductType == VER_NT_WORKSTATION)
167  ProductType = 'w';
168  else
169  ProductType = 's';
170 
171  /* Print all necessary identification information into the Platform string */
172  ss << os.dwMajorVersion << '.'
173  << os.dwMinorVersion << '.'
174  << os.dwBuildNumber << '.'
175  << os.wServicePackMajor << '.'
176  << os.wServicePackMinor << '.'
177  << ProductType << '.';
178  }
179 
180  /* We also need to know about the processor architecture.
181  To retrieve this information accurately, check whether "GetNativeSystemInfo" is exported and use it then, otherwise fall back to "GetSystemInfo". */
182  hKernel32 = GetModuleHandleW(L"KERNEL32.DLL");
183  GetSysInfo = (GETSYSINFO)GetProcAddress(hKernel32, "GetNativeSystemInfo");
184 
185  if(!GetSysInfo)
186  GetSysInfo = (GETSYSINFO)GetProcAddress(hKernel32, "GetSystemInfo");
187 
188  GetSysInfo(&si);
190 
192 }
193 
199 void
201 {
202  DWORD Length;
203  string Value;
204  WCHAR ConfigFile[MAX_PATH];
205 
206  /* Most values are only needed if we're going to submit anything */
207  if(m_Submit)
208  {
209  /* Build the path to the configuration file from the application's path */
210  GetModuleFileNameW(NULL, ConfigFile, MAX_PATH);
211  Length = wcsrchr(ConfigFile, '\\') - ConfigFile + 1;
212  wcscpy(&ConfigFile[Length], CONFIGURATION_FILENAMEW);
213 
214  /* Check if it exists */
216  EXCEPTION("Missing \"" CONFIGURATION_FILENAMEA "\" configuration file!\n");
217 
218  /* Get the user name */
219  m_AuthenticationRequestString = "&sourceid=";
220  Value = GetINIValue(L"Login", L"SourceID", ConfigFile);
221 
222  if(Value.empty())
223  EXCEPTION("SourceID is missing in the configuration file\n");
224 
226 
227  /* Get the password */
228  m_AuthenticationRequestString += "&password=";
229  Value = GetINIValue(L"Login", L"Password", ConfigFile);
230 
231  if(Value.empty())
232  EXCEPTION("Password is missing in the configuration file\n");
233 
235 
236  /* If we don't have any Comment string yet, try to find one in the INI file */
237  if(m_Comment.empty())
238  m_Comment = GetINIValue(L"Submission", L"Comment", ConfigFile);
239  }
240 }
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2373
#define VER_NT_WORKSTATION
DWORD WINAPI GetModuleFileNameW(HINSTANCE hModule, LPWSTR lpFilename, DWORD nSize)
Definition: loader.c:600
ULONG dwOSVersionInfoSize
Definition: rtltypes.h:265
#define FATAL(Message)
Definition: precomp.h:57
static int argc
Definition: ServiceArgs.c:12
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
void(WINAPI * GETSYSINFO)(LPSYSTEM_INFO)
_Check_return_ _CRTIMP int __cdecl _wtoi(_In_z_ const wchar_t *_Str)
_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)
_Check_return_ unsigned long __cdecl wcstoul(_In_z_ const wchar_t *_Str, _Out_opt_ _Deref_post_z_ wchar_t **_EndPtr, _In_ int _Radix)
#define argv
Definition: mplay32.c:18
BOOL WINAPI GetVersionExW(IN LPOSVERSIONINFOW lpVersionInformation)
Definition: version.c:37
UINT WINAPI GetWindowsDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2351
#define true
Definition: osdep.h:36
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
string m_SystemInfoRequestString
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:802
smooth NULL
Definition: ftsmooth.c:416
_Check_return_ _CRTIMP _CONST_RETURN wchar_t *__cdecl wcsrchr(_In_z_ const wchar_t *_Str, _In_ wchar_t _Ch)
#define false
Definition: osdep.h:35
void ParseParameters(int argc, wchar_t *argv[])
#define EXCEPTION(Message)
Definition: precomp.h:56
unsigned long m_RepeatCount
void GetConfigurationFromFile()
string UnicodeToAscii(PCWSTR UnicodeString)
Definition: tools.cpp:261
ULONG dwMajorVersion
Definition: rtltypes.h:243
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define _countof(array)
Definition: sndvol32.h:68
#define MAX_PATH
Definition: compat.h:26
#define WINAPI
Definition: msvc.h:6
string EscapeString(const char *Input)
Definition: tools.cpp:24
unsigned long DWORD
Definition: ntddk_ex.h:95
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
ULONG dwBuildNumber
Definition: rtltypes.h:245
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1250
string GetINIValue(PCWCH AppName, PCWCH KeyName, PCWCH FileName)
Definition: tools.cpp:187
struct _SYSTEM_INFO * LPSYSTEM_INFO
WORD wProcessorArchitecture
Definition: winbase.h:1135
ULONG dwMinorVersion
Definition: rtltypes.h:244
#define CONFIGURATION_FILENAMEW
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
#define GetProcAddress(x, y)
Definition: compat.h:419
#define ss
Definition: i386-dis.c:432
#define CONFIGURATION_FILENAMEA
#define GetEnvironmentVariableW(x, y, z)
Definition: compat.h:421
string m_AuthenticationRequestString
void GetSystemInformation()