⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mylog.h

📁 SQLBig5BugTool 宽字符操作问题
💻 H
字号:
// MyLog.h: interface for the CMyLog class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_MYLOG_H__57385D54_8132_42D6_956F_353BB47893C2__INCLUDED_)
#define AFX_MYLOG_H__57385D54_8132_42D6_956F_353BB47893C2__INCLUDED_

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


//#include "BaseSupport.h"

#pragma warning(disable:4786)

#include <map>
#include <string>
#include <vector>
#include <set>

#include <windows.h>

#ifndef _countof
#define _countof(arr) sizeof(arr)/sizeof(arr[0])
#endif

inline BOOL IsControlKeyDown()
{
	return (GetAsyncKeyState(VK_CONTROL)&0x8000)>0;
}

inline BOOL IsShiftKeyDown()
{
	return (GetAsyncKeyState(VK_SHIFT)&0x8000)>0;
}

inline BOOL IsNumLockOn()
{
	return (GetAsyncKeyState(VK_NUMLOCK)&0x1)>0;
}

inline BOOL IsCapitalOn()
{
	return (GetKeyState(VK_CAPITAL)&0x1)>0;
}

class  CMyLog  
{
public:	
	static const char *const GetProcessName();
	
	static const char*const GetExeFilePath();
	
public:
	static CMyLog& GetLogInstance();
	
	virtual ~CMyLog();
	
	//记录其他日志
	static void WriteLogEx(
		const char* const	pszLogFile,
		const char* const	pszFmt,
		...
		);
	
	//记录调试日志
	static void WriteDebugLog(
		const char* const	pszFmt,
		...
		);
	
	//记录运行日志
	static void WriteAppLog(
		const char* const pszFmt,
		...
		);
	
	//记录异常日志
	static void WriteExceptionLog(
		const char* const	pszFmt,
		...
		);
	
	////////////////////////
	//AppendXXX 都不记录日志头
	
	//记录调试日志
	static void AppendDebugLog(
		const char* const	pszFmt,
		...
		);
	
	//记录运行日志
	static void AppendAppLog(
		const char* const pszFmt,
		...
		);
	
	//记录异常日志
	static void AppendExceptionLog(
		const char* const	pszFmt,
		...
		);
	
	static void WriteLogText(
		const char *const	pszLogFile,
		const char* const	pszTxt,
		const bool			bNewLine=true,
		const bool			bAppendHeader=true
		);
	
private:
	
	static void BackupDetect(const char *const pszLogFile);
	
private:
	CMyLog();
	
private:
	char m_szExeFilePath[MAX_PATH+128];
	char *m_pchCurrentProcessName;
	
	char m_szShortCurrentProcessName[MAX_PATH];
	
	char m_szAppLogFilePath[MAX_PATH];
	char m_szDebugLogFilePath[MAX_PATH];
	char m_szExceptionFilePath[MAX_PATH];
	
	CRITICAL_SECTION	m_csLog;
	
	bool m_bWriteAppLogToFile;
};

#define WRITE_APP_LOG CMyLog::WriteAppLog

#define WRITE_EXCEPTION_LOG CMyLog::WriteExceptionLog

#define WRITE_DEBUG_LOG CMyLog::WriteDebugLog

#define APPEND_APP_LOG CMyLog::AppendAppLog

#define APPEND_EXCEPTION_LOG CMyLog::AppendExceptionLog

#define APPEND_DEBUG_LOG CMyLog::AppendDebugLog

#define TRACEERROR CMyLog::WriteDebugLog

#define WRITE_APP_LOGEX CMyLog::WriteLogEx



void TraceOut(			  
			  const char* const pszFmt,
			  ...
			  );

#define TRACEOUT TraceOut

long MyGetFileSize( const char *const pszFile ) ;

#ifdef _DEBUG
#define DBGOUT TraceOut
#else

#define DBGOUT 
#endif

