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.

190 lines
4.0 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 szFile )
  15. {
  16. __HCP_FUNC_ENTRY( "ProcessHHK" );
  17. USES_CONVERSION;
  18. HRESULT hr;
  19. HHK::Merger::FileEntity ent( szFile );
  20. MPC::string szTitle;
  21. __MPC_EXIT_IF_METHOD_FAILS(hr, ent.Init());
  22. while(ent.MoveNext() == true)
  23. {
  24. HHK::Section* sec = ent.GetSection();
  25. HHK::Section::EntryIter it;
  26. if(szTitle.size() && HHK::Reader::StrColl( sec->m_szTitle.c_str(), szTitle.c_str() ) < 0)
  27. {
  28. wprintf( L"Keyword out of order: '%s' after '%s'\n", A2W( sec->m_szTitle.c_str() ), A2W( szTitle.c_str() ) );
  29. }
  30. if(szTitle.size() && HHK::Reader::StrColl( sec->m_szTitle.c_str(), szTitle.c_str() ) == 0)
  31. {
  32. wprintf( L"Duplicate Keyword: '%s'\n", A2W( sec->m_szTitle.c_str() ) );
  33. }
  34. szTitle = sec->m_szTitle.c_str();
  35. for(it = sec->m_lstEntries.begin(); it != sec->m_lstEntries.end(); it++)
  36. {
  37. HHK::Entry& entry = *it;
  38. if(entry.m_szTitle.size() == 0)
  39. {
  40. wprintf( L"Keyword with an empty title: '%s'\n", A2W( sec->m_szTitle.c_str() ) );
  41. }
  42. if(entry.m_lstUrl.size() == 0)
  43. {
  44. wprintf( L"Keyword with a title but not URL: '%s' => '%s' \n", A2W( sec->m_szTitle.c_str() ), A2W( entry.m_szTitle.c_str() ) );
  45. }
  46. }
  47. }
  48. hr = S_OK;
  49. __HCP_FUNC_CLEANUP;
  50. __HCP_FUNC_EXIT(hr);
  51. }
  52. void ExtractHhkName( MPC::wstring& szFullName,
  53. LPCWSTR szFileName )
  54. {
  55. LPCWSTR szEnd;
  56. LPCWSTR szEnd2;
  57. if((szEnd = wcsrchr( szFileName, '\\' )) &&
  58. (szEnd2 = wcsrchr( szEnd , '.' )) )
  59. {
  60. MPC::wstring szTmp;
  61. szTmp = L"ms-its:";
  62. szTmp += szFileName;
  63. szTmp += L"::/";
  64. szTmp += MPC::wstring( szEnd+1, szEnd2 );
  65. szTmp += L".hhk";
  66. szFullName = szTmp;
  67. }
  68. else
  69. {
  70. szFullName = szFileName;
  71. }
  72. }
  73. HRESULT ExpandAndProcessHHK( LPCWSTR szFile )
  74. {
  75. __HCP_FUNC_ENTRY( "ExpandAndProcessHHK" );
  76. HRESULT hr;
  77. MPC::wstring szFileName;
  78. if(MPC::MSITS::IsCHM( szFile ) == false && StrStrIW( szFile, L".hhk" ) == NULL)
  79. {
  80. ExtractHhkName( szFileName, szFile );
  81. }
  82. else
  83. {
  84. szFileName = szFile;
  85. }
  86. wprintf( L"Processing '%s'...\n", szFileName.c_str() );
  87. hr = ProcessHHK( szFileName.c_str() );
  88. __HCP_FUNC_EXIT(hr);
  89. }
  90. /////////////////////////////////////////////////////////////////////////////
  91. //
  92. int __cdecl wmain( int argc ,
  93. LPCWSTR argv[] )
  94. {
  95. HRESULT hr;
  96. MPC::wstring szFile;
  97. if(argc < 2)
  98. {
  99. wprintf( L"Usage: %s <file to analyze>\n", argv[0] );
  100. exit( 1 );
  101. }
  102. if(FAILED(hr = ::CoInitializeEx( NULL, COINIT_MULTITHREADED )))
  103. {
  104. wprintf( L"No COM!!\n" );
  105. exit(2);
  106. }
  107. MPC::SubstituteEnvVariables( szFile = argv[1] );
  108. {
  109. MPC::FileSystemObject fso( szFile.c_str() );
  110. if(fso.IsDirectory())
  111. {
  112. MPC::FileSystemObject::List lst;
  113. MPC::FileSystemObject::Iter it;
  114. if(FAILED(hr = fso.EnumerateFiles( lst )))
  115. {
  116. wprintf( L"Failed to read directory %s: %08x\n", szFile.c_str(), hr );
  117. exit(2);
  118. }
  119. for(it=lst.begin(); it!=lst.end(); it++)
  120. {
  121. MPC::wstring szSubFile;
  122. (*it)->get_Path( szSubFile );
  123. if(StrStrIW( szSubFile.c_str(), L".chm" ))
  124. {
  125. (void)ExpandAndProcessHHK( szSubFile.c_str() );
  126. }
  127. }
  128. }
  129. else
  130. {
  131. if(FAILED(hr = ExpandAndProcessHHK( szFile.c_str() )))
  132. {
  133. wprintf( L"Failed to process %s: %08x\n", argv[1], hr );
  134. exit(3);
  135. }
  136. }
  137. }
  138. ::CoUninitialize();
  139. return 0;
  140. }