//  FtpManager.h: interface for the CFtpManager class.
//
//
////////////////////////////////////////////////////////////////////

#
if   ! defined(AFX_FTPMANAGER_H__58719070_7813_4A0F_9392_9A8F217EC94A__INCLUDED_)
#define AFX_FTPMANAGER_H__58719070_7813_4A0F_9392_9A8F217EC94A__INCLUDED_

#
if  _MSC_VER  >   1000
#pragma once
#endif 
//  _MSC_VER > 1000

#include 
" Wininet.h "

typedef BOOL (
* ListFtpServerFilesCallBackProc)(LPVOID pThis,LPCTSTR lpListedFile,WIN32_FIND_DATA  & FileInfo,LPVOID lpParam);

class CFtpManager  
{
public:
    enum E_ListFileType { FileTypeDirectory 
=   1  , FileTypeSubDirectory  =   2  , FileTypeFile  =   4 };
    LPVOID    m_lpParam[
4 ];
public:
    bool IsFtpConnect(){
return  m_hStartFtpOpen != NULL;}
    
void  SetFtpCallBack(INTERNET_STATUS_CALLBACK lpfnCallProc) {m_lpfnInternetCallback  =  lpfnCallProc;}
    BOOL FtpFindFiles(LPCTSTR lpDirectory ,DWORD dwListType ,ListFtpServerFilesCallBackProc lpfnCallBack,LPVOID lpParam,LPCTSTR lpExt 
=  NULL);
    BOOL FtpUpLoadFile(LPCTSTR lpLocalFile,LPCTSTR lpSavedName);
    
//  if FileExist return 1, not return 0 ,server error return -2,command error return -1.
     int  FtpFileExist(LPCTSTR lpFtpFileName);
    
//  Must Use Root Path.
    BOOL ChangeCWD(LPCTSTR lpWorkPath);
    
//  dwDelay is Second.
    BOOL ReConnectFtp(DWORD dwDelay);
    
//  PassiveMode is Unsafe Mode.
    BOOL ConnectFtp(LPCTSTR lpServer,UINT uPort,LPCTSTR lpUser,LPCTSTR lpPass,BOOL bPassive);
    
void  DisConnectFtp();
    DWORD FtpErrorMsgToCode(LPCTSTR lpErrorMsg);
    static 
void  CALLBACK InternetStatusCallbackProc(HINTERNET hInternet, DWORD_PTR dwContext, DWORD dwInternetStatus, LPVOID lpvStatusInformation, DWORD dwStatusInformationLength);
    CFtpManager(LPCTSTR lpLogFile,DWORD dwTimeOut 
=   60  );
    virtual 
~ CFtpManager();

protected:
    INTERNET_STATUS_CALLBACK m_lpfnInternetCallback;
    HINTERNET    m_hFtpFile;
    HINTERNET    m_hStartFtpOpen;
    HINTERNET    m_hStartFtpConnct;
    String        m_strServer;
    UINT        m_uPort;
    String        m_strUser;
    String        m_strUserPass;
    BOOL        m_bPassive;
    BOOL        m_bCancleUpLoad;
    String        m_strFtpLog;
    DWORD        m_dwTimeOut;
};

#endif 
//  !defined(AFX_FTPMANAGER_H__58719070_7813_4A0F_9392_9A8F217EC94A__INCLUDED_)
//  FtpManager.cpp: implementation of the CFtpManager class.
//
//
////////////////////////////////////////////////////////////////////

#include 
" stdafx.h "
#include 
" FtpManager.h "
#include 
" StaticFunctions.h "
#pragma comment(lib,
" Wininet.lib " )

#ifdef _DEBUG
#include 
" afxinet.h "
#endif 
//  _DEBUG

#ifdef _DEBUG
#undef THIS_FILE
static 
char  THIS_FILE[] = __FILE__;
#define 
new  DEBUG_NEW
#endif

#define CStaticFunctions::LogToFileWithTime  (void)0
// ////////////////////////////////////////////////////////////////////
//
 Construction/Destruction
//
////////////////////////////////////////////////////////////////////

