92 lines
1.4 KiB
C++
92 lines
1.4 KiB
C++
|
|
|
|
#include "FirefoxPasswordManager.h"
|
|
#include "Common.h"
|
|
|
|
char lastErrorMesg[10000];
|
|
|
|
void PrintMessage( int level, char *mesg , ...)
|
|
{
|
|
va_list vl;
|
|
|
|
va_start( vl , mesg );
|
|
vsprintf( lastErrorMesg , mesg , vl );
|
|
va_end( vl );
|
|
|
|
// if we are not debugging then print DEBUG level messages
|
|
#ifdef DEBUG
|
|
printf("%s", lastErrorMesg );
|
|
#else
|
|
if( level != MESG_DEBUG )
|
|
printf("%s", lastErrorMesg );
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* Converts given string to lower case....
|
|
*
|
|
*/
|
|
void StrLwr(char *str)
|
|
{
|
|
int n=strlen(str);
|
|
|
|
for(int i=0; i<n; i++)
|
|
{
|
|
if( str[i] >=65 && str[i]<=90 )
|
|
str[i]+=32;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* Checks if specified directory exists
|
|
*
|
|
* return MC_TRUE if directory exists else MC_FALSE
|
|
*
|
|
*/
|
|
int IsDirectoryExists( char *path )
|
|
{
|
|
if( path == NULL )
|
|
return 0;
|
|
|
|
#ifdef WIN32
|
|
|
|
DWORD attr = GetFileAttributes(path);
|
|
|
|
if( (attr == -1) || !(attr & FILE_ATTRIBUTE_DIRECTORY ) )
|
|
{
|
|
PrintMessage(MESG_ERROR, "\n IsDirectoryExists : Directory does not exist : [%s] ", path);
|
|
return 0;
|
|
}
|
|
|
|
return 1;
|
|
|
|
#else
|
|
|
|
char *program = (char*) malloc(strlen(path)+20);
|
|
|
|
if( program == NULL )
|
|
return 0;
|
|
|
|
strcpy(program, "test -d ");
|
|
strcat(program, path);
|
|
|
|
int result= system(program);
|
|
free(program);
|
|
|
|
if( result != 0 )
|
|
{
|
|
PrintMessage(MESG_ERROR, "\n IsDirectoryExists : Directory does not exist : [%s] ", path);
|
|
return 0;
|
|
}
|
|
|
|
return 1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|