#include "StdAfx.h" #include "FileUploadControl.h" #include "ProcessController.h" //#include "AOIDefinition.h" #define FTPUPLOADER_NAME _T("FTPUploader.exe") #define COPYMANAGER_NAME _T("CopyManager.exe") #define FTP_HOME_PATH_LTPS _T("ltps/") #define FTP_HOME_PATH_LTPS01 _T("ltps01/") #define COPYDATA_FTP_ADD_FILE 27 // "AOIDefinition.h" CFileUploadControl::CFileUploadControl(void) { InitializeCriticalSection(&m_csImgUpload); } CFileUploadControl::~CFileUploadControl(void) { DeleteCriticalSection(&m_csImgUpload); } void CFileUploadControl::RestartFTPUploader(CString strFilePath) { KillProcess(FTPUPLOADER_NAME); Sleep(100); CString strPath; strPath.Format(_T("%s\\%s"),strFilePath,FTPUPLOADER_NAME); int nSize = 0; char* strTemp = NULL; #ifdef _UNICODE nSize = WideCharToMultiByte(CP_ACP, 0, strPath.GetBuffer(), -1, NULL, 0, NULL,NULL); strTemp = new char[nSize]; WideCharToMultiByte(CP_ACP, 0, strPath.GetBuffer(), -1, strTemp, nSize, NULL, NULL); #else nSize = strPath.GetLength(); strTemp = new char[nSize+1]; memcpy(strTemp, strPath.GetBuffer(), sizeof(char)*nSize); strTemp[nSize] = NULL; #endif WinExec(strTemp, SW_HIDE); if(strTemp) { delete[] strTemp; strTemp = NULL; } } void CFileUploadControl::RestartCopyManager(CString strFilePath) { KillProcess(COPYMANAGER_NAME); Sleep(100); CString strPath; strPath.Format(_T("%s\\%s"),strFilePath,COPYMANAGER_NAME); int nSize = 0; char* strTemp = NULL; #ifdef _UNICODE nSize = WideCharToMultiByte(CP_ACP, 0, strPath.GetBuffer(), -1, NULL, 0, NULL,NULL); strTemp = new char[nSize]; WideCharToMultiByte(CP_ACP, 0, strPath.GetBuffer(), -1, strTemp, nSize, NULL, NULL); #else nSize = strPath.GetLength(); strTemp = new char[nSize+1]; memcpy(strTemp, strPath.GetBuffer(), sizeof(char)*nSize); strTemp[nSize] = NULL; #endif WinExec(strTemp, SW_HIDE); if(strTemp) { delete[] strTemp; strTemp = NULL; } } void CFileUploadControl::StartFTPUploader(CString strFilePath) { CString strPath; strPath.Format(_T("%s\\%s"),strFilePath,FTPUPLOADER_NAME); int nSize = 0; char* strTemp = NULL; #ifdef _UNICODE nSize = WideCharToMultiByte(CP_ACP, 0, strPath.GetBuffer(), -1, NULL, 0, NULL,NULL); strTemp = new char[nSize]; WideCharToMultiByte(CP_ACP, 0, strPath.GetBuffer(), -1, strTemp, nSize, NULL, NULL); #else nSize = strPath.GetLength(); strTemp = new char[nSize+1]; memcpy(strTemp, strPath.GetBuffer(), sizeof(char)*nSize); strTemp[nSize] = NULL; #endif WinExec(strTemp, SW_HIDE); if(strTemp) { delete[] strTemp; strTemp = NULL; } } void CFileUploadControl::StartCopyManager(CString strFilePath) { CString strPath; strPath.Format(_T("%s\\%s"),strFilePath,COPYMANAGER_NAME); int nSize = 0; char* strTemp = NULL; #ifdef _UNICODE nSize = WideCharToMultiByte(CP_ACP, 0, strPath.GetBuffer(), -1, NULL, 0, NULL,NULL); strTemp = new char[nSize]; WideCharToMultiByte(CP_ACP, 0, strPath.GetBuffer(), -1, strTemp, nSize, NULL, NULL); #else nSize = strPath.GetLength(); strTemp = new char[nSize+1]; memcpy(strTemp, strPath.GetBuffer(), sizeof(char)*nSize); strTemp[nSize] = NULL; #endif WinExec(strTemp, SW_HIDE); if(strTemp) { delete[] strTemp; strTemp = NULL; } } BOOL CFileUploadControl::KillProcess(CString strProcess) { const int MaxNum = 100; int count = 0; PROCESSLIST ProcessList[MaxNum]; CProcessController ProcessController; count = ProcessController.GetProcessList(ProcessList, MaxNum); for (int i=0; im_eCommend = eMakeResultInfo; // // sprintf_s(pParam->m_strRawFileFolder,sizeof(char)*255,"%s",(LPSTR)(LPCTSTR)strRawFolderPath); // sprintf_s(pParam->m_strImageFileFolder,sizeof(char)*255,"%s",(LPSTR)(LPCTSTR)strHostFolderPath); // // copydata.dwData = eMakeResultInfo; // copydata.cbData = sizeof(CCommendParam); // copydata.lpData = pParam; // // DWORD dwReturn = 0; // DWORD dwError = 0; // // if (NULL == hWnd) // { // g_pLog->DisplayMessage(_T("Find CopyManager Program : Fail..")); // StartCopyManager(_T("C:\\AOIServer")); // } // else // { // if( SendMessageTimeout(hWnd, WM_COPYDATA, NULL, (LPARAM)©data, SMTO_NORMAL, 5000, (PDWORD_PTR)(dwReturn) ) == TRUE ) // { // g_pLog->DisplayMessage(_T("Send Data to CopyManager : Success.")); // bRet = TRUE; // } // else // { // g_pLog->DisplayMessage(_T("Send Data to CopyManager : Fail.")); // bRet = FALSE; // } // } // // g_pLog->DisplayMessage(_T("Raw[%s]"), pParam->m_strRawFileFolder); // g_pLog->DisplayMessage(_T("Image[%s]"), pParam->m_strImageFileFolder); // // delete pParam; // // return TRUE; // } // BOOL CFileUploadControl::UploadFileByFTPUploader(CCommendParam &Param) // { // HWND hWnd; // BOOL bRet = FALSE; // // COPYDATASTRUCT copydata = {0,0,0}; // // hWnd = ::FindWindow(NULL, _T("CopyManager")); // // copydata.dwData = eFileCopy; // copydata.cbData = sizeof(CCommendParam); // copydata.lpData = &Param; // // DWORD dwReturn = 0; // DWORD dwError = 0; // // if (NULL == hWnd) // { // g_pLog->DisplayMessage(_T("Find CopyManager Program : Fail.")); // StartCopyManager(_T("C:\\AOIServer")); // } // else // { // if( SendMessageTimeout(hWnd, WM_COPYDATA, NULL, (LPARAM)©data, SMTO_NORMAL, 60000, (PDWORD_PTR)(dwReturn) ) == TRUE ) // { // g_pLog->DisplayMessage(_T("Send Data to CopyManager : Success.")); // bRet = TRUE; // } // else // { // g_pLog->DisplayMessage(_T("Send Data to CopyManager : Fail.")); // RestartCopyManager(_T("C:\\AOIServer")); //A2E FTPUploader // bRet = FALSE; // } // } // // g_pLog->DisplayMessage(_T("Local[%s]"), Param.m_strOriginPath); // g_pLog->DisplayMessage(_T("Host[%s]"), Param.m_strTargetPath); // // return bRet; // } BOOL CFileUploadControl::UploadFileByFTPUploader(CString strLocalFilePath, CString strHostSubFolder, BOOL bDelete) { HWND hWnd; BOOL bRet = FALSE; COPYDATASTRUCT copydata = {0,0,0}; CFTPParamCopyData Param; hWnd = ::FindWindow(NULL, _T("FTPUploader")); Param.bUpload=TRUE; Param.bDelete = bDelete; Param.bMakeResultFile = FALSE; #ifdef _UNICODE WideCharToMultiByte(CP_ACP, 0, strLocalFilePath, -1, Param.strLocalFilePath, strLocalFilePath.GetLength(), NULL, NULL); WideCharToMultiByte(CP_ACP, 0, strHostSubFolder, -1, Param.strHostSubFolder, strHostSubFolder.GetLength(), NULL, NULL); #else sprintf_s(Param.strLocalFilePath,sizeof(char)*255,"%s",strLocalFilePath); sprintf_s(Param.strHostSubFolder,sizeof(char)*255,"%s",strHostSubFolder); #endif copydata.dwData = COPYDATA_FTP_ADD_FILE; copydata.cbData = sizeof(CFTPParamCopyData); copydata.lpData = &Param; DWORD dwReturn = 0; DWORD dwError = 0; if (NULL == hWnd) { g_pLog->DisplayMessage(_T("Find FTPUploader Program : Fail.")); StartFTPUploader(_T("D:\\DIT_Review")); //210805 } else { //sprintf_s(Param.strHostSubFolder,sizeof(char)*255,"%s%s",FTP_HOME_PATH_LTPS01, (LPSTR)(LPCTSTR)strHostSubFolder); if( SendMessageTimeout(hWnd, WM_COPYDATA, NULL, (LPARAM)©data, SMTO_NORMAL, 5000, (PDWORD_PTR)(dwReturn) ) == TRUE ) { g_pLog->DisplayMessage(_T("Send Data to FTPUploader : Success.")); bRet = TRUE; } else { g_pLog->DisplayMessage(_T("Send Data to FTPUploader : Fail.")); RestartFTPUploader(_T("D:\\DIT_Review")); //A2E FTPUploader //210805 bRet = FALSE; } } g_pLog->DisplayMessage(_T("Local[%s]"), Param.strLocalFilePath); g_pLog->DisplayMessage(_T("Host[%s]"), Param.strHostSubFolder); return bRet; } BOOL CFileUploadControl::DownloadFileByFTPUploader(CString strHostSubFolder, CString strLocalFilePath) { HWND hWnd = ::FindWindow(NULL, _T("FTPUploader")); BOOL bRet = FALSE; if (NULL == hWnd) { g_pLog->DisplayMessage(_T("Find FTPUploader Program : Fail.")); StartFTPUploader(_T("C:\\AOIServer")); } else { COPYDATASTRUCT copydata = {0,0,0}; CFTPParamCopyData Param; Param.bUpload=FALSE; Param.bDelete = FALSE; sprintf_s(Param.strLocalFilePath,sizeof(char)*255,"%s",strLocalFilePath); sprintf_s(Param.strHostSubFolder,sizeof(char)*255,"%s",strHostSubFolder); sprintf_s(Param.strFindFileName,sizeof(char)*255,"%s",""); copydata.dwData = COPYDATA_FTP_ADD_FILE; copydata.cbData = sizeof(CFTPParamCopyData); copydata.lpData = &Param; DWORD dwReturn = 0; DWORD dwError = 0; if( SendMessageTimeout(hWnd, WM_COPYDATA, NULL, (LPARAM)©data, SMTO_NORMAL, 5000, (PDWORD_PTR)(dwReturn) ) == TRUE ) { g_pLog->DisplayMessage(_T("Send Data to FTPUploader : Success.")); bRet = TRUE; } else { g_pLog->DisplayMessage(_T("Send Data to FTPUploader : Fail.")); bRet = FALSE; } g_pLog->DisplayMessage(_T("Local[%s]"), Param.strLocalFilePath); g_pLog->DisplayMessage(_T("Host[%s]"), Param.strHostSubFolder); } return bRet; } BOOL CFileUploadControl::FindDownloadFileByFTPUploader(CString strHostSubFolder, CString strLocalFilePath, CString strFileName) { HWND hWnd = ::FindWindow(NULL, _T("FTPUploader")); BOOL bRet = FALSE; if (NULL == hWnd) { g_pLog->DisplayMessage(_T("Find FTPUploader Program : Fail.")); StartFTPUploader(_T("C:\\AOIServer")); } else { COPYDATASTRUCT copydata = {0,0,0}; CFTPParamCopyData Param; Param.bUpload=FALSE; Param.bDelete = FALSE; sprintf_s(Param.strLocalFilePath,sizeof(char)*255,"%s",strLocalFilePath); sprintf_s(Param.strHostSubFolder,sizeof(char)*255,"%s",strHostSubFolder); sprintf_s(Param.strFindFileName,sizeof(char)*255,"%s",strFileName); copydata.dwData = COPYDATA_FTP_ADD_FILE; copydata.cbData = sizeof(CFTPParamCopyData); copydata.lpData = &Param; DWORD dwReturn = 0; DWORD dwError = 0; if( SendMessageTimeout(hWnd, WM_COPYDATA, NULL, (LPARAM)©data, SMTO_NORMAL, 5000, (PDWORD_PTR)(dwReturn) ) == TRUE ) { g_pLog->DisplayMessage(_T("Send Data to FTPUploader : Success.")); bRet = TRUE; } else { g_pLog->DisplayMessage(_T("Send Data to FTPUploader : Fail.")); bRet = FALSE; } g_pLog->DisplayMessage(_T("Local[%s]"), Param.strLocalFilePath); g_pLog->DisplayMessage(_T("Host[%s]"), Param.strHostSubFolder); g_pLog->DisplayMessage(_T("FindFile[%s]"), Param.strFindFileName); } return bRet; } // BOOL CFileUploadControl::DownloadStack(CString strHostSubFolder, CString strLocalFilePath, CString strFileName) // { // HWND hWnd = ::FindWindow(NULL, _T("FTPUploader")); // BOOL bRet = FALSE; // // if (NULL == hWnd) // { // g_pLog->DisplayMessage(TRUE, _T("Find to FTPUploader Program : Fail.")); // StartFTPUploader(_T("C:\\AOIServer")); // } // else // { // COPYDATASTRUCT copydata = {0,0,0}; // // CFTPParamCopyData Param; // // Param.bUpload=FALSE; // Param.bDelete=TRUE; // // sprintf_s(Param.strLocalFilePath,sizeof(char)*255,_T("%s"),(LPSTR)(LPCTSTR)strLocalFilePath); // sprintf_s(Param.strHostSubFolder,sizeof(char)*255,_T("%s"),(LPSTR)(LPCTSTR)strHostSubFolder); // sprintf_s(Param.strFindFileName,sizeof(char)*255,_T("%s"),(LPSTR)(LPCTSTR)strFileName); // copydata.dwData = COPYDATA_FTP_ADD_FILE; // copydata.cbData = sizeof(CFTPParamCopyData); // copydata.lpData = &Param; // // DWORD dwReturn = 0; // DWORD dwError = 0; // if( SendMessageTimeout(hWnd, WM_COPYDATA, NULL, (LPARAM)©data, SMTO_NORMAL, 5000, (PDWORD_PTR)(dwReturn) ) == TRUE ) // { // g_pLog->DisplayMessage(TRUE, _T("Send Data to FTPUploader : Success.")); // bRet = TRUE; // } // else // { // g_pLog->DisplayMessage(TRUE, _T("Send Data to FTPUploader : Fail.")); // bRet = FALSE; // } // // g_pLog->DisplayMessage(TRUE, _T("Local[%s]"), Param.strLocalFilePath); // g_pLog->DisplayMessage(TRUE, _T("Host[%s]"), Param.strHostSubFolder); // g_pLog->DisplayMessage(TRUE, _T("GlassID[%s]"), Param.strFindFileName); // } // // return bRet; // } // BOOL CFileUploadControl::UploadImageByFTPUploader(CCommendParam &Param) // { // HWND hWnd; // BOOL bRet = FALSE; // // COPYDATASTRUCT copydata = {0,0,0}; // // hWnd = ::FindWindow(NULL, _T("CopyManager")); // // copydata.dwData = eDirectoryCopy; // copydata.cbData = sizeof(CCommendParam); // copydata.lpData = &Param; // // DWORD dwReturn = 0; // DWORD dwError = 0; // // if (NULL == hWnd) // { // g_pLog->DisplayMessage(TRUE, _T("Find CopyManager Program : Fail.")); // StartCopyManager(_T("C:\\AOIServer")); // } // else // { // if( SendMessageTimeout(hWnd, WM_COPYDATA, NULL, (LPARAM)©data, SMTO_NORMAL, 60000, (PDWORD_PTR)(dwReturn) ) == TRUE ) // { // g_pLog->DisplayMessage(TRUE, _T("Send Data to CopyManager : Success.")); // bRet = TRUE; // } // else // { // g_pLog->DisplayMessage(TRUE, _T("Send Data to CopyManager : Fail.")); // bRet = FALSE; // } // } // // g_pLog->DisplayMessage(TRUE, "Local[%s]", Param.m_strOriginPath); // g_pLog->DisplayMessage(TRUE, "Host[%s]", Param.m_strTargetPath); // // return bRet; // } BOOL CFileUploadControl::UploadImageByFTPUploader(CString strLocalFolderPath, CString strHostSubFolder, CString strFileFormat, BOOL bDelete/*=FALSE*/) { HWND hWnd; BOOL bRet = FALSE; COPYDATASTRUCT copydata = {0,0,0}; CFTPParamCopyData FTPParam; hWnd = ::FindWindow(NULL, _T("FTPUploader")); FTPParam.bUpload=TRUE; FTPParam.bDelete = bDelete; FTPParam.bMakeResultFile = TRUE; #ifdef _UNICODE WideCharToMultiByte(CP_ACP, 0, strLocalFolderPath, -1, FTPParam.strFolderPath, strLocalFolderPath.GetLength(), NULL, NULL); WideCharToMultiByte(CP_ACP, 0, strHostSubFolder, -1, FTPParam.strHostSubFolder, strHostSubFolder.GetLength(), NULL, NULL); WideCharToMultiByte(CP_ACP, 0, strFileFormat, -1, FTPParam.strFolderFormat, strFileFormat.GetLength(), NULL, NULL); #else sprintf_s(FTPParam.strFolderPath,sizeof(char)*255,"%s",strLocalFolderPath); sprintf_s(FTPParam.strHostSubFolder,sizeof(char)*255,"%s",strHostSubFolder); sprintf_s(FTPParam.strFolderFormat,sizeof(char)*255,"%s",strFileFormat); #endif copydata.dwData = COPYDATA_FTP_ADD_FILE; copydata.cbData = sizeof(CFTPParamCopyData); copydata.lpData = &FTPParam; DWORD dwReturn = 0; DWORD dwError = 0; if (NULL == hWnd) { g_pLog->DisplayMessage(_T("Find FTPUploader Program : Fail.")); StartFTPUploader(_T("C:\\DIT_Review")); } else { //sprintf_s(Param.strHostSubFolder,sizeof(char)*255,"%s%s",FTP_HOME_PATH_LTPS01, (LPSTR)(LPCTSTR)strHostSubFolder); if( SendMessageTimeout(hWnd, WM_COPYDATA, NULL, (LPARAM)©data, SMTO_NORMAL, 5000, (PDWORD_PTR)(dwReturn) ) == TRUE ) { g_pLog->DisplayMessage(_T("Send Data to FTPUploader : Success.")); bRet = TRUE; } else { g_pLog->DisplayMessage(_T("Send Data to FTPUploader : Fail.")); bRet = FALSE; } } g_pLog->DisplayMessage(_T("Local[%s]"), FTPParam.strFolderPath); g_pLog->DisplayMessage(_T("Host[%s]"), FTPParam.strHostSubFolder); return bRet; }