CFtpManager::CFtpManager(LPCTSTR lpLogFile,DWORD dwTimeOut)
{
    m_dwTimeOut 
=  dwTimeOut  *   1000 ;
    m_strFtpLog 
=  lpLogFile;
    m_hStartFtpOpen 
=  NULL;
    m_hStartFtpConnct 
=  NULL;
    m_hFtpFile 
=  NULL;
    m_bCancleUpLoad 
=  FALSE;
    m_lpfnInternetCallback 
=  NULL;
    ZeroMemory(m_lpParam,sizeof(m_lpParam));
}

CFtpManager::
~ CFtpManager()
{
    DisConnectFtp();
}

void  CFtpManager::DisConnectFtp()
{
    
if (m_hFtpFile)
    {
        InternetCloseHandle(m_hFtpFile);
        m_hFtpFile 
=  NULL;
    }
    
if (m_hStartFtpConnct)
    {
        CStaticFunctions::LogToFileWithTime(m_strFtpLog.c_str(),FALSE,TEXT(
" Disconnect FTP Connection.\n " ));
        InternetCloseHandle(m_hStartFtpConnct);
        m_hStartFtpConnct 
=  NULL;
    }
    
if (m_hStartFtpOpen)
    {
        InternetCloseHandle(m_hStartFtpOpen);
        m_hStartFtpOpen 
=  NULL;
    }
}

BOOL CFtpManager::ConnectFtp(LPCTSTR lpServer, UINT uPort, LPCTSTR lpUser, LPCTSTR lpPass, BOOL bPassive)
{
    BOOL bRet 
=  FALSE;
    
if (lpServer)
        m_strServer 
=  lpServer;
    m_uPort 
=  uPort;
    
if (lpUser)
        m_strUser 
=  lpUser;
    
if (lpPass)
        m_strUserPass 
=  lpPass;
    m_bPassive 
=  bPassive;
    CStaticFunctions::RemovePrefixString(const_cast
< LPTSTR >  (m_strServer.c_str()) , TEXT( " ftp:// " ));
    
return  ReConnectFtp( 0 );
}

BOOL CFtpManager::ReConnectFtp(DWORD dwDelay)
{
    BOOL bRet 
=  FALSE;
    DisConnectFtp();
    Sleep(dwDelay
* 1000 );
    DWORD dwFlags 
=   0 ;
    InternetGetConnectedState(
& dwFlags,  0 );
    m_hStartFtpOpen 
=  InternetOpen(TEXT( " King_AutoFtpConnect " ),
        (dwFlags 
&  INTERNET_CONNECTION_PROXY)  ==  INTERNET_CONNECTION_PROXY  ?  INTERNET_OPEN_TYPE_PRECONFIG : INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY,
        NULL , NULL , 
0 );

    
if ( ! m_hStartFtpOpen)
    {
        CStaticFunctions::LogToFileWithTime(m_strFtpLog.c_str(),TRUE,TEXT(
" Erron On Open Internet Connection. Err:%d\n " ) , GetLastError());
        
return  bRet;
    }

    
//  --set timeout durations for connects, sends, and receives.
    
    
if  (FALSE  ==  InternetSetOption(m_hStartFtpOpen, 
        INTERNET_OPTION_RECEIVE_TIMEOUT, 
& m_dwTimeOut, 
        sizeof(DWORD)))
    {
        
//  not necessarily a serious error, but report it anyway.
        CStaticFunctions::LogToFileWithTime(m_strFtpLog.c_str(),FALSE,TEXT( " Erron On Set Connection Receive Timeout. Err:%d\n " ) , GetLastError());
    }
    
    
if  (FALSE  ==  InternetSetOption(m_hStartFtpOpen, 
        INTERNET_OPTION_SEND_TIMEOUT, 
& m_dwTimeOut, 
        sizeof(DWORD)))
    {
        
//  not necessarily a serious error, but report it anyway.
        CStaticFunctions::LogToFileWithTime(m_strFtpLog.c_str(),FALSE,TEXT( " Erron On Set Connection Send Timeout. Err:%d\n " ) , GetLastError());
    }
    
    
if  (FALSE  ==  InternetSetOption(m_hStartFtpOpen, 
        INTERNET_OPTION_CONNECT_TIMEOUT, 
& m_dwTimeOut, 
        sizeof(DWORD)))
    {
        
//  not necessarily a serious error, but report it anyway.
        CStaticFunctions::LogToFileWithTime(m_strFtpLog.c_str(),FALSE,TEXT( " Erron On Set Connection Connect Timeout. Err:%d\n " ) , GetLastError());
    }

    m_hStartFtpConnct 
=  InternetConnect(m_hStartFtpOpen,m_strServer.c_str(),m_uPort,
        CStaticFunctions::IsEmptyString(m_strUser) 
?  NULL : m_strUser.c_str() ,
        CStaticFunctions::IsEmptyString(m_strUserPass) 
?  NULL : m_strUserPass.c_str() , 
        INTERNET_SERVICE_FTP , ( m_bPassive 
?  INTERNET_FLAG_PASSIVE :  0  ) , NULL );

    
if ( ! m_hStartFtpConnct)
    {
        CStaticFunctions::LogToFileWithTime(m_strFtpLog.c_str(),TRUE,TEXT(
" Erron On FTP Connection. Err:%d\n " ) , GetLastError());
        DisConnectFtp();
        
return  bRet;
    }

    CStaticFunctions::LogToFileWithTime(m_strFtpLog.c_str(),FALSE,TEXT(
" Connect To FTP Server.\n " ));
//      InternetSetStatusCallback(m_hStartFtpConnct,m_lpfnInternetCallback ? m_lpfnInternetCallback : InternetStatusCallbackProc);
     return  TRUE;
}

BOOL CFtpManager::ChangeCWD(LPCTSTR lpWorkPath)
{
    BOOL bRet 
=  FALSE;
    
if (m_hStartFtpConnct  &&  lpWorkPath)
    {
        
// CStaticFunctions::RemovePostfixString(const_cast<LPTSTR> (strWorkPath.c_str()) , TEXT("/"));
         if ( FtpSetCurrentDirectory(m_hStartFtpConnct,lpWorkPath)  ==  TRUE)
            bRet 
=  TRUE;
        
else
            CStaticFunctions::LogToFileWithTime(m_strFtpLog.c_str(),TRUE,TEXT(
" Erron On Set Current FTP Directory. Err:%d\n " ) , GetLastError());

//          TCHAR szError[MAX_PATH] = {0};
//
         DWORD dwErrorSize = MAX_PATH;
//
         DWORD dwLastErrorMsg = 0;
//
         InternetGetLastResponseInfo(&dwLastErrorMsg,szError,&dwErrorSize);
    }

    
return  bRet;
}

int  CFtpManager::FtpFileExist(LPCTSTR lpFtpFileName)
{
    
int  iRet  =   - 2 ;
    
if ( ! lpFtpFileName)
        
return   0 ;
    TCHAR szError[MAX_PATH] 
=  { 0 };
    DWORD dwErrorSize 
=  MAX_PATH;
    DWORD dwLastErrorMsg 
=   0 ;
    HINTERNET hFind 
=  NULL;
    String strCmd 
=  TEXT( " SIZE  " );
    strCmd
+= lpFtpFileName;

    
//  -- Try Receive File Size.
     if ( FtpCommand(m_hStartFtpConnct,FALSE,FTP_TRANSFER_TYPE_ASCII,strCmd.c_str(),(DWORD_PTR) this ,NULL) )
    {
        InternetGetLastResponseInfo(
& dwLastErrorMsg,szError, & dwErrorSize);
        dwLastErrorMsg 
=  FtpErrorMsgToCode(szError);
        
if ( dwLastErrorMsg == 550 )
        {
            
//  550 File Not Found, 
            iRet  =   0 ;
        }
        
else   if (dwLastErrorMsg  ==   500 )
        {
            
//  500 Unknown Command.
            iRet  =   - 1 ;
        }
        
else   if (dwLastErrorMsg == 213 )
        {
            
//  213 Return Size
            iRet  =   1 ;
        }
    }
    
else
    {
        
if (GetLastError() == ERROR_INTERNET_EXTENDED_ERROR)
        {
            InternetGetLastResponseInfo(
& dwLastErrorMsg,szError, & dwErrorSize);
            dwLastErrorMsg 
=  FtpErrorMsgToCode(szError);
            
// ERROR_INVALID_PARAMETER
             if ( dwLastErrorMsg == 550 )
            {
                
//  550 File Not Found, 
                iRet  =   0 ;
            }
            
else   if (dwLastErrorMsg  ==   500 )
            {
                
//  500 Unknown Command.
                iRet  =   - 1 ;
            }
        }
    }

    
//  -- If Server Not Support SIZE Command, Try Use FtpOpenFile to Test it .
     if (iRet ==- 1 )
    {
        HINTERNET hOpenTest 
=  FtpOpenFile(m_hStartFtpConnct,lpFtpFileName,GENERIC_READ,FTP_TRANSFER_TYPE_BINARY,(DWORD_PTR) this );
        
if (hOpenTest)
        {
            InternetCloseHandle(hOpenTest);
            
//  -- Open Success,File Exist.
            iRet  =   1 ;
        }
        
else
        {
            DWORD dwLastError 
=  GetLastError();
            dwErrorSize 
=  MAX_PATH;
            
if (dwLastError == ERROR_INTERNET_EXTENDED_ERROR)
            {
                InternetGetLastResponseInfo(
& dwLastError,szError, & dwErrorSize);
                String strCmdRet 
=  szError;
                
if ( strCmdRet.find(TEXT( " 553 " )) !=- 1   ||  strCmdRet.find(TEXT( " 550 " )) !=- 1 )
                    iRet 
=   0 ;
                
else
                {
                    CStaticFunctions::LogToFileWithTime(m_strFtpLog.c_str(),FALSE,TEXT(
" FtpFileExist FtpOpenFile Error MSG:\n%s\n " ) , szError);
                    TRACE(
" FtpFileExist Error MSG:\n%s\n "  , szError);
                }
            }
        }
    }

    
//  -- If FtpOpenFile Break A Unknown Error , We Try FtpFindFirstFile to get it.
     if (iRet  ==   - 1 )
    {
        WIN32_FIND_DATA FindInfo 
=  { 0 };
        hFind 
=  FtpFindFirstFile(m_hStartFtpConnct,lpFtpFileName, & FindInfo,  0  , (DWORD_PTR) this );
        
if (hFind)
        {
            InternetCloseHandle(hFind);
            iRet 
=   1 ;
        }
        
else
        {
            
// ERROR_INTERNET_EXTENDED_ERROR.
            DWORD dwLastError  =  GetLastError();
            dwErrorSize 
=  MAX_PATH;
            
if (dwLastError == ERROR_INTERNET_EXTENDED_ERROR)
            {
                InternetGetLastResponseInfo(
& dwLastError,szError, & dwErrorSize);
                String strCmdRet 
=  szError;
                
if ( strCmdRet.find(TEXT( " 553 " )) !=- 1   ||  strCmdRet.find(TEXT( " 550 " )) !=- 1 )
                    iRet 
=   0 ;
                
else
                {
                    CStaticFunctions::LogToFileWithTime(m_strFtpLog.c_str(),FALSE,TEXT(
" FtpFileExist FtpFindFirstFile Error MSG:\n%s\n " ) , szError);
                    TRACE(
" FtpFileExist Error MSG:\n%s\n "  , szError);
                }
            }
            
// TRACE("FtpFileExist Error MSG:\n%s\n" , szError);
        }

    }
    
return  iRet;
}

void  CFtpManager::InternetStatusCallbackProc(HINTERNET hInternet, DWORD_PTR dwContext, DWORD dwInternetStatus, LPVOID lpvStatusInformation, DWORD dwStatusInformationLength)
{
    CFtpManager 
* pThis  =  (CFtpManager  * )dwContext;
    TRACE(TEXT(
" Status = %d\n " ),dwInternetStatus); // INTERNET_STATUS_CLOSING_CONNECTION INTERNET_FLAG_RELOAD
     if (dwInternetStatus == INTERNET_STATUS_RESPONSE_RECEIVED)
        TRACE(TEXT(
" \tRecive Size %d\n " ), * (PDWORD)lpvStatusInformation);
    
else   if (dwInternetStatus == INTERNET_STATUS_REQUEST_SENT)
        TRACE(TEXT(
" \tSend Size %d\n " ), * (PDWORD)lpvStatusInformation);

}

DWORD CFtpManager::FtpErrorMsgToCode(LPCTSTR lpErrorMsg)
{
    DWORD dwRet 
=  StrToInt(lpErrorMsg);
    
return  dwRet;
}

BOOL CFtpManager::FtpUpLoadFile(LPCTSTR lpLocalFile, LPCTSTR lpSavedName)
{
    BOOL bRet 
=  FALSE;
    
if (::PathFileExists(lpLocalFile))
    {
        String strUpName;
        
if (lpSavedName)
            strUpName 
=  lpSavedName;
        
else
            strUpName 
=  ::PathFindFileName(lpLocalFile);
        InternetSetStatusCallback(m_hStartFtpConnct,m_lpfnInternetCallback 
?  m_lpfnInternetCallback : InternetStatusCallbackProc);
        
// This Function Can't Work With PassiveMode Correctly?
        bRet  =  FtpPutFile(m_hStartFtpConnct,lpLocalFile,strUpName.c_str(),FTP_TRANSFER_TYPE_BINARY,(DWORD_PTR) this );
        TCHAR szError[MAX_PATH] 
=  { 0 };
        DWORD dwErrorSize 
=  MAX_PATH;
        DWORD dwLastErrorMsg 
=   0 ;
        
if ( ! bRet)
        {
            InternetGetLastResponseInfo(
& dwLastErrorMsg,szError, & dwErrorSize);
            CStaticFunctions::LogToFileWithTime(m_strFtpLog.c_str(),TRUE,TEXT(
" Erron On FtpPutFile. Err:%d\n " ) , GetLastError());
            dwErrorSize 
=  MAX_PATH;
        }
        InternetSetStatusCallback(m_hStartFtpConnct,NULL);
    }
    
return  bRet;
}