typedef std::map<ULONG,std::string> STD_MAP_ULONG_2_STRING;

typedef std::map<std::string,std::string> STD_MAP_STRING_2_STRING;

typedef std::map<std::string,LONG> STD_MAP_STRING_2_LONG;
typedef std::map<std::string,ULONG> STD_MAP_STRING_2_ULONG;

typedef std::map<DWORD,DWORD> STD_MAP_DWORD_2_DWORD;


typedef std::pair<std::string,std::string>	STRING_PAIR;
typedef std::pair<std::string,LONG>			PAIR_STRING_LONG;
typedef std::pair<LONG,LONG>				PAIR_LONG_LONG;
typedef std::pair<LONG,std::string>			PAIR_LONG_STRING;

typedef std::vector<STRING_PAIR>	STRING_PAIR_LIST;

typedef std::vector<std::string>	STRING_LIST;
typedef std::vector<LONG>			LONG_LIST;
typedef std::vector<ULONG>			ULONG_LIST;

typedef std::set<ULONG>			ULONG_SET;

typedef std::map<std::string,STRING_LIST> STD_MAP_STRING_2_STRINGLIST;
typedef std::map<std::string,LONG_LIST> STD_MAP_STRING_2_LONG_LIST;
typedef std::map<std::string,ULONG_LIST> STD_MAP_STRING_2_ULONG_LIST;

typedef std::vector<PBYTE> PBYTE_LIST;

void StringListToString(
						STRING_LIST&		StrList,
						std::string&		str,
						const char*			pszToken=";"
						);

enum PARSE_STRING_CASE_CAST{psccAutoCastNone=1012,psccAutoCastUpper,psccAutoCastLower};

BOOL ParseString(
				 const std::string	strStr,
				 const std::string	strTokenString,
				 STRING_LIST&		StrList,
				 const bool			bAutoLeftTrim=true ,
				 const bool			bAutoRightTrim=true  ,
				 const bool			bSkipEmpty=false ,
				 const bool			bEliminateMultipleToken=false,
				 const bool			bAutoClearList=true,
				 const bool			bNoDuplicate=false,
				 const bool			bFailedIfDuplicated=false,
				 const PARSE_STRING_CASE_CAST	psccAutoCastCase=psccAutoCastNone
				 );

void	ParseStringEx(
					  const std::string	strStr,
					  const std::string	strBeginToken,
					  const std::string	strEndToken,
					  STRING_LIST&		StrList,
					  const bool		bAutoLeftTrim=true ,
					  const bool		bAutoRightTrim=true  ,
					  const bool		bSkipEmpty=false
					  );


template <class T>
void GetAllElementInBothList(T& StrList,T& StrListFull,T& StrListOut)
{
	StrListOut.clear();
	
	for(T::iterator itr=StrList.begin();itr!=StrList.end();itr++)
	{
		if(StrListFull.end()!=std::find(StrListFull.begin(),StrListFull.end(),*itr))
		{
			StrListOut.push_back(*itr);
		}
	}
}

template <class T>
void GetAllElementInList(T& StrList,T& StrListFull,T& StrListDiff)
{
	StrListDiff.clear();
	
	for(T::iterator itr=StrList.begin();itr!=StrList.end();itr++)
	{
		if(StrListFull.end()==std::find(StrListFull.begin(),StrListFull.end(),*itr))
		{
			StrListDiff.push_back(*itr);
		}
	}
}

