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.

95 lines
1.7 KiB

  1. // Active Directory Display Specifier Upgrade Tool
  2. //
  3. // Copyright (c) 2001 Microsoft Corporation
  4. //
  5. // class Amanuensis, records a log of the analysis phase
  6. //
  7. // 8 Mar 2001 sburns
  8. #include "headers.hxx"
  9. #include <iostream>
  10. #include "Amanuensis.hpp"
  11. #include "resource.h"
  12. Amanuensis::Amanuensis(int outputInterval_)
  13. :
  14. outputInterval(outputInterval_)
  15. {
  16. LOG_CTOR(Amanuensis);
  17. lastOutput = entries.begin();
  18. }
  19. void
  20. Amanuensis::AddEntry(const String& entry)
  21. {
  22. LOG_FUNCTION2(Amanuensis::AddEntry, entry);
  23. // empty entries are ok, these are treated as newlines.
  24. // insert the new entry at the end of the list.
  25. StringList::iterator last =
  26. entries.insert(entries.end(), entry + L"\r\n");
  27. if (outputInterval && !(entries.size() % outputInterval))
  28. {
  29. Flush();
  30. }
  31. }
  32. void
  33. Amanuensis::AddErrorEntry(HRESULT hr, int stringResId)
  34. {
  35. LOG_FUNCTION(Amanuensis::AddErrorEntry);
  36. ASSERT(FAILED(hr));
  37. ASSERT(stringResId);
  38. AddErrorEntry(hr, String::load(stringResId));
  39. }
  40. void
  41. Amanuensis::AddErrorEntry(HRESULT hr, const String& message)
  42. {
  43. LOG_FUNCTION(Amanuensis::AddErrorEntry);
  44. ASSERT(FAILED(hr));
  45. ASSERT(!message.empty());
  46. AddEntry(
  47. String::format(
  48. IDS_ERROR_ENTRY,
  49. message.c_str(),
  50. GetErrorMessage(hr).c_str()));
  51. }
  52. void
  53. Amanuensis::Flush()
  54. {
  55. LOG_FUNCTION(Amanuensis::Flush);
  56. // output all entries since the last entry that we output.
  57. while (lastOutput != entries.end())
  58. {
  59. AnsiString ansi;
  60. lastOutput->convert(ansi);
  61. // CODEWORK: here we're just dumping to the console, but we might want
  62. // an abstraction of the output...
  63. std::cout << ansi;
  64. ++lastOutput;
  65. }
  66. }