BOOL CFtpManager::FtpFindFiles(LPCTSTR lpDirectory ,DWORD dwListType ,ListFtpServerFilesCallBackProc lpfnCallBack,LPVOID lpParam,LPCTSTR lpExt)
{
    BOOL bRet 
=  FALSE;
    BOOL bUserCancle 
=  FALSE;
    {
        HINTERNET hFind 
=  NULL;
        
int  iMaxLen  =  lstrlen(lpDirectory) + 16 ;
        String strListPath;
        strListPath.resize(iMaxLen);
        
if (lpDirectory)
            CStaticFunctions::AddPostfixString(const_cast
< LPTSTR > (strListPath.c_str()),lpDirectory,TEXT( " / " ),iMaxLen);
        strListPath.resize(lstrlen(strListPath.c_str()));
        
if (lpExt)
            strListPath 
+=  lpExt;
        
else
            strListPath 
+=  TEXT( " *.* " );

        WIN32_FIND_DATA m_FindFileData 
=  { 0 };
        hFind 
=  FtpFindFirstFile(m_hStartFtpConnct,strListPath.c_str(),  & m_FindFileData,  0  , (DWORD_PTR) this );
        
if  (hFind  !=  NULL)  
        {    
            
do  
            {
                
if ( lstrcmp(m_FindFileData.cFileName, TEXT( " . " )) == 0   ||  lstrcmp(m_FindFileData.cFileName, TEXT( " .. " )) == 0  )
                    
continue ;
                strListPath.resize(iMaxLen);
                
if (lpDirectory)
                    CStaticFunctions::AddPostfixString(const_cast
< LPTSTR > (strListPath.c_str()),lpDirectory,TEXT( " / " ),iMaxLen);
                
else
                    strListPath.resize(
0 );
                strListPath.resize(lstrlen(strListPath.c_str()));
                strListPath 
+=  m_FindFileData.cFileName;
                
if ( (m_FindFileData.dwFileAttributes  &  FILE_ATTRIBUTE_DIRECTORY) )
                {
                    
//  -- Test if Find File is Directory.
                     if ( dwListType  &  FileTypeDirectory )
                    {
                        
if ! lpfnCallBack( this ,strListPath.c_str(),m_FindFileData,lpParam) )
                        {
                            bUserCancle 
=  TRUE;
                            
break ;
                        }
                    }

                    
if (dwListType  &  FileTypeSubDirectory)
                    {
                        bRet 
=  FtpFindFiles(strListPath.c_str(),dwListType,lpfnCallBack,lpParam,lpExt);
                        
if (GetLastError() == ERROR_CANCELLED)
                        {
                            bUserCancle 
=  TRUE;
                            
break ;
                        }
                    }
                }
                
else
                {
                    
if ( dwListType  &  FileTypeFile )
                    {
                        
if ! lpfnCallBack( this ,strListPath.c_str(),m_FindFileData,lpParam) )
                        {
                            bUserCancle 
=  TRUE;
                            
break ;
                        }
                    }
                }                                
            } 
while (InternetFindNextFile(hFind,  & m_FindFileData)  !=   0 );
            
            InternetCloseHandle(hFind);
            bRet 
=  TRUE;
        }
        
