Fixed issue #1642: Incorrect behavior if repo is located on root of drive
[TortoiseGit.git] / src / Utils / SpeedPostEmail.h
blob6ec46cf1b6a9758a6e46557aa5b5c03a667a5fff
1 #pragma once
3 #ifndef GET_SAFE_STRING
4 #define GET_SAFE_STRING(str) ( (str)?(str):_T("") )
5 #endif
6 // _vsnprintf º¯Êý
7 #ifndef _vsnprintf_hw
8 #ifdef UNICODE
9 #define _vsnprintf_hw _vsnwprintf
10 #else
11 #define _vsnprintf_hw _vsnprintf
12 #endif
13 #endif
14 #define HANDLE_IS_VALID(h) ( (HANDLE)(h)!=NULL && (HANDLE)(h)!=INVALID_HANDLE_VALUE )
16 template<class T>
17 int FindFromStaticArray ( IN T *pAry, IN int nArySize, IN T Find )
19 if ( !pAry ) return -1;
20 for ( int i=0; i<nArySize; i++ )
22 if ( pAry[i] == Find )
23 return i;
25 return -1;
29 // ×¢Ò⣺Èç¹ûÊÇ´Ó CString ÖвéÕÒʱ Find ǧÍò²»ÒªÓà LPCTSTR »òÕß char* ±äÁ¿£¬Ò»¶¨ÊÇÒªÓà CString ±äÁ¿
31 template<class T1, class T2>
32 int FindFromArray ( IN T1 &Ary, IN T2 Find )
34 int nCount = (int)Ary.GetSize();
35 for ( int i=0; i<nCount; i++ )
37 T2 tGetValue = Ary.GetAt(i);
38 if ( tGetValue == Find )
39 return i;
41 return -1;
45 // ´ÓÊý×é Ary_Org ÖвéÕÒ£¬Ö»Òª Ary_Find ÖÐÈκÎÒ»¸öÔªËØÔÚ Ary_Org ÖгöÏÖ¹ý
46 // ¾Í·µ»Ø¸ÃÔªËØÔÚ Ary_Org ÖеÄλÖÃ
48 template<class T1, class T2>
49 int FindFromArray ( IN T1 &Ary_Org, IN T1 &Ary_Find, OUT T2 &Element )
51 int nCount = Ary_Find.GetSize();
52 for ( int i=0; i<nCount; i++ )
54 T2 tGetValue = Ary_Find.GetAt(i);
55 int nFindPos = FindFromArray ( Ary_Org, tGetValue );
56 if ( nFindPos >= 0 )
58 Element = Ary_Org.GetAt ( nFindPos );
59 return nFindPos;
62 return -1;
65 template<class T1, class T2, class T3, class T4>
66 int FindFromArray ( IN T1 &Ary, IN T2 Find, IN T3 &AppAry, IN T4 AppFind )
68 int nCount = Ary.GetSize();
69 for ( int i=0; i<nCount; i++ )
71 if ( Ary.GetAt(i) == Find &&
72 AppAry.GetAt(i) == AppFind )
74 return i;
77 return -1;
80 template<class T1>
81 int FindFromArray ( IN T1 &Ary_Src, IN T1 &Ary_Find )
83 int nCount = Ary_Src.GetSize();
84 for ( int i=0; i<nCount; i++ )
86 if ( FindFromArray ( Ary_Find, Ary_Src.GetAt(i) ) >= 0 )
87 return i;
89 return -1;
92 enum
94 STRING_IS_MULTICHARS = 0, // ÊǶà×Ö½Ú×Ö·û´®
95 STRING_IS_UNICODE, // ÊÇUNICODE×Ö·û´®
96 STRING_IS_SOFTCODE, // ÊǺͳÌÐòÒ»ÑùµÄ×Ö·û´®±àÂë
99 class CMultiByteString
101 public:
102 CMultiByteString ( LPCTSTR lpszOrg, int nOrgStringEncodeType=STRING_IS_SOFTCODE, OUT char *pOutBuf=NULL, int nOutBufSize=0 );
103 ~CMultiByteString ();
104 char *GetBuffer()
106 if ( m_pszData ) return m_pszData;
107 return "";
109 // »ñÈ¡×Ö·û´®¸öÊý
110 int GetLength()
112 return m_nCharactersNumber;
114 // »ñÈ¡×Ö·û´®Õ¼ÓÃÄÚ´æ´óС£¨×Ö½ÚÊý£¬°üÀ¨×Ö·û´®½áÊøµÄ'\0'ËùÕ¼µÄλÖã©
115 int GetSize()
117 return m_nDataSize;
119 private:
120 char *m_pszData; // ±£´æÄ¿±ê×Ö·û´®µÄ»º³å
121 int m_nDataSize; // Ä¿±ê×Ö·û´®Õ¼ÓõÄÄÚ´æ´óС£¨×Ö½ÚÊý£¬°üÀ¨×Ö·û´®½áÊøµÄ'\0'£©
122 int m_nCharactersNumber; // Ä¿±ê×Ö·û´®µÄ¸öÊý
123 BOOL m_bNewBuffer; // ÊÇ·ñÔÚÕâ¸öÀàÖÐÉêÇëÁËÄÚ´æ
126 CString GetCompatibleString ( LPVOID lpszOrg, BOOL bOrgIsUnicode, int nOrgLength=-1 );
127 CString FormatDateTime ( COleDateTime &DateTime, LPCTSTR pFormat );
128 CString FormatString ( LPCTSTR lpszStr, ... );
129 int hwGetFileAttr ( LPCTSTR lpFileName, OUT CFileStatus *pFileStatus=NULL );
130 CString FormatBytes ( double fBytesNum, BOOL bShowUnit=TRUE, int nFlag=0 );
131 BOOL WaitForThreadEnd ( HANDLE *phThread, DWORD dwWaitTime=10*1000 );
133 //{{AFX_INSERT_LOCATION}}
134 // Microsoft Visual C++ will insert additional declarations immediately before the previous line.