secureswitools/swianalysistoolkit/source/common/osinterface.cpp
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2005-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 the License "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: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "osinterface.h"
       
    20 #include <windows.h>
       
    21 #include <Shlwapi.h>
       
    22 #include "symbiantypes.h"
       
    23 
       
    24 const int KLen = 256;
       
    25 
       
    26 const std::vector <STRING>  OSInterface::ExtractFilesFromDirectory(const STRING& aRootDir,const STRING& aExtension)                    
       
    27 	{
       
    28 	STRING			pathOfFile;
       
    29 	STRING			patternOfString;
       
    30 	WIN32_FIND_DATA fileInfo;
       
    31 
       
    32     patternOfString = aRootDir + _T("\\*.*") ;
       
    33 
       
    34 	HANDLE hToFile = ::FindFirstFile(patternOfString.c_str(), &fileInfo);	
       
    35 	
       
    36 	std::vector<STRING> aDirFiles;
       
    37 
       
    38 	if(hToFile != INVALID_HANDLE_VALUE)
       
    39 		{
       
    40 		do
       
    41 			{
       
    42 			if(fileInfo.cFileName[0] != '.')
       
    43 				{
       
    44 				pathOfFile.erase();
       
    45 				
       
    46 				pathOfFile = aRootDir + _T("\\")+ fileInfo.cFileName;
       
    47 				STRING file = fileInfo.cFileName;
       
    48 								
       
    49 				STRING extOfString = file.substr(file.rfind(_T(".")) + 1);
       
    50 				
       
    51 				if(aExtension.length())
       
    52 					{
       
    53 					if(extOfString == aExtension)
       
    54 						{
       
    55 						aDirFiles.push_back(pathOfFile);
       
    56 						}
       
    57 					}
       
    58 				else
       
    59 					{
       
    60 					bool valid = IsInteger(file);
       
    61 					if(valid)
       
    62 						{
       
    63 						aDirFiles.push_back(pathOfFile);
       
    64 						}
       
    65 					}
       
    66 				}
       
    67 			}while(::FindNextFile(hToFile , &fileInfo));
       
    68 
       
    69 		::FindClose(hToFile);
       
    70 	  	}
       
    71 	return aDirFiles;
       
    72 	}
       
    73 
       
    74 
       
    75 void OSInterface::DeleteFilesFromDirectory(const STRING& aRootDir,const STRING& aExtension)                    
       
    76 	{
       
    77 	STRING			patternOfString;
       
    78 	WIN32_FIND_DATA fileInfo;
       
    79     patternOfString = aRootDir + _T("\\*.*") ;
       
    80 	
       
    81 	HANDLE hToFile = ::FindFirstFile(patternOfString.c_str(), &fileInfo);	
       
    82 	
       
    83 	if(hToFile != INVALID_HANDLE_VALUE)
       
    84 		{
       
    85 		do
       
    86 			{
       
    87 			if(fileInfo.cFileName[0] != '.')
       
    88 				{
       
    89 				
       
    90 				STRING file = fileInfo.cFileName;
       
    91 				
       
    92 				STRING extOfString = file.substr(file.rfind(_T(".")) + 1);
       
    93 
       
    94 				if(extOfString == aExtension)
       
    95 					{
       
    96 					::DeleteFile(file.c_str());
       
    97 					}
       
    98 				}		
       
    99 			}while(::FindNextFile(hToFile , &fileInfo));
       
   100 
       
   101 		::FindClose(hToFile);
       
   102 	  	}
       
   103 	}
       
   104 
       
   105 bool OSInterface::IsInteger(const STRING& aFileName) 
       
   106 	{ 
       
   107 	const _TCHAR* name = aFileName.c_str();
       
   108 	while(*name >= '0' && *name <= '9')
       
   109 		{
       
   110 		name++;
       
   111 		}
       
   112 	if(*name != 0)
       
   113 		{
       
   114 		return false;
       
   115 		}
       
   116 	return true;
       
   117 	} 
       
   118 
       
   119 
       
   120 int OSInterface::CheckIfDirectory(const STRING& aFile) 
       
   121 	{
       
   122 	return ::PathIsDirectory(aFile.c_str());
       
   123 	}
       
   124 
       
   125 int OSInterface::DeleteDirectory(STRING& aDirectory) 
       
   126 	{
       
   127 	return ::RemoveDirectory(aDirectory.c_str());
       
   128 	}
       
   129 
       
   130 void OSInterface::ReadPrivateProfile(const STRING& aIniSectionName , const STRING& aRootLabel ,const STRING& aCertstoreFile , _TCHAR* aBuf)
       
   131 	{
       
   132 	::GetPrivateProfileString(aIniSectionName.c_str() , aRootLabel.c_str(), _T(""), aBuf, KLen , aCertstoreFile.c_str());
       
   133 	}
       
   134