
#pragma once
#include <stdio.h>
#include <locale.h>
#include <stdlib.h>
#include <time.h> //或者 #include <ctime>
#include <io.h>
#pragma comment(lib, "version.lib")
#include "../cJson/cJSON.h"
#include "tinyxml2.h"
#include "Log4c.h"
#include <vector>
#include <string>

namespace Global
{
	//////////////////////////////////////////////////////////////////////////
	// 升级包请求体;
	typedef struct
	{
		std::string appid;
		std::string devicemodel;
		std::string dnum;
		std::string ver;
		std::string type;
	} __update_post__;

	// 升级包返回体;
	typedef struct
	{
		std::string servertime;
		std::string callid;
		std::string status;
		std::string note;
		std::string language;
		std::string apiversion;
		typedef struct
		{
			std::string now;
			std::string type;
			std::string appid;
			std::string apptype;
			std::string version;
			std::string verid;
			std::string md5;
			std::string size;
			std::string minicon;
			std::string midicon;
			std::string fileurl;
			std::string increment;
			std::string appendver;
			std::string updatetime;
		} __upcontent__;
		__upcontent__ upcontent;
	} __update_result__;

	// 烧录数据请求体;
	typedef struct
	{
		std::string clienttype;
		//std::string	projectid;
		std::string version;
		std::string bid; //批次号;
		std::string mac; // mac地址;
	} __burndata_post__;

	typedef struct
	{
		std::string name;
		std::string type;
	} __burndata__;

	typedef struct
	{
		std::string message;
		std::string code;
		std::string factoryname;
		std::string factoryip;
		std::string factoryNum;
		std::string version;
		std::string projectid;
		std::string clienttype;
		std::string host;
		std::vector<__burndata__> obj;
	} __burndata_result__;

	typedef struct CHASSIS
	{
		bool IsCopyDID;
		bool IsCopyMAC;
		bool IsCopyKEY;
		bool IsCopyESN;
		bool IsCopyWiDi;
		bool IsCopyWidevine;
		bool IsCopyKEY2_2;
		bool IsCopyKEY2_3;
		bool IsCopyCikey;
		bool IsCopyChannel;
		bool IsCopyWB;
		bool IsDisplayClientType;
		bool IsWritePID;
		bool IsWBInit;
		bool IsMTKInit;
		bool IsOsdLanguage;
		bool IsShopLanguage;
		bool IsCopyClientType;
		bool IsMGKKeyEnb;
		bool IsNovaTakHDCPEnb;

		int Delay;
		unsigned int ProjectID;
		std::string Channel;
		std::string WBFile;
		std::string CheckString;
		std::string ClientType;
		std::string MACType;
		std::string HDCPKeyType;
		std::string HDCPKey22Type;
		std::string HDCPKey23Type;
		std::string ESNType;
		std::string WiDiType;
		std::string WidevineType;
		std::string CIKeyType;
		std::string OsdLanguage;
		std::string ShopLanguage;
		std::string MGKKeyType;
		std::string NovaTakHDCPType;
		std::string url;	// 在线服务器;
		std::string name;	// chassis name;

		CHASSIS& operator=(const CHASSIS& that)
		{
			if (this != &that)
			{
				url = that.url;
				name = that.name;
				IsCopyDID = that.IsCopyDID;
				IsCopyMAC = that.IsCopyMAC;
				IsCopyKEY = that.IsCopyKEY;
				IsCopyESN = that.IsCopyESN;
				IsCopyWiDi = that.IsCopyWiDi;
				IsCopyWidevine = that.IsCopyWidevine;
				IsCopyKEY2_2 = that.IsCopyKEY2_2;
				IsCopyKEY2_3 = that.IsCopyKEY2_3;
				IsCopyCikey = that.IsCopyCikey;
				IsCopyChannel = that.IsCopyChannel;
				IsCopyWB = that.IsCopyWB;
				IsDisplayClientType = that.IsDisplayClientType;
				IsWritePID = that.IsWritePID;
				IsWBInit = that.IsWBInit;
				IsMTKInit = that.IsMTKInit;
				IsOsdLanguage = that.IsOsdLanguage;
				IsShopLanguage = that.IsShopLanguage;
				IsCopyClientType = that.IsCopyClientType;
				IsMGKKeyEnb = that.IsMGKKeyEnb;
				IsNovaTakHDCPEnb = that.IsNovaTakHDCPEnb;

				Delay = that.Delay;
				ProjectID = that.ProjectID;

				Channel = that.Channel;
				WBFile = that.WBFile;
				CheckString = that.CheckString;
				ClientType = that.ClientType;
				MACType = that.MACType;
				HDCPKeyType = that.HDCPKeyType;
				HDCPKey22Type = that.HDCPKey22Type;
				HDCPKey23Type = that.HDCPKey23Type;
				ESNType = that.ESNType;
				WiDiType = that.WiDiType;
				WidevineType = that.WidevineType;
				CIKeyType = that.CIKeyType;
				OsdLanguage = that.OsdLanguage;
				ShopLanguage = that.ShopLanguage;
				MGKKeyType = that.MGKKeyType;
				NovaTakHDCPType = that.NovaTakHDCPType;
			}
			return *this;
		}
	} TChassis, * pTChassis;

