2 * PROJECT: ReactOS Automatic Testing Utility
3 * LICENSE: GNU GPLv2 or any later version as published by the Free Software Foundation
4 * PURPOSE: Class for managing all the configuration parameters
5 * COPYRIGHT: Copyright 2009-2011 Colin Finck <colin@reactos.org>
10 #define CONFIGURATION_FILENAMEA "rosautotest.ini"
11 #define CONFIGURATION_FILENAMEW L"rosautotest.ini"
13 typedef void (WINAPI
*GETSYSINFO
)(LPSYSTEM_INFO
);
16 * Constructs an empty CConfiguration object
18 CConfiguration::CConfiguration()
19 : m_CrashRecovery(false),
20 m_PrintToConsole(true),
24 WCHAR WindowsDirectory
[MAX_PATH
];
26 /* Check if we are running under ReactOS from the SystemRoot directory */
27 if(!GetWindowsDirectoryW(WindowsDirectory
, MAX_PATH
))
28 FATAL("GetWindowsDirectoryW failed");
30 m_IsReactOS
= !_wcsnicmp(&WindowsDirectory
[3], L
"reactos", 7);
34 * Parses the passed parameters and sets the appropriate configuration settings.
37 * The number of parameters (argc parameter of the wmain function)
40 * Pointer to a wchar_t array containing the parameters (argv parameter of the wmain function)
43 CConfiguration::ParseParameters(int argc
, wchar_t* argv
[])
45 /* Parse the command line arguments */
46 for(int i
= 1; i
< argc
; i
++)
48 if(argv
[i
][0] == '-' || argv
[i
][0] == '/')
54 m_Comment
= UnicodeToAscii(argv
[i
]);
58 m_PrintToConsole
= false;
62 m_CrashRecovery
= true;
74 throw CInvalidParameterException();
79 /* Which parameter is this? */
82 /* Copy the parameter */
85 else if(m_Test
.empty())
87 /* Copy the parameter converted to ASCII */
88 m_Test
= UnicodeToAscii(argv
[i
]);
92 throw CInvalidParameterException();
97 /* The /r and /w options shouldn't be used in conjunction */
98 if(m_CrashRecovery
&& m_Submit
)
99 throw CInvalidParameterException();
103 * Gets information about the running system and sets the appropriate configuration settings.
106 CConfiguration::GetSystemInformation()
109 GETSYSINFO GetSysInfo
;
115 /* Get the build from the define */
117 ss
<< KERNEL_VERSION_BUILD_HEX
;
127 /* No, then use the info from GetVersionExW */
128 os
.dwOSVersionInfoSize
= sizeof(os
);
130 if(!GetVersionExW((LPOSVERSIONINFOW
)&os
))
131 FATAL("GetVersionExW failed\n");
133 if(os
.dwMajorVersion
< 5)
134 EXCEPTION("Application requires at least Windows 2000!\n");
136 if(os
.wProductType
== VER_NT_WORKSTATION
)
141 /* Print all necessary identification information into the Platform string */
142 ss
<< os
.dwMajorVersion
<< '.'
143 << os
.dwMinorVersion
<< '.'
144 << os
.dwBuildNumber
<< '.'
145 << os
.wServicePackMajor
<< '.'
146 << os
.wServicePackMinor
<< '.'
147 << ProductType
<< '.';
150 /* We also need to know about the processor architecture.
151 To retrieve this information accurately, check whether "GetNativeSystemInfo" is exported and use it then, otherwise fall back to "GetSystemInfo". */
152 hKernel32
= GetModuleHandleW(L
"KERNEL32.DLL");
153 GetSysInfo
= (GETSYSINFO
)GetProcAddress(hKernel32
, "GetNativeSystemInfo");
156 GetSysInfo
= (GETSYSINFO
)GetProcAddress(hKernel32
, "GetSystemInfo");
159 ss
<< si
.wProcessorArchitecture
;
161 m_SystemInfoRequestString
= ss
.str();
165 * Reads additional configuration options from the INI file.
167 * ParseParameters should be called before this function to get the desired result.
170 CConfiguration::GetConfigurationFromFile()
174 WCHAR ConfigFile
[MAX_PATH
];
176 /* Most values are only needed if we're going to submit anything */
179 /* Build the path to the configuration file from the application's path */
180 GetModuleFileNameW(NULL
, ConfigFile
, MAX_PATH
);
181 Length
= wcsrchr(ConfigFile
, '\\') - ConfigFile
+ 1;
182 wcscpy(&ConfigFile
[Length
], CONFIGURATION_FILENAMEW
);
184 /* Check if it exists */
185 if(GetFileAttributesW(ConfigFile
) == INVALID_FILE_ATTRIBUTES
)
186 EXCEPTION("Missing \"" CONFIGURATION_FILENAMEA
"\" configuration file!\n");
188 /* Get the user name */
189 m_AuthenticationRequestString
= "&sourceid=";
190 Value
= GetINIValue(L
"Login", L
"SourceID", ConfigFile
);
193 EXCEPTION("SourceID is missing in the configuration file\n");
195 m_AuthenticationRequestString
+= EscapeString(Value
);
197 /* Get the password */
198 m_AuthenticationRequestString
+= "&password=";
199 Value
= GetINIValue(L
"Login", L
"Password", ConfigFile
);
202 EXCEPTION("Password is missing in the configuration file\n");
204 m_AuthenticationRequestString
+= EscapeString(Value
);
206 /* If we don't have any Comment string yet, try to find one in the INI file */
207 if(m_Comment
.empty())
208 m_Comment
= GetINIValue(L
"Submission", L
"Comment", ConfigFile
);