Source code of Windows XP (NT5)
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.

215 lines
7.8 KiB

  1. /******************************************************************************
  2. * Temp conversion utility to take registry entries and populate the class store with those entries.
  3. *****************************************************************************/
  4. /******************************************************************************
  5. includes
  6. ******************************************************************************/
  7. #include "precomp.hxx"
  8. #include "..\appmgr\resource.h"
  9. extern HINSTANCE ghInstance;
  10. /******************************************************************************
  11. defines and prototypes
  12. ******************************************************************************/
  13. extern CLSID CLSID_ClassStore;
  14. extern const IID IID_IClassStore;
  15. extern const IID IID_IClassAdmin;
  16. LONG
  17. UpdatePackage(
  18. MESSAGE * pMessage,
  19. BOOL fUsageFlag,
  20. DWORD Context,
  21. char * pClsidString,
  22. char * pAppid,
  23. char * ServerName,
  24. DWORD * pMajorVersion,
  25. DWORD * pMinorVersion,
  26. DWORD * pLocale );
  27. LONG
  28. FindCLSIDFromFileExtension(
  29. MESSAGE * pMessage,
  30. BasicRegistry * pFileExtKey,
  31. char * ClsidBuffer,
  32. DWORD * SizeofClsidBuffer,
  33. char * szExt );
  34. LONG
  35. UpdateDatabaseFromFileExt(
  36. MESSAGE * pMessage )
  37. {
  38. BasicRegistry * pHKCR = new BasicRegistry( pMessage->hRoot );
  39. BasicRegistry * pFileKey;
  40. LONG Error;
  41. int Index;
  42. //
  43. // Get the file extension entries one by one. A file extension entry
  44. // is one whose name starts with a ".". So we enumerate the keys
  45. // looking for file extensions and add to the class dictionary.
  46. // Note that this step is carried out AFTER the class dictionary is
  47. // already populated, so we can assume that the class dictionary is
  48. // present.
  49. //
  50. pHKCR->InitForEnumeration(0);
  51. for ( Index = 0;Error != ERROR_NO_MORE_ITEMS;++Index )
  52. {
  53. char FileExtBuffer[ 256 ];
  54. DWORD SizeOfFileExtBuffer = 256;
  55. Error = pHKCR->NextKey( FileExtBuffer,
  56. &SizeOfFileExtBuffer,
  57. &pFileKey,
  58. pMessage->ftLow, pMessage->ftHigh );
  59. if( (Error == ERROR_SUCCESS ) && (FileExtBuffer[0] == '.') )
  60. {
  61. LONG Error2;
  62. char ClsidBuffer[256];
  63. DWORD SizeofClsidBuffer = 256;
  64. // this is a file extension key.
  65. // Given a file extension key, figure out the CLSID.
  66. /*****
  67. if(_stricmp(FileExtBuffer, ".doc" ) == 0 )
  68. printf("Hello1");
  69. ******/
  70. Error2 = FindCLSIDFromFileExtension(
  71. pMessage,
  72. pFileKey,
  73. ClsidBuffer,
  74. &SizeofClsidBuffer,
  75. FileExtBuffer );
  76. if( Error2 != ERROR_NO_MORE_ITEMS )
  77. {
  78. CLASS_ENTRY * pClsEntry;
  79. // Enter into the Clsid dictionary.
  80. if( (pClsEntry = pMessage->pClsDict->Search( &ClsidBuffer[0] ) ) != 0 )
  81. {
  82. int len = strlen( FileExtBuffer );
  83. char * p = new char[ len + 1];
  84. strcpy( p, FileExtBuffer );
  85. pClsEntry->FileExtList.Add( p );
  86. }
  87. }
  88. }
  89. // close the key if we opened it.
  90. if( Error == ERROR_SUCCESS )
  91. delete pFileKey;
  92. }
  93. return ERROR_SUCCESS;
  94. }
  95. LONG
  96. FindCLSIDFromFileExtension(
  97. MESSAGE * pMessage,
  98. BasicRegistry * pFileExtKey,
  99. char * ClsidBuffer,
  100. DWORD * pSizeofClsidBuffer,
  101. char * szExt )
  102. {
  103. char Buffer[256];
  104. DWORD SizeofBuffer;
  105. BasicRegistry * pClsidKey;
  106. HKEY pTempKey;
  107. BasicRegistry * pProgIDKey;
  108. LONG Error = ERROR_NO_MORE_ITEMS;
  109. int fFound = 0;
  110. // Find the unnamed value. This is the progid value. Under this, a CLSID key should be present.
  111. SizeofBuffer = 256;
  112. Error = pFileExtKey->QueryValue("", &Buffer[0], &SizeofBuffer );
  113. // Get the key named in the Buffer.
  114. Error = RegOpenKeyEx( pMessage->hRoot,
  115. &Buffer[0],
  116. 0,
  117. KEY_ALL_ACCESS,
  118. &pTempKey );
  119. pProgIDKey = new BasicRegistry( pTempKey );
  120. if( Error == ERROR_SUCCESS )
  121. {
  122. // Now get the CLSID subkey under this prog id key.
  123. Error = pProgIDKey->Find( "CLSID", &pClsidKey );
  124. if( Error == ERROR_SUCCESS )
  125. {
  126. // Find the unnamed value in this
  127. Error = pClsidKey->QueryValue( "", &ClsidBuffer[0], pSizeofClsidBuffer );
  128. delete pClsidKey;
  129. }
  130. else
  131. {
  132. CLSID TempClsid;
  133. // uuid create on TempClsid here
  134. UuidCreate(&TempClsid);
  135. // Convert that to a string.
  136. CLSIDToString( &TempClsid, &ClsidBuffer[0] );
  137. CLASS_ENTRY * pClassEntry = new CLASS_ENTRY;
  138. memcpy( pClassEntry->ClsidString,
  139. &ClsidBuffer[0],
  140. SIZEOF_STRINGIZED_CLSID );
  141. pMessage->pClsDict->Insert( pClassEntry );
  142. char * pT = new char [SIZEOF_STRINGIZED_CLSID];
  143. memcpy( pT,
  144. &ClsidBuffer[0],
  145. SIZEOF_STRINGIZED_CLSID );
  146. UpdatePackage( pMessage,
  147. 0, // clsid update
  148. CTX_LOCAL_SERVER,
  149. pT,
  150. 0,
  151. pMessage->pPackagePath,
  152. 0,
  153. 0,
  154. 0 );
  155. Error = ERROR_SUCCESS;
  156. }
  157. delete pProgIDKey;
  158. }
  159. else
  160. {
  161. // Message that the file extension couldn't be mapped to a prog ID
  162. char szCaption [256];
  163. char szBuffer[256];
  164. ::LoadString(ghInstance, IDS_BOGUS_EXTENSION, szBuffer, 256);
  165. strcat(szBuffer, szExt);
  166. strncpy(szCaption, pMessage->pPackagePath, 256);
  167. int iReturn = ::MessageBox(pMessage->hwnd, szBuffer,
  168. szCaption,
  169. MB_OK);
  170. }
  171. return Error == ERROR_SUCCESS ? Error: ERROR_NO_MORE_ITEMS;
  172. }