template<class T>
BOOL AddList(
			 T& StrListFrom,
			 T& StrListTo,
			 const BOOL bAutoRemoveDuplicated=FALSE,
			 const BOOL bFailedIfDuplicated=FALSE
			 )
{
	if(bFailedIfDuplicated)
	{
		for(T::iterator itr=StrListFrom.begin();itr!=StrListFrom.end();itr++)
		{
			if(StrListTo.end()!=std::find(StrListTo.begin(),StrListTo.end(),*itr))
			{
				return FALSE;
			}
		}
	}
	
	if(bAutoRemoveDuplicated)
	{
		for(T::iterator itr=StrListFrom.begin();itr!=StrListFrom.end();itr++)
		{
			if(StrListTo.end()==std::find(StrListTo.begin(),StrListTo.end(),*itr))
			{
				StrListTo.push_back(*itr);
			}
		}
	}
	else
	{
		for(T::iterator itr=StrListFrom.begin();itr!=StrListFrom.end();itr++)
		{
			StrListTo.push_back(*itr);
		}
	}
	return TRUE;
}

long SetDefaultCurrentDir();

std::string FormatString(	  
						 const char* const pszFmt,
						 ...
						 );


void MultiSZToStringList(
						 const char *const	pszMultiSZ,
						 STRING_LIST&		StrList
						 );

std::string GetFullPath(const char* pszFilePath);

BOOL MyMoveFile(std::string strFromDir,std::string strToDir,std::string strFilePath);

BOOL MakeSureFilePathExists(
							const char* pszFilePath,
							const bool  bFileNameIncluded=FALSE
							);


BOOL ChooseFolder(
				  const char* pszTitle,
				  HWND hWnd,
				  std::string  strInitFolder,
				  std::string& strFolder,
				  const char* pszRootRestrict=0
				  );

void StringTrimLeft(std::string& strTxt) ;

void StringTrimRight(std::string& strTxt) ;


inline std::string ReplaceWith(std::string str,std::string strToReplace,std::string strReplaceTarget)
{
	long npos=-1;
	
	long pos=npos;
	
	std::string strResult=str;
	
	while(npos!=(pos=strResult.find(strToReplace.c_str())))
	{
		strResult.replace(pos,strToReplace.length(),strReplaceTarget);
	}
	
	return strResult;
}

BOOL GetSubString(
				  const char* pszString,
				  const char* pszStrBeginWith,
				  const char* pszStrEndWith,
				  std::string& strSubString,
				  const BOOL  bEndWithOptional=TRUE
				  );


//返回当前 exe 的目录 ( 包括 \ )
const char*const GetExeDir();



BOOL CopyTextToClipboard(
						 const HWND  hWnd,
						 const char *pszTxt,
						 const BOOL  bUniCode=IsShiftKeyDown()
						 );

class CMyRefCounter
{
public:
	CMyRefCounter()
	{
		m_plCounter=0;
	}
	CMyRefCounter(long* plCounter):
	m_plCounter(plCounter)
	{
		if(m_plCounter)
		{
			*m_plCounter=*m_plCounter+1;
		}
	};
	
	virtual ~CMyRefCounter()
	{
		if(m_plCounter)
		{
			*m_plCounter=*m_plCounter-1;
		}
	};
	
private:
	long* m_plCounter;
};


struct FILE_VERSION_INFO
{
	std::string strFileVersion;
};


BOOL GetSubFolderList(
					  const char*	pszFolderBase,
					  const char*	pszFolder,
					  STRING_LIST&	SubFolderList,
					  const LONG	lLevel=1
					  );

void GetVersionInfo(
					const char*			pszFilePath,
					FILE_VERSION_INFO&	FileVersionInfo
					);




long ActivateWnd(
				 const HWND hWnd
				 );

BOOL MyDeleteFile(const char *pszFilePath,const BOOL bEnableUndo);


void GetLastErrorMsg(
					 std::string&	strLastErrorMsg,
					 const DWORD	dwLastError=GetLastError()
					 );



BOOL IsNumber(const char *psz);

#define BEGIN_FOR() {long lLoop=0;
#define CHECK_FOR_LOOP_TIME()  if(lLoop++>1000) {TRACEOUT("Too much loop in for(...).force break");break;};
#define END_FOR() }

#endif // !defined(AFX_MYLOG_H__57385D54_8132_42D6_956F_353BB47893C2__INCLUDED_)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -