Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

446 lines
11 KiB

  1. /*****************************************************************************
  2. Copyright (c) 2001, Microsoft Corporation All rights reserved.
  3. Module Name:
  4. res.h
  5. Abstract:
  6. The declaration of class CMuiResource, CMuiCmdInfo ..
  7. Revision History:
  8. 2001-10-01 sunggch created.
  9. Revision.
  10. *******************************************************************************/
  11. template < class T >
  12. class CVector {
  13. public:
  14. CVector() : MAX_SIZE(1000),m_index(0),m_dwExpand(1) { base = offset = new T [MAX_SIZE]; };
  15. CVector( UINT size ) : MAX_SIZE(size), m_index(0),m_dwExpand(1) { base = offset = new T [MAX_SIZE]; };
  16. virtual ~ CVector () { delete [] base; };
  17. void Push_back(T value ) { // *offset ++ = value; };
  18. if (m_index < MAX_SIZE * m_dwExpand )
  19. *offset ++ = value;
  20. else {
  21. m_dwExpand ++;
  22. T * pbase = NULL;
  23. T * poffset = NULL;
  24. pbase = poffset = new T [MAX_SIZE * m_dwExpand ];
  25. for (UINT i = 0; i < MAX_SIZE * ( m_dwExpand -1 ); i++ )
  26. memcpy(poffset++,&base[i],sizeof(T));
  27. delete [] base;
  28. DWORD dwCount = (DWORD) (poffset - pbase);
  29. base = pbase;
  30. offset = poffset;
  31. *offset++ = value;
  32. }
  33. m_index ++;
  34. }
  35. BOOL Empty( );
  36. BOOL Find(DWORD dwValue) { // this shouldn't be here, but there is vc++ bug regarding template.
  37. for ( UINT i = 0; i < (UINT) (offset - base); i ++ ) {
  38. if ( PtrToUlong( GetValue(i) ) & 0xFFFF0000) {
  39. if ( !( _tcstoul( GetValue(i), NULL, 10 ) - dwValue ) )
  40. return TRUE;
  41. }
  42. else {
  43. if (! ( PtrToUlong(GetValue(i) ) - dwValue ) )
  44. return TRUE;
  45. }
  46. }
  47. return FALSE;
  48. };
  49. void Clear() { offset = base; m_index = 0; };
  50. T operator [] (UINT index ) { return base[index]; };
  51. T GetValue ( UINT index ) { return base[index]; };
  52. CVector ( const CVector<T> &cv );
  53. CVector<T> & operator = (const CVector<T> & cv );
  54. UINT Size() { assert (base); return (UINT)(offset - base ); };
  55. private:
  56. T * base;
  57. UINT m_index;
  58. UINT m_dwExpand;
  59. T * offset;
  60. const UINT MAX_SIZE;
  61. };
  62. typedef CVector <LPTSTR> cvstring;
  63. typedef CVector <LPCTSTR> cvcstring;
  64. typedef CVector <WORD> cvword;
  65. class CResource {
  66. public:
  67. BOOL EndUpdateResource ( BOOL bDiscard );
  68. HANDLE BeginUpdateResource (BOOL bDeleteExistingResources );
  69. CResource ();
  70. virtual ~ CResource ();
  71. CResource (const CResource & cr );
  72. CResource & operator = (const CResource & cr );
  73. // enumerate resource
  74. cvcstring * EnumResTypes (LONG_PTR lParam = NULL );
  75. cvcstring * EnumResNames (LPCTSTR pszType,LONG_PTR lParam = NULL );
  76. cvword * EnumResLangID ( LPCTSTR lpType,LPCTSTR lpName,LONG_PTR lParam = NULL );
  77. BOOL UpdateResource (LPCTSTR lpType,LPCTSTR lpName,WORD wLanguage, LPVOID lpData, DWORD cbData);
  78. // delete all resource, we can replace the value as well.
  79. BOOL SetAllResource(LPVOID lpData, DWORD cbData );
  80. HRSRC FindResourceEx (LPCTSTR lpType, LPCTSTR lpName,WORD wLanguage )
  81. { return ::FindResourceEx(m_hRes, lpType, lpName, wLanguage ); };
  82. virtual void SetResType(LPCTSTR pszType) { m_vwResType -> Push_back((LPCTSTR)pszType); };
  83. virtual void SetResName(LPCTSTR pszName) { m_vwResName -> Push_back((LPCTSTR)pszName); };
  84. virtual void SetResLangID(WORD wLangID) {m_vwResLangID -> Push_back(wLangID); };
  85. cvcstring * GetResType () {return m_vwResType; };
  86. cvcstring * GetResName () {return m_vwResName; };
  87. cvword * GetResLangID () {return m_vwResLangID; };
  88. DWORD SizeofResource( HRSRC hResInfo ) { return ::SizeofResource(m_hRes,hResInfo); };
  89. HGLOBAL LoadResource (HRSRC hResInfo ) { return ::LoadResource(m_hRes, hResInfo); };
  90. LPVOID LockResource( HGLOBAL hResData ) { return :: LockResource(hResData); };
  91. BOOL FreeLibrary(void) { return ::FreeLibrary(m_hRes); }
  92. //LoadResource ( );
  93. protected :
  94. HMODULE m_hRes;
  95. LPCTSTR m_pszFile; // why not using "string m_sFile "
  96. private :
  97. HANDLE m_hResUpdate;
  98. cvcstring * m_vwResType;
  99. cvcstring * m_vwResName;
  100. cvword * m_vwResLangID;
  101. //LPCTSTR ** m_pTmp;
  102. public:
  103. };
  104. class CMUIData {
  105. class CMap {
  106. friend CMUIData;
  107. LPCTSTR m_lpType;
  108. LPCTSTR m_lpName;
  109. WORD m_wLangID;
  110. CMap ();// : m_lpType(NULL),m_lpName(NULL),m_wLangID(0) { };
  111. virtual ~ CMap() {};
  112. static PVOID operator new ( size_t size );
  113. static void operator delete ( void *p );
  114. };
  115. public:
  116. CMUIData() : m_iSize(0) { m_cmap = m_poffset = NULL ; };
  117. virtual ~ CMUIData();
  118. void SetAllData ( LPCTSTR lpType, LPCTSTR lpName, WORD wLang, UINT i );
  119. LPCTSTR GetType ( UINT i ) const { assert ( i < m_iSize); return m_cmap[i].m_lpType; };
  120. LPCTSTR GetName ( UINT i ) const { assert ( i < m_iSize); return m_cmap[i].m_lpName; };
  121. WORD GetLangID ( UINT i) const { assert ( i < m_iSize); return m_cmap[i].m_wLangID; };
  122. INT SizeofData ( ) const { return m_iSize ; };
  123. void SetType( UINT index, LPCTSTR lpType );
  124. private:
  125. private :
  126. UINT m_iSize;
  127. static CMap * m_cmap;
  128. static CMap * m_poffset;
  129. static UINT m_index;
  130. static const UINT MAX_SIZE_RESOURCE;
  131. };
  132. // Place all data in public area for performance. we don't want to call Get... although calling Add..
  133. class CMUITree
  134. {
  135. public:
  136. CMUITree * m_Next;
  137. CMUITree * m_ChildFirst;
  138. LPCTSTR m_lpTypeorName;
  139. WORD m_wLangID;
  140. public:
  141. CMUITree() : m_Next(NULL), m_ChildFirst(NULL), m_lpTypeorName(NULL), m_wLangID(0) {};
  142. virtual ~ CMUITree() { };
  143. void AddTypeorName( LPCTSTR lpType );
  144. void AddLangID ( WORD wLangID );
  145. // we keep path with AddTypeofName by controling Child pointer.
  146. BOOL DeleteType ( LPCTSTR lpTypeorName );
  147. // DeleteLangID ( CMUITree *pcmName, WORD wLangID ); // does not support in this time.
  148. DWORD NumOfChild();
  149. private :
  150. CMUITree(CMUITree & cmuit) {}; // NOT_IMPLETMENT_YET
  151. CMUITree & operator = (CMUITree & cmuit) {} ; // NOT_IMPLETMENT_YET
  152. };
  153. class CMUIResource : public CResource
  154. {
  155. public :
  156. CMUIResource();
  157. CMUIResource(LPCTSTR pszName);
  158. virtual ~CMUIResource() ;
  159. CMUIResource(const CMUIResource & cmui );
  160. CMUIResource & operator = (const CMUIResource & cmui);
  161. BOOL Create( LPCTSTR pszFile );
  162. BOOL CreatePE( LPCTSTR pszNewResFile , LPCTSTR pszSrcResFile);
  163. virtual BOOL WriteResFile(LPCTSTR pszSource, LPCTSTR pszMuiFile , LPCTSTR lpCommandLine, WORD wLanguageID = 0 );
  164. virtual BOOL DeleteResource (WORD wLang = 0 );
  165. virtual BOOL FillMuiData(cvcstring * vType, WORD wLanguageID, BOOL fForceLocalizedLangID );
  166. virtual void PrtVerbose ( DWORD dwRate);
  167. BOOL DeleteResItem(LPCTSTR lpType, LPCTSTR lpName=NULL,WORD wLanguageID = 0);
  168. MD5_CTX * CreateChecksum (cvcstring * cvChecksumResourceTypes,WORD wChecksumLangId);
  169. MD5_CTX * CreateChecksumWithAllRes(WORD wChecksumLangId);
  170. BOOL AddChecksumToVersion(BYTE * pbMD5Digest);
  171. BOOL UpdateNtHeader(LPCTSTR pszFileName, DWORD dwUpdatedField );
  172. protected :
  173. private :
  174. BOOL WriteResource(HANDLE hFile, HMODULE hModule, WORD wLanguage, LPCSTR lpName, LPCSTR lpType, HRSRC hRsrc);
  175. BOOL WriteResHeader(HANDLE hFile, LONG ResSize, LPCSTR lpType, LPCSTR lpName, WORD wLanguage, DWORD* pdwBytesWritten, DWORD* pdwHeaderSize);
  176. BOOL bInsertHeader(HANDLE hFile);
  177. void PutByte(HANDLE OutFile, TCHAR b, ULONG *plSize1, ULONG *plSize2);
  178. void PutWord(HANDLE OutFile, WORD w, ULONG *plSize1, ULONG *plSize2);
  179. void PutDWord(HANDLE OutFile, DWORD l, ULONG *plSize1, ULONG *plSize2);
  180. void PutString(HANDLE OutFile, LPCSTR szStr , ULONG *plSize1, ULONG *plSize2);
  181. void PutStringW(HANDLE OutFile, LPCWSTR szStr , ULONG *plSize1, ULONG *plSize2);
  182. void PutPadding(HANDLE OutFile, int paddingCount, ULONG *plSize1, ULONG *plSize2);
  183. private:
  184. void CheckTypeStability();
  185. DWORD AlignDWORD ( DWORD dwValue) { return ( (dwValue+3) & ~3 ); };
  186. private:
  187. HANDLE m_hFile;
  188. CMUIData m_cMuiData;
  189. CMUITree *m_pcmTreeRoot;
  190. public:
  191. MD5_CTX * m_pMD5;
  192. WORD m_wChecksumLangId; // we put this in public for perfomance.
  193. enum {
  194. IMAGE_SIZE = 0x00000001L,
  195. HEADER_SIZE = 0x00000010L,
  196. CHECKSUM = 0x00000100L,
  197. };
  198. };
  199. /**********************************************
  200. class CArgVerify
  201. ***********************************************/
  202. class CCommandInfo {
  203. public :
  204. CCommandInfo() { };
  205. virtual ~CCommandInfo() { };
  206. virtual BOOL CreateArgList(INT argc, TCHAR * argv [] ) = 0;
  207. private :
  208. };
  209. class CMuiCmdInfo : public CCommandInfo {
  210. class CMap {
  211. friend CMuiCmdInfo;
  212. LPCTSTR m_first;
  213. LPTSTR * m_second;
  214. UINT m_count;
  215. CMap () : m_first( NULL ),m_count(0){m_second = new LPTSTR[100]; }; // we have more than 16 resource type.need to generalize
  216. ~ CMap () { delete [] m_second; }
  217. };
  218. public :
  219. CMuiCmdInfo();
  220. virtual ~CMuiCmdInfo();
  221. CMuiCmdInfo(CMuiCmdInfo& cav); // copy constructor
  222. BOOL CreateArgList(INT argc, TCHAR * argv [] );
  223. LPTSTR * GetValueLists ( LPCTSTR pszKey, DWORD& dwCount );
  224. void SetArgLists(LPTSTR pszArgLists, LPTSTR m_pszArgNeedValueList, LPTSTR pszArgAllowFileValue,
  225. LPTSTR pszArgAllowMultiValue );
  226. private :
  227. CMuiCmdInfo& operator=(CMuiCmdInfo& cav) ; // do not allow = operation
  228. LPCTSTR getArgValue ( LPTSTR pszArg );
  229. LPCTSTR getArgString ( LPTSTR pszArg);
  230. BOOL isFile ( LPCTSTR pszArg );
  231. BOOL isNumber ( LPCTSTR pszArg );
  232. BOOL isNeedValue( LPCTSTR pszArg );
  233. BOOL isAllowFileValue(LPCTSTR pszArg);
  234. BOOL isAllowMultiFileValues( LPCTSTR pszArg );
  235. private : // member data
  236. CMap m_cmap[256];
  237. UINT m_uiCount;
  238. TCHAR *m_buf, *m_buf2; // just in case no new,resource name exist. we can delete this on the destructor.
  239. LPTSTR m_pszArgLists;
  240. LPTSTR m_pszArgNeedValueList; // arg., which is need values
  241. LPTSTR m_pszArgAllowFileValue;
  242. LPTSTR m_pszArgAllowMultiValue;
  243. };