#pragma once

#include "HTTPFile.h"

//#include "List.h"

//using namespace RTL;

//#include "../ZipLib/RZipRapper.h"

#include "GradientStatic.h"

#include <PatchCommon/PatchInfoList.h>

#pragma warning( disable : 4786 )
#include <vector>
#include <map>





//UINT AFXAPI HashKey(CString& string);

class CUpdateManager
{
public:
	void Init();

	bool ProcessNoticeFiles();
	bool LoadServerPatchInfo();
//	bool LoadLocalPatchInfoCache();
	bool CollectDownloadFileList( bool bFileCheckMode );
	bool DownloadUpdateFile();
	bool ExtractPatchFiles();

	void AddToPkg2FileNameBucket( char* szPkgName, char* szFileName );

	bool CleanUp();

	void Terminate()
	{
		m_bTerminate = true;
	}

	void SetServerClosed( bool b )
	{
		m_bServerClosed = b;
	}



	static BOOL		m_bUpdateLogin;

	CHTTPFile		m_HTTPFile;
	CString			m_strServerPath;

	void			SetVersion( int nVersion ) { m_nVersion = nVersion; }
	int				GetVersion() { return m_nVersion; }

	void			SetRootPath( CString strRootPath ) { m_strRootPath = strRootPath; }

	void SetProgressInfo( float* pfFileProgressPercentage, float* pfProgressPercentage, CGradientStatic *pInfoWnd, CWnd *pDisplayWnd)
	{
		m_pInfoWnd = pInfoWnd;
		m_pDisplayWnd = pDisplayWnd;

		m_pfProgressPercentage = pfProgressPercentage;
		m_pfFileProgressPercentage = pfFileProgressPercentage;
		m_HTTPFile.SetProgressWnd( m_pDisplayWnd , m_pInfoWnd, pfFileProgressPercentage );
	}

	CUpdateManager();
	~CUpdateManager();
//	void Update( CString strPath  );


private:
	int				m_nVersion;
	bool m_bServerClosed;
	
	CGradientStatic *m_pDisplayState;
	CWnd			*m_pZipCountDisplayState;
	
	CString			m_strRootPath;
	
	float*			m_pfProgressPercentage;
	float*			m_pfFileProgressPercentage;
	
	int				m_nFileCount;
	
	
	
	CPatchInfoList m_ServerFileInfoList;
	
	struct IndexPair
	{
		int IdxServer;
		int idxLocal;
	};
	//CMap<CString, CString&,  CArray<IndexPair, IndexPair&>*, CArray<IndexPair, IndexPair&>* > m_mapPackageName2IndexPairArray;
	std::map< PTR_STRING, std::vector< char* > *, PTR_STRING_LESS > m_mapPackageName2FileNameVectorPtr;
	
	static CGradientStatic *m_pInfoWnd;
	static CWnd			*m_pDisplayWnd;
	
	bool m_bTerminate;
	
	
	
	//	bool SaveLocalCache();
	//	bool CreateFileInfoCache();
	long GetFileCountInSubDir( const char* szSubDirName );
	
	
	//void LoadClientFileInfoCacheList();
	//void SaveClientFileInfoCacheList();
};
