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.

548 lines
14 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. #define HOME 1
  9. /******************************************************************************
  10. defines and prototypes
  11. ******************************************************************************/
  12. extern CLSID CLSID_ClassStore;
  13. extern const IID IID_IClassAdmin;
  14. const IID IID_IClassStore = {
  15. 0x00000190,
  16. 0x0000,
  17. 0x0000,
  18. { 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 }
  19. };
  20. void GatherArguments(
  21. int argc,
  22. char * argv[],
  23. MESSAGE * pMessage );
  24. HRESULT UpdateDatabaseFromRegistry(
  25. MESSAGE * pMessage );
  26. HRESULT UpdateClassStoreFromDatabase(
  27. MESSAGE * pMessage,
  28. IClassAdmin * pClassAdmin );
  29. IClassAdmin * InitializeClassStoreInterfaces(
  30. MESSAGE * pMessage );
  31. void ReleaseClassStoreInterfaces(
  32. MESSAGE * pMessage,
  33. IClassAdmin * pClassAdmin);
  34. HRESULT AddToClassStore(
  35. MESSAGE *pMessage,
  36. IClassAdmin * pClassAdmin );
  37. void DumpOnePackage(
  38. MESSAGE * pMessage,
  39. PACKAGEDETAIL * p );
  40. void DumpOneAppDetail(
  41. MESSAGE * pMessage,
  42. APPDETAIL * pA );
  43. void DumpOneClass(
  44. MESSAGE * pMessage,
  45. CLASSDETAIL * pClassDetail );
  46. void DumpIIDEntries(
  47. IIDICT * pIIDict );
  48. void DumpOneIIDEntry(
  49. ITF_ENTRY * pITFEntry );
  50. void
  51. DumpOneTypelib(
  52. MESSAGE * pMessage,
  53. CLSID * pClsid );
  54. HRESULT VerifyArguments(
  55. MESSAGE * pMessage );
  56. /******************************************************************************
  57. Globals
  58. ******************************************************************************/
  59. char * SwitchSpecified[26];
  60. char * AdditionalSwitchParam[26];
  61. BOOL DumpAll = 1;
  62. /******************************************************************************
  63. Da Code
  64. ******************************************************************************/
  65. void Usage()
  66. {
  67. printf("\nUsage:");
  68. //////////////////////////////////////////////////////////////////////////
  69. printf("\n\t -a <Architecture> - valid values are:" );
  70. printf("\n\t\t [ Intel, Alpha]");
  71. //////////////////////////////////////////////////////////////////////////
  72. printf("\n\t -o <OS> - valid values are:");
  73. printf("\n\t\t [Winnt, Win95, Win31]" );
  74. printf("\n\t -p <Full Package Path (including name eg \\foo\bar\baz.cab>");
  75. //////////////////////////////////////////////////////////////////////////
  76. printf("\n\t -r <RunFlags> - NotImplemeted yet");
  77. //////////////////////////////////////////////////////////////////////////
  78. printf("\n\t -n <Package name >" );
  79. //////////////////////////////////////////////////////////////////////////
  80. printf("\n\t -k <Registry key: eg \\Software\\Classes (always assumed under HKLM");
  81. printf("\n\t\t eg \\Software\\Classes for HKLM\\Software\\Classes or HKCR" );
  82. printf("\n\t -s <Setup Command including switches>");
  83. printf("\n\t -z <Dump, but dont update class store>");
  84. printf("\n\t -c <Class store path >");
  85. //////////////////////////////////////////////////////////////////////////
  86. printf("\n\t -i <icon path>");
  87. //////////////////////////////////////////////////////////////////////////
  88. }
  89. int __cdecl main( int argc, char * argv[] )
  90. {
  91. MESSAGE * pMessage = new MESSAGE;
  92. IClassAdmin * pClassAdmin;
  93. HRESULT hr;
  94. // gather arguments
  95. GatherArguments( argc, argv, pMessage );
  96. if( pMessage->SetRootKey( SwitchSpecified[ 'K' - 'A' ] ) != ERROR_SUCCESS )
  97. {
  98. printf("\nCannot open Key: %s\n", AdditionalSwitchParam[ 'K' - 'A' ] );
  99. exit( MAKE_HRESULT( SEVERITY_ERROR,
  100. FACILITY_WIN32,
  101. ERROR_INVALID_PARAMETER) );
  102. }
  103. if( (hr = VerifyArguments( pMessage)) != S_OK )
  104. {
  105. printf("\nInvalid arguments, hr = 0x%x\n", hr );
  106. exit( hr );
  107. }
  108. UpdateDatabaseFromRegistry( pMessage );
  109. pClassAdmin = InitializeClassStoreInterfaces( pMessage );
  110. UpdateClassStoreFromDatabase( pMessage, pClassAdmin );
  111. ReleaseClassStoreInterfaces( pMessage, pClassAdmin );
  112. return 0;
  113. }
  114. void
  115. GatherArguments(
  116. int argc,
  117. char * argv[],
  118. MESSAGE * pMessage )
  119. {
  120. int Index = 1;
  121. char * argp;
  122. memset(&SwitchSpecified[0], '\0', sizeof(SwitchSpecified)/sizeof(char *) );
  123. // For switches that do not take arguments, do not advance the index pointer
  124. // in the switch handler.
  125. while( Index < argc )
  126. {
  127. argp = argv[Index];
  128. if( (*argp == '-') || (*argp == '/') )++argp;
  129. switch( toupper(*argp) )
  130. {
  131. case 'A':
  132. ++Index;
  133. SwitchSpecified[ 'A' - 'A'] = argp = argv[ Index ];
  134. break;
  135. case 'O':
  136. ++Index;
  137. SwitchSpecified[ 'O' - 'A'] = argp = argv[ Index ];
  138. break;
  139. case 'P':
  140. ++Index;
  141. SwitchSpecified[ 'P' - 'A'] = argp = argv[ Index ];
  142. pMessage->pPackagePath = argp;
  143. break;
  144. case 'N':
  145. ++Index;
  146. SwitchSpecified['N' - 'A'] = argp = argv[Index];
  147. pMessage->pPackageName = argp;
  148. break;
  149. case 'K':
  150. ++Index;
  151. SwitchSpecified['K' - 'A'] = argp = argv[Index];
  152. pMessage->pRegistryKeyName = argp;
  153. break;
  154. case 'S':
  155. ++Index;
  156. SwitchSpecified['S' - 'A'] = argp = argv[Index];
  157. pMessage->pSetupCommand = argp;
  158. break;
  159. case 'Z':
  160. SwitchSpecified['Z' - 'A'] = argp = argv[Index];
  161. pMessage->fDumpOnly = 1;
  162. pMessage->pDumpOnePackage = DumpOnePackage;
  163. break;
  164. case 'C':
  165. ++Index;
  166. SwitchSpecified['C' - 'A'] = argp = argv[Index];
  167. pMessage->pClassStoreName = argp;
  168. break;
  169. case 'I':
  170. ++Index;
  171. SwitchSpecified['I' - 'A'] = argp = argv[Index];
  172. pMessage->pIconPath = argp;
  173. break;
  174. case 'D':
  175. ++Index;
  176. SwitchSpecified['D' - 'A'] = argp = argv[Index];
  177. pMessage->pClassStoreDomainName = argp;
  178. break;
  179. case 'R':
  180. pMessage->ActFlags = ACTFLG_RunLocally;
  181. break;
  182. default:
  183. printf( "\nUnknown switch %c", *argp );
  184. Usage();
  185. exit(1);
  186. }
  187. ++Index;
  188. }
  189. // update base registry key.
  190. if( SwitchSpecified[ 'K' - 'A' ] == 0 )
  191. pMessage->pRegistryKeyName = "\\Software\\Classes";
  192. // updatre class store name.
  193. if( SwitchSpecified[ 'C' - 'A' ] == 0 )
  194. pMessage->pClassStoreName = "classstore3";
  195. // update class store domain name
  196. if(SwitchSpecified[ 'D' - 'A' ] == 0 )
  197. pMessage->pClassStoreDomainName = "olecs";
  198. // update architecture.
  199. if( SwitchSpecified[ 'A'-'A'] && SwitchSpecified['O' - 'A'] )
  200. {
  201. DWORD O,A;
  202. int i;
  203. static char * pArcStrings[] = { "Unknown",
  204. "Intel",
  205. "Mips",
  206. "Alpha",
  207. "PPC"
  208. };
  209. static DWORD Arc[] =
  210. {
  211. PROCESSOR_ARCHITECTURE_UNKNOWN,
  212. PROCESSOR_ARCHITECTURE_INTEL,
  213. PROCESSOR_ARCHITECTURE_MIPS,
  214. PROCESSOR_ARCHITECTURE_ALPHA,
  215. PROCESSOR_ARCHITECTURE_PPC
  216. };
  217. static char * pOsStrings[] =
  218. {
  219. "Winnt",
  220. "Win95",
  221. "Win31"
  222. };
  223. static DWORD Os[] =
  224. {
  225. OS_WINNT,
  226. OS_WIN95,
  227. OS_WIN31
  228. };
  229. for (i = 0; i < sizeof( pArcStrings)/sizeof(char *);++i )
  230. {
  231. if( _stricmp( pArcStrings[ i ], SwitchSpecified[ 'A'-'A' ]) == 0 )
  232. A = Arc[ i ];
  233. }
  234. for (i = 0; i < sizeof( pOsStrings)/sizeof(char *);++i )
  235. {
  236. if( _stricmp( pOsStrings[ i ], SwitchSpecified[ 'O'-'A' ]) == 0 )
  237. O = Os[ i ];
  238. }
  239. pMessage->Architecture = MAKEARCHITECTURE(A,O);
  240. }
  241. }
  242. IClassAdmin *
  243. InitializeClassStoreInterfaces( MESSAGE * pMessage )
  244. {
  245. IClassAdmin *pClassAdmin = NULL;
  246. IMoniker *pmk = NULL;
  247. LPBC pbc = NULL;
  248. ULONG chEaten;
  249. char Buffer[_MAX_PATH ];
  250. OLECHAR MonikerBuffer[(_MAX_PATH+1)*2 ];
  251. if( pMessage->fDumpOnly )
  252. return 0;
  253. HRESULT hr = CoInitialize(NULL);
  254. if( FAILED(hr) )
  255. {
  256. printf( "Client CoInitialize failed Ox%x!\n", hr );
  257. return 0;
  258. }
  259. hr = CreateBindCtx (0, &pbc);
  260. if (!SUCCEEDED(hr))
  261. {
  262. printf( "CreateBindCtx failed Ox%x!\n", hr );
  263. return 0;
  264. }
  265. strcpy(Buffer, "ADCS:");
  266. strcat(Buffer, pMessage->pClassStoreName );
  267. mbstowcs( MonikerBuffer, Buffer, strlen(Buffer)+1 );
  268. chEaten = 0;
  269. hr = MkParseDisplayName (pbc, MonikerBuffer, &chEaten,&pmk);
  270. if (!SUCCEEDED(hr))
  271. {
  272. printf( "MkParseDisplayName failed Ox%x!\n", hr );
  273. return 0;
  274. }
  275. hr = pmk->BindToObject (
  276. pbc,
  277. NULL,
  278. IID_IClassAdmin,
  279. (void **) &pClassAdmin);
  280. if (!SUCCEEDED(hr))
  281. {
  282. printf( "BindToObject failed Ox%x!\n", hr );
  283. return 0;
  284. }
  285. pmk->Release();
  286. pbc->Release();
  287. return pClassAdmin;
  288. }
  289. void
  290. ReleaseClassStoreInterfaces( MESSAGE * pMessage, IClassAdmin * pClassAdmin)
  291. {
  292. if( pMessage->fDumpOnly || (pClassAdmin == 0) )
  293. return;
  294. pClassAdmin->Release();
  295. }
  296. void
  297. DumpIIDEntries( IIDICT * pIIDict )
  298. {
  299. ITF_ENTRY * pITFEntry = pIIDict->GetFirst();
  300. if( pITFEntry )
  301. do
  302. {
  303. printf("\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
  304. printf("\nIID = %s", pITFEntry->IID );
  305. DumpOneIIDEntry( pITFEntry );
  306. printf("\n<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
  307. pITFEntry = pIIDict->GetNext( pITFEntry );
  308. } while (pITFEntry != 0 );
  309. }
  310. void
  311. DumpOneIIDEntry(ITF_ENTRY * pITFEntry )
  312. {
  313. printf("\nProxyStubClsid = %s", pITFEntry->Clsid );
  314. printf("\nTypelibID = %s", pITFEntry->TypelibID );
  315. }
  316. void
  317. DumpOnePackage(
  318. MESSAGE * pMessage,
  319. PACKAGEDETAIL * p )
  320. {
  321. DWORD count;
  322. printf("\n++++++++++++++++++++++++++++++++++++++++++++++++++");
  323. printf( "\nClassPathType = %d", p->PathType );
  324. wprintf(L"\nPackagePath = %s", p->pszPath );
  325. wprintf(L"\nIconPath = %s", p->pszIconPath );
  326. wprintf(L"\nSetup Command = %s", p->pszSetupCommand );
  327. printf("\nActFlags = %d", p->dwActFlags );
  328. wprintf(L"\nVendor = %s", p->pszVendor );
  329. wprintf(L"\nPackageName = %s", p->pszPackageName );
  330. wprintf(L"\nProductName = %s", p->pszProductName );
  331. wprintf(L"\ndwContext = %d", p->dwContext );
  332. wprintf(L"\nCsPlatform = (PlatformID= 0x%x, VersionHi = 0x%x, VersionLo = 0x%x, ProcessorArchitecture = 0x%x",
  333. p->Platform.dwPlatformId,
  334. p->Platform.dwVersionHi,
  335. p->Platform.dwVersionLo,
  336. p->Platform.dwProcessorArch );
  337. wprintf(L"\ndwLocale = 0x%x", p->Locale );
  338. wprintf(L"\ndwVersionHi = %d", p->dwVersionHi );
  339. wprintf(L"\ndwVersionLo = %d", p->dwVersionLo );
  340. wprintf(L"\nCountOfApps = %d", p->cApps );
  341. for( count = 0;
  342. count < p->cApps;
  343. ++count )
  344. {
  345. DumpOneAppDetail( pMessage, &p->pAppDetail[count] );
  346. }
  347. printf("\n--------------------------------------------------");
  348. }
  349. void
  350. DumpOneAppDetail(
  351. MESSAGE * pMessage,
  352. APPDETAIL * pA )
  353. {
  354. char Buffer[ 100 ];
  355. DWORD count;
  356. CLASS_ENTRY * pC;
  357. CLSIDToString( &pA->AppID, &Buffer[0] );
  358. printf( "\n\t\tAPPID = %s", &Buffer[0] );
  359. if( pA->cClasses )
  360. {
  361. for( count = 0;
  362. count < pA->cClasses;
  363. ++count )
  364. {
  365. char Buffer[50];
  366. CLSIDToString( &pA->prgClsIdList[count],&Buffer[0] );
  367. pC = pMessage->pClsDict->Search( &Buffer[0] );
  368. if( pC )
  369. DumpOneClass( pMessage, &pC->ClassAssociation );
  370. }
  371. }
  372. if( pA->cTypeLibIds )
  373. {
  374. for( count = 0;
  375. count < pA->cTypeLibIds;
  376. ++count )
  377. {
  378. DumpOneTypelib( pMessage, pA->prgTypeLibIdList );
  379. }
  380. }
  381. else
  382. printf( "\n\t\t No Typelibs present" );
  383. }
  384. void
  385. DumpOneClass( MESSAGE * pMessage, CLASSDETAIL * pClassDetail )
  386. {
  387. char Buffer[ _MAX_PATH ];
  388. DWORD count;
  389. CLSIDToString( &pClassDetail->Clsid, &Buffer[0] );
  390. printf( "\n\t\t\tCLSID = %s", &Buffer[0] );
  391. wprintf( L"\n\t\t\tDescription = %s", pClassDetail->pszDesc );
  392. wprintf( L"\n\t\t\tIconPath = %s", pClassDetail->pszIconPath );
  393. CLSIDToString( &pClassDetail->TreatAsClsid, &Buffer[0] );
  394. printf( "\n\t\t\tTreatAsClsid = %s", &Buffer[0] );
  395. CLSIDToString( &pClassDetail->AutoConvertClsid, &Buffer[0] );
  396. printf( "\n\t\t\tAutoConvertClsid = %s", &Buffer[0] );
  397. printf("\n\t\t\tCountOfFileExtensions = %d", pClassDetail->cFileExt );
  398. if( pClassDetail->cFileExt )
  399. {
  400. for(count = 0;
  401. count < pClassDetail->cFileExt;
  402. count++
  403. )
  404. {
  405. wprintf( L"\n\t\t\tFileExt = %s", pClassDetail->prgFileExt[ count ] );
  406. }
  407. }
  408. else
  409. {
  410. printf("\n\t\t\tOtherFileExt = None" );
  411. }
  412. wprintf(L"\n\t\t\tMimeType = %s", pClassDetail->pMimeType );
  413. wprintf(L"\n\t\t\tDefaultProgid = %s", pClassDetail->pDefaultProgId );
  414. printf("\n\t\t\tCountOfOtherProgIds = %d", pClassDetail->cOtherProgId );
  415. if( pClassDetail->cOtherProgId )
  416. {
  417. for(count = 0;
  418. count < pClassDetail->cOtherProgId;
  419. count++
  420. )
  421. {
  422. wprintf( L"\n\t\t\tOtherProgId = %s", pClassDetail->prgOtherProgId[ count ] );
  423. }
  424. }
  425. else
  426. {
  427. printf("\n\t\t\tOtherProgId = None" );
  428. }
  429. printf("\n");
  430. }
  431. void
  432. DumpOneTypelib(
  433. MESSAGE * pMessage,
  434. CLSID * pClsid )
  435. {
  436. char Buffer[ _MAX_PATH ];
  437. CLSIDToString( pClsid, &Buffer[0] );
  438. printf( "\n\t\t\tTypelibID = %s", &Buffer[0] );
  439. printf("\n");
  440. }