AUDataManage.h 1.99 KB
#pragma once
#include "afxinet.h" 

#define WM_UPDATEPROCESS WM_USER + 1
#define WM_CRASH_CLOSE	 WM_USER + 2

#define PROCESS_KILLCLIENT		1
#define PROCESS_DOWNLOADFILE	2
#define PROCESS_DELETEOLDFILE		3
#define PROCESS_UNZIP			4
#define PROCESS_COMPLETE		5

typedef struct STU_CONFIG 
{
	CString sAppName;
	CString sSelfName;
	CString sVersion;
	CString sAppDir;
	CString sUpdateDir;
	CString sTempDir;
	CString sZipName;

	CString sServerIP;
	CString sUserName;
	CString sPassWord;

	STU_CONFIG operator= (STU_CONFIG& stuConfig)
	{
		sAppName = stuConfig.sAppName;
		sSelfName = stuConfig.sSelfName;
		sVersion = stuConfig.sVersion;
		sAppDir = stuConfig.sAppDir;
		sUpdateDir = stuConfig.sUpdateDir;
		sTempDir = stuConfig.sTempDir;
		sZipName = stuConfig.sZipName;
		sServerIP = stuConfig.sServerIP;
		sUserName = stuConfig.sUserName;
		sPassWord = stuConfig.sPassWord;
		return *this;
	}
}APPConfig;

extern void Log(CString sLog);


//class Lock
//{
//private:
//	CCriticalSection m_cs;
//public:
//	Lock(CCriticalSection  cs) : m_cs(cs)
//	{
//		m_cs.Lock();
//	}
//	~Lock()
//	{
//		m_cs.Unlock();
//	}
//};

class CAUDataManage
{
public:
	static CAUDataManage *Instantialize();
	static void DestoryInstance();
	~CAUDataManage();

public:
	BOOL CheckVersion();
	void Update();
	void RestartClient();

private:
	CAUDataManage();
	CAUDataManage(const CAUDataManage &);
	CAUDataManage& operator = (const CAUDataManage &);

	BOOL KillCilent(CString sClientName);
	BOOL DownloadClientFile();
	void CreateTempFolder();
	void DeleteDirectory(CString sDirectory);
	CString GetModulePath();
	void ReplaceClientFile(CString sAppDir);
	APPConfig ReadConfig(CString sConfigName);
	void CopyClientFile(CString sSrcFile, CString sDstFile);
	void DownloadFile(CString sSrcFile, CString sDstFile, CFtpConnection *pFtpConnection);

private:
	static CAUDataManage *m_pInstance;
	static CCriticalSection m_csLocker;

	APPConfig m_stuConfigData;
	CString m_sConfigFilePath;
	CString m_sConfigFileName;
	BOOL Unzip(CString sSrcDir, CString sDstDir);
};