// PatchSFXDlg.h : header file
//

#pragma once
#include "afxwin.h"
#include "afxcmn.h"
#include "afxmt.h"
#include "afxtempl.h"
#include "logedit.h"

struct SharedData
{
    SharedData() { InitSharedData(); }

    void InitSharedData()
    {
        m_bStopWorkerThread = FALSE;
        m_nCurrentFiles = 0;
        m_nCurrentDataSize = 0;
        m_szCurrentExtract.Empty();
        m_ProgressList.RemoveAll();
    }

    BOOL    m_bStopWorkerThread;

    int     m_nCurrentFiles;
    int     m_nCurrentDataSize;

    CString         m_szCurrentExtract;
    CList<CString>  m_ProgressList;
};

// CPatchSFXDlg dialog
class CPatchSFXDlg : public CDialog
{
// Construction
public:
	CPatchSFXDlg(CWnd* pParent = NULL);	// standard constructor

// Dialog Data
	enum { IDD = IDD_PATCHSFX_DIALOG };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support


// Implementation
protected:

	HICON m_hIcon;

	// Generated message map functions
	virtual BOOL OnInitDialog();	
	afx_msg void OnPaint();
    afx_msg void OnTimer(UINT_PTR nIDEvent);
    afx_msg void OnBnClickedBtnExtractTo();
    afx_msg void OnBnClickedBtnPatchNow();
    afx_msg void OnClose();
    afx_msg void OnBnClickedBtnPatchList();
    afx_msg HCURSOR OnQueryDragIcon();

    DECLARE_MESSAGE_MAP()

private:

    static unsigned __stdcall ExtractWorker(void *pArg);

    bool CheckExtractPosVersion();
    void UpdateProgress(SharedData& sharedData);
    void StopWorker();

    CEdit           m_edExtractPos;    
    CLogEdit        m_edLog;
    CString         m_szFileProgress;
    CProgressCtrl   m_prgExtract;

    CButton         m_btnExtractPos;
    CButton         m_btnPatchAdvanced;

    CButton         m_btnPatchDone;
    CButton         m_btnPatchNow;
    CButton         m_btnPatchCancel;

    CString         m_szPatchFileName;
    CString         m_szInstalledPathKey;
    CString         m_szRegKeyValue;

    ULONGLONG       m_dwTotalFileSize;
    DWORD           m_dwMinver;
    DWORD           m_dwMaxver;
    int             m_nTotalFileNum;

    HANDLE          m_hExtractThread;
    UINT            m_nExtractThreadID;

    CCriticalSection    m_csProgress;
    SharedData          m_SharedData;
    CString             m_szCurrentExtract;

    CList<CString>  m_PatchFolderList;    
public:
    afx_msg void OnBnClickedPatchDone();
};
