@ -761,6 +761,14 @@ ImportConfigFile()
TCHAR destination [ MAX_PATH ] ;
TCHAR destination [ MAX_PATH ] ;
PTCHAR fileName = source + fn . nFileOffset ;
PTCHAR fileName = source + fn . nFileOffset ;
/* check if the source points to the config_dir */
if ( wcsncmp ( source , o . global_config_dir , wcslen ( o . global_config_dir ) ) = = 0
| | wcsncmp ( source , o . config_dir , wcslen ( o . config_dir ) ) = = 0 )
{
ShowLocalizedMsg ( IDS_ERR_IMPORT_SOURCE , source ) ;
return ;
}
_sntprintf_0 ( destination , _T ( " %s \\ %s " ) , o . config_dir , fileName ) ;
_sntprintf_0 ( destination , _T ( " %s \\ %s " ) , o . config_dir , fileName ) ;
destination [ _tcslen ( destination ) - _tcslen ( o . ext_string ) - 1 ] = _T ( ' \0 ' ) ;
destination [ _tcslen ( destination ) - _tcslen ( o . ext_string ) - 1 ] = _T ( ' \0 ' ) ;
@ -770,27 +778,29 @@ ImportConfigFile()
_sntprintf_0 ( destination , _T ( " %s \\ %s " ) , destination , fileName ) ;
_sntprintf_0 ( destination , _T ( " %s \\ %s " ) , destination , fileName ) ;
if ( ! CopyFile ( source , destination , TRUE ) )
bool no_overwrite = TRUE ;
while ( ! CopyFile ( source , destination , no_overwrite ) )
{
{
if ( GetLastError ( ) == ERROR_FILE_EXISTS )
if ( GetLastError ( ) != ERROR_FILE_EXISTS | | ! no_overwrite )
{
{
fileName [ _tcslen ( fileName ) - _tcslen ( o . ext_string ) - 1 ] = _T ( ' \0 ' ) ;
MsgToEventLog ( EVENTLOG_ERROR_TYPE , L " Copy file <%s> to <%s> failed (error = %lu) " ,
ShowLocalizedMsg ( IDS_ERR_IMPORT_EXISTS , fileName ) ;
source , destination , GetLastError ( ) ) ;
ShowLocalizedMsg ( IDS_ERR_IMPORT_FAILED , destination ) ;
return ;
return ;
}
}
/* A file with same name exists. Ask the user whether to replace or not. */
if ( ShowLocalizedMsgEx ( MB_YESNO , _T ( PACKAGE_NAME ) , IDS_NFO_IMPORT_OVERWRITE , fileName ) = = IDNO )
return ;
/* try again with overwrite allowed */
no_overwrite = FALSE ;
}
}
else
{
ShowLocalizedMsg ( IDS_NFO_IMPORT_SUCCESS ) ;
ShowLocalizedMsg ( IDS_NFO_IMPORT_SUCCESS ) ;
return ;
return ;
}
}
}
ShowLocalizedMsg ( IDS_ERR_IMPORT_FAILED , destination ) ;
ShowLocalizedMsg ( IDS_ERR_IMPORT_FAILED , destination ) ;
}
}
}
}
# ifdef DEBUG
# ifdef DEBUG