This commit is contained in:
Birunthan Mohanathas 2012-05-29 19:43:24 +03:00
parent 902e734e62
commit f20170406e
4 changed files with 25 additions and 27 deletions

View File

@ -277,19 +277,19 @@ void Log(int nLevel, const WCHAR* message)
void LogWithArgs(int nLevel, const WCHAR* format, ...) void LogWithArgs(int nLevel, const WCHAR* format, ...)
{ {
WCHAR* buffer = new WCHAR[4096]; WCHAR* buffer = new WCHAR[1024];
va_list args; va_list args;
va_start( args, format ); va_start(args, format);
_invalid_parameter_handler oldHandler = _set_invalid_parameter_handler(RmNullCRTInvalidParameterHandler); _invalid_parameter_handler oldHandler = _set_invalid_parameter_handler(RmNullCRTInvalidParameterHandler);
_CrtSetReportMode(_CRT_ASSERT, 0); _CrtSetReportMode(_CRT_ASSERT, 0);
errno = 0; errno = 0;
_vsnwprintf_s(buffer, 4096, _TRUNCATE, format, args); _vsnwprintf_s(buffer, 1024, _TRUNCATE, format, args);
if (errno != 0) if (errno != 0)
{ {
nLevel = LOG_ERROR; nLevel = LOG_ERROR;
_snwprintf_s(buffer, 4096, _TRUNCATE, L"LogWithArgs internal error: %s", format); _snwprintf_s(buffer, 1024, _TRUNCATE, L"Internal error: %s", format);
} }
_set_invalid_parameter_handler(oldHandler); _set_invalid_parameter_handler(oldHandler);

View File

@ -254,7 +254,7 @@ const WCHAR* CMeasure::CheckSubstitute(const WCHAR* buffer)
if (re == NULL) if (re == NULL)
{ {
MakePlainSubstitute(str, i); MakePlainSubstitute(str, i);
Log(LOG_NOTICE, ConvertToWide(error).c_str()); LogWithArgs(LOG_NOTICE, L"%S", error);
} }
else else
{ {

View File

@ -205,37 +205,34 @@ void CMeasureNet::UpdateIFTable()
for (size_t i = 0; i < c_NumOfTables; ++i) for (size_t i = 0; i < c_NumOfTables; ++i)
{ {
std::string desc((char*)ifTable->table[i].bDescr, ifTable->table[i].dwDescrLen); const WCHAR* type = L"";
std::wstring type;
switch (ifTable->table[i].dwType) switch (ifTable->table[i].dwType)
{ {
case IF_TYPE_ETHERNET_CSMACD: case IF_TYPE_ETHERNET_CSMACD:
type += L"Ethernet"; type = L"Ethernet";
break; break;
case IF_TYPE_PPP: case IF_TYPE_PPP:
type += L"PPP"; type = L"PPP";
break; break;
case IF_TYPE_SOFTWARE_LOOPBACK: case IF_TYPE_SOFTWARE_LOOPBACK:
type += L"Loopback"; type = L"Loopback";
break; break;
case IF_TYPE_IEEE80211: case IF_TYPE_IEEE80211:
type += L"IEEE802.11"; type = L"IEEE802.11";
break; break;
case IF_TYPE_TUNNEL: case IF_TYPE_TUNNEL:
type += L"Tunnel"; type = L"Tunnel";
break; break;
case IF_TYPE_IEEE1394: case IF_TYPE_IEEE1394:
type += L"IEEE1394"; type = L"IEEE1394";
break; break;
default: default:
type += L"Other"; type = L"Other";
break; break;
} }
LogWithArgs(LOG_DEBUG, L"%i: %s", (int)i + 1, ConvertToWide(desc.c_str()).c_str()); LogWithArgs(LOG_DEBUG, L"%i: %.*S", (int)i + 1, ifTable->table[i].dwDescrLen, (char*)ifTable->table[i].bDescr);
LogWithArgs(LOG_DEBUG, L" Type=%s(%i)", LogWithArgs(LOG_DEBUG, L" Type=%s(%i)", type, ifTable->table[i].dwType);
type.c_str(), ifTable->table[i].dwType);
} }
Log(LOG_DEBUG, L"------------------------------"); Log(LOG_DEBUG, L"------------------------------");
} }

View File

@ -76,21 +76,22 @@ void LuaManager::Finalize()
void LuaManager::ReportErrors(lua_State* L) void LuaManager::ReportErrors(lua_State* L)
{ {
std::string error = lua_tostring(L, -1); const char* error = lua_tostring(L, -1);
lua_pop(L, 1); lua_pop(L, 1);
const char* pos = error + 4; // Skip the drive
// Get rid of everything up to the filename // Get rid of everything up to the filename
std::string::size_type pos = 4; // Skip the drive while (*pos != ':')
pos = error.find_first_of(':', pos);
pos = error.find_last_of('\\', pos);
if (pos != std::string::npos)
{ {
error.erase(0, ++pos); if (*pos == '\\')
{
error = pos + 1;
}
++pos;
} }
std::wstring str = L"Script: "; LogWithArgs(LOG_ERROR, L"Script: %S", error);
str += ConvertToWide(error.c_str());
Log(LOG_ERROR, str.c_str());
} }
void LuaManager::PushWide(lua_State* L, const WCHAR* str) void LuaManager::PushWide(lua_State* L, const WCHAR* str)