	typedef struct __READCHECK__
	{
		bool IsPID = true;
		bool IsCHANNEL = true;
		bool IsOSD = true;
		bool IsSHOP = true;
		bool IsDID = true;
		bool IsMAC = true;
		bool IsHDCP = true;
		bool IsHDCP22 = true;
		bool IsWIDI = true;
		bool IsWIDEVINE = true;
		bool IsESN = true;
		bool IsCI = true;
	}TReadCheck, * pTReadCheck;

	typedef struct __WRITECHECK__
	{
		//bool IsPID = true;
		//bool IsCHANNEL = true;
		//bool IsOSD = true;
		//bool IsSHOP = true;
		bool IsDID = true;
		bool IsMAC = true;
		bool IsHDCP = true;
		bool IsHDCP22 = true;
		bool IsWIDI = true;
		bool IsWIDEVINE = true;
		bool IsESN = true;
		bool IsCI = true;
	}TWriteCheck, * pWriteCheck;

	typedef struct __WRITEDONE__
	{
		bool IsPID = true;
		bool IsCHANNEL = true;
		bool IsOSD = true;
		bool IsSHOP = true;
		bool IsDID = true;
		bool IsMAC = true;
		bool IsHDCP = true;
		bool IsHDCP22 = true;
		bool IsWIDI = true;
		bool IsWIDEVINE = true;
		bool IsESN = true;
		bool IsCI = true;
	}TWriteDone, * pTWriteDone;

	extern Global::TChassis g_AutoOnlineChassis;
	// 配置文件;
	typedef struct TCONFIG
	{
		std::string com;
		std::string baudrate;
		std::string chassis;
		int mode;
		int warncount = 200;
		int waitboot = 5000;
		std::string siacpcmdfile;
		std::string serverurl;
		std::map<std::string, std::string> channel;
		std::map<std::string, std::string> language;
		std::map<std::string, std::string> keyfolder;
		std::map<std::string, TChassis> chassislist;
		TReadCheck readcheck;
		TWriteCheck writecheck;
		TWriteDone writedone;
	} TConfig, * pTConfig;

	// 网卡类型;
	enum NICKIND
	{
		// pci网卡;
		NIC_PCI,
		// usb网卡;
		NIC_USB,
		// 虚拟网卡;
		NIC_ROOT,
		// 仿真网卡;
		NIC_SWD,
		// 未知类型;
		NIC_UNK
	};

	typedef struct __MAC_ADDRESS__
	{
		INT nNICKind;
		TCHAR szNICKind[16];
		TCHAR szMacAddress[MAX_PATH];
		TCHAR szDevicePath[MAX_PATH];
	} MacAddress, * pMacAddress;
	//////////////////////////////////////////////////////////////////////////
	// 全局变量;
	extern BOOL g_bTestHost;
	extern TCHAR g_szCurModuleDir[MAX_PATH];
	extern TCHAR g_szCurModulePath[MAX_PATH];
	extern TCHAR g_szFna[MAX_PATH];
	extern TCHAR g_szConfig[MAX_PATH];
	extern std::string g_strMacs;
	extern std::vector<MacAddress> g_vtMac;
	extern TConfig g_tConfig;

	//////////////////////////////////////////////////////////////////////////
	// 全局函数;
	void GetConfig();
	void SetConfig();
	bool GetVersion(IN const TCHAR* fname, OUT WORD* pdwFileVersion, OUT WORD* pdwProductVerion);
	BOOL GetVersion(IN HMODULE hModule, OUT DWORD(&dwFVArray)[4], OUT DWORD(&dwPVArray)[4]);
	void WriteTextLog(const TCHAR* format, ...);
	std::string EnCode_UTF8URL(IN const CHAR* pText);
	std::string& trim(std::string& str);
	// 获取网卡地址;
	INT GetMacAddress();
	// 字符串是否由数字、字母、符号组成;
	BOOL IsValidString(LPCTSTR lpszString);

	// 获取系统当前串口数量;
	BOOL GetSysSerialPort(std::vector<std::string>& vtports);
}; // namespace Global
