// PatchMaker.h: interface for the CPatchMaker class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_PATCHMAKER_H__6D7C0314_CD51_4721_AC77_D3CFB22F57F7__INCLUDED_)
#define AFX_PATCHMAKER_H__6D7C0314_CD51_4721_AC77_D3CFB22F57F7__INCLUDED_

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

#include "ZipArchive.h"
#include "PatchInfoList.h"

#include "Patch_Util.h"

#include <map>


//////////////////////////////////////////////////////////////////////////
enum FILE_LOCATION_TYPE	{ FILE_NONE, FILE_ON_FTP, FILE_ON_HTTP, FILE_ON_LOCAL };






//////////////////////////////////////////////////////////////////////////

class CPatchMaker  
{
public:

    CPatchMaker();
	virtual ~CPatchMaker();

	bool Go( CEdit* pEditOutput );

	enum PATCHMAKER_STATE
	{
		PMS_IDLE,
		PMS_LOAD_SERVER_PATCHINFO_LIST,
		PMS_BUILD_LOCAL_PATCHINFO_LIST,
		PMS_COLLECT_UPDATE_FILE_LIST,
		PMS_UPDATE_PACKAGE,
		PMS_UPDATE_PATCHINFO
	};

	PATCHMAKER_STATE GetState()
	{
		return m_PatchmakerState;
	}

	void SetPackageFilePath(const char* sz)     { m_strPackageFilePath = sz; }
	void SetLocalFilePath(const char* sz)       { m_strLocalFilePath = sz;   }
	void SetDestFilePath(const char* sz)        { m_strDestFilePath = sz;    }
	void SetSourceType(FILE_LOCATION_TYPE tp)   { m_SourceType = tp;         }
	void SetDestType(FILE_LOCATION_TYPE tp)     { m_DestType = tp;           }
	void SetPackageSize(DWORD dw)               { m_dwPackageMaxSize = dw; }
	void SetUpdateVersion(DWORD dw)             { m_dwUpdateVersion = dw;  }
	void SetFTPServerAddr(const char* sz)       { m_strFTPServerAddr = sz; }
	void SetFTPAccount(const char* sz)          { m_strFTPAccount = sz;    }
	void SetFTPPassword(const char* sz)         { m_strFTPPassword = sz;   }
	void SetFTPPort(int n)                      { m_nFTPPort = n; }
	void SetPassiveMode(BOOL b)                 { m_bPassiveMode = b; }
	void SetPartialFileCompare(bool b)          { m_bPartialFileCompare = b; }
    void SetCheckNoticeFolder(bool b)           { m_bCheckNoticeFolder = b;  }

    int GetPatchInfoVersion();

protected:

	CZipArchive m_ZipArc;
	CArray<int, int> m_arrIndexToUpdateLocalFile;

	CPatchInfoList m_LocalPatchInfo;
	CPatchInfoList m_ServerPatchInfo;

	std::map< PTR_STRING, int, PTR_STRING_LESS > m_mapFileName2ServerListIndex;

	// 각각의 패스들. 반드시 path seperator( \ ) 로 끝나야 한다.
	// -> CPatchMaker 클래스 내에서 seperator 자동 추가로 변경
	CString m_strPackageFilePath;
	CString m_strLocalFilePath;
	CString m_strDestFilePath;

	FILE_LOCATION_TYPE m_SourceType;
	FILE_LOCATION_TYPE m_DestType;

	CStringArray m_astrFileNameWithSubDirExclusionList;	
		// 제외 파일 중 특정 서브폴더상에 위치하는 파일
	CStringArray m_astrFileNameExclusionList;
		// 제외 파일 중 서브폴더와는 상관없이 파일이름만으로 판별하는것
		// . .. 과 같은 디렉토리명, vssver.scc 같은 필요없는 파일들
	CStringArray m_astrSubDirExclusionList;
	

	long m_dwUpdateVersion;	// 업데이트 할 새 버전

	CString m_strFTPServerAddr;
	CString m_strFTPAccount;
	CString m_strFTPPassword;

	int m_nFTPPort;
    BOOL m_bPassiveMode;
	
    bool m_bPartialFileCompare;
    bool m_bCheckNoticeFolder;

	CString m_strCurrentNewPackageFileName;

	DWORD m_dwPackageMaxSize;

	PATCHMAKER_STATE m_PatchmakerState;

	CString m_strStateInfoString;
	

	bool CheckValidity( CEdit* pEditOutput );

	bool LoadServerPatchInfoList();
	bool BuildLocalPatchInfoList();
	bool CollectUpdateFileList();
	bool UpdatePackage();
	bool UpdatePatchInfo();
	
	const char* GetNextPackageFileName();
	bool IsExcludedFile( const char* szFileName );
	bool IsExcludedFileWithSubDir( const char* szFileNameWithSubDir );
	bool IsExcludedSubDir( const char* szSubDir );
	bool IsSoleFileWithSubDir( const char* szFileNameWithSubDir );
};

#endif // !defined(AFX_PATCHMAKER_H__6D7C0314_CD51_4721_AC77_D3CFB22F57F7__INCLUDED_)
