ApiLog.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //---------------------------------------------------------------------------
  2. #include "FileZillaPCH.h"
  3. #include "ApiLog.h"
  4. //////////////////////////////////////////////////////////////////////
  5. // Konstruktion/Destruktion
  6. //////////////////////////////////////////////////////////////////////
  7. CApiLog::CApiLog()
  8. {
  9. FIntern = NULL;
  10. }
  11. CApiLog::~CApiLog()
  12. {
  13. }
  14. void CApiLog::InitIntern(TFileZillaIntern * Intern)
  15. {
  16. FIntern = Intern;
  17. }
  18. TFileZillaIntern * CApiLog::GetIntern()
  19. {
  20. return FIntern;
  21. }
  22. bool CApiLog::LoggingMessageType(int nMessageType) const
  23. {
  24. return
  25. (nMessageType < FZ_LOG_APIERROR) ||
  26. ((nMessageType-FZ_LOG_APIERROR) < FIntern->GetDebugLevel());
  27. }
  28. void CApiLog::LogMessage(int nMessageType, LPCTSTR pMsgFormat, ...) const
  29. {
  30. DebugAssert(nMessageType>=FZ_LOG_STATUS && nMessageType<=FZ_LOG_DEBUG);
  31. if (!LoggingMessageType(nMessageType))
  32. return;
  33. va_list ap;
  34. va_start(ap, pMsgFormat);
  35. CString text;
  36. text.FormatV(pMsgFormat, ap);
  37. va_end(ap);
  38. if (nMessageType>=FZ_LOG_DEBUG)
  39. return;
  40. SendLogMessage(nMessageType, text);
  41. }
  42. void CApiLog::LogMessageRaw(int nMessageType, LPCTSTR pMsg) const
  43. {
  44. DebugAssert(nMessageType>=FZ_LOG_STATUS && nMessageType<=FZ_LOG_DEBUG);
  45. if (!LoggingMessageType(nMessageType))
  46. return;
  47. if (nMessageType>=FZ_LOG_DEBUG)
  48. return;
  49. SendLogMessage(nMessageType, pMsg);
  50. }
  51. void CApiLog::SendLogMessage(int nMessageType, LPCTSTR pMsg) const
  52. {
  53. if (!LoggingMessageType(nMessageType))
  54. return;
  55. //Displays a message in the message log
  56. t_ffam_statusmessage *pStatus = new t_ffam_statusmessage;
  57. pStatus->post = TRUE;
  58. pStatus->status = pMsg;
  59. pStatus->type = nMessageType;
  60. if (!FIntern->PostMessage(FZ_MSG_MAKEMSG(FZ_MSG_STATUS, 0), (LPARAM)pStatus))
  61. delete pStatus;
  62. }
  63. CString CApiLog::GetOption(int OptionID) const
  64. {
  65. DebugAssert(FIntern != NULL);
  66. return FIntern->GetOption(OptionID);
  67. }
  68. int CApiLog::GetOptionVal(int OptionID) const
  69. {
  70. DebugAssert(FIntern != NULL);
  71. return FIntern->GetOptionVal(OptionID);
  72. }
  73. void CApiLog::LogError(int Error)
  74. {
  75. wchar_t * Buffer;
  76. int Len = FormatMessage(
  77. FORMAT_MESSAGE_FROM_SYSTEM |
  78. FORMAT_MESSAGE_IGNORE_INSERTS |
  79. FORMAT_MESSAGE_ARGUMENT_ARRAY |
  80. FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, Error, 0, (LPTSTR)&Buffer, 0, NULL);
  81. if (Len > 0)
  82. {
  83. LogMessageRaw(FZ_LOG_ERROR, Buffer);
  84. LocalFree(Buffer);
  85. }
  86. }