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_IsInteractive(false),
21 m_PrintToConsole(true),
25 WCHAR WindowsDirectory
[MAX_PATH
];
26 WCHAR Interactive
[32];
28 /* Check if we are running under ReactOS from the SystemRoot directory */
29 if(!GetWindowsDirectoryW(WindowsDirectory
, MAX_PATH
))
30 FATAL("GetWindowsDirectoryW failed");
32 m_IsReactOS
= !_wcsnicmp(&WindowsDirectory
[3], L
"reactos", 7);
34 if(GetEnvironmentVariableW(L
"WINETEST_INTERACTIVE", Interactive
, _countof(Interactive
)))
35 m_IsInteractive
= _wtoi(Interactive
);
39 * Parses the passed parameters and sets the appropriate configuration settings.
42 * The number of parameters (argc parameter of the wmain function)
45 * Pointer to a wchar_t array containing the parameters (argv parameter of the wmain function)
48 CConfiguration::ParseParameters(int argc
, wchar_t* argv
[])
50 /* Parse the command line arguments */
51 for(int i
= 1; i
< argc
; i
++)
53 if(argv
[i
][0] == '-' || argv
[i
][0] == '/')
59 m_Comment
= UnicodeToAscii(argv
[i
]);
63 m_PrintToConsole
= false;
67 m_CrashRecovery
= true;
79 throw CInvalidParameterException();
84 /* Which parameter is this? */
87 /* Copy the parameter */
90 else if(m_Test
.empty())
92 /* Copy the parameter converted to ASCII */
93 m_Test
= UnicodeToAscii(argv
[i
]);
97 throw CInvalidParameterException();
102 /* The /r and /w options shouldn't be used in conjunction */
103 if(m_CrashRecovery
&& m_Submit
)
104 throw CInvalidParameterException();
108 * Gets information about the running system and sets the appropriate configuration settings.
111 CConfiguration::GetSystemInformation()
114 GETSYSINFO GetSysInfo
;
120 /* Get the build from the define */
122 ss
<< KERNEL_VERSION_BUILD_HEX
;
132 /* No, then use the info from GetVersionExW */
133 os
.dwOSVersionInfoSize
= sizeof(os
);
135 if(!GetVersionExW((LPOSVERSIONINFOW
)&os
))
136 FATAL("GetVersionExW failed\n");
138 if(os
.dwMajorVersion
< 5)
139 EXCEPTION("Application requires at least Windows 2000!\n");
141 if(os
.wProductType
== VER_NT_WORKSTATION
)
146 /* Print all necessary identification information into the Platform string */
147 ss
<< os
.dwMajorVersion
<< '.'
148 << os
.dwMinorVersion
<< '.'
149 << os
.dwBuildNumber
<< '.'
150 << os
.wServicePackMajor
<< '.'
151 << os
.wServicePackMinor
<< '.'
152 << ProductType
<< '.';
155 /* We also need to know about the processor architecture.
156 To retrieve this information accurately, check whether "GetNativeSystemInfo" is exported and use it then, otherwise fall back to "GetSystemInfo". */
157 hKernel32
= GetModuleHandleW(L
"KERNEL32.DLL");
158 GetSysInfo
= (GETSYSINFO
)GetProcAddress(hKernel32
, "GetNativeSystemInfo");
161 GetSysInfo
= (GETSYSINFO
)GetProcAddress(hKernel32
, "GetSystemInfo");
164 ss
<< si
.wProcessorArchitecture
;
166 m_SystemInfoRequestString
= ss
.str();
170 * Reads additional configuration options from the INI file.
172 * ParseParameters should be called before this function to get the desired result.
175 CConfiguration::GetConfigurationFromFile()
179 WCHAR ConfigFile
[MAX_PATH
];
181 /* Most values are only needed if we're going to submit anything */
184 /* Build the path to the configuration file from the application's path */
185 GetModuleFileNameW(NULL
, ConfigFile
, MAX_PATH
);
186 Length
= wcsrchr(ConfigFile
, '\\') - ConfigFile
+ 1;
187 wcscpy(&ConfigFile
[Length
], CONFIGURATION_FILENAMEW
);
189 /* Check if it exists */
190 if(GetFileAttributesW(ConfigFile
) == INVALID_FILE_ATTRIBUTES
)
191 EXCEPTION("Missing \"" CONFIGURATION_FILENAMEA
"\" configuration file!\n");
193 /* Get the user name */
194 m_AuthenticationRequestString
= "&sourceid=";
195 Value
= GetINIValue(L
"Login", L
"SourceID", ConfigFile
);
198 EXCEPTION("SourceID is missing in the configuration file\n");
200 m_AuthenticationRequestString
+= EscapeString(Value
);
202 /* Get the password */
203 m_AuthenticationRequestString
+= "&password=";
204 Value
= GetINIValue(L
"Login", L
"Password", ConfigFile
);
207 EXCEPTION("Password is missing in the configuration file\n");
209 m_AuthenticationRequestString
+= EscapeString(Value
);
211 /* If we don't have any Comment string yet, try to find one in the INI file */
212 if(m_Comment
.empty())
213 m_Comment
= GetINIValue(L
"Submission", L
"Comment", ConfigFile
);