else
        {
            TCHAR szError[MAX_PATH] 
=  { 0 };
            DWORD dwErrorSize 
=  MAX_PATH;
            DWORD dwLastErrorMsg 
=   0 ;
            InternetGetLastResponseInfo(
& dwLastErrorMsg,szError, & dwErrorSize);
            CStaticFunctions::LogToFileWithTime(m_strFtpLog.c_str(),FALSE,TEXT(
" FtpFindFiles return NULL. Err:%d\n " ) , GetLastError());
            TRACE(
" FtpFindFiles Error MSG:\n%s\n "  , szError);
        }
    }
    
if (bUserCancle)
    {
        SetLastError(ERROR_CANCELLED);
    }
    
else
        SetLastError(ERROR_SUCCESS);
    
return  bRet;    
}
BOOL CStaticFunctions::AddPrefixString(LPTSTR lpOutPut, LPCTSTR lpOldString, LPCTSTR lpPrefix, UINT uMaxSize , bool bSensitivity)
{
    
if (lpOutPut == NULL  ||  lpOldString == NULL  ||  lpPrefix == NULL )
        
return  FALSE;
    String strOutput 
=  lpOldString;
    
int  iPreLen  =  lstrlen(lpPrefix);
    
if (bSensitivity)
    {
        
if (StrCmpN(lpPrefix,lpOldString,iPreLen) == 0 )
        {
            
if (lpOutPut == lpOldString)
                
return  TRUE;
            
else
                lstrcpyn(lpOutPut,lpOldString,uMaxSize);
        }
        
else
        {
            lstrcpyn(lpOutPut,lpPrefix,uMaxSize);
            StrCatBuff(lpOutPut,strOutput.c_str(),uMaxSize);
        }
    }
    
else
    {
        
if (StrCmpNI(lpPrefix,lpOldString,iPreLen) == 0 )
        {
            
if (lpOutPut == lpOldString)
                
return  TRUE;
            
else
                lstrcpyn(lpOutPut,lpOldString,uMaxSize);
        }
        
else
        {
            lstrcpyn(lpOutPut,lpPrefix,uMaxSize);
            StrCatBuff(lpOutPut,strOutput.c_str(),uMaxSize);
        }
    }
    
return  TRUE;
}

