|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Definitions for the class CATBase. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "../inc/CATBase.h" |
|
20 #include "../inc/CATParseXML.h" |
|
21 |
|
22 // ----------------------------------------------------------------------------- |
|
23 // CATBase::CATBase |
|
24 // Constructor. |
|
25 // ----------------------------------------------------------------------------- |
|
26 CATBase::CATBase(void) |
|
27 { |
|
28 LOG_FUNC_ENTRY("CATBase::CATBase"); |
|
29 } |
|
30 |
|
31 // ----------------------------------------------------------------------------- |
|
32 // CATBase::~CATBase |
|
33 // Destructor. |
|
34 // ----------------------------------------------------------------------------- |
|
35 CATBase::~CATBase(void) |
|
36 { |
|
37 LOG_FUNC_ENTRY("CATBase::~CATBase"); |
|
38 } |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // CATBase::ChangeToLower |
|
42 // Converts any uppercase letter to lowercase. |
|
43 // ----------------------------------------------------------------------------- |
|
44 void CATBase::ChangeToLower( string& sInput ) |
|
45 { |
|
46 LOG_LOW_FUNC_ENTRY("CATBase::ChangeToLower"); |
|
47 int iLength = (int)sInput.size(); |
|
48 for( int i = 0 ; i < iLength ; i++ ) |
|
49 { |
|
50 sInput[i] = (char)tolower( sInput[i] ); |
|
51 } |
|
52 } |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // CATBase::ChangeToUpper |
|
56 // Converts any uppercase letter to lowercase. |
|
57 // ----------------------------------------------------------------------------- |
|
58 void CATBase::ChangeToUpper( string& sInput ) |
|
59 { |
|
60 LOG_LOW_FUNC_ENTRY("CATBase::ChangeToUpper"); |
|
61 int iLength = (int)sInput.size(); |
|
62 for( int i = 0 ; i < iLength ; i++ ) |
|
63 { |
|
64 sInput[i] = (char)toupper( sInput[i] ); |
|
65 } |
|
66 } |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // CATBase::TrimString |
|
70 // Remove spaces and tabulatures from beginning and |
|
71 // end of given string. |
|
72 // ----------------------------------------------------------------------------- |
|
73 void CATBase::TrimString( string& sInput ) |
|
74 { |
|
75 LOG_LOW_FUNC_ENTRY("CATBase::TrimString"); |
|
76 if( sInput.empty() ) |
|
77 return; |
|
78 //Remove spaces and tabulatures from beginning of string |
|
79 while( !sInput.empty() && ( sInput[0] == SPACE_CHAR_VALUE || sInput[0] == TAB_CHAR_VALUE ) ) |
|
80 { |
|
81 sInput.erase( 0, 1 ); |
|
82 } |
|
83 //Remove spaces and tabulatures from end of string |
|
84 while( !sInput.empty() && ( sInput[sInput.size()-1] == SPACE_CHAR_VALUE || sInput[sInput.size()-1] == TAB_CHAR_VALUE ) ) |
|
85 { |
|
86 sInput.erase( sInput.size()-1, 1 ); |
|
87 } |
|
88 } |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // CATBase::SearchFileWithExtension |
|
92 // Searches files with given extension from path. |
|
93 // ----------------------------------------------------------------------------- |
|
94 bool CATBase::SearchFileWithExtension( const char* pPathAndExt, bool bPrintErrors, string& sErrorLog ) |
|
95 { |
|
96 LOG_FUNC_ENTRY("CATBase::SearchFileWithExtension"); |
|
97 WIN32_FIND_DATA FindFileData; |
|
98 HANDLE hFind; |
|
99 string sTemp( pPathAndExt ); |
|
100 |
|
101 //Find file |
|
102 hFind = FindFirstFile( sTemp.c_str(), &FindFileData ); |
|
103 if (hFind == INVALID_HANDLE_VALUE) |
|
104 { |
|
105 string sErrorString( "No " ); |
|
106 //Get extension |
|
107 string sExt( pPathAndExt ); |
|
108 sExt.erase( 0, sExt.find_last_of( "." ) ); |
|
109 |
|
110 sErrorString.append( sExt ); |
|
111 sErrorString.append( " files in directory: " ); |
|
112 |
|
113 string sWithoutExt( pPathAndExt ); |
|
114 sWithoutExt.erase( sWithoutExt.find_last_of( "." )-1, string::npos ); |
|
115 sErrorString.append( sWithoutExt ); |
|
116 |
|
117 if( bPrintErrors ) |
|
118 { |
|
119 //string sTemp( pPathAndExt ); |
|
120 //printf( "Can not find: %s.\n", pPathAndExt ); |
|
121 printf( sErrorString.c_str() ); |
|
122 } |
|
123 else |
|
124 { |
|
125 //Add line change if sErrorString not empty |
|
126 if( !sErrorLog.empty() ) |
|
127 sErrorString.insert( 0, "\n" ); |
|
128 sErrorLog.append( sErrorString ); |
|
129 } |
|
130 return false; |
|
131 } |
|
132 else |
|
133 { |
|
134 FindClose(hFind); |
|
135 return true; |
|
136 } |
|
137 } |
|
138 |
|
139 // ----------------------------------------------------------------------------- |
|
140 // CATBase::GetPathOrFileName |
|
141 // Returns path to file or file name. |
|
142 // ----------------------------------------------------------------------------- |
|
143 string CATBase::GetPathOrFileName( bool bFileName, string sInput ) |
|
144 { |
|
145 LOG_LOW_FUNC_ENTRY("CATBase::GetPathOrFileName"); |
|
146 string sRet; |
|
147 size_t iPos = sInput.size()-1; |
|
148 |
|
149 sInput = ChangeSlashToBackSlash( sInput ); |
|
150 |
|
151 //Find character '\' starting from end of string |
|
152 while( iPos > 0 && sInput[iPos] != '\\' ) |
|
153 { |
|
154 iPos--; |
|
155 } |
|
156 if( iPos > 0 ) |
|
157 { |
|
158 //Return file name |
|
159 if( bFileName ) |
|
160 { |
|
161 sInput.erase( 0, iPos+1 ); |
|
162 sRet = sInput; |
|
163 } |
|
164 else //Return file path |
|
165 { |
|
166 sInput.erase( iPos+1, string::npos ); |
|
167 sRet = sInput; |
|
168 } |
|
169 } |
|
170 else |
|
171 { |
|
172 if( !bFileName ) |
|
173 return sRet; |
|
174 sRet = sInput; |
|
175 } |
|
176 return sRet; |
|
177 } |
|
178 |
|
179 // ----------------------------------------------------------------------------- |
|
180 // CATBase::GetFileNameUsingExt |
|
181 // Searches files with given extension from path. |
|
182 // ----------------------------------------------------------------------------- |
|
183 string CATBase::GetFileNameUsingExt( const char* pPathAndExt ) |
|
184 { |
|
185 LOG_FUNC_ENTRY("CATBase::GetFileNameUsingExt"); |
|
186 WIN32_FIND_DATA FindFileData; |
|
187 HANDLE hFind; |
|
188 string sRet; |
|
189 |
|
190 //Find file |
|
191 hFind = FindFirstFile( pPathAndExt, &FindFileData ); |
|
192 if (hFind == INVALID_HANDLE_VALUE) |
|
193 { |
|
194 //if( bPrintErrors ) |
|
195 printf( "Can not find: %s.\n", pPathAndExt ); |
|
196 return sRet; |
|
197 } |
|
198 else |
|
199 { |
|
200 sRet.append( FindFileData.cFileName ); |
|
201 FindClose(hFind); |
|
202 return sRet; |
|
203 } |
|
204 } |
|
205 |
|
206 // ----------------------------------------------------------------------------- |
|
207 // CATBase::GetStringUntilNextSpace |
|
208 // Function returns string from begin of given string until next space, |
|
209 // characters until next space are removed from sInput string. |
|
210 // ----------------------------------------------------------------------------- |
|
211 string CATBase::GetStringUntilNextSpace( string& sInput, bool bEraseFromInput ) |
|
212 { |
|
213 LOG_LOW_FUNC_ENTRY("CATBase::GetStringUntilNextSpace"); |
|
214 string sTemp( sInput ); |
|
215 size_t iSize = sTemp.find_first_of(' '); |
|
216 if( iSize != string::npos ) |
|
217 { |
|
218 sTemp.resize( iSize ); |
|
219 if( bEraseFromInput ) |
|
220 sInput.erase( 0, (iSize+1) ); |
|
221 } |
|
222 else |
|
223 { |
|
224 if ( bEraseFromInput ) |
|
225 sInput.clear(); |
|
226 } |
|
227 return sTemp; |
|
228 } |
|
229 |
|
230 // ----------------------------------------------------------------------------- |
|
231 // CATBase::GetStringUntilMainId |
|
232 // Function returns string from begin of given string until next atool's main id <AT>, |
|
233 // characters until next main id are removed from sInput string. |
|
234 // ----------------------------------------------------------------------------- |
|
235 string CATBase::GetStringUntilMainId( string& sInput, bool bEraseFromInput ) |
|
236 { |
|
237 LOG_LOW_FUNC_ENTRY("CATBase::GetStringUntilMainId"); |
|
238 string sTemp( sInput ); |
|
239 size_t iSize = sTemp.find(MAIN_ID); |
|
240 if( iSize != string::npos ) |
|
241 { |
|
242 sTemp.resize( iSize ); |
|
243 if( bEraseFromInput ) |
|
244 sInput.erase( 0, (iSize) ); |
|
245 } |
|
246 else |
|
247 { |
|
248 if ( bEraseFromInput ) |
|
249 sInput.clear(); |
|
250 } |
|
251 return sTemp; |
|
252 } |
|
253 |
|
254 // ----------------------------------------------------------------------------- |
|
255 // CATBase::ChangeSlashToBackSlash |
|
256 // Function changes all BackSlash characters to Slash character from |
|
257 // given string. |
|
258 // ----------------------------------------------------------------------------- |
|
259 string CATBase::ChangeSlashToBackSlash( string sInput ) |
|
260 { |
|
261 LOG_LOW_FUNC_ENTRY("CATBase::ChangeSlashToBackSlash"); |
|
262 for( unsigned int i = 0 ; i < sInput.length() ; i++ ) |
|
263 { |
|
264 if( sInput[i] == '/' ) |
|
265 { |
|
266 sInput[i] = '\\'; |
|
267 } |
|
268 } |
|
269 return sInput; |
|
270 } |
|
271 |
|
272 |
|
273 // ----------------------------------------------------------------------------- |
|
274 // CATBase::ParseTimeStamp |
|
275 // Function returns time parsed from start of trace message |
|
276 // ----------------------------------------------------------------------------- |
|
277 unsigned __int64 CATBase::ParseTimeStamp( string sLineStart ) |
|
278 { |
|
279 unsigned __int64 iTime(0); |
|
280 |
|
281 int iHours(0), iMinutes(0), iSeconds(0), iMiliseconds(0), iMicroseconds(0); |
|
282 int iErr(0), iRet(0); |
|
283 |
|
284 TrimString( sLineStart ); |
|
285 string sTimeString = GetStringUntilNextSpace( sLineStart ); |
|
286 |
|
287 // Get time |
|
288 int iPos = sTimeString.find( ":" ); |
|
289 if( iPos != string::npos ) // ':' found, this is timestamp from fastTrace/traceViewer |
|
290 { |
|
291 // possible formats |
|
292 // hh:mm:ss - seconds (ft) |
|
293 // hh:mm:ss:mmm - miliseconds (ft/tw) |
|
294 // hh:mm:ss:mmmmmm - microseconds (ft/tw) |
|
295 // hh:mm:ss:nnnnnnnnn - nanoseconds (ft) - ignore last 3digits |
|
296 |
|
297 iRet = sscanf_s( sTimeString.c_str(), "%d:%d:%d.%3d%3d", &iHours, &iMinutes, &iSeconds, &iMiliseconds, &iMicroseconds ); |
|
298 if( iRet == 5 || iRet == 4 ) |
|
299 { |
|
300 // get microseconds |
|
301 iTime = ( ( ( iHours*60 + iMinutes )*60 + iSeconds )*1000 + iMiliseconds )*1000 + iMicroseconds; |
|
302 } |
|
303 else |
|
304 { |
|
305 iErr = true; |
|
306 } |
|
307 } |
|
308 else if( sTimeString.find( "." ) != string::npos ) // epoc timestamp in format ssss.mmm |
|
309 { |
|
310 iRet = sscanf_s( sTimeString.c_str(), "%d.%d", &iSeconds, &iMiliseconds ); |
|
311 if( iRet == 2 ) |
|
312 { |
|
313 // get microseconds |
|
314 iTime = ( ( ( iHours*60 + iMinutes )*60 + iSeconds )*1000 + iMiliseconds )*1000 + iMicroseconds; |
|
315 } |
|
316 else |
|
317 { |
|
318 iErr = true; |
|
319 } |
|
320 } |
|
321 else // timestamp in microseconds from binary log file or from ft |
|
322 { |
|
323 iRet = sscanf_s( sTimeString.c_str(), "%016I64x", &iTime); |
|
324 if( iRet == 1 ) |
|
325 { |
|
326 } |
|
327 else |
|
328 { |
|
329 iErr = true; |
|
330 } |
|
331 } |
|
332 |
|
333 if( iErr ) |
|
334 cout << "Error, can not read timestamp.\n"; |
|
335 |
|
336 return iTime; |
|
337 } |
|
338 |
|
339 // ----------------------------------------------------------------------------- |
|
340 // CATBase::FileExists |
|
341 // Check if given file exists. |
|
342 // ----------------------------------------------------------------------------- |
|
343 bool CATBase::FileExists( const char * pFilename ) |
|
344 { |
|
345 LOG_FUNC_ENTRY("CATBase::FileExists"); |
|
346 DWORD dwRet = GetFileAttributes( pFilename ); |
|
347 if( dwRet == INVALID_FILE_ATTRIBUTES ) |
|
348 { |
|
349 return false; |
|
350 } |
|
351 else |
|
352 { |
|
353 //Is file directory? |
|
354 if( dwRet & FILE_ATTRIBUTE_DIRECTORY ) |
|
355 { |
|
356 return false; |
|
357 } |
|
358 } |
|
359 return true; |
|
360 } |
|
361 |
|
362 bool CATBase::IsFileReadOnly( const char* pFilename ) |
|
363 { |
|
364 LOG_FUNC_ENTRY("CATBase::IsFileReadOnly"); |
|
365 DWORD dwRet = GetFileAttributes( pFilename ); |
|
366 if( dwRet == INVALID_FILE_ATTRIBUTES ) |
|
367 return false; |
|
368 if( dwRet & FILE_ATTRIBUTE_READONLY ) |
|
369 return true; |
|
370 return false; |
|
371 } |
|
372 |
|
373 bool CATBase::SetFileReadOnly( const char* pFileName ) |
|
374 { |
|
375 LOG_FUNC_ENTRY("CATBase::SetFileReadOnly"); |
|
376 DWORD dw = GetFileAttributes( pFileName ); |
|
377 if( dw == INVALID_FILE_ATTRIBUTES ) |
|
378 return false; |
|
379 if( dw & FILE_ATTRIBUTE_READONLY ) |
|
380 return true; |
|
381 dw = dw | FILE_ATTRIBUTE_READONLY ; |
|
382 if ( SetFileAttributes( pFileName, dw ) ) |
|
383 return true; |
|
384 return false; |
|
385 } |
|
386 bool CATBase::SetFileWritable( const char* pFileName ) |
|
387 { |
|
388 LOG_FUNC_ENTRY("CATBase::SetFileWritable"); |
|
389 DWORD dw = GetFileAttributes( pFileName ); |
|
390 if( dw == INVALID_FILE_ATTRIBUTES ) |
|
391 return false; |
|
392 if( ! dw & FILE_ATTRIBUTE_READONLY ) |
|
393 return true; |
|
394 dw = dw ^ FILE_ATTRIBUTE_READONLY ; |
|
395 if ( SetFileAttributes( pFileName, dw ) ) |
|
396 return true; |
|
397 return false; |
|
398 } |
|
399 |
|
400 // ----------------------------------------------------------------------------- |
|
401 // CATBase::FileCopyToPath |
|
402 // Copies file to given path |
|
403 // ----------------------------------------------------------------------------- |
|
404 bool CATBase::FileCopyToPath(const string& sFile, const string& sToPath) |
|
405 { |
|
406 LOG_FUNC_ENTRY("CATBase::FileCopyToPath"); |
|
407 // Display message |
|
408 cout << AT_MSG << "Copy " << sFile << AT_FILE_TO << sToPath << endl; |
|
409 if ( sFile.empty() || sToPath.empty() ) |
|
410 { |
|
411 LOG_FUNC_EXIT("CATBase::FileCopyToPath Error, empty parameter"); |
|
412 return false; |
|
413 } |
|
414 // Copy using windows api (seems not to work when relavite path .. |
|
415 /* |
|
416 // Full path where to copy |
|
417 string sDestination = sToPath; |
|
418 // Append '\' to string if not exists |
|
419 if ( sDestination.length() > 1 ) |
|
420 { |
|
421 const char cLastChar = sDestination[ sDestination.length() -1 ]; |
|
422 if ( cLastChar != DASH ) |
|
423 sDestination.append("\\"); |
|
424 } |
|
425 int iRet = 0; |
|
426 iRet = CopyFile( sFile.c_str(), sDestination.c_str(), false ); |
|
427 if ( iRet != 0 ) |
|
428 { |
|
429 return false; |
|
430 } |
|
431 */ |
|
432 string sCommand; |
|
433 sCommand.append( "copy /Y \""); |
|
434 sCommand.append( sFile ); |
|
435 sCommand.append( "\" \"" ); |
|
436 sCommand.append( sToPath ); |
|
437 sCommand.append( "\" > nul 2>&1" ); |
|
438 LOG_STRING( sCommand ); |
|
439 int iRet = 0; |
|
440 iRet = (int)system( sCommand.c_str() ); |
|
441 if ( iRet != 0 ) |
|
442 return false; |
|
443 return true; |
|
444 } |
|
445 |
|
446 // ----------------------------------------------------------------------------- |
|
447 // CATBase::FileMoveToPath |
|
448 // Copies file to given path |
|
449 // ----------------------------------------------------------------------------- |
|
450 bool CATBase::FileMoveToPath(const string& sFile, const string& sToPath) |
|
451 { |
|
452 LOG_FUNC_ENTRY("CATBase::FileMoveToPath"); |
|
453 // Display message |
|
454 cout << AT_MSG << "Move " << sFile << AT_FILE_TO << sToPath << endl; |
|
455 if ( sFile.empty() || sToPath.empty() ) |
|
456 { |
|
457 LOG_FUNC_EXIT("CATBase::FileMoveToPath Error, empty parameter"); |
|
458 return false; |
|
459 } |
|
460 // Move (again windows api function does not support relative path .. in it |
|
461 /* |
|
462 // Get filename from sFile |
|
463 string sFileName = GetPathOrFileName( true, sFile ); |
|
464 // Full path where to copy |
|
465 string sDestination = sToPath; |
|
466 // Append '\' to string if not exists |
|
467 if ( sDestination.length() > 1 ) |
|
468 { |
|
469 const char cLastChar = sDestination[ sDestination.length() -1 ]; |
|
470 if ( cLastChar != DASH ) |
|
471 sDestination.append("\\"); |
|
472 } |
|
473 int iRet = 0; |
|
474 iRet = MoveFile( sFile.c_str(), sDestination.c_str()); |
|
475 if ( iRet != 0 ) |
|
476 { |
|
477 return false; |
|
478 } |
|
479 */ |
|
480 string sCommand; |
|
481 sCommand.append( "move /Y \""); |
|
482 sCommand.append( sFile ); |
|
483 sCommand.append( "\" \"" ); |
|
484 sCommand.append( sToPath ); |
|
485 sCommand.append( "\" > nul 2>&1" ); |
|
486 LOG_STRING( sCommand ); |
|
487 int iRet = 0; |
|
488 iRet = (int)system( sCommand.c_str() ); |
|
489 if ( iRet != 0 ) |
|
490 return false; |
|
491 return true; |
|
492 } |
|
493 // ----------------------------------------------------------------------------- |
|
494 // CATBase::CreateTempPath |
|
495 // Creates temporary directory path for given mmp file |
|
496 // ----------------------------------------------------------------------------- |
|
497 string CATBase::CreateTempPath(const string& sMmpFileWithPath) |
|
498 { |
|
499 LOG_FUNC_ENTRY("CATBase::CreateTempPath"); |
|
500 string sTempPath = GetPathOrFileName( false, sMmpFileWithPath ); |
|
501 sTempPath.append( AT_TEMP_DIR ); |
|
502 sTempPath.append( "\\" ); |
|
503 return sTempPath; |
|
504 } |
|
505 |
|
506 // ----------------------------------------------------------------------------- |
|
507 // CATBase::RemovePathAndExt |
|
508 // Removes extension from file name and returns file name without extension. |
|
509 // ----------------------------------------------------------------------------- |
|
510 string CATBase::RemovePathAndExt( string sFileName, bool bReverseFindExt) |
|
511 { |
|
512 LOG_LOW_FUNC_ENTRY("CATBase::RemovePathAndExt"); |
|
513 string sRet; |
|
514 sFileName = GetPathOrFileName( true, sFileName ); |
|
515 if ( bReverseFindExt ) |
|
516 { |
|
517 // Remove extension from reverse |
|
518 size_t iPos = sFileName.find_last_of('.'); |
|
519 if( iPos != string::npos ) |
|
520 { |
|
521 sFileName.resize( sFileName.find_last_of('.') ); |
|
522 sRet = sFileName; |
|
523 } |
|
524 } |
|
525 else |
|
526 { |
|
527 // Remove extension finding first . |
|
528 size_t iPos = sFileName.find_first_of('.'); |
|
529 if( iPos != string::npos ) |
|
530 { |
|
531 sFileName.resize( sFileName.find_first_of('.') ); |
|
532 sRet = sFileName; |
|
533 } |
|
534 } |
|
535 return sRet; |
|
536 } |
|
537 |
|
538 // ----------------------------------------------------------------------------- |
|
539 // CATBase::IsTargetTypeSupported |
|
540 // Checks from constant array is this target unsupported |
|
541 // ----------------------------------------------------------------------------- |
|
542 bool CATBase::IsTargetTypeSupported(string sTargetType) |
|
543 { |
|
544 LOG_FUNC_ENTRY("CATBase::IsTargetTypeSupported"); |
|
545 // compare to list |
|
546 int iArraySize = sizeof( UNSUPPORTED_TARGET_TYPES ) / sizeof( string ); |
|
547 for ( int i=0 ; i < iArraySize ; i++ ) |
|
548 { |
|
549 string sUnsupported = UNSUPPORTED_TARGET_TYPES[i]; |
|
550 // lowercase both |
|
551 ChangeToLower(sTargetType); |
|
552 ChangeToLower(sUnsupported); |
|
553 // compare |
|
554 if ( sUnsupported.compare( sTargetType ) == 0 ) |
|
555 { |
|
556 return false; |
|
557 } |
|
558 } |
|
559 return true; |
|
560 } |
|
561 |
|
562 // ----------------------------------------------------------------------------- |
|
563 // CATBase::IsTargetTypeKernelSide |
|
564 // Checks from constant array is this target type kernel side |
|
565 // ----------------------------------------------------------------------------- |
|
566 bool CATBase::IsTargetTypeKernelSide(string sTargetType) |
|
567 { |
|
568 LOG_FUNC_ENTRY("CATBase::IsTargetTypeKernelSide"); |
|
569 // compare to list |
|
570 int iArraySize = sizeof( KERNEL_SIDE_TARGET_TYPES ) / sizeof( string ); |
|
571 for ( int i=0 ; i < iArraySize ; i++ ) |
|
572 { |
|
573 string sUnsupported = KERNEL_SIDE_TARGET_TYPES[i]; |
|
574 // lowercase both |
|
575 ChangeToLower(sTargetType); |
|
576 ChangeToLower(sUnsupported); |
|
577 // compare |
|
578 if ( sUnsupported.compare( sTargetType ) == 0 ) |
|
579 { |
|
580 return true; |
|
581 } |
|
582 } |
|
583 return false; |
|
584 } |
|
585 |
|
586 bool CATBase::CheckVariant( const string& sEpocRoot, const string& sVariant ) |
|
587 { |
|
588 LOG_FUNC_ENTRY("CATBase::CheckVariant"); |
|
589 string sFileToCheck; |
|
590 // Add epoc root |
|
591 if( sEpocRoot.size() > 1 ) |
|
592 sFileToCheck.append( sEpocRoot ); |
|
593 // Add path |
|
594 sFileToCheck.append( VARIANT_DIR ) ; |
|
595 // Add variant |
|
596 sFileToCheck.append( sVariant ); |
|
597 // Add extension |
|
598 sFileToCheck.append( VARIANT_FILE_EXTENSION ); |
|
599 // check does FileExists |
|
600 return FileExists( sFileToCheck.c_str() ); |
|
601 } |
|
602 bool CATBase::IsDefaultVariant( const string& sEpocRoot ) |
|
603 { |
|
604 LOG_FUNC_ENTRY("CATBase::IsDefaultVariant"); |
|
605 string sFileToCheck; |
|
606 // Add epoc root |
|
607 if( sEpocRoot.size() > 1 ) |
|
608 sFileToCheck.append( sEpocRoot ); |
|
609 // Add path |
|
610 sFileToCheck.append( VARIANT_DIR ) ; |
|
611 // Add variant |
|
612 sFileToCheck.append( "DEFAULT" ); |
|
613 // Add extension |
|
614 sFileToCheck.append( VARIANT_FILE_EXTENSION ); |
|
615 // check does FileExists |
|
616 return FileExists( sFileToCheck.c_str() ); |
|
617 } |
|
618 |
|
619 // ----------------------------------------------------------------------------- |
|
620 // CATBase::FileDelete |
|
621 // FileDelete |
|
622 // ----------------------------------------------------------------------------- |
|
623 bool CATBase::FileDelete(const string& sFile, bool bPrint ) |
|
624 { |
|
625 LOG_FUNC_ENTRY("CATBase::FileDelete"); |
|
626 // does file even exists |
|
627 if ( !FileExists( sFile.c_str() ) ) |
|
628 return false; |
|
629 // delete file |
|
630 int iRet = _unlink( sFile.c_str() ); |
|
631 // if print on display error |
|
632 if ( iRet && bPrint ) |
|
633 { |
|
634 cout << AT_MSG << "Error, deleting file " << sFile |
|
635 << endl; |
|
636 } |
|
637 // if print on display message |
|
638 else if ( !iRet && bPrint ) |
|
639 { |
|
640 cout << AT_MSG << "Delete " << sFile << endl; |
|
641 } |
|
642 // return |
|
643 if ( iRet ) |
|
644 return false; |
|
645 return true; |
|
646 } |
|
647 // ----------------------------------------------------------------------------- |
|
648 // CATBase::DirDelete |
|
649 // Delelete directory |
|
650 // ----------------------------------------------------------------------------- |
|
651 bool CATBase::DirDelete(const string& sDir, bool bPrint ) |
|
652 { |
|
653 LOG_FUNC_ENTRY("CATBase::DirDelete"); |
|
654 if ( sDir.find( AT_TEMP_DIR) == string::npos ) |
|
655 return false; |
|
656 |
|
657 if ( sDir.length() < 2 ) |
|
658 return false; |
|
659 |
|
660 string sDir2; |
|
661 if ( sDir.at(1) != ':' ) |
|
662 { |
|
663 char cDir[MAX_LINE_LENGTH]; |
|
664 GetCurrentDirectory( MAX_LINE_LENGTH , cDir ); |
|
665 sDir2.append( cDir ); |
|
666 sDir2.append( "\\" ); |
|
667 sDir2.append( sDir ); |
|
668 } |
|
669 else |
|
670 sDir2.append( sDir ); |
|
671 |
|
672 // does directory exists |
|
673 DWORD dwRet = GetFileAttributes( sDir2.c_str() ); |
|
674 if ( dwRet == INVALID_FILE_ATTRIBUTES ) |
|
675 return false; |
|
676 else if ( ! (dwRet & FILE_ATTRIBUTE_DIRECTORY) ) |
|
677 { |
|
678 return false; |
|
679 } |
|
680 // Delete dir |
|
681 string sCmd( "rmdir /S /Q " ); |
|
682 sCmd.append( sDir2 ); |
|
683 sCmd.append( " > nul 2>&1" ); |
|
684 int iRet = (int)system( sCmd.c_str() ); |
|
685 if ( iRet && bPrint) |
|
686 { |
|
687 cout << AT_MSG << "Error, deleting directory " << sDir2 << endl; |
|
688 } |
|
689 else if ( !iRet && bPrint ) |
|
690 { |
|
691 cout << AT_MSG << "Delete directory " << sDir2 << endl; |
|
692 } |
|
693 if ( iRet ) |
|
694 return false; |
|
695 return true; |
|
696 } |
|
697 |
|
698 // ----------------------------------------------------------------------------- |
|
699 // CATBase::DirCreate |
|
700 // Create directory |
|
701 // ----------------------------------------------------------------------------- |
|
702 bool CATBase::DirCreate(const string& sDir, bool bPrint ) |
|
703 { |
|
704 LOG_FUNC_ENTRY("CATBase::DirCreate"); |
|
705 |
|
706 if ( sDir.length() < 2 ) |
|
707 return false; |
|
708 |
|
709 string sDir2; |
|
710 if ( sDir.at(1) != ':' ) |
|
711 { |
|
712 char cDir[MAX_LINE_LENGTH]; |
|
713 GetCurrentDirectory( MAX_LINE_LENGTH , cDir ); |
|
714 sDir2.append( cDir ); |
|
715 sDir2.append( "\\" ); |
|
716 sDir2.append( sDir ); |
|
717 } |
|
718 else |
|
719 sDir2.append( sDir ); |
|
720 |
|
721 // does directory exists |
|
722 DWORD dwRet = GetFileAttributes( sDir2.c_str() ); |
|
723 if ( dwRet != INVALID_FILE_ATTRIBUTES ) |
|
724 { |
|
725 if( dwRet & FILE_ATTRIBUTE_DIRECTORY ) |
|
726 return false; |
|
727 } |
|
728 // Create dir |
|
729 string sCmd( "mkdir " ); |
|
730 sCmd.append( sDir2 ); |
|
731 sCmd.append( " > nul 2>&1" ); |
|
732 int iRet = (int)system( sCmd.c_str() ); |
|
733 if ( iRet && bPrint) |
|
734 { |
|
735 cout << AT_MSG << "Error, creating directory " << sDir2 << endl; |
|
736 } |
|
737 else if ( !iRet && bPrint ) |
|
738 { |
|
739 cout << AT_MSG << "Directory " << sDir2 << " created" << endl; |
|
740 } |
|
741 if ( iRet ) |
|
742 return false; |
|
743 return true; |
|
744 } |
|
745 |
|
746 // ----------------------------------------------------------------------------- |
|
747 // CATBase::ConvertTCHARtoString |
|
748 // Convert TCHAR* to std::string |
|
749 // ----------------------------------------------------------------------------- |
|
750 string CATBase::ConvertTCHARtoString(TCHAR* charArray) |
|
751 { |
|
752 LOG_LOW_FUNC_ENTRY("CATBase::ConvertTCHARtoString"); |
|
753 // Loop char array |
|
754 stringstream ss; |
|
755 int iIndex = 0; |
|
756 char c = (char) charArray[iIndex]; |
|
757 // until null termination |
|
758 while ( c != '\0' ) |
|
759 { |
|
760 ss << c; |
|
761 iIndex++; |
|
762 c = (char) charArray[iIndex]; |
|
763 } |
|
764 // return string |
|
765 return ss.str(); |
|
766 } |
|
767 |
|
768 // ----------------------------------------------------------------------------- |
|
769 // CATBase::ConvertTCHARtoString |
|
770 // Get list of files in directory |
|
771 // ----------------------------------------------------------------------------- |
|
772 vector<string> CATBase::DirList(const string& sDirectory |
|
773 , bool bListDirs, bool bAddPathToFile) |
|
774 { |
|
775 LOG_FUNC_ENTRY("CATBase::DirList"); |
|
776 // Create string to modify it |
|
777 string sDir = sDirectory; |
|
778 // Add if missing '\' & '*' to the sDirectory |
|
779 if ( sDir.at( sDir.size()-1 ) != '\\' ) |
|
780 sDir.append( "\\" ); |
|
781 // Path to add to file string if specified |
|
782 string sPath = sDir; |
|
783 // Add * to for windows api to find all files |
|
784 sDir.append( "*" ); |
|
785 // convert directory string to LPCSTR |
|
786 LPCSTR dir( sDir.c_str() ); |
|
787 // vector to store file list |
|
788 vector<string> vFileList; |
|
789 // Using win32 api to find list of files in directory |
|
790 // file data "container" |
|
791 WIN32_FIND_DATA fileData; |
|
792 // handle to directory |
|
793 HANDLE hFinder = FindFirstFile( dir, &fileData ); |
|
794 if ( hFinder == INVALID_HANDLE_VALUE ) |
|
795 { |
|
796 // no files found |
|
797 return vFileList; |
|
798 } |
|
799 // loop files add to vector and return |
|
800 while( FindNextFile(hFinder, &fileData ) ) |
|
801 { |
|
802 DWORD dw = fileData.dwFileAttributes; |
|
803 // skip if its directory and bListDirs not specified |
|
804 if ( dw & FILE_ATTRIBUTE_DIRECTORY && ! bListDirs) |
|
805 continue; |
|
806 // add files to vector |
|
807 string sFile = ConvertTCHARtoString( fileData.cFileName ); |
|
808 // Add given path to file string if specified |
|
809 if ( bAddPathToFile ) |
|
810 sFile.insert( 0, sPath ); |
|
811 vFileList.push_back( sFile ); |
|
812 } |
|
813 // Close file find handler |
|
814 FindClose( hFinder ); |
|
815 return vFileList; |
|
816 } |
|
817 |
|
818 // ----------------------------------------------------------------------------- |
|
819 // CATBase::ParseRelativePathToString |
|
820 // ParseRelative |
|
821 // ----------------------------------------------------------------------------- |
|
822 void CATBase::ParseRelativePathString(string& sPathString) |
|
823 { |
|
824 LOG_LOW_FUNC_ENTRY("CATBase::ParseRelativePathString"); |
|
825 string sParsed; |
|
826 // find .. |
|
827 size_t iDots = sPathString.find( ".." ); |
|
828 while ( iDots != string::npos ) |
|
829 { |
|
830 RemoveRelativePath( sPathString, iDots ); |
|
831 iDots = sPathString.find( ".." ); |
|
832 } |
|
833 } |
|
834 |
|
835 // ----------------------------------------------------------------------------- |
|
836 // CATBase::RemoveRelativePath |
|
837 // Remove relative path from string (using given index) |
|
838 // ----------------------------------------------------------------------------- |
|
839 void CATBase::RemoveRelativePath(string& sString, size_t iDots) |
|
840 { |
|
841 LOG_LOW_FUNC_ENTRY("CATBase::RemoveRelativePath"); |
|
842 // Chck if accidentally given wrong parameter |
|
843 if ( iDots == string::npos |
|
844 || iDots < 1 ) |
|
845 return; |
|
846 // Parsed string |
|
847 string sParsed; |
|
848 // Find position of last backslash before dots |
|
849 size_t i = sString.rfind("\\", iDots-2 ); |
|
850 // Pickup start part (depending is the backslash at last parts first char) |
|
851 if ( sString.at(iDots+2) != '\\' ) |
|
852 sParsed = sString.substr( 0, i+1 ) ; |
|
853 else |
|
854 sParsed = sString.substr( 0, i ); |
|
855 // Pick up last part |
|
856 sParsed.append( sString.substr( iDots+2, sString.size() ) ); |
|
857 sString = sParsed; |
|
858 } |
|
859 |
|
860 // ----------------------------------------------------------------------------- |
|
861 // Get extension from given string |
|
862 // ----------------------------------------------------------------------------- |
|
863 string CATBase::GetExtension(const string& sString) |
|
864 { |
|
865 LOG_LOW_FUNC_ENTRY("CATBase::GetExtension"); |
|
866 // find last . |
|
867 size_t iDot = sString.find_last_of( "." ); |
|
868 // return string after . if found |
|
869 if ( iDot != string::npos ) |
|
870 return sString.substr(iDot+1, sString.length()-(iDot+1) ); |
|
871 // otherwise return given string |
|
872 return sString; |
|
873 } |
|
874 |
|
875 // ----------------------------------------------------------------------------- |
|
876 // CATBase::DirectoryExists |
|
877 // Check if given directory exists. |
|
878 // ----------------------------------------------------------------------------- |
|
879 bool CATBase::DirectoryExists( const char* pDirname ) |
|
880 { |
|
881 LOG_FUNC_ENTRY("CATBase::DirectoryExists"); |
|
882 size_t iLenght = strlen( pDirname ); |
|
883 |
|
884 if ( iLenght < 2 ) |
|
885 return false; |
|
886 |
|
887 string sDir; |
|
888 if ( pDirname[1] != ':' ) |
|
889 { |
|
890 char cDir[MAX_LINE_LENGTH]; |
|
891 GetCurrentDirectory( MAX_LINE_LENGTH , cDir ); |
|
892 sDir.append( cDir ); |
|
893 sDir.append( "\\" ); |
|
894 sDir.append( pDirname ); |
|
895 } |
|
896 else |
|
897 sDir.append( pDirname ); |
|
898 |
|
899 DWORD dwRet = GetFileAttributes( sDir.c_str() ); |
|
900 if( dwRet == INVALID_FILE_ATTRIBUTES ) |
|
901 { |
|
902 return false; |
|
903 } |
|
904 else |
|
905 { |
|
906 //Is file directory? |
|
907 if( dwRet & FILE_ATTRIBUTE_DIRECTORY ) |
|
908 { |
|
909 return true; |
|
910 } |
|
911 else |
|
912 { |
|
913 return false; |
|
914 } |
|
915 } |
|
916 } |
|
917 |
|
918 // ----------------------------------------------------------------------------- |
|
919 // CATBase::ConvertUnixPathToWin |
|
920 // ----------------------------------------------------------------------------- |
|
921 void CATBase::ConvertUnixPathToWin( string& sPath ) |
|
922 { |
|
923 LOG_LOW_FUNC_ENTRY("CATBase::ConvertUnixPathToWin"); |
|
924 size_t iSpot = 0; |
|
925 // convert '/' to '\' |
|
926 iSpot = sPath.find( "/" ); |
|
927 while( iSpot != string::npos ) |
|
928 { |
|
929 sPath.replace(iSpot,1, "\\"); |
|
930 iSpot = sPath.find( "/", iSpot+1 ); |
|
931 } |
|
932 // convert '\\' to '\' |
|
933 iSpot = sPath.find( "\\\\" ); |
|
934 while( iSpot != string::npos ) |
|
935 { |
|
936 sPath.replace(iSpot,2,"\\"); |
|
937 iSpot = sPath.find( "\\\\" ); |
|
938 } |
|
939 } |
|
940 |
|
941 // ----------------------------------------------------------------------------- |
|
942 // CATBase::RemoveAllAfterDotIfTwoDots |
|
943 // Removes all after first '.' |
|
944 // if given string contains 2 '.' or more |
|
945 // ----------------------------------------------------------------------------- |
|
946 void CATBase::RemoveAllAfterDotIfTwoDots(string& sModName) |
|
947 { |
|
948 LOG_LOW_FUNC_ENTRY("CATBase::RemoveAllAfterDotIfTwoDots"); |
|
949 // did we find variable? |
|
950 size_t found; |
|
951 // Find first '.' |
|
952 found = sModName.find("."); |
|
953 if ( found != string::npos ) |
|
954 { |
|
955 // Try find second '.' |
|
956 found = sModName.find(".", found+1); |
|
957 if ( found != string::npos ) |
|
958 { |
|
959 // Remove all after first '.' |
|
960 sModName = sModName.substr(0, sModName.find(".")+1 ); |
|
961 } |
|
962 } |
|
963 } |
|
964 // ----------------------------------------------------------------------------- |
|
965 // CATBase::CreateTemporaryCpp |
|
966 // ----------------------------------------------------------------------------- |
|
967 bool CATBase::CreateTemporaryCpp( const string& sId, |
|
968 const string& sPath |
|
969 ,const string& sS60FileName |
|
970 ,const string& sS60FilePath |
|
971 ,int iLogOption |
|
972 ,int iIsDebug |
|
973 ,int iAllocCallStackSize |
|
974 ,int iFreeCallStackSize ) |
|
975 { |
|
976 LOG_FUNC_ENTRY("CATBase::CreateTemporaryCpp"); |
|
977 // Add slash to path if missing |
|
978 string sTempCpp = sPath; |
|
979 if( sTempCpp.at( sTempCpp.length() - 1 ) != '\\' ) |
|
980 sTempCpp.append("\\"); |
|
981 |
|
982 // append temporary cpp name with id in middle |
|
983 sTempCpp.append( AT_TEMP_CPP_LOWER_START ); |
|
984 sTempCpp.append( sId ); |
|
985 sTempCpp.append( AT_TEMP_CPP_LOWER_END ); |
|
986 |
|
987 //Open and truncate temporary cpp |
|
988 ofstream out( sTempCpp.c_str() , ios::trunc ); |
|
989 if ( ! out.good() ) |
|
990 { |
|
991 out.close(); |
|
992 return false; |
|
993 } |
|
994 // Headers |
|
995 out << "#include <e32base.h>"; |
|
996 // Is debug |
|
997 out << "\nconst TInt ATTempDebug(" << iIsDebug << ");"; |
|
998 // Log option |
|
999 out << "\nconst TInt ATTempLogOption(" << iLogOption << ");"; |
|
1000 // Alloc call stack |
|
1001 out << "\nconst TInt ATTempAllocCallStackSize(" << iAllocCallStackSize << ");"; |
|
1002 // Free call stack |
|
1003 out << "\nconst TInt ATTempFreeCallStackSize(" << iFreeCallStackSize << ");"; |
|
1004 // Log file name |
|
1005 out << "\n_LIT( ATTempLogFileName, \"" << sS60FileName << "\" );"; |
|
1006 // Log file path |
|
1007 out << "\n_LIT( ATTempLogFilePath, \"" << sS60FilePath << "\" );"; |
|
1008 // Version number |
|
1009 out << "\n_LIT( ATTempVersion, \"" << ATOOL_COMPATIBILITY_STRING << "\" );"; |
|
1010 // Variable functions use enumeration values that are defined in memoryhook (customuser.h) |
|
1011 // We use constants here so that we don't need to include the header file, wich |
|
1012 // might cause problems. |
|
1013 /* Enumeration copied to comment for notes |
|
1014 enum TATOptions |
|
1015 { |
|
1016 ELogFileName = 1, |
|
1017 EVersion = 2 , |
|
1018 ELogOption = 3, |
|
1019 EDebug = 4, |
|
1020 EAllocCallStackSize = 5, |
|
1021 EFreeCallStackSize = 6, |
|
1022 ELogFilePath = 7 |
|
1023 }; |
|
1024 */ |
|
1025 out << "\nTInt GetInt( const TUint8 aType )"; |
|
1026 out << "\n{"; |
|
1027 out << "\nswitch( aType )"; |
|
1028 out << "\n{"; |
|
1029 out << "\ncase 4: return ATTempDebug; "; |
|
1030 out << "\ncase 3: return ATTempLogOption;"; |
|
1031 out << "\ncase 5: return ATTempAllocCallStackSize;"; |
|
1032 out << "\ncase 6: return ATTempFreeCallStackSize;"; |
|
1033 out << "\ndefault: return KErrArgument;"; |
|
1034 out << "\n}"; |
|
1035 out << "\n}"; |
|
1036 out << "\nTPtrC GetString( const TUint8 aType )"; |
|
1037 out << "\n{"; |
|
1038 out << "\nswitch( aType )"; |
|
1039 out << "\n{"; |
|
1040 out << "\ncase 1: return ATTempLogFileName();"; |
|
1041 out << "\ncase 2: return ATTempVersion();"; |
|
1042 out << "\ncase 7: return ATTempLogFilePath();"; |
|
1043 out << "\ndefault: return KNullDesC();"; |
|
1044 out << "\n}"; |
|
1045 out << "\n}"; |
|
1046 |
|
1047 /** Todo: Old way of separate functions, these here for backup support and to ease testing. */ |
|
1048 /** Unnessesary in the future, so can be removed then (1.8.2). */ |
|
1049 |
|
1050 out << "\n_LIT( KFileName, \""; |
|
1051 out << sS60FileName; |
|
1052 out << "\" );\n"; |
|
1053 |
|
1054 out << "\n_LIT( KFilePath, \""; |
|
1055 out << sS60FilePath; |
|
1056 out << "\" );\n"; |
|
1057 |
|
1058 // Hardcoded version number for support. |
|
1059 out << "\n/* The AnalyzeTool version number used. */"; |
|
1060 out << "\n_LIT( KAtoolVersion, \"1.7.6;1.10.0\" );\n"; |
|
1061 |
|
1062 out << "\nconst TFileName LogFileName()"; |
|
1063 out << "\n {"; |
|
1064 out << "\n return TFileName( KFileName() );"; |
|
1065 out << "\n }"; |
|
1066 |
|
1067 out << "\nconst TPath LogFilePath()"; |
|
1068 out << "\n {"; |
|
1069 out << "\n return TPath( KFilePath() );"; |
|
1070 out << "\n }"; |
|
1071 |
|
1072 out << "\nTUint32 AllocCallStackSize()"; |
|
1073 out << "\n {"; |
|
1074 out << "\n return TUint32( "; |
|
1075 out << iAllocCallStackSize; |
|
1076 out << " );\n"; |
|
1077 out << "\n }"; |
|
1078 |
|
1079 out << "\nTUint32 FreeCallStackSize()"; |
|
1080 out << "\n {"; |
|
1081 out << "\n return TUint32( "; |
|
1082 out << iFreeCallStackSize; |
|
1083 out << " );\n"; |
|
1084 out << "\n }"; |
|
1085 |
|
1086 out << "\nconst TFileName AtoolVersion()"; |
|
1087 out << "\n {"; |
|
1088 out << "\n return TFileName( KAtoolVersion() );"; |
|
1089 out << "\n }"; |
|
1090 |
|
1091 out << "\nTUint32 LogOption()"; |
|
1092 out << "\n {"; |
|
1093 out << "\n return TUint32( "; |
|
1094 out << iLogOption; |
|
1095 out << " );"; |
|
1096 out << "\n }"; |
|
1097 |
|
1098 out << "\nTUint32 IsDebug()"; |
|
1099 out << "\n {"; |
|
1100 out << "\n return TUint32( "; |
|
1101 out << iIsDebug; |
|
1102 out << " );"; |
|
1103 out << "\n }"; |
|
1104 |
|
1105 // End of file and close |
|
1106 out << "\n\n// End of File\n"; |
|
1107 out.close(); |
|
1108 cout << AT_MSG << "Created " << sTempCpp << endl; |
|
1109 return true; |
|
1110 } |
|
1111 |
|
1112 // ----------------------------------------------------------------------------- |
|
1113 // CATBase::IsDataFile |
|
1114 // ----------------------------------------------------------------------------- |
|
1115 bool CATBase::IsDataFile( string sFile ) |
|
1116 { |
|
1117 LOG_FUNC_ENTRY("CATBase::IsDataFile"); |
|
1118 // Check that sFile not empty |
|
1119 if ( sFile.empty() || sFile.length() < 1 ) |
|
1120 return false; |
|
1121 |
|
1122 // Temporary line char array. |
|
1123 char cLineFromFile[MAX_LINE_LENGTH]; |
|
1124 //Open file |
|
1125 ifstream in( sFile.c_str() ); |
|
1126 |
|
1127 //File open ok? |
|
1128 if( !in.good() ) |
|
1129 return false; |
|
1130 |
|
1131 //Read all lines |
|
1132 in.getline( cLineFromFile, MAX_LINE_LENGTH ); |
|
1133 |
|
1134 string sLineFromFile( cLineFromFile ); |
|
1135 in.close(); |
|
1136 if( sLineFromFile.find( "DATA_FILE_VERSION" ) != string::npos ) |
|
1137 return true; |
|
1138 else |
|
1139 return false; |
|
1140 } |
|
1141 |
|
1142 // ----------------------------------------------------------------------------- |
|
1143 // CATBase::IsBinaryLogFile |
|
1144 // ----------------------------------------------------------------------------- |
|
1145 bool CATBase::IsBinaryLogFile( string sFile ) |
|
1146 { |
|
1147 LOG_FUNC_ENTRY("CATBase::IsDataFile"); |
|
1148 // Check that sFile not empty |
|
1149 if ( sFile.empty() || sFile.length() < 1 ) |
|
1150 return false; |
|
1151 |
|
1152 // Temporary line char array. |
|
1153 char cLineFromFile[MAX_LINE_LENGTH]; |
|
1154 //Open file |
|
1155 ifstream in( sFile.c_str() ); |
|
1156 |
|
1157 //File open ok? |
|
1158 if( !in.good() ) |
|
1159 return false; |
|
1160 |
|
1161 //Read all lines |
|
1162 in.getline( cLineFromFile, MAX_LINE_LENGTH ); |
|
1163 |
|
1164 string sLineFromFile( cLineFromFile ); |
|
1165 in.close(); |
|
1166 |
|
1167 if( sLineFromFile.find( "ATOOL_BINARY_FILE_VERSION" ) != string::npos ) |
|
1168 return true; |
|
1169 else |
|
1170 return false; |
|
1171 } |
|
1172 |
|
1173 // ----------------------------------------------------------------------------- |
|
1174 // CATBase::ParseStringToVector |
|
1175 // ----------------------------------------------------------------------------- |
|
1176 vector<string> CATBase::ParseStringToVector( const string& sInput, char separator ) |
|
1177 { |
|
1178 LOG_LOW_FUNC_ENTRY("CATBase::ParseStringToVector"); |
|
1179 string sString(sInput); |
|
1180 // Elements vector |
|
1181 vector<string> vStrings; |
|
1182 size_t iPos = sString.find( separator ); |
|
1183 // If can not find it return vector with just one element |
|
1184 if ( iPos == string::npos ) |
|
1185 { |
|
1186 // Don't add empty item into vector. |
|
1187 if ( sString.size() > 0 ) |
|
1188 vStrings.push_back( sString ); |
|
1189 return vStrings; |
|
1190 } |
|
1191 // Loop elements |
|
1192 while( iPos != string::npos ) |
|
1193 { |
|
1194 string sElement = sString.substr(0, iPos); |
|
1195 vStrings.push_back( sElement ); |
|
1196 sString.erase(0, iPos +1 ); |
|
1197 iPos = sString.find( separator ); |
|
1198 } |
|
1199 // Add last element if any |
|
1200 if ( sString.size() > 0 ) |
|
1201 vStrings.push_back( sString ); |
|
1202 // Return elements |
|
1203 return vStrings; |
|
1204 } |
|
1205 |
|
1206 // ----------------------------------------------------------------------------- |
|
1207 // CATBase::FilterString |
|
1208 // Filter string out of unwanted characters. The list of allowed |
|
1209 // characters is defined in CFILTERSTRING. |
|
1210 // ----------------------------------------------------------------------------- |
|
1211 string CATBase::FilterString( const string& sString ) |
|
1212 { |
|
1213 LOG_LOW_FUNC_ENTRY("CATBase::FilterString"); |
|
1214 string sFiltered; |
|
1215 for( size_t i = 0 ; i < sString.length() ; i++ ) |
|
1216 { |
|
1217 const char p = sString.at( i ); |
|
1218 if ( strchr( CFILTERSTRING, p ) != 0 ) |
|
1219 sFiltered.push_back( p ); |
|
1220 } |
|
1221 return sFiltered; |
|
1222 } |
|
1223 |
|
1224 // ----------------------------------------------------------------------------- |
|
1225 // CATBase::FilterExtraSpaces |
|
1226 // Replaces multiple continuous spaces with single. Won't leave |
|
1227 // spaces in start or end of string. |
|
1228 // ----------------------------------------------------------------------------- |
|
1229 void CATBase::FilterExtraSpaces( string& sString ) |
|
1230 { |
|
1231 LOG_LOW_FUNC_ENTRY("CATBase::FilterExtraSpaces"); |
|
1232 string sFiltered; |
|
1233 // Loop thru char array. |
|
1234 for( size_t i = 0 ; i < sString.length(); i++ ) |
|
1235 { |
|
1236 // Is char space? |
|
1237 if ( sString.at( i ) == ' ' ) |
|
1238 { |
|
1239 // Pick up space if filtered does not contain char as last. |
|
1240 if ( sFiltered.rbegin() == sFiltered.rend() ) |
|
1241 sFiltered.push_back( sString.at( i ) ); |
|
1242 else if ( * ( sFiltered.rbegin() ) != ' ' ) |
|
1243 sFiltered.push_back( sString.at( i ) ); |
|
1244 } |
|
1245 else |
|
1246 sFiltered.push_back( sString.at( i ) ); |
|
1247 } |
|
1248 |
|
1249 // Remove first and/or last character if it is space. |
|
1250 if ( sFiltered.begin() != sFiltered.end() ) |
|
1251 { |
|
1252 if( * ( sFiltered.begin() ) == ' ' ) |
|
1253 sFiltered.erase( 0, 1 ); |
|
1254 } |
|
1255 if ( sFiltered.rbegin() != sFiltered.rend() ) |
|
1256 { |
|
1257 if( * ( sFiltered.rbegin() ) == ' ' ) |
|
1258 sFiltered.resize( sFiltered.length()-1 ); |
|
1259 } |
|
1260 sString = sFiltered; |
|
1261 } |
|
1262 |
|
1263 |
|
1264 bool CATBase::hexToDec( string& sHex, unsigned int& iDec ) |
|
1265 { |
|
1266 LOG_LOW_FUNC_ENTRY("CATBase::hexToDec"); |
|
1267 istringstream ss( sHex ); |
|
1268 ss.setf( ios::hex, ios::basefield ); |
|
1269 if( ( ss >> iDec ) ) |
|
1270 return true; |
|
1271 return false; |
|
1272 } |
|
1273 |
|
1274 bool CATBase::hexToDec( string& sHex, int& iDec ) |
|
1275 { |
|
1276 LOG_LOW_FUNC_ENTRY("CATBase::hexToDec"); |
|
1277 istringstream ss( sHex ); |
|
1278 ss.setf( ios::hex, ios::basefield ); |
|
1279 if( ( ss >> iDec ) ) |
|
1280 return true; |
|
1281 return false; |
|
1282 } |
|
1283 |
|
1284 bool CATBase::hexToDec( string& sHex, unsigned long& ulDec ) |
|
1285 { |
|
1286 LOG_LOW_FUNC_ENTRY("CATBase::hexToDec"); |
|
1287 istringstream ss( sHex ); |
|
1288 ss.setf( ios::hex, ios::basefield ); |
|
1289 if( ( ss >> ulDec ) ) |
|
1290 return true; |
|
1291 return false; |
|
1292 } |
|
1293 |
|
1294 bool CATBase::hexToDec( string& sHex, unsigned long long& ullDec ) |
|
1295 { |
|
1296 LOG_LOW_FUNC_ENTRY("CATBase::hexToDec"); |
|
1297 istringstream ss( sHex ); |
|
1298 ss.setf( ios::hex, ios::basefield ); |
|
1299 if( ( ss >> ullDec ) ) |
|
1300 return true; |
|
1301 return false; |
|
1302 } |
|
1303 |
|
1304 /** |
|
1305 * Used to create array of integer & hex value pairs. |
|
1306 */ |
|
1307 struct CHexMap |
|
1308 { |
|
1309 char chr; |
|
1310 int value; |
|
1311 }; |
|
1312 |
|
1313 // ----------------------------------------------------------------------------- |
|
1314 // CATBase::_httoi |
|
1315 // ----------------------------------------------------------------------------- |
|
1316 unsigned long CATBase::_httoi(const char *value) |
|
1317 { |
|
1318 LOG_LOW_FUNC_ENTRY("CATBase::_httoi"); |
|
1319 unsigned long l; |
|
1320 string s( value ); |
|
1321 if ( CATBase::hexToDec( s, l ) ) |
|
1322 return l; |
|
1323 return 0; |
|
1324 } |
|
1325 |
|
1326 |
|
1327 // ----------------------------------------------------------------------------- |
|
1328 // CATBase::NumberToHexString(int) |
|
1329 // ----------------------------------------------------------------------------- |
|
1330 string CATBase::NumberToHexString( unsigned int i ) |
|
1331 { |
|
1332 LOG_LOW_FUNC_ENTRY("CATBase::IntToHexString"); |
|
1333 stringstream ss; |
|
1334 ss << "0x" << hex << i; |
|
1335 string retval; retval = ss.str().c_str(); |
|
1336 return retval; |
|
1337 } |
|
1338 // ----------------------------------------------------------------------------- |
|
1339 // CATBase::NumberToHexString(long) |
|
1340 // ----------------------------------------------------------------------------- |
|
1341 string CATBase::NumberToHexString( unsigned long i ) |
|
1342 { |
|
1343 LOG_LOW_FUNC_ENTRY("CATBase::IntToHexString"); |
|
1344 stringstream ss; |
|
1345 ss << "0x" << hex << i; |
|
1346 string retval; retval = ss.str().c_str(); |
|
1347 return retval; |
|
1348 } |
|
1349 |
|
1350 // ----------------------------------------------------------------------------- |
|
1351 // CATBase::IsHexCharacter |
|
1352 // ----------------------------------------------------------------------------- |
|
1353 bool CATBase::IsHexCharacter(const TCHAR *value) |
|
1354 { |
|
1355 LOG_LOW_FUNC_ENTRY("CATBase::IsHexCharacter"); |
|
1356 const int HexMapL = 22; |
|
1357 CHexMap HexMap[HexMapL] = |
|
1358 { |
|
1359 {'0', 0}, {'1', 1}, |
|
1360 {'2', 2}, {'3', 3}, |
|
1361 {'4', 4}, {'5', 5}, |
|
1362 {'6', 6}, {'7', 7}, |
|
1363 {'8', 8}, {'9', 9}, |
|
1364 {'A', 10}, {'B', 11}, |
|
1365 {'C', 12}, {'D', 13}, |
|
1366 {'E', 14}, {'F', 15}, |
|
1367 {'a', 10}, {'b', 11}, |
|
1368 {'c', 12}, {'d', 13}, |
|
1369 {'e', 14}, {'f', 15} |
|
1370 }; |
|
1371 bool found = false; |
|
1372 for (int i = 0; i < HexMapL; i++) |
|
1373 { |
|
1374 if(HexMap[i].chr == *value) |
|
1375 { |
|
1376 found = true; |
|
1377 break; |
|
1378 } |
|
1379 } |
|
1380 return found; |
|
1381 } |
|
1382 |
|
1383 // ----------------------------------------------------------------------------- |
|
1384 // CATBase::IsAscii(const char*,const unsigned int) |
|
1385 // ----------------------------------------------------------------------------- |
|
1386 bool CATBase::IsAscii( const char* pInput, const unsigned int iLength ) |
|
1387 { |
|
1388 LOG_LOW_FUNC_ENTRY("CATBase::IsAscii"); |
|
1389 bool bRet = true; |
|
1390 const char* pPoint = pInput; |
|
1391 for( unsigned int i = 0 ; i < iLength ; i++) |
|
1392 { |
|
1393 if( !__isascii(*pPoint) ) |
|
1394 { |
|
1395 bRet = false; |
|
1396 break; |
|
1397 } |
|
1398 pPoint++; |
|
1399 } |
|
1400 return bRet; |
|
1401 } |
|
1402 |
|
1403 // ----------------------------------------------------------------------------- |
|
1404 // CATBase::GetEpocRoot( string& sEpocRoot ) |
|
1405 // ----------------------------------------------------------------------------- |
|
1406 bool CATBase::GetEpocRoot( string& sEpocRoot ) |
|
1407 { |
|
1408 LOG_FUNC_ENTRY( "CATBase::GetEpocRoot" ); |
|
1409 bool bRet = true; |
|
1410 //Find EPOCROOT from environment variable |
|
1411 char* pEpocRoot = getenv ("EPOCROOT"); |
|
1412 if( pEpocRoot == NULL ) |
|
1413 { |
|
1414 const char pDevicesPath[] = "C:\\Program Files\\Common Files\\Symbian\\devices.xml"; |
|
1415 CATParseXML parser; |
|
1416 //Find EPOCROOT from devices |
|
1417 sEpocRoot = parser.GetEpocRootPathFromXML(pDevicesPath); |
|
1418 if( sEpocRoot.empty() ) |
|
1419 { |
|
1420 printf("EPOCROOT not set to environment variables.\n"); |
|
1421 bRet = false; |
|
1422 } |
|
1423 } |
|
1424 else |
|
1425 { |
|
1426 sEpocRoot.append( pEpocRoot ); |
|
1427 LOG_STRING( "EpocRoot :" << sEpocRoot ); |
|
1428 } |
|
1429 //Remove trailing slash |
|
1430 if ( sEpocRoot.size() > 1 && sEpocRoot[ sEpocRoot.length()-1 ] == '\\' ) |
|
1431 sEpocRoot.resize( sEpocRoot.length()-1 ); |
|
1432 return bRet; |
|
1433 } |
|
1434 //End of file |