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.

410 lines
9.7 KiB

  1. ////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // File: mig.h
  4. //
  5. // History: 01-Jan-01 VadimB Resurrected.
  6. //
  7. // Desc: This file contains all object definitions used by the
  8. // Migdb-related code.
  9. //
  10. ////////////////////////////////////////////////////////////////////////////////////
  11. #ifndef __MIG_H__
  12. #define __MIG_H__
  13. ///////////////////////////////////////////////////////////////////////////////
  14. //
  15. // MigDb support
  16. // objects that translate the entries into MigDB entries
  17. //
  18. //
  19. // Migration entry matching operation
  20. // for our purposes we always use MIGOP_AND
  21. //
  22. typedef enum tagMIGMATCHOPERATION {
  23. MIGOP_AND,
  24. MIGOP_OR
  25. } MIGMATCHOPERATION;
  26. //
  27. // attribute types used by migdb
  28. //
  29. typedef enum tagMIGATTRTYPE {
  30. NONE,
  31. COMPANYNAME,
  32. FILEDESCRIPTION,
  33. FILEVERSION,
  34. INTERNALNAME,
  35. LEGALCOPYRIGHT,
  36. ORIGINALFILENAME,
  37. PRODUCTNAME,
  38. PRODUCTVERSION,
  39. FILESIZE,
  40. ISMSBINARY,
  41. ISWIN9XBINARY,
  42. INWINDIR,
  43. INCATDIR,
  44. INHLPDIR,
  45. INSYSDIR,
  46. INPROGRAMFILES,
  47. ISNOTSYSROOT,
  48. CHECKSUM,
  49. EXETYPE,
  50. DESCRIPTION,
  51. INPARENTDIR,
  52. INROOTDIR,
  53. PNPID,
  54. HLPTITLE,
  55. ISWIN98,
  56. HASVERSION,
  57. REQFILE,
  58. BINFILEVER,
  59. BINPRODUCTVER,
  60. FILEDATEHI,
  61. FILEDATELO,
  62. FILEVEROS,
  63. FILEVERTYPE,
  64. FC,
  65. UPTOBINPRODUCTVER,
  66. UPTOBINFILEVER,
  67. SECTIONKEY,
  68. REGKEYPRESENT,
  69. ATLEASTWIN98,
  70. ARG
  71. } MIGATTRTYPE;
  72. //
  73. // Attribute table entry --
  74. // used to describe how particular attribute appears in Migdb vs our XML
  75. //
  76. typedef struct tagATTRLISTENTRY {
  77. MIGATTRTYPE MigAttrType; // type as it appears in migration db (tag)
  78. TCHAR* szOutputName; // attribute as it's supposed to appear in .inx file
  79. DWORD XMLAttrType; // type as it appears in xml (dword/mask)
  80. TCHAR* szAttributeName; // attribute as it appears in .xml file (ascii)
  81. } ATTRLISTENTRY, *PATTRLISTENTRY;
  82. //
  83. // Macro to define migdb entry when the entry name is the same for both xml and inf
  84. //
  85. #define MIGDB_ENTRY(entry) { entry, NULL, SDB_MATCHINGINFO_##entry, _T(#entry) }
  86. //
  87. // Macro to define migdb entry when the entry name is not the same
  88. // entry with equivalent entry being present in xml
  89. //
  90. #define MIGDB_ENTRY2(entry, entXML, entInf) \
  91. { entry, _T(#entInf), SDB_MATCHINGINFO_##entXML, _T(#entXML) }
  92. //
  93. // entry with no equivalence in xml
  94. //
  95. #define MIGDB_ENTRY3(entry, entInf) \
  96. { entry, _T(#entInf), 0, NULL }
  97. #define MIGDB_ENTRY4(entry) \
  98. { entry, _T(#entry), 0, NULL }
  99. #define MIGDB_ENTRY5(entry, entInc, entXML) \
  100. { entry, _T(#entry), SDB_MATCHINGINFO_##entInc, _T(#entXML) }
  101. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  102. //
  103. // MigDB parser
  104. //
  105. //
  106. class MigEntry; // collection of attributes
  107. class MigSection; // section (collection of entries or other sections)
  108. class MigAttribute; // indivitual attribute
  109. class MigDatabase; // migration database
  110. // this is a "named" collection of attributes
  111. // equivalent to a line in an inf file
  112. //
  113. //
  114. class MigEntry : public SdbArrayElement {
  115. public:
  116. // construction
  117. MigEntry(MigDatabase* pMigDB) :
  118. m_pMigDB(pMigDB) {};
  119. // properties
  120. //
  121. // implied: m_csName
  122. //
  123. SdbArray<MigAttribute> m_rgAttrs; // attributes (collection of pointers of type MigAttribute*)
  124. //
  125. // pointer to mig database
  126. //
  127. MigDatabase* m_pMigDB;
  128. // methods
  129. //
  130. // Dump inf into a file
  131. //
  132. CString dump(void);
  133. // format entry name (exe name)
  134. //
  135. CString FormatName(void);
  136. //
  137. // translate from the matching file into MigEntry
  138. //
  139. MigEntry& operator=(SdbMatchingFile& rMatchingFile);
  140. };
  141. //
  142. // these are "matching exes" - aka "Section"
  143. //
  144. //
  145. class MigSection : public SdbArrayElement {
  146. // implied: m_csName (aka "section name or exe name")
  147. public:
  148. // each element of the array
  149. // may be of the type MigMatchingFile OR
  150. // MigSection
  151. // we determine which one that is using rtti
  152. //
  153. MigSection(MigDatabase* pMigDB) :
  154. m_pMigDB(pMigDB),
  155. m_nEntry(0),
  156. m_bTopLevel(FALSE),
  157. m_Operation(MIGOP_AND) {};
  158. SdbArray<SdbArrayElement> m_rgEntries; // these are matching exes or subsections
  159. MIGMATCHOPERATION m_Operation; // operation (AND/OR)
  160. BOOL m_bTopLevel; // top level Section or not
  161. LONG m_nEntry;
  162. MigDatabase* m_pMigDB;
  163. MigSection& operator=(SdbMatchOperation& rMatch);
  164. //
  165. // method to dump the section into the file
  166. //
  167. CString dump(LPCTSTR lpszDescription = NULL, int* pIndexContents = NULL, BOOL bNoHeader = FALSE, BOOL bInline = TRUE);
  168. };
  169. //
  170. // MigAttribute
  171. //
  172. class MigAttribute : public SdbArrayElement {
  173. public: // methods
  174. MigAttribute(MigDatabase* pMigDB) :
  175. m_pMigDB(pMigDB),
  176. m_type(NONE),
  177. m_bNot(FALSE),
  178. m_pSection(NULL) {};
  179. ~MigAttribute() {
  180. if (m_pSection != NULL) {
  181. delete m_pSection;
  182. }
  183. }
  184. // implied m_csName
  185. public: // data
  186. MIGATTRTYPE m_type;
  187. BOOL m_bNot; // is operation NOT applied
  188. union {
  189. LONG m_lValue; // long value for the attribute
  190. ULONG m_ulValue; // ulong value
  191. DWORD m_dwValue;
  192. ULONGLONG m_ullValue; // unsigned long long
  193. ULARGE_INTEGER m_uliValue; // unsigned large integer
  194. // if this attribute is REQFile then we use special
  195. // value along with the pointer to Attribute collection
  196. };
  197. CString m_csValue; // string value
  198. MigSection* m_pSection; // section (used for ARG and REQFILE)
  199. MigDatabase* m_pMigDB;
  200. CString dump(void);
  201. };
  202. class MigApp : public SdbArrayElement {
  203. public:
  204. MigApp(MigDatabase* pMigDB) :
  205. m_pMigDB(pMigDB),
  206. m_pSection(NULL),
  207. m_bShowInSimplifiedView(FALSE) {}
  208. ~MigApp() {
  209. if (m_pSection != NULL) {
  210. delete m_pSection;
  211. }
  212. }
  213. // implied m_csName
  214. CString m_csSection; // name used in .inf file
  215. CString m_csDescription; // description from .inf file
  216. // section that is used (can represent single file or a real section)
  217. MigSection* m_pSection; // section (contents of the app tag)
  218. BOOL m_bShowInSimplifiedView;
  219. SdbArray<SdbArrayElement> m_rgArgs; // ARGs that go with this...
  220. MigDatabase* m_pMigDB; // Mig db
  221. CString dump(VOID);
  222. MigApp& operator=(SdbWin9xMigration& rMig);
  223. };
  224. class MigDatabase {
  225. public:
  226. MigDatabase() :
  227. m_dwStringCount(0),
  228. m_dwExeCount(0) { }
  229. ~MigDatabase() {
  230. POSITION pos = m_mapSections.GetStartPosition();
  231. CString csSection;
  232. SdbArray<SdbArrayElement>* prgApp;
  233. while(pos) {
  234. m_mapSections.GetNextAssoc(pos, csSection, (LPVOID&)prgApp);
  235. delete prgApp;
  236. }
  237. }
  238. //
  239. // methods:
  240. //
  241. CString GetAppTitle(
  242. SdbWin9xMigration* pAppMig
  243. );
  244. BOOL MigDatabase::AddApp( // adds application to the migdb
  245. MigApp* pApp
  246. );
  247. CString GetSectionFromExe(
  248. SdbExe* pExe
  249. );
  250. CString GetDescriptionStringID(
  251. SdbWin9xMigration* pMigration
  252. );
  253. CString GetDescriptionString(
  254. SdbWin9xMigration* pMigration
  255. );
  256. CString FormatDescriptionStringID(
  257. SdbWin9xMigration* pMigration
  258. );
  259. BOOL Populate(
  260. VOID
  261. );
  262. BOOL PopulateStrings(
  263. VOID
  264. );
  265. BOOL DumpMigDBStrings(
  266. LPCTSTR lpszFilename
  267. );
  268. BOOL DumpMigDBInf(
  269. LPCTSTR lpszFilename
  270. );
  271. //
  272. // just the temporary storage for db we're working with (this is the db that has exes -> which is AppHelpDatabase)
  273. //
  274. SdbDatabase* m_pFixDatabase;
  275. SdbDatabase* m_pAppHelpDatabase;
  276. SdbDatabase* m_pMessageDatabase;
  277. //
  278. // output - supplemental sections
  279. //
  280. CStringArray m_rgOut; // output strings that contain supplemental sections
  281. //
  282. // String table, maps string ids to string content
  283. //
  284. CMapStringToString m_mapStringsOut;
  285. //
  286. // maps section names to arrays of objects of type MigApp
  287. //
  288. CMapStringToPtr m_mapSections;
  289. //
  290. // simple counter for strings to aid in the process of generating unique names
  291. //
  292. DWORD m_dwStringCount;
  293. //
  294. // count of exes to keep entries unique
  295. //
  296. DWORD m_dwExeCount;
  297. };
  298. class CMigDBException : public CException {
  299. public:
  300. CMigDBException(LPCTSTR lpszError = NULL) {
  301. if (lpszError != NULL) {
  302. m_csError = lpszError;
  303. }
  304. }
  305. virtual BOOL GetErrorMessage(LPTSTR lpszMessage, UINT nMaxError, PUINT puiHelpContext = NULL) {
  306. if (m_csError.GetLength() > 0 && nMaxError > (UINT)m_csError.GetLength()) {
  307. StringCchCopy(lpszMessage, nMaxError, (LPCTSTR)m_csError);
  308. return TRUE;
  309. }
  310. return FALSE;
  311. }
  312. CString m_csError;
  313. };
  314. BOOL WriteMigDBFile(
  315. SdbDatabase* pFixDatabase,
  316. SdbDatabase* pAppHelpDatabase,
  317. SdbDatabase* pMessageDatabase,
  318. LPCTSTR lpszFileName
  319. );
  320. #endif