|
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(); |
|
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::ChangeSlashToBackSlash |
|
232 // Function changes all BackSlash characters to Slash character from |
|
233 // given string. |
|
234 // ----------------------------------------------------------------------------- |
|
235 string CATBase::ChangeSlashToBackSlash( string sInput ) |
|
236 { |
|
237 LOG_LOW_FUNC_ENTRY("CATBase::ChangeSlashToBackSlash"); |
|
238 for( unsigned int i = 0 ; i < sInput.length() ; i++ ) |
|
239 { |
|
240 if( sInput[i] == '/' ) |
|
241 { |
|
242 sInput[i] = '\\'; |
|
243 } |
|
244 } |
|
245 return sInput; |
|
246 } |
|
247 |
|
248 // ----------------------------------------------------------------------------- |
|
249 // CATBase::FileExists |
|
250 // Check if given file exists. |
|
251 // ----------------------------------------------------------------------------- |
|
252 bool CATBase::FileExists( const char * pFilename ) |
|
253 { |
|
254 LOG_FUNC_ENTRY("CATBase::FileExists"); |
|
255 DWORD dwRet = GetFileAttributes( pFilename ); |
|
256 if( dwRet == INVALID_FILE_ATTRIBUTES ) |
|
257 { |
|
258 return false; |
|
259 } |
|
260 else |
|
261 { |
|
262 //Is file directory? |
|
263 if( dwRet & FILE_ATTRIBUTE_DIRECTORY ) |
|
264 { |
|
265 return false; |
|
266 } |
|
267 } |
|
268 return true; |
|
269 } |
|
270 |
|
271 bool CATBase::IsFileReadOnly( const char* pFilename ) |
|
272 { |
|
273 LOG_FUNC_ENTRY("CATBase::IsFileReadOnly"); |
|
274 DWORD dwRet = GetFileAttributes( pFilename ); |
|
275 if( dwRet == INVALID_FILE_ATTRIBUTES ) |
|
276 return false; |
|
277 if( dwRet & FILE_ATTRIBUTE_READONLY ) |
|
278 return true; |
|
279 return false; |
|
280 } |
|
281 |
|
282 bool CATBase::SetFileReadOnly( const char* pFileName ) |
|
283 { |
|
284 LOG_FUNC_ENTRY("CATBase::SetFileReadOnly"); |
|
285 DWORD dw = GetFileAttributes( pFileName ); |
|
286 if( dw == INVALID_FILE_ATTRIBUTES ) |
|
287 return false; |
|
288 if( dw & FILE_ATTRIBUTE_READONLY ) |
|
289 return true; |
|
290 dw = dw | FILE_ATTRIBUTE_READONLY ; |
|
291 if ( SetFileAttributes( pFileName, dw ) ) |
|
292 return true; |
|
293 return false; |
|
294 } |
|
295 bool CATBase::SetFileWritable( const char* pFileName ) |
|
296 { |
|
297 LOG_FUNC_ENTRY("CATBase::SetFileWritable"); |
|
298 DWORD dw = GetFileAttributes( pFileName ); |
|
299 if( dw == INVALID_FILE_ATTRIBUTES ) |
|
300 return false; |
|
301 if( ! dw & FILE_ATTRIBUTE_READONLY ) |
|
302 return true; |
|
303 dw = dw ^ FILE_ATTRIBUTE_READONLY ; |
|
304 if ( SetFileAttributes( pFileName, dw ) ) |
|
305 return true; |
|
306 return false; |
|
307 } |
|
308 |
|
309 // ----------------------------------------------------------------------------- |
|
310 // CATBase::FileCopyToPath |
|
311 // Copies file to given path |
|
312 // ----------------------------------------------------------------------------- |
|
313 bool CATBase::FileCopyToPath(const string& sFile, const string& sToPath) |
|
314 { |
|
315 LOG_FUNC_ENTRY("CATBase::FileCopyToPath"); |
|
316 // Display message |
|
317 cout << AT_MSG << "Copy " << sFile << AT_FILE_TO << sToPath << endl; |
|
318 if ( sFile.empty() || sToPath.empty() ) |
|
319 { |
|
320 LOG_FUNC_EXIT("CATBase::FileCopyToPath Error, empty parameter"); |
|
321 return false; |
|
322 } |
|
323 // Copy using windows api (seems not to work when relavite path .. |
|
324 /* |
|
325 // Full path where to copy |
|
326 string sDestination = sToPath; |
|
327 // Append '\' to string if not exists |
|
328 if ( sDestination.length() > 1 ) |
|
329 { |
|
330 const char cLastChar = sDestination[ sDestination.length() -1 ]; |
|
331 if ( cLastChar != DASH ) |
|
332 sDestination.append("\\"); |
|
333 } |
|
334 int iRet = 0; |
|
335 iRet = CopyFile( sFile.c_str(), sDestination.c_str(), false ); |
|
336 if ( iRet != 0 ) |
|
337 { |
|
338 return false; |
|
339 } |
|
340 */ |
|
341 string sCommand; |
|
342 sCommand.append( "copy /Y \""); |
|
343 sCommand.append( sFile ); |
|
344 sCommand.append( "\" \"" ); |
|
345 sCommand.append( sToPath ); |
|
346 sCommand.append( "\" > nul 2>&1" ); |
|
347 LOG_STRING( sCommand ); |
|
348 int iRet = 0; |
|
349 iRet = (int)system( sCommand.c_str() ); |
|
350 if ( iRet != 0 ) |
|
351 return false; |
|
352 return true; |
|
353 } |
|
354 |
|
355 // ----------------------------------------------------------------------------- |
|
356 // CATBase::FileMoveToPath |
|
357 // Copies file to given path |
|
358 // ----------------------------------------------------------------------------- |
|
359 bool CATBase::FileMoveToPath(const string& sFile, const string& sToPath) |
|
360 { |
|
361 LOG_FUNC_ENTRY("CATBase::FileMoveToPath"); |
|
362 // Display message |
|
363 cout << AT_MSG << "Move " << sFile << AT_FILE_TO << sToPath << endl; |
|
364 if ( sFile.empty() || sToPath.empty() ) |
|
365 { |
|
366 LOG_FUNC_EXIT("CATBase::FileMoveToPath Error, empty parameter"); |
|
367 return false; |
|
368 } |
|
369 // Move (again windows api function does not support relative path .. in it |
|
370 /* |
|
371 // Get filename from sFile |
|
372 string sFileName = GetPathOrFileName( true, sFile ); |
|
373 // Full path where to copy |
|
374 string sDestination = sToPath; |
|
375 // Append '\' to string if not exists |
|
376 if ( sDestination.length() > 1 ) |
|
377 { |
|
378 const char cLastChar = sDestination[ sDestination.length() -1 ]; |
|
379 if ( cLastChar != DASH ) |
|
380 sDestination.append("\\"); |
|
381 } |
|
382 int iRet = 0; |
|
383 iRet = MoveFile( sFile.c_str(), sDestination.c_str()); |
|
384 if ( iRet != 0 ) |
|
385 { |
|
386 return false; |
|
387 } |
|
388 */ |
|
389 string sCommand; |
|
390 sCommand.append( "move /Y \""); |
|
391 sCommand.append( sFile ); |
|
392 sCommand.append( "\" \"" ); |
|
393 sCommand.append( sToPath ); |
|
394 sCommand.append( "\" > nul 2>&1" ); |
|
395 LOG_STRING( sCommand ); |
|
396 int iRet = 0; |
|
397 iRet = (int)system( sCommand.c_str() ); |
|
398 if ( iRet != 0 ) |
|
399 return false; |
|
400 return true; |
|
401 } |
|
402 // ----------------------------------------------------------------------------- |
|
403 // CATBase::CreateTempPath |
|
404 // Creates temporary directory path for given mmp file |
|
405 // ----------------------------------------------------------------------------- |
|
406 string CATBase::CreateTempPath(const string& sMmpFileWithPath) |
|
407 { |
|
408 LOG_FUNC_ENTRY("CATBase::CreateTempPath"); |
|
409 string sTempPath = GetPathOrFileName( false, sMmpFileWithPath ); |
|
410 sTempPath.append( AT_TEMP_DIR ); |
|
411 sTempPath.append( "\\" ); |
|
412 return sTempPath; |
|
413 } |
|
414 |
|
415 // ----------------------------------------------------------------------------- |
|
416 // CATBase::RemovePathAndExt |
|
417 // Removes extension from file name and returns file name without extension. |
|
418 // ----------------------------------------------------------------------------- |
|
419 string CATBase::RemovePathAndExt( string sFileName, bool bReverseFindExt) |
|
420 { |
|
421 LOG_LOW_FUNC_ENTRY("CATBase::RemovePathAndExt"); |
|
422 string sRet; |
|
423 sFileName = GetPathOrFileName( true, sFileName ); |
|
424 if ( bReverseFindExt ) |
|
425 { |
|
426 // Remove extension from reverse |
|
427 size_t iPos = sFileName.find_last_of('.'); |
|
428 if( iPos != string::npos ) |
|
429 { |
|
430 sFileName.resize( sFileName.find_last_of('.') ); |
|
431 sRet = sFileName; |
|
432 } |
|
433 } |
|
434 else |
|
435 { |
|
436 // Remove extension finding first . |
|
437 size_t iPos = sFileName.find_first_of('.'); |
|
438 if( iPos != string::npos ) |
|
439 { |
|
440 sFileName.resize( sFileName.find_first_of('.') ); |
|
441 sRet = sFileName; |
|
442 } |
|
443 } |
|
444 return sRet; |
|
445 } |
|
446 |
|
447 // ----------------------------------------------------------------------------- |
|
448 // CATBase::IsTargetTypeSupported |
|
449 // Checks from constant array is this target unsupported |
|
450 // ----------------------------------------------------------------------------- |
|
451 bool CATBase::IsTargetTypeSupported(string sTargetType) |
|
452 { |
|
453 LOG_FUNC_ENTRY("CATBase::IsTargetTypeSupported"); |
|
454 // compare to list |
|
455 int iArraySize = sizeof( UNSUPPORTED_TARGET_TYPES ) / sizeof( string ); |
|
456 for ( int i=0 ; i < iArraySize ; i++ ) |
|
457 { |
|
458 string sUnsupported = UNSUPPORTED_TARGET_TYPES[i]; |
|
459 // lowercase both |
|
460 ChangeToLower(sTargetType); |
|
461 ChangeToLower(sUnsupported); |
|
462 // compare |
|
463 if ( sUnsupported.compare( sTargetType ) == 0 ) |
|
464 { |
|
465 return false; |
|
466 } |
|
467 } |
|
468 return true; |
|
469 } |
|
470 |
|
471 // ----------------------------------------------------------------------------- |
|
472 // CATBase::IsTargetTypeKernelSide |
|
473 // Checks from constant array is this target type kernel side |
|
474 // ----------------------------------------------------------------------------- |
|
475 bool CATBase::IsTargetTypeKernelSide(string sTargetType) |
|
476 { |
|
477 LOG_FUNC_ENTRY("CATBase::IsTargetTypeKernelSide"); |
|
478 // compare to list |
|
479 int iArraySize = sizeof( KERNEL_SIDE_TARGET_TYPES ) / sizeof( string ); |
|
480 for ( int i=0 ; i < iArraySize ; i++ ) |
|
481 { |
|
482 string sUnsupported = KERNEL_SIDE_TARGET_TYPES[i]; |
|
483 // lowercase both |
|
484 ChangeToLower(sTargetType); |
|
485 ChangeToLower(sUnsupported); |
|
486 // compare |
|
487 if ( sUnsupported.compare( sTargetType ) == 0 ) |
|
488 { |
|
489 return true; |
|
490 } |
|
491 } |
|
492 return false; |
|
493 } |
|
494 |
|
495 bool CATBase::CheckVariant( const string& sEpocRoot, const string& sVariant ) |
|
496 { |
|
497 LOG_FUNC_ENTRY("CATBase::CheckVariant"); |
|
498 string sFileToCheck; |
|
499 // Add epoc root |
|
500 if( sEpocRoot.size() > 1 ) |
|
501 sFileToCheck.append( sEpocRoot ); |
|
502 // Add path |
|
503 sFileToCheck.append( VARIANT_DIR ) ; |
|
504 // Add variant |
|
505 sFileToCheck.append( sVariant ); |
|
506 // Add extension |
|
507 sFileToCheck.append( VARIANT_FILE_EXTENSION ); |
|
508 // check does FileExists |
|
509 return FileExists( sFileToCheck.c_str() ); |
|
510 } |
|
511 bool CATBase::IsDefaultVariant( const string& sEpocRoot ) |
|
512 { |
|
513 LOG_FUNC_ENTRY("CATBase::IsDefaultVariant"); |
|
514 string sFileToCheck; |
|
515 // Add epoc root |
|
516 if( sEpocRoot.size() > 1 ) |
|
517 sFileToCheck.append( sEpocRoot ); |
|
518 // Add path |
|
519 sFileToCheck.append( VARIANT_DIR ) ; |
|
520 // Add variant |
|
521 sFileToCheck.append( "DEFAULT" ); |
|
522 // Add extension |
|
523 sFileToCheck.append( VARIANT_FILE_EXTENSION ); |
|
524 // check does FileExists |
|
525 return FileExists( sFileToCheck.c_str() ); |
|
526 } |
|
527 |
|
528 // ----------------------------------------------------------------------------- |
|
529 // CATBase::FileDelete |
|
530 // FileDelete |
|
531 // ----------------------------------------------------------------------------- |
|
532 bool CATBase::FileDelete(const string& sFile, bool bPrint ) |
|
533 { |
|
534 LOG_FUNC_ENTRY("CATBase::FileDelete"); |
|
535 // does file even exists |
|
536 if ( !FileExists( sFile.c_str() ) ) |
|
537 return false; |
|
538 // delete file |
|
539 int iRet = _unlink( sFile.c_str() ); |
|
540 // if print on display error |
|
541 if ( iRet && bPrint ) |
|
542 { |
|
543 cout << AT_MSG << "Error, deleting file " << sFile |
|
544 << endl; |
|
545 } |
|
546 // if print on display message |
|
547 else if ( !iRet && bPrint ) |
|
548 { |
|
549 cout << AT_MSG << "Delete " << sFile << endl; |
|
550 } |
|
551 // return |
|
552 if ( iRet ) |
|
553 return false; |
|
554 return true; |
|
555 } |
|
556 // ----------------------------------------------------------------------------- |
|
557 // CATBase::DirDelete |
|
558 // Delelete directory |
|
559 // ----------------------------------------------------------------------------- |
|
560 bool CATBase::DirDelete(const string& sDir, bool bPrint ) |
|
561 { |
|
562 LOG_FUNC_ENTRY("CATBase::DirDelete"); |
|
563 if ( sDir.find( AT_TEMP_DIR) == string::npos ) |
|
564 return false; |
|
565 |
|
566 if ( sDir.length() < 2 ) |
|
567 return false; |
|
568 |
|
569 string sDir2; |
|
570 if ( sDir.at(1) != ':' ) |
|
571 { |
|
572 char cDir[MAX_LINE_LENGTH]; |
|
573 GetCurrentDirectory( MAX_LINE_LENGTH , cDir ); |
|
574 sDir2.append( cDir ); |
|
575 sDir2.append( "\\" ); |
|
576 sDir2.append( sDir ); |
|
577 } |
|
578 else |
|
579 sDir2.append( sDir ); |
|
580 |
|
581 // does directory exists |
|
582 DWORD dwRet = GetFileAttributes( sDir2.c_str() ); |
|
583 if ( dwRet == INVALID_FILE_ATTRIBUTES ) |
|
584 return false; |
|
585 else if ( ! (dwRet & FILE_ATTRIBUTE_DIRECTORY) ) |
|
586 { |
|
587 return false; |
|
588 } |
|
589 // Delete dir |
|
590 string sCmd( "rmdir /S /Q " ); |
|
591 sCmd.append( sDir2 ); |
|
592 sCmd.append( " > nul 2>&1" ); |
|
593 int iRet = (int)system( sCmd.c_str() ); |
|
594 if ( iRet && bPrint) |
|
595 { |
|
596 cout << AT_MSG << "Error, deleting directory " << sDir2 << endl; |
|
597 } |
|
598 else if ( !iRet && bPrint ) |
|
599 { |
|
600 cout << AT_MSG << "Delete directory " << sDir2 << endl; |
|
601 } |
|
602 if ( iRet ) |
|
603 return false; |
|
604 return true; |
|
605 } |
|
606 |
|
607 // ----------------------------------------------------------------------------- |
|
608 // CATBase::DirCreate |
|
609 // Create directory |
|
610 // ----------------------------------------------------------------------------- |
|
611 bool CATBase::DirCreate(const string& sDir, bool bPrint ) |
|
612 { |
|
613 LOG_FUNC_ENTRY("CATBase::DirCreate"); |
|
614 |
|
615 if ( sDir.length() < 2 ) |
|
616 return false; |
|
617 |
|
618 string sDir2; |
|
619 if ( sDir.at(1) != ':' ) |
|
620 { |
|
621 char cDir[MAX_LINE_LENGTH]; |
|
622 GetCurrentDirectory( MAX_LINE_LENGTH , cDir ); |
|
623 sDir2.append( cDir ); |
|
624 sDir2.append( "\\" ); |
|
625 sDir2.append( sDir ); |
|
626 } |
|
627 else |
|
628 sDir2.append( sDir ); |
|
629 |
|
630 // does directory exists |
|
631 DWORD dwRet = GetFileAttributes( sDir2.c_str() ); |
|
632 if ( dwRet != INVALID_FILE_ATTRIBUTES ) |
|
633 { |
|
634 if( dwRet & FILE_ATTRIBUTE_DIRECTORY ) |
|
635 return false; |
|
636 } |
|
637 // Create dir |
|
638 string sCmd( "mkdir " ); |
|
639 sCmd.append( sDir2 ); |
|
640 sCmd.append( " > nul 2>&1" ); |
|
641 int iRet = (int)system( sCmd.c_str() ); |
|
642 if ( iRet && bPrint) |
|
643 { |
|
644 cout << AT_MSG << "Error, creating directory " << sDir2 << endl; |
|
645 } |
|
646 else if ( !iRet && bPrint ) |
|
647 { |
|
648 cout << AT_MSG << "Directory " << sDir2 << " created" << endl; |
|
649 } |
|
650 if ( iRet ) |
|
651 return false; |
|
652 return true; |
|
653 } |
|
654 |
|
655 // ----------------------------------------------------------------------------- |
|
656 // CATBase::ConvertTCHARtoString |
|
657 // Convert TCHAR* to std::string |
|
658 // ----------------------------------------------------------------------------- |
|
659 string CATBase::ConvertTCHARtoString(TCHAR* charArray) |
|
660 { |
|
661 LOG_LOW_FUNC_ENTRY("CATBase::ConvertTCHARtoString"); |
|
662 // Loop char array |
|
663 stringstream ss; |
|
664 int iIndex = 0; |
|
665 char c = (char) charArray[iIndex]; |
|
666 // until null termination |
|
667 while ( c != '\0' ) |
|
668 { |
|
669 ss << c; |
|
670 iIndex++; |
|
671 c = (char) charArray[iIndex]; |
|
672 } |
|
673 // return string |
|
674 return ss.str(); |
|
675 } |
|
676 |
|
677 // ----------------------------------------------------------------------------- |
|
678 // CATBase::ConvertTCHARtoString |
|
679 // Get list of files in directory |
|
680 // ----------------------------------------------------------------------------- |
|
681 vector<string> CATBase::DirList(const string& sDirectory |
|
682 , bool bListDirs, bool bAddPathToFile) |
|
683 { |
|
684 LOG_FUNC_ENTRY("CATBase::DirList"); |
|
685 // Create string to modify it |
|
686 string sDir = sDirectory; |
|
687 // Add if missing '\' & '*' to the sDirectory |
|
688 if ( sDir.at( sDir.size()-1 ) != '\\' ) |
|
689 sDir.append( "\\" ); |
|
690 // Path to add to file string if specified |
|
691 string sPath = sDir; |
|
692 // Add * to for windows api to find all files |
|
693 sDir.append( "*" ); |
|
694 // convert directory string to LPCSTR |
|
695 LPCSTR dir( sDir.c_str() ); |
|
696 // vector to store file list |
|
697 vector<string> vFileList; |
|
698 // Using win32 api to find list of files in directory |
|
699 // file data "container" |
|
700 WIN32_FIND_DATA fileData; |
|
701 // handle to directory |
|
702 HANDLE hFinder = FindFirstFile( dir, &fileData ); |
|
703 if ( hFinder == INVALID_HANDLE_VALUE ) |
|
704 { |
|
705 // no files found |
|
706 return vFileList; |
|
707 } |
|
708 // loop files add to vector and return |
|
709 while( FindNextFile(hFinder, &fileData ) ) |
|
710 { |
|
711 DWORD dw = fileData.dwFileAttributes; |
|
712 // skip if its directory and bListDirs not specified |
|
713 if ( dw & FILE_ATTRIBUTE_DIRECTORY && ! bListDirs) |
|
714 continue; |
|
715 // add files to vector |
|
716 string sFile = ConvertTCHARtoString( fileData.cFileName ); |
|
717 // Add given path to file string if specified |
|
718 if ( bAddPathToFile ) |
|
719 sFile.insert( 0, sPath ); |
|
720 vFileList.push_back( sFile ); |
|
721 } |
|
722 // Close file find handler |
|
723 FindClose( hFinder ); |
|
724 return vFileList; |
|
725 } |
|
726 |
|
727 // ----------------------------------------------------------------------------- |
|
728 // CATBase::ParseRelativePathToString |
|
729 // ParseRelative |
|
730 // ----------------------------------------------------------------------------- |
|
731 void CATBase::ParseRelativePathString(string& sPathString) |
|
732 { |
|
733 LOG_LOW_FUNC_ENTRY("CATBase::ParseRelativePathString"); |
|
734 string sParsed; |
|
735 // find .. |
|
736 size_t iDots = sPathString.find( ".." ); |
|
737 while ( iDots != string::npos ) |
|
738 { |
|
739 RemoveRelativePath( sPathString, iDots ); |
|
740 iDots = sPathString.find( ".." ); |
|
741 } |
|
742 } |
|
743 |
|
744 // ----------------------------------------------------------------------------- |
|
745 // CATBase::RemoveRelativePath |
|
746 // Remove relative path from string (using given index) |
|
747 // ----------------------------------------------------------------------------- |
|
748 void CATBase::RemoveRelativePath(string& sString, size_t iDots) |
|
749 { |
|
750 LOG_LOW_FUNC_ENTRY("CATBase::RemoveRelativePath"); |
|
751 // Chck if accidentally given wrong parameter |
|
752 if ( iDots == string::npos |
|
753 || iDots < 1 ) |
|
754 return; |
|
755 // Parsed string |
|
756 string sParsed; |
|
757 // Find position of last backslash before dots |
|
758 size_t i = sString.rfind("\\", iDots-2 ); |
|
759 // Pickup start part (depending is the backslash at last parts first char) |
|
760 if ( sString.at(iDots+2) != '\\' ) |
|
761 sParsed = sString.substr( 0, i+1 ) ; |
|
762 else |
|
763 sParsed = sString.substr( 0, i ); |
|
764 // Pick up last part |
|
765 sParsed.append( sString.substr( iDots+2, sString.size() ) ); |
|
766 sString = sParsed; |
|
767 } |
|
768 |
|
769 // ----------------------------------------------------------------------------- |
|
770 // Get extension from given string |
|
771 // ----------------------------------------------------------------------------- |
|
772 string CATBase::GetExtension(const string& sString) |
|
773 { |
|
774 LOG_LOW_FUNC_ENTRY("CATBase::GetExtension"); |
|
775 // find last . |
|
776 size_t iDot = sString.find_last_of( "." ); |
|
777 // return string after . if found |
|
778 if ( iDot != string::npos ) |
|
779 return sString.substr(iDot+1, sString.length()-(iDot+1) ); |
|
780 // otherwise return given string |
|
781 return sString; |
|
782 } |
|
783 |
|
784 // ----------------------------------------------------------------------------- |
|
785 // CATBase::DirectoryExists |
|
786 // Check if given directory exists. |
|
787 // ----------------------------------------------------------------------------- |
|
788 bool CATBase::DirectoryExists( const char* pDirname ) |
|
789 { |
|
790 LOG_FUNC_ENTRY("CATBase::DirectoryExists"); |
|
791 size_t iLenght = strlen( pDirname ); |
|
792 |
|
793 if ( iLenght < 2 ) |
|
794 return false; |
|
795 |
|
796 string sDir; |
|
797 if ( pDirname[1] != ':' ) |
|
798 { |
|
799 char cDir[MAX_LINE_LENGTH]; |
|
800 GetCurrentDirectory( MAX_LINE_LENGTH , cDir ); |
|
801 sDir.append( cDir ); |
|
802 sDir.append( "\\" ); |
|
803 sDir.append( pDirname ); |
|
804 } |
|
805 else |
|
806 sDir.append( pDirname ); |
|
807 |
|
808 DWORD dwRet = GetFileAttributes( sDir.c_str() ); |
|
809 if( dwRet == INVALID_FILE_ATTRIBUTES ) |
|
810 { |
|
811 return false; |
|
812 } |
|
813 else |
|
814 { |
|
815 //Is file directory? |
|
816 if( dwRet & FILE_ATTRIBUTE_DIRECTORY ) |
|
817 { |
|
818 return true; |
|
819 } |
|
820 else |
|
821 { |
|
822 return false; |
|
823 } |
|
824 } |
|
825 } |
|
826 |
|
827 // ----------------------------------------------------------------------------- |
|
828 // CATBase::ConvertUnixPathToWin |
|
829 // ----------------------------------------------------------------------------- |
|
830 void CATBase::ConvertUnixPathToWin( string& sPath ) |
|
831 { |
|
832 LOG_LOW_FUNC_ENTRY("CATBase::ConvertUnixPathToWin"); |
|
833 size_t iSpot = 0; |
|
834 // convert '/' to '\' |
|
835 iSpot = sPath.find( "/" ); |
|
836 while( iSpot != string::npos ) |
|
837 { |
|
838 sPath.replace(iSpot,1, "\\"); |
|
839 iSpot = sPath.find( "/", iSpot+1 ); |
|
840 } |
|
841 // convert '\\' to '\' |
|
842 iSpot = sPath.find( "\\\\" ); |
|
843 while( iSpot != string::npos ) |
|
844 { |
|
845 sPath.replace(iSpot,2,"\\"); |
|
846 iSpot = sPath.find( "\\\\" ); |
|
847 } |
|
848 } |
|
849 |
|
850 // ----------------------------------------------------------------------------- |
|
851 // CATBase::RemoveAllAfterDotIfTwoDots |
|
852 // Removes all after first '.' |
|
853 // if given string contains 2 '.' or more |
|
854 // ----------------------------------------------------------------------------- |
|
855 void CATBase::RemoveAllAfterDotIfTwoDots(string& sModName) |
|
856 { |
|
857 LOG_LOW_FUNC_ENTRY("CATBase::RemoveAllAfterDotIfTwoDots"); |
|
858 // did we find variable? |
|
859 size_t found; |
|
860 // Find first '.' |
|
861 found = sModName.find("."); |
|
862 if ( found != string::npos ) |
|
863 { |
|
864 // Try find second '.' |
|
865 found = sModName.find(".", found+1); |
|
866 if ( found != string::npos ) |
|
867 { |
|
868 // Remove all after first '.' |
|
869 sModName = sModName.substr(0, sModName.find(".")+1 ); |
|
870 } |
|
871 } |
|
872 } |
|
873 // ----------------------------------------------------------------------------- |
|
874 // CATBase::CreateTemporaryCpp |
|
875 // ----------------------------------------------------------------------------- |
|
876 bool CATBase::CreateTemporaryCpp( const string& sId, |
|
877 const string& sPath |
|
878 ,const string& sS60FileName |
|
879 ,int iLogOption |
|
880 ,int iIsDebug |
|
881 ,int iAllocCallStackSize |
|
882 ,int iFreeCallStackSize ) |
|
883 { |
|
884 LOG_FUNC_ENTRY("CATBase::CreateTemporaryCpp"); |
|
885 // Add slash to path if missing |
|
886 string sTempCpp = sPath; |
|
887 if( sTempCpp.at( sTempCpp.length() - 1 ) != '\\' ) |
|
888 sTempCpp.append("\\"); |
|
889 |
|
890 // append temporary cpp name with id in middle |
|
891 sTempCpp.append( AT_TEMP_CPP_LOWER_START ); |
|
892 sTempCpp.append( sId ); |
|
893 sTempCpp.append( AT_TEMP_CPP_LOWER_END ); |
|
894 |
|
895 //Open and truncate temporary cpp |
|
896 ofstream out( sTempCpp.c_str() , ios::trunc ); |
|
897 if ( ! out.good() ) |
|
898 { |
|
899 out.close(); |
|
900 return false; |
|
901 } |
|
902 // Headers |
|
903 out << "#include <e32base.h>"; |
|
904 // Is debug |
|
905 out << "\nconst TInt ATTempDebug(" << iIsDebug << ");"; |
|
906 // Log option |
|
907 out << "\nconst TInt ATTempLogOption(" << iLogOption << ");"; |
|
908 // Alloc call stack |
|
909 out << "\nconst TInt ATTempAllocCallStackSize(" << iAllocCallStackSize << ");"; |
|
910 // Free call stack |
|
911 out << "\nconst TInt ATTempFreeCallStackSize(" << iFreeCallStackSize << ");"; |
|
912 // Log file name |
|
913 out << "\n_LIT( ATTempLogFileName, \"" << sS60FileName << "\" );"; |
|
914 // Version number |
|
915 out << "\n_LIT( ATTempVersion, \"" << ATOOL_COMPATIBILITY_STRING << "\" );"; |
|
916 // Variable functions use enumeration values that are defined in memoryhook (customuser.h) |
|
917 // We use constants here so that we don't need to include the header file, wich |
|
918 // might cause problems. |
|
919 /* Enumeration copied to comment for notes |
|
920 enum TATOptions |
|
921 { |
|
922 ELogFileName = 1, |
|
923 EVersion = 2 , |
|
924 ELogOption = 3, |
|
925 EDebug = 4, |
|
926 EAllocCallStackSize = 5, |
|
927 EFreeCallStackSize = 6 |
|
928 }; |
|
929 */ |
|
930 out << "\nTInt GetInt( const TUint8 aType )"; |
|
931 out << "\n{"; |
|
932 out << "\nswitch( aType )"; |
|
933 out << "\n{"; |
|
934 out << "\ncase 4: return ATTempDebug; "; |
|
935 out << "\ncase 3: return ATTempLogOption;"; |
|
936 out << "\ncase 5: return ATTempAllocCallStackSize;"; |
|
937 out << "\ncase 6: return ATTempFreeCallStackSize;"; |
|
938 out << "\ndefault: return KErrArgument;"; |
|
939 out << "\n}"; |
|
940 out << "\n}"; |
|
941 out << "\nTPtrC GetString( const TUint8 aType )"; |
|
942 out << "\n{"; |
|
943 out << "\nswitch( aType )"; |
|
944 out << "\n{"; |
|
945 out << "\ncase 1: return ATTempLogFileName();"; |
|
946 out << "\ncase 2: return ATTempVersion();"; |
|
947 out << "\ndefault: return KNullDesC();"; |
|
948 out << "\n}"; |
|
949 out << "\n}"; |
|
950 |
|
951 /** Todo: Old way of separate functions, these here for backup support and to ease testing. */ |
|
952 /** Unnessesary in the future, so can be removed then (1.8.2). */ |
|
953 |
|
954 out << "\n_LIT( KFileName, \""; |
|
955 out << sS60FileName; |
|
956 out << "\" );\n"; |
|
957 |
|
958 // Hardcoded version number for support. |
|
959 out << "\n/* The AnalyzeTool version number used. */"; |
|
960 out << "\n_LIT( KAtoolVersion, \"1.7.5;1.9.1\" );\n"; |
|
961 |
|
962 out << "\nconst TFileName LogFileName()"; |
|
963 out << "\n {"; |
|
964 out << "\n return TFileName( KFileName() );"; |
|
965 out << "\n }"; |
|
966 |
|
967 out << "\nTUint32 AllocCallStackSize()"; |
|
968 out << "\n {"; |
|
969 out << "\n return TUint32( "; |
|
970 out << iAllocCallStackSize; |
|
971 out << " );\n"; |
|
972 out << "\n }"; |
|
973 |
|
974 out << "\nTUint32 FreeCallStackSize()"; |
|
975 out << "\n {"; |
|
976 out << "\n return TUint32( "; |
|
977 out << iFreeCallStackSize; |
|
978 out << " );\n"; |
|
979 out << "\n }"; |
|
980 |
|
981 out << "\nconst TFileName AtoolVersion()"; |
|
982 out << "\n {"; |
|
983 out << "\n return TFileName( KAtoolVersion() );"; |
|
984 out << "\n }"; |
|
985 |
|
986 out << "\nTUint32 LogOption()"; |
|
987 out << "\n {"; |
|
988 out << "\n return TUint32( "; |
|
989 out << iLogOption; |
|
990 out << " );"; |
|
991 out << "\n }"; |
|
992 |
|
993 out << "\nTUint32 IsDebug()"; |
|
994 out << "\n {"; |
|
995 out << "\n return TUint32( "; |
|
996 out << iIsDebug; |
|
997 out << " );"; |
|
998 out << "\n }"; |
|
999 |
|
1000 // End of file and close |
|
1001 out << "\n\n// End of File\n"; |
|
1002 out.close(); |
|
1003 cout << AT_MSG << "Created " << sTempCpp << endl; |
|
1004 return true; |
|
1005 } |
|
1006 |
|
1007 // ----------------------------------------------------------------------------- |
|
1008 // CATBase::IsDataFile |
|
1009 // ----------------------------------------------------------------------------- |
|
1010 bool CATBase::IsDataFile( string sFile ) |
|
1011 { |
|
1012 LOG_FUNC_ENTRY("CATBase::IsDataFile"); |
|
1013 // Check that sFile not empty |
|
1014 if ( sFile.empty() || sFile.length() < 1 ) |
|
1015 return false; |
|
1016 |
|
1017 // Temporary line char array. |
|
1018 char cLineFromFile[MAX_LINE_LENGTH]; |
|
1019 //Open file |
|
1020 ifstream in( sFile.c_str() ); |
|
1021 |
|
1022 //File open ok? |
|
1023 if( !in.good() ) |
|
1024 return false; |
|
1025 |
|
1026 //Read all lines |
|
1027 in.getline( cLineFromFile, MAX_LINE_LENGTH ); |
|
1028 |
|
1029 string sLineFromFile( cLineFromFile ); |
|
1030 in.close(); |
|
1031 if( sLineFromFile.find( "DATA_FILE_VERSION" ) != string::npos ) |
|
1032 return true; |
|
1033 else |
|
1034 return false; |
|
1035 } |
|
1036 |
|
1037 |
|
1038 // ----------------------------------------------------------------------------- |
|
1039 // CATBase::ParseStringToVector |
|
1040 // ----------------------------------------------------------------------------- |
|
1041 vector<string> CATBase::ParseStringToVector( const string& sInput, char separator ) |
|
1042 { |
|
1043 LOG_LOW_FUNC_ENTRY("CATBase::ParseStringToVector"); |
|
1044 string sString(sInput); |
|
1045 // Elements vector |
|
1046 vector<string> vStrings; |
|
1047 size_t iPos = sString.find( separator ); |
|
1048 // If can not find it return vector with just one element |
|
1049 if ( iPos == string::npos ) |
|
1050 { |
|
1051 // Don't add empty item into vector. |
|
1052 if ( sString.size() > 0 ) |
|
1053 vStrings.push_back( sString ); |
|
1054 return vStrings; |
|
1055 } |
|
1056 // Loop elements |
|
1057 while( iPos != string::npos ) |
|
1058 { |
|
1059 string sElement = sString.substr(0, iPos); |
|
1060 vStrings.push_back( sElement ); |
|
1061 sString.erase(0, iPos +1 ); |
|
1062 iPos = sString.find( separator ); |
|
1063 } |
|
1064 // Add last element if any |
|
1065 if ( sString.size() > 0 ) |
|
1066 vStrings.push_back( sString ); |
|
1067 // Return elements |
|
1068 return vStrings; |
|
1069 } |
|
1070 |
|
1071 // ----------------------------------------------------------------------------- |
|
1072 // CATBase::FilterString |
|
1073 // Filter string out of unwanted characters. The list of allowed |
|
1074 // characters is defined in CFILTERSTRING. |
|
1075 // ----------------------------------------------------------------------------- |
|
1076 string CATBase::FilterString( const string& sString ) |
|
1077 { |
|
1078 LOG_LOW_FUNC_ENTRY("CATBase::FilterString"); |
|
1079 string sFiltered; |
|
1080 for( size_t i = 0 ; i < sString.length() ; i++ ) |
|
1081 { |
|
1082 const char p = sString.at( i ); |
|
1083 if ( strchr( CFILTERSTRING, p ) != 0 ) |
|
1084 sFiltered.push_back( p ); |
|
1085 } |
|
1086 return sFiltered; |
|
1087 } |
|
1088 |
|
1089 // ----------------------------------------------------------------------------- |
|
1090 // CATBase::FilterExtraSpaces |
|
1091 // Replaces multiple continuous spaces with single. Won't leave |
|
1092 // spaces in start or end of string. |
|
1093 // ----------------------------------------------------------------------------- |
|
1094 void CATBase::FilterExtraSpaces( string& sString ) |
|
1095 { |
|
1096 LOG_LOW_FUNC_ENTRY("CATBase::FilterExtraSpaces"); |
|
1097 string sFiltered; |
|
1098 // Loop thru char array. |
|
1099 for( size_t i = 0 ; i < sString.length(); i++ ) |
|
1100 { |
|
1101 // Is char space? |
|
1102 if ( sString.at( i ) == ' ' ) |
|
1103 { |
|
1104 // Pick up space if filtered does not contain char as last. |
|
1105 if ( sFiltered.rbegin() == sFiltered.rend() ) |
|
1106 sFiltered.push_back( sString.at( i ) ); |
|
1107 else if ( * ( sFiltered.rbegin() ) != ' ' ) |
|
1108 sFiltered.push_back( sString.at( i ) ); |
|
1109 } |
|
1110 else |
|
1111 sFiltered.push_back( sString.at( i ) ); |
|
1112 } |
|
1113 |
|
1114 // Remove first and/or last character if it is space. |
|
1115 if ( sFiltered.begin() != sFiltered.end() ) |
|
1116 { |
|
1117 if( * ( sFiltered.begin() ) == ' ' ) |
|
1118 sFiltered.erase( 0, 1 ); |
|
1119 } |
|
1120 if ( sFiltered.rbegin() != sFiltered.rend() ) |
|
1121 { |
|
1122 if( * ( sFiltered.rbegin() ) == ' ' ) |
|
1123 sFiltered.resize( sFiltered.length()-1 ); |
|
1124 } |
|
1125 sString = sFiltered; |
|
1126 } |
|
1127 |
|
1128 |
|
1129 bool CATBase::hexToDec( string& sHex, unsigned int& iDec ) |
|
1130 { |
|
1131 LOG_LOW_FUNC_ENTRY("CATBase::hexToDec"); |
|
1132 istringstream ss( sHex ); |
|
1133 ss.setf( ios::hex, ios::basefield ); |
|
1134 if( ( ss >> iDec ) ) |
|
1135 return true; |
|
1136 return false; |
|
1137 } |
|
1138 |
|
1139 bool CATBase::hexToDec( string& sHex, int& iDec ) |
|
1140 { |
|
1141 LOG_LOW_FUNC_ENTRY("CATBase::hexToDec"); |
|
1142 istringstream ss( sHex ); |
|
1143 ss.setf( ios::hex, ios::basefield ); |
|
1144 if( ( ss >> iDec ) ) |
|
1145 return true; |
|
1146 return false; |
|
1147 } |
|
1148 |
|
1149 bool CATBase::hexToDec( string& sHex, unsigned long& ulDec ) |
|
1150 { |
|
1151 LOG_LOW_FUNC_ENTRY("CATBase::hexToDec"); |
|
1152 istringstream ss( sHex ); |
|
1153 ss.setf( ios::hex, ios::basefield ); |
|
1154 if( ( ss >> ulDec ) ) |
|
1155 return true; |
|
1156 return false; |
|
1157 } |
|
1158 |
|
1159 bool CATBase::hexToDec( string& sHex, unsigned long long& ullDec ) |
|
1160 { |
|
1161 LOG_LOW_FUNC_ENTRY("CATBase::hexToDec"); |
|
1162 istringstream ss( sHex ); |
|
1163 ss.setf( ios::hex, ios::basefield ); |
|
1164 if( ( ss >> ullDec ) ) |
|
1165 return true; |
|
1166 return false; |
|
1167 } |
|
1168 |
|
1169 /** |
|
1170 * Used to create array of integer & hex value pairs. |
|
1171 */ |
|
1172 struct CHexMap |
|
1173 { |
|
1174 char chr; |
|
1175 int value; |
|
1176 }; |
|
1177 |
|
1178 // ----------------------------------------------------------------------------- |
|
1179 // CATBase::_httoi |
|
1180 // ----------------------------------------------------------------------------- |
|
1181 unsigned long CATBase::_httoi(const char *value) |
|
1182 { |
|
1183 LOG_LOW_FUNC_ENTRY("CATBase::_httoi"); |
|
1184 unsigned long l; |
|
1185 string s( value ); |
|
1186 if ( CATBase::hexToDec( s, l ) ) |
|
1187 return l; |
|
1188 return 0; |
|
1189 } |
|
1190 |
|
1191 |
|
1192 // ----------------------------------------------------------------------------- |
|
1193 // CATBase::NumberToHexString(int) |
|
1194 // ----------------------------------------------------------------------------- |
|
1195 string CATBase::NumberToHexString( unsigned int i ) |
|
1196 { |
|
1197 LOG_LOW_FUNC_ENTRY("CATBase::IntToHexString"); |
|
1198 stringstream ss; |
|
1199 ss << "0x" << hex << i; |
|
1200 string retval; retval = ss.str().c_str(); |
|
1201 return retval; |
|
1202 } |
|
1203 // ----------------------------------------------------------------------------- |
|
1204 // CATBase::NumberToHexString(long) |
|
1205 // ----------------------------------------------------------------------------- |
|
1206 string CATBase::NumberToHexString( unsigned long i ) |
|
1207 { |
|
1208 LOG_LOW_FUNC_ENTRY("CATBase::IntToHexString"); |
|
1209 stringstream ss; |
|
1210 ss << "0x" << hex << i; |
|
1211 string retval; retval = ss.str().c_str(); |
|
1212 return retval; |
|
1213 } |
|
1214 |
|
1215 // ----------------------------------------------------------------------------- |
|
1216 // CATBase::IsHexCharacter |
|
1217 // ----------------------------------------------------------------------------- |
|
1218 bool CATBase::IsHexCharacter(const TCHAR *value) |
|
1219 { |
|
1220 LOG_LOW_FUNC_ENTRY("CATBase::IsHexCharacter"); |
|
1221 const int HexMapL = 22; |
|
1222 CHexMap HexMap[HexMapL] = |
|
1223 { |
|
1224 {'0', 0}, {'1', 1}, |
|
1225 {'2', 2}, {'3', 3}, |
|
1226 {'4', 4}, {'5', 5}, |
|
1227 {'6', 6}, {'7', 7}, |
|
1228 {'8', 8}, {'9', 9}, |
|
1229 {'A', 10}, {'B', 11}, |
|
1230 {'C', 12}, {'D', 13}, |
|
1231 {'E', 14}, {'F', 15}, |
|
1232 {'a', 10}, {'b', 11}, |
|
1233 {'c', 12}, {'d', 13}, |
|
1234 {'e', 14}, {'f', 15} |
|
1235 }; |
|
1236 bool found = false; |
|
1237 for (int i = 0; i < HexMapL; i++) |
|
1238 { |
|
1239 if(HexMap[i].chr == *value) |
|
1240 { |
|
1241 found = true; |
|
1242 break; |
|
1243 } |
|
1244 } |
|
1245 return found; |
|
1246 } |
|
1247 |
|
1248 // ----------------------------------------------------------------------------- |
|
1249 // CATBase::IsAscii(const char*,const unsigned int) |
|
1250 // ----------------------------------------------------------------------------- |
|
1251 bool CATBase::IsAscii( const char* pInput, const unsigned int iLength ) |
|
1252 { |
|
1253 LOG_LOW_FUNC_ENTRY("CATBase::IsAscii"); |
|
1254 bool bRet = true; |
|
1255 const char* pPoint = pInput; |
|
1256 for( unsigned int i = 0 ; i < iLength ; i++) |
|
1257 { |
|
1258 if( !__isascii(*pPoint) ) |
|
1259 { |
|
1260 bRet = false; |
|
1261 break; |
|
1262 } |
|
1263 pPoint++; |
|
1264 } |
|
1265 return bRet; |
|
1266 } |
|
1267 |
|
1268 // ----------------------------------------------------------------------------- |
|
1269 // CATBase::GetEpocRoot( string& sEpocRoot ) |
|
1270 // ----------------------------------------------------------------------------- |
|
1271 bool CATBase::GetEpocRoot( string& sEpocRoot ) |
|
1272 { |
|
1273 LOG_FUNC_ENTRY( "CATBase::GetEpocRoot" ); |
|
1274 bool bRet = true; |
|
1275 //Find EPOCROOT from environment variable |
|
1276 char* pEpocRoot = getenv ("EPOCROOT"); |
|
1277 if( pEpocRoot == NULL ) |
|
1278 { |
|
1279 const char pDevicesPath[] = "C:\\Program Files\\Common Files\\Symbian\\devices.xml"; |
|
1280 CATParseXML parser; |
|
1281 //Find EPOCROOT from devices |
|
1282 sEpocRoot = parser.GetEpocRootPathFromXML(pDevicesPath); |
|
1283 if( sEpocRoot.empty() ) |
|
1284 { |
|
1285 printf("EPOCROOT not set to environment variables.\n"); |
|
1286 bRet = false; |
|
1287 } |
|
1288 } |
|
1289 else |
|
1290 { |
|
1291 sEpocRoot.append( pEpocRoot ); |
|
1292 LOG_STRING( "EpocRoot :" << sEpocRoot ); |
|
1293 } |
|
1294 //Remove trailing slash |
|
1295 if ( sEpocRoot.size() > 1 && sEpocRoot[ sEpocRoot.length()-1 ] == '\\' ) |
|
1296 sEpocRoot.resize( sEpocRoot.length()-1 ); |
|
1297 return bRet; |
|
1298 } |
|
1299 //End of file |