SDC C-Project CF Review 프로그램
LYW
2021-10-14 e8ba1e78e72f3f7ec2841f55fd90253b4dc414df
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#pragma once
 
#include "FTPUploadParam.h"
#include "TimerThreadPools.h"
#include <afxinet.h>
#include <deque>
 
#define        MAX_BUFFER_COUNT                100
 
enum EnumFTPNotify
{
    eFTPConnection = 0,
    eFTPDisConnection,
    eFTPConnectionFail,
    eFTPFileUploadSuccess,
    eFTPFileUploadFail,
    eFTPFileDownloadSuccess,
    eFTPFileDownloadFail,
    eFTPError
};
 
enum FTPThreadType { FTPThreadType_Download=0, FTPThreadType_Upload, FTPThreadType_Count };
 
typedef std::deque<CFTPUploadParam>                    DeqFTPUploadParam;
typedef std::deque<CFTPUploadParam>::iterator        DeqFTPUploadParamIt;
typedef std::deque<CFTPUploadParam>::const_iterator    constDeqFTPUploadParamIt;
 
interface IFTPThreadPool2Parent
{
    virtual void IFTP2P_DisplayLogMessage(int nType, int nLogIndex) = 0;
    virtual void IFTP2P_DisplayNotifyMessage(int nType, int nNotifyType, int nLogIndex) = 0;
};
 
class CFTPThreadPool : public CTimerThreadPools
{
public:
    CFTPThreadPool(int nType, DWORD dwPeriod=100);
    virtual ~CFTPThreadPool(void);
 
    virtual BOOL StartThread();
    virtual void StopThread();
 
    // process
    BOOL    AddUploadParam(const CFTPUploadParam& uploadParam);
 
    // setter
    void    SetConnectionTimeout(int nTimeout);
    void    SetConnectionInfo(CString strIP, CString strUserID, CString strPassword, int nPort, int nTimeout, CString strHomePath, CString strIP2, CString strUserID2, CString strPassword2, int nPort2, int nTimeout2, CString strHomePath2, CString strIP3, CString strUserID3, CString strPassword3, int nPort3, int nTimeout3, CString strHomePath3, BOOL bPassive, BOOL WSIChk);
    void    SetIFTP2P(IFTPThreadPool2Parent *pIFTP2P)        { m_pIFTP2P = pIFTP2P; }
 
    // getter
    const CString* GetLogBuffer(int nIndex);
    int        GetUploadListCount()                            { return (int)m_deqUploadList.size(); }
    const CFTPUploadParam* GetUploadList(int nIdx);
    void    GetUploadListCountInfo( UINT& nReadyCount, UINT& nProcessCount, UINT& nCompletCount, UINT& nTotalCount );
    void    GetUploadList(DeqFTPUploadParam& deqUploadParam);
 
protected:
    virtual void TimerThreadProcess(PVOID pParameter);
    BOOL    Process_Upload(CFTPUploadParam& uploadParam);
    BOOL    Process_Download(CFTPUploadParam& downloadParam);
    BOOL    Process_UploadAck(int nResultCode, const CFTPUploadParam& uploadParam);
    BOOL    Process_DownloadAck(int nResultCode, const CFTPUploadParam& uploadParam);
    
    void    DisplayLogMessage(const CString& strMessage);
    void    DisplayResultMessage(BOOL bResult, const CString& strServer, const CString& strLocal);
    void    DisplaynNotifyTypeMessage(int nNotifyType, const CString& strMessage);
    CString GetInternetErrorCodeToString( DWORD dwErrorCode );
    void    NotifyMessage( int nNotifyType, const CString& strUploadPath, const CString& strLocalPath, BOOL bSendErrorCode );
 
 
    BOOL    ConnectMain();
    BOOL    Connect();
    BOOL    Disconnect();
    BOOL    ChangeDirectory(const CString& strPath, BOOL bCreate=FALSE);
    BOOL    Upload(const CFTPUploadParam& Param);
    BOOL    Upload_Signal(const CFTPUploadParam& Param);
    BOOL    Download(const CFTPUploadParam& Param);
 
    static BOOL CreatePathDir(const CString& strFilename=_T(""))
    {
        CString csPrefix(_T("")), csToken(_T(""));
        int nStart = 0, nEnd;
        CFileFind filefinder;
        CString strDirPath = strFilename;
        BOOL bResult = FALSE;
        while( (nEnd = strFilename.Find('\\', nStart)) >= 0)
        {
            csToken = strFilename.Mid(nStart, nEnd-nStart);
            CreateDirectory(csPrefix + csToken, NULL);
 
            csPrefix += csToken;
            csPrefix += _T("\\");
            nStart = nEnd+1;
        }
        strDirPath = strDirPath.Left(strDirPath.ReverseFind('\\'));
        bResult = filefinder.FindFile(strDirPath,NULL);
 
        return bResult;
    }
 
 
protected:
    int                        m_nType;
    IFTPThreadPool2Parent*    m_pIFTP2P;
 
    BOOL                    m_bConnect;
 
    CFtpFileFind*            m_pFileFind;
    CFtpConnection*            m_pConnection;
    CInternetSession*        m_pSession;
 
    CString                    m_strIP;
    CString                    m_strID;
    CString                    m_strPassword;
    int                        m_nPort;
    BOOL                    m_bPassive;
    int                        m_nConnectionTimeout;
 
    // [C-PRJ] Image Upload Define - KHT (2020/11/19)
    CString                    m_strIP2;
    CString                    m_strID2;
    CString                    m_strPassword2;
    int                        m_nPort2;
    int                        m_nConnectionTimeout2;
    CString                    m_strDefaultFolderPath2;
 
    //201218 CJH - Download¿ë IP Ãß°¡
    CString                    m_strIP3;
    CString                    m_strID3;
    CString                    m_strPassword3;
    int                        m_nPort3;
    int                        m_nConnectionTimeout3;
    CString                    m_strDefaultFolderPath3;
 
    DeqFTPUploadParam        m_deqUploadList;
    CCriticalSection        m_csUploadList;
    CCriticalSection        m_csFtpProcess;
    CCriticalSection        m_csLogIndex;
 
    CString                    m_strDefaultFolderPath;
    CString                    m_strLastErrorMessage;
 
    int                        m_nCurLogIndex;
    CString                    m_strLogBuffer[MAX_BUFFER_COUNT];
 
    UINT                    m_nProcessCount;
    UINT                    m_nCompletCount;
    UINT                    m_nTotalCount;
 
    BOOL                    m_bSharedFolder;
    BOOL                    m_bWSIChk;
};