
#pragma once
#include <stdio.h>
#include <locale.h>
#include <stdlib.h>
//#include <time.h> //或者 #include <ctime>
#include <ctime>
#include <io.h>
#pragma comment(lib,"version.lib")
#include <vector>
#include <string>
// GDI+
#include <gdiplus.h>
using namespace Gdiplus;
#pragma comment(lib, "gdiplus.lib")


#ifndef _UNICODE 
typedef string TString;
#else
typedef wstring TString;
#endif

//////////////////////////////////////////////////////////////////////////
// dll相关;
extern HMODULE g_hdll;
extern BOOL LoadLogLibarary();
extern void FreeLogLibarary();

typedef DWORD(*irc_IsAppRunning)(LPCTSTR lpszAppDir);
typedef bool (*irc_StartIRApp)(LPCTSTR lpszAppDir, LPCTSTR lpSignalXml, DWORD dwPort);
typedef bool (*irc_CloseApp)();
typedef bool (*irc_Connect)(LPCTSTR lpServer, int port);
typedef void (*irc_DisConnect)();
typedef bool (*irc_loadSignalDataSet)(LPCTSTR lpDatasetXml);
typedef LPCTSTR(*irc_getDeviceNames)();
typedef LPCTSTR(*irc_getSignalsName)();
typedef bool (*irc_sendSignal)(LPCTSTR lpSignal, int send_times, int sleep_time);
typedef bool (*irc_sendSignals)(LPCTSTR lpSignals, int sleep_time);
typedef bool (*irc_sendRepeatsSignal)(LPCTSTR lpSignal, int repeat_time);

extern int g_nIRControl;
extern irc_IsAppRunning g_IsAppRunning;
extern irc_StartIRApp g_StartIRApp;
extern irc_CloseApp g_CloseApp;
extern irc_Connect g_Connect;
extern irc_DisConnect g_DisConnect;
extern irc_getDeviceNames g_getDeviceNames;
extern irc_getSignalsName g_getSignalsName;
extern irc_loadSignalDataSet g_loadSignalDataSet;
extern irc_sendSignal g_sendSignal;
extern irc_sendSignals g_sendSignals;
extern irc_sendRepeatsSignal g_sendRepeatsSignal;
//////////////////////////////////////////////////////////////////////////

namespace Global
{
	typedef struct __ST_CONFIG__
	{
		// ir-device;
		std::string redratpath;
		bool bGenerics;
		std::string signaldir;
		std::string use_signal;

		// SATService;
		bool bAutoLogin;
		std::string strSATUserName;
		std::string strSATPassword;
		std::string strActuator;
		std::string strServiceIP;
		std::string strServicePort;		
	}STConfig, * pSTConfig;

	//////////////////////////////////////////////////////////////////////////
	// 全局变量;
	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 STConfig g_Config;
	extern TCHAR g_szPython27Dir[MAX_PATH];
	extern ULONGLONG g_ulWaitTime;

	//////////////////////////////////////////////////////////////////////////
	// 全局函数;
	void GetConfig();
	int ReadReg(char* path, char* key, char* value);
	BOOL Python27Dir();
	BOOL GetSysSerialPort(std::vector<std::string>& vtports);
	void WriteTextLog(const TCHAR* format, ...);
	void WriteTextLogEx(int nType, const TCHAR* format, ...);
	BOOL LoadImgFromFile(IN Image** pImg, LPCTSTR lpPath);
	BOOL LoadImgFromBuffer(IN Image** pImg, IN BYTE* pBuffer, IN CONST INT& nBufLen);
	BOOL LoadImgFromBuffer(IN Image** pImg, LPCTSTR lpPath);
	int GetEncoderClsid(IN CONST WCHAR* format, OUT CLSID* pClsid);
	Image* LoadImgFromResource(IN HMODULE hModule, IN LPCTSTR lpName, IN LPCTSTR lpType);
	BOOL SaveImgByRotate(LPCTSTR lpszFileName, BYTE* pBuffer, CONST INT& nBufLen, BOOL bHoriontal, BOOL bVertically);
	void MKDIR(LPCTSTR dir);
	bool GetVersion(OUT WORD* pdwFileVersion, OUT WORD* pdwProductVerion);
};
