/* ==========================================================================
* 작 성 자 : 이순규
* 작 성 일 : 2007.06.25
* 내    용 : 패처 다이얼로그
* 주의사항 : 
*===========================================================================*/
#pragma once

#include "skin/SkinDialog.h"
#include "skin/SkinButton.h"
#include "skin/SkinProgressBar.h"
#include "skin/SkinRoundGauge.h"
#include "skin/SkinImageSlide.h"
#include "skin/SkinHtmlView.h"
//#include "skin/SkinText.h"

#define WM_USER_MESSAGE (WM_APP + 1)	// User defined message.


/// 패치 메시지 박스 캡션
#define PATCHER					"IrisPatcher"
#define PATCHER_FILENAME		"IrisPatcher.exe"
//#define PATCHER_INI_FILENAME	"PatcherIni.txt"
//#define PATCH_LIST_VERSION		1
//#define PATCH_LIST_FILENAME		"patchlist.txt"
//#define PATCH_CONFIG_FILENAME	"Launcher/PatchConfig.txt"
#define SKNINFO_FILENAME		"skin.txt"
#define URLINFO_FILENAME		"url.txt"
#define GAMEEXE_FILENAME		"IrisClient.exe"
#define CMD_LINE                "116.125.70.52"
//#define PATCH_Z_FILENAME		"patch.z"
#define PATCHER_NEW_FILENAME	"IrisPatcher_New.exe"
#define LAUNCHER_FILENAME		"IrisLauncher.exe"

class cPatcher;

/// 컨트롤 아이디
enum
{
	CID_OK = 1000,
	CID_CLOSE,
	CID_HOME,
	CID_JOIN,
	CID_WINMODE,
	CID_PROGRESS,
	CID_PROGAUGE,
	CID_STATUS,
	CID_BOARD,
};

/// URL 주소
enum eUrlAddress
{
	/// 홈페이지
	URL_HOME,
	/// 회원가입
	URL_JOIN,
	/// 
	URL_COUNT,
};

/// 패치 상태
enum ePatchStatus
{
	/// 검색 중
	PATCH_SEARCHING = 0,
	/// 패치 중
	PATCH_PATCHING,
	/// 패치 완료
	PATCH_COMPLETE,
	///
	STEP_COUNT
};


/// 유저 에러 메시지.
enum ERROR_MSG_TYPE
{
	_UMT_ERROR_INIT_,
	_UMT_ERROR_SAVE_,
	_UMT_ERROR_DOWNLOAD_,
    _UMT_ERROR_PARSE_,
	_UMT_ERROR_MEMORY_ALLOC_,
	_UMT_ERROR_MEMORY_FREE_,
	_UMT_ERROR_UPDATE_,
	_UMT_ERROR_SEARCH_,
	_UMT_ERROR_CREATE_FOLDER_,
// 	_UMT_ERROR_OPEN_,
// 	_UMT_ERROR_LIST_,
// 	_UMT_ERROR_FILE_,
// 	_UMT_ERROR_COMPLETE_,
};

/// 패처 다이얼로그
class cPatcherDlg : public cSkinDialog
{
public:
	cPatcherDlg( const cString& path, const cString& hostName, const cString& baseDir, const cString& cmdLine, CWnd* parent = 0 );
	~cPatcherDlg();

	void BeginThread();
	void EndThread( bool result, bool updateSelf );

	void SetProgressMax( ePatchStatus status, int max );
	void SetProgressPos( const char* fileName, int pos );

protected:
	/// 설정 정보 로딩
	//bool LoadConfig();

	/// Url 정보 로딩
	bool LoadUrl();

	/// 옵션 정보 저장
	//void SaveOptInfo();

	/// 런처를 실행
	bool RunLauncher();

	/// 게임을 실행
	bool RunGame();

	void SetStatus( ePatchStatus status );

protected:
	static DWORD WINAPI ThreadProc( LPVOID param );

protected:
	void OnOK();
	void OnCancel();

	/// 메시지
	afx_msg int OnCreate( LPCREATESTRUCT lpCreateStruct );
	afx_msg void OnDestroy();
	virtual BOOL OnInitDialog();
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	afx_msg HBRUSH OnCtlColor( CDC* pDC, CWnd* pWnd, UINT nCtlColor );

	/// 스킨 메시지
	afx_msg void OnOkButton();
	afx_msg void OnCloseButton();
	afx_msg void OnHomeButton();
	afx_msg void OnJoinButton();
	afx_msg LRESULT OnUserMessage(WPARAM wParam, LPARAM lParam);
	DECLARE_MESSAGE_MAP()

private:
	/// 경로
	cString mPath;

	/// 호스트 이름
	cString mHostName;

	/// 기반 디렉토리
	cString mBaseDir;

	cString mCmdLine;

	/// Url 배열
	cString mUrlArray[URL_COUNT];

	/// 패처
	static cPatcher* mPatcher;
	HANDLE mThread;

private:
	/// 아이콘 핸들
	HICON mIcon;

	/// Ok 버튼
	cSkinButton mStartButton;

	/// 종료 버튼
	cSkinButton mCloseButton;

	/// 홈페이지 버튼
	cSkinButton mHomeButton;

	/// 회원가입 버튼
	cSkinButton mJoinButton;

	/// 진행 바
	unsigned int mProgressTotalNum;
	cSkinProgressBar mProgressBar;

	/// 공지 사항 뷰
	cSkinHtmlView* mBoardView;

	CStatic	mStatusStatic;
	ePatchStatus mStatus;
};
