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.

130 lines
2.7 KiB

  1. /******************************************************************************
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. main.cpp
  5. Abstract:
  6. This file contains the implementation of ReformatHHK utility, used to load
  7. and sort HHK files.
  8. Revision History:
  9. Davide Massarenti (Dmassare) 06/09/2000
  10. created
  11. ******************************************************************************/
  12. #include "stdafx.h"
  13. //////////////////////////////////////////////////////////////////////
  14. HRESULT ProcessHHK( LPCWSTR szFileIn, LPCWSTR szFileOut )
  15. {
  16. __HCP_FUNC_ENTRY( "ProcessHHK" );
  17. HRESULT hr;
  18. HHK::Merger merger;
  19. HHK::Writer writer;
  20. __MPC_EXIT_IF_METHOD_FAILS(hr, merger.PrepareSortingOfHhk( writer, szFileIn, szFileOut ));
  21. while(merger.MoveNext())
  22. {
  23. __MPC_EXIT_IF_METHOD_FAILS(hr, writer.OutputSection( merger.GetSection() ));
  24. }
  25. hr = S_OK;
  26. __HCP_FUNC_CLEANUP;
  27. __HCP_FUNC_EXIT(hr);
  28. }
  29. void ExtractHhkName( MPC::wstring& szFullName,
  30. LPCWSTR szFileName )
  31. {
  32. LPCWSTR szEnd;
  33. LPCWSTR szEnd2;
  34. if((szEnd = wcsrchr( szFileName, '\\' )) &&
  35. (szEnd2 = wcsrchr( szEnd , '.' )) )
  36. {
  37. MPC::wstring szTmp;
  38. szTmp = L"ms-its:";
  39. szTmp += szFileName;
  40. szTmp += L"::/";
  41. szTmp += MPC::wstring( szEnd+1, szEnd2 );
  42. szTmp += L".hhk";
  43. szFullName = szTmp;
  44. }
  45. else
  46. {
  47. szFullName = szFileName;
  48. }
  49. }
  50. HRESULT ExpandAndProcessHHK( LPCWSTR szFileIn, LPCWSTR szFileOut )
  51. {
  52. __HCP_FUNC_ENTRY( "ExpandAndProcessHHK" );
  53. HRESULT hr;
  54. MPC::wstring szFileName;
  55. if(MPC::MSITS::IsCHM( szFileIn ) == false && StrStrIW( szFileIn, L".hhk" ) == NULL)
  56. {
  57. ExtractHhkName( szFileName, szFileIn );
  58. }
  59. else
  60. {
  61. szFileName = szFileIn;
  62. }
  63. wprintf( L"Processing '%s'...\n", szFileName.c_str() );
  64. hr = ProcessHHK( szFileName.c_str(), szFileOut );
  65. __HCP_FUNC_EXIT(hr);
  66. }
  67. /////////////////////////////////////////////////////////////////////////////
  68. //
  69. int __cdecl wmain( int argc ,
  70. LPCWSTR argv[] )
  71. {
  72. HRESULT hr;
  73. MPC::wstring szFileIn;
  74. MPC::wstring szFileOut;
  75. if(argc != 3)
  76. {
  77. wprintf( L"Usage: %s <file to process> <output>\n", argv[0] );
  78. exit( 1 );
  79. }
  80. if(FAILED(hr = ::CoInitializeEx( NULL, COINIT_MULTITHREADED )))
  81. {
  82. wprintf( L"No COM!!\n" );
  83. exit(2);
  84. }
  85. MPC::SubstituteEnvVariables( szFileIn = argv[1] );
  86. MPC::SubstituteEnvVariables( szFileOut = argv[2] );
  87. if(FAILED(hr = ExpandAndProcessHHK( szFileIn.c_str(), szFileOut.c_str() )))
  88. {
  89. wprintf( L"Failed to process %s: %08x\n", argv[1], hr );
  90. exit(3);
  91. }
  92. ::CoUninitialize();
  93. return 0;
  94. }