BOOL CStaticFunctions::AddPostfixString(LPTSTR lpOutPut, LPCTSTR lpOldString, LPCTSTR lpPostfix, UINT uMaxSize, bool bSensitivity)
{
    
if (lpOutPut == NULL  ||  lpOldString == NULL  ||  lpPostfix == NULL )
        
return  FALSE;
    
int  iOldLen  =  lstrlen(lpOldString);
    
int  iPostLen  =  lstrlen(lpPostfix);
    
if (iPostLen  >  iOldLen)
    {
        
if (lpOutPut == lpOldString)
        {
            StrCatBuff(lpOutPut,lpPostfix,uMaxSize);
        }
        
else
        {
            lstrcpyn(lpOutPut,lpOldString,uMaxSize);
            StrCatBuff(lpOutPut,lpPostfix,uMaxSize);
        }
        
return  TRUE;
    }
    
if (bSensitivity)
    {
        
if (StrCmpN(lpPostfix,(lpOldString + iOldLen - iPostLen),iPostLen) == 0 )
        {
            
if (lpOutPut == lpOldString)
                
return  TRUE;
            
else
                lstrcpyn(lpOutPut,lpOldString,uMaxSize);
        }
        
else
        {
            
if (lpOutPut == lpOldString)
            {
                StrCatBuff(lpOutPut,lpPostfix,uMaxSize);
            }
            
else
            {
                lstrcpyn(lpOutPut,lpOldString,uMaxSize);
                StrCatBuff(lpOutPut,lpPostfix,uMaxSize);
            }
        }
    }
    
else
    {
        
if (StrCmpNI(lpPostfix,(lpOldString + iOldLen - iPostLen),iPostLen) == 0 )
        {
            
if (lpOutPut == lpOldString)
                
return  TRUE;
            
else
                lstrcpyn(lpOutPut,lpOldString,uMaxSize);
        }
        
else
        {
            
if (lpOutPut == lpOldString)
            {
                StrCatBuff(lpOutPut,lpPostfix,uMaxSize);
            }
            
else
            {
                lstrcpyn(lpOutPut,lpOldString,uMaxSize);
                StrCatBuff(lpOutPut,lpPostfix,uMaxSize);
            }
        }
    }
    
return  TRUE;
}

BOOL CStaticFunctions::RemovePrefixString(LPTSTR lpOutPut,LPCTSTR lpPrefix, bool bSensitivity)
{
    
if ( lpOutPut == NULL  ||  lpPrefix ==  NULL )
        
return  FALSE;
    String strOutput 
=  lpOutPut;
    
int  iPreLen  =  lstrlen(lpPrefix);
    
if (bSensitivity)
    {
        
if (StrCmpN(lpPrefix,lpOutPut,iPreLen) == 0 )
        {
            lstrcpyn(lpOutPut,strOutput.c_str()
+ iPreLen,strOutput.length());
        }
    }
    
else
    {
        
if (StrCmpNI(lpPrefix,lpOutPut,iPreLen) == 0 )
        {
            lstrcpyn(lpOutPut,strOutput.c_str()
+ iPreLen,strOutput.length());
        }
    }
    
return  TRUE;
}

BOOL CStaticFunctions::RemovePostfixString(LPTSTR lpOutPut,LPCTSTR lpPostfix, bool bSensitivity)
{
    
if ( lpOutPut == NULL  ||  lpPostfix ==  NULL )
        
return  FALSE;
    
int  iPostLen  =  lstrlen(lpPostfix);
    
int  iOldLen  =  lstrlen(lpOutPut);
    
if (bSensitivity)
    {
        
if (StrCmpN(lpPostfix,(lpOutPut + iOldLen - iPostLen),iPostLen) == 0 )
        {
            lpOutPut[iOldLen
- iPostLen]  =  TEXT('\ 0 ');
        }
    }
    
else
    {
        
if (StrCmpNI(lpPostfix,(lpOutPut + iOldLen - iPostLen),iPostLen) == 0 )
        {
            lpOutPut[iOldLen
- iPostLen]  =  TEXT('\ 0 ');
        }
    }
    
return  TRUE;
}
posted on 2006-11-29 10:44 孤独的夜 阅读(2709) 评论(0)  编辑 收藏 引用 所属分类: Windows SDK
只有注册用户登录后才能发表评论。