diff --git a/Scylla/Logger.cpp b/Scylla/Logger.cpp index f25d7d3..1b2ab15 100644 --- a/Scylla/Logger.cpp +++ b/Scylla/Logger.cpp @@ -1,112 +1,99 @@ #include "Logger.h" #include +//#include +#include +#include #include -#include - -WCHAR Logger::logbuf[300]; -char Logger::logbufChar[300]; void Logger::log(const WCHAR * format, ...) { - if (!format) - { - return; - } + static WCHAR buf[300]; - //ZeroMemory(logbuf, sizeof(logbuf)); + if(!format) + return; va_list va_alist; va_start (va_alist, format); - _vsnwprintf_s(logbuf, _countof(logbuf), _countof(logbuf) - 1, format, va_alist); + _vsnwprintf_s(buf, _countof(buf) - 1, format, va_alist); va_end (va_alist); - write(logbuf); + write(buf); } void Logger::log(const char * format, ...) { - if (!format) - { - return; - } + static char buf[300]; - //ZeroMemory(logbufChar, sizeof(logbufChar)); + if(!format) + return; va_list va_alist; va_start (va_alist, format); - _vsnprintf_s(logbufChar, _countof(logbufChar), _countof(logbufChar) - 1, format, va_alist); + _vsnprintf_s(buf, _countof(buf) - 1, format, va_alist); va_end (va_alist); - write(logbufChar); + write(buf); } void Logger::write(const CHAR * str) { - size_t len = strlen(str) + 1; - WCHAR * buf = new WCHAR[len]; - - size_t convertedChars = 0; - mbstowcs_s(&convertedChars, buf, len, str, _TRUNCATE); - - write(buf); - - delete[] buf; + write(ATL::CA2W(str)); } FileLog::FileLog(const WCHAR * fileName) { GetModuleFileName(0, this->filePath, _countof(this->filePath)); PathRemoveFileSpec(this->filePath); PathAppend(this->filePath, fileName); } void FileLog::write(const CHAR * str) { /* std::wofstream file(filePath, std::wofstream::app); if(!file.fail()) { file << str << std::endl; } */ - FILE * pFile; + FILE * pFile = 0; if (_wfopen_s(&pFile, filePath, L"a") == 0) { fputs(str, pFile); fputs("\r\n", pFile); fclose(pFile); } } void FileLog::write(const WCHAR * str) { /* std::wofstream file(filePath, std::wofstream::app); if(!file.fail()) { file << str << std::endl; } */ - FILE * pFile; + FILE * pFile = 0; if (_wfopen_s(&pFile, filePath, L"a") == 0) { fputws(str, pFile); fputws(L"\r\n", pFile); fclose(pFile); } } void ListboxLog::setWindow(HWND window) { this->window = window; } -void ListboxLog::write(const WCHAR * str) +void ListboxLog::write(const WCHAR* str) { LRESULT index = SendMessageW(window, LB_ADDSTRING, 0, reinterpret_cast(str)); SendMessage(window, LB_SETCURSEL, index, 0); UpdateWindow(window); } diff --git a/Scylla/Logger.h b/Scylla/Logger.h index a4f22e8..f2f3bc5 100644 --- a/Scylla/Logger.h +++ b/Scylla/Logger.h @@ -1,53 +1,47 @@ - #pragma once #include class Logger { public: virtual void log(const WCHAR * format, ...); virtual void log(const CHAR * format, ...); protected: virtual void write(const WCHAR * str) = 0; virtual void write(const CHAR * str); - -private: - - static WCHAR logbuf[300]; - static char logbufChar[300]; }; class FileLog : public Logger { public: FileLog(const WCHAR * fileName); private: void write(const WCHAR * str); void write(const CHAR * str); WCHAR filePath[MAX_PATH]; }; class ListboxLog : public Logger { public: ListboxLog() : window(0) { } ListboxLog(HWND window); void setWindow(HWND window); private: void write(const WCHAR * str); //void write(const CHAR * str); HWND window; };