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()
20 WCHAR WindowsDirectory
[MAX_PATH
];
22 /* Zero-initialize variables */
23 m_CrashRecovery
= false;
27 /* Check if we are running under ReactOS from the SystemRoot directory */
28 if(!GetWindowsDirectoryW(WindowsDirectory
, MAX_PATH
))
29 FATAL("GetWindowsDirectoryW failed");
31 m_IsReactOS
= !_wcsnicmp(&WindowsDirectory
[3], L
"reactos", 7);
35 * Parses the passed parameters and sets the appropriate configuration settings.
38 * The number of parameters (argc parameter of the wmain function)
41 * Pointer to a wchar_t array containing the parameters (argv parameter of the wmain function)
44 CConfiguration::ParseParameters(int argc
, wchar_t* argv
[])
46 /* Parse the command line arguments */
47 for(int i
= 1; i
< argc
; i
++)
49 if(argv
[i
][0] == '-' || argv
[i
][0] == '/')
55 m_Comment
= UnicodeToAscii(argv
[i
]);
59 m_CrashRecovery
= true;
71 throw CInvalidParameterException();
76 /* Which parameter is this? */
79 /* Copy the parameter */
82 else if(m_Test
.empty())
84 /* Copy the parameter converted to ASCII */
85 m_Test
= UnicodeToAscii(argv
[i
]);
89 throw CInvalidParameterException();
94 /* The /r and /w options shouldn't be used in conjunction */
95 if(m_CrashRecovery
&& m_Submit
)
96 throw CInvalidParameterException();
100 * Gets information about the running system and sets the appropriate configuration settings.
103 CConfiguration::GetSystemInformation()
106 GETSYSINFO GetSysInfo
;
112 /* Get the build from the define */
114 ss
<< KERNEL_VERSION_BUILD_HEX
;
124 /* No, then use the info from GetVersionExW */
125 os
.dwOSVersionInfoSize
= sizeof(os
);
127 if(!GetVersionExW((LPOSVERSIONINFOW
)&os
))
128 FATAL("GetVersionExW failed\n");
130 if(os
.dwMajorVersion
< 5)
131 EXCEPTION("Application requires at least Windows 2000!\n");
133 if(os
.wProductType
== VER_NT_WORKSTATION
)
138 /* Print all necessary identification information into the Platform string */
139 ss
<< os
.dwMajorVersion
<< '.'
140 << os
.dwMinorVersion
<< '.'
141 << os
.dwBuildNumber
<< '.'
142 << os
.wServicePackMajor
<< '.'
143 << os
.wServicePackMinor
<< '.'
144 << ProductType
<< '.';
147 /* We also need to know about the processor architecture.
148 To retrieve this information accurately, check whether "GetNativeSystemInfo" is exported and use it then, otherwise fall back to "GetSystemInfo". */
149 hKernel32
= GetModuleHandleW(L
"KERNEL32.DLL");
150 GetSysInfo
= (GETSYSINFO
)GetProcAddress(hKernel32
, "GetNativeSystemInfo");
153 GetSysInfo
= (GETSYSINFO
)GetProcAddress(hKernel32
, "GetSystemInfo");
156 ss
<< si
.wProcessorArchitecture
;
158 m_SystemInfoRequestString
= ss
.str();
162 * Reads additional configuration options from the INI file.
164 * ParseParameters should be called before this function to get the desired result.
167 CConfiguration::GetConfigurationFromFile()
171 WCHAR ConfigFile
[MAX_PATH
];
173 /* Most values are only needed if we're going to submit anything */
176 /* Build the path to the configuration file from the application's path */
177 GetModuleFileNameW(NULL
, ConfigFile
, MAX_PATH
);
178 Length
= wcsrchr(ConfigFile
, '\\') - ConfigFile
+ 1;
179 wcscpy(&ConfigFile
[Length
], CONFIGURATION_FILENAMEW
);
181 /* Check if it exists */
182 if(GetFileAttributesW(ConfigFile
) == INVALID_FILE_ATTRIBUTES
)
183 EXCEPTION("Missing \"" CONFIGURATION_FILENAMEA
"\" configuration file!\n");
185 /* Get the user name */
186 m_AuthenticationRequestString
= "&sourceid=";
187 Value
= GetINIValue(L
"Login", L
"SourceID", ConfigFile
);
190 EXCEPTION("SourceID is missing in the configuration file\n");
192 m_AuthenticationRequestString
+= EscapeString(Value
);
194 /* Get the password */
195 m_AuthenticationRequestString
+= "&password=";
196 Value
= GetINIValue(L
"Login", L
"Password", ConfigFile
);
199 EXCEPTION("Password is missing in the configuration file\n");
201 m_AuthenticationRequestString
+= EscapeString(Value
);
203 /* If we don't have any Comment string yet, try to find one in the INI file */
204 if(m_Comment
.empty())
205 m_Comment
= GetINIValue(L
"Submission", L
"Comment", ConfigFile
);