unicode logger

This commit is contained in:
NtQuery 2014-03-14 21:03:53 +01:00
parent 55ace2599b
commit 2dc709b487
2 changed files with 18 additions and 35 deletions

View File

@ -9,6 +9,7 @@
enum eLogType {TS_LOG_NORMAL, TS_LOG_ERROR, TS_LOG_COMMAND, TS_LOG_DEBUG}; enum eLogType {TS_LOG_NORMAL, TS_LOG_ERROR, TS_LOG_COMMAND, TS_LOG_DEBUG};
typedef void(*fLogCallback)(const char* szString, eLogType Type); typedef void(*fLogCallback)(const char* szString, eLogType Type);
typedef void(*fLogCallbackW)(const wchar_t* szString, eLogType Type);
typedef bool (*tScripterLoadFileA)(const char*); typedef bool (*tScripterLoadFileA)(const char*);
typedef bool (*tScripterLoadFileW)(const wchar_t*); typedef bool (*tScripterLoadFileW)(const wchar_t*);
@ -18,6 +19,7 @@ typedef bool (*tScripterPause)();
typedef bool (*tScripterAutoDebugA)(const char*); typedef bool (*tScripterAutoDebugA)(const char*);
typedef bool (*tScripterAutoDebugW)(const wchar_t*); typedef bool (*tScripterAutoDebugW)(const wchar_t*);
typedef void (*tScripterSetLogCallback)(fLogCallback Callback); typedef void (*tScripterSetLogCallback)(fLogCallback Callback);
typedef void (*tScripterSetLogCallbackW)(fLogCallbackW Callback);
typedef bool (*tScripterExecuteWithTitanMistA)(const char*, const char*); typedef bool (*tScripterExecuteWithTitanMistA)(const char*, const char*);
typedef bool (*tScripterExecuteWithTitanMistW)(const wchar_t*, const wchar_t*); typedef bool (*tScripterExecuteWithTitanMistW)(const wchar_t*, const wchar_t*);

View File

@ -24,7 +24,6 @@ static TCHAR FileNameIni[MAX_PATH] = {};
//functions //functions
static INT_PTR CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); static INT_PTR CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
static bool GetFileDialog(TCHAR[MAX_PATH]); static bool GetFileDialog(TCHAR[MAX_PATH]);
static void AddLogMessage(const char* szLogMessage, eLogType Type);
static void AddLogMessageW(const wchar_t* szLogMessage, eLogType Type); static void AddLogMessageW(const wchar_t* szLogMessage, eLogType Type);
static void SettingSet(const TCHAR* name, const TCHAR* value); static void SettingSet(const TCHAR* name, const TCHAR* value);
static void SettingGet(const TCHAR* name, TCHAR* value, int value_size); static void SettingGet(const TCHAR* name, TCHAR* value, int value_size);
@ -35,7 +34,7 @@ static DWORD WINAPI TitanScriptExecThread(LPVOID lpParam);
//TitanScript functions //TitanScript functions
static tScripterLoadFileW load_file = NULL; static tScripterLoadFileW load_file = NULL;
static tScripterExecuteWithTitanMistW exec = NULL; static tScripterExecuteWithTitanMistW exec = NULL;
static tScripterSetLogCallback set_log_callback = NULL; static tScripterSetLogCallbackW set_log_callback = NULL;
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{ {
@ -102,8 +101,8 @@ INT_PTR CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{ {
load_file = GetTSFunctionPointer( LoadFileW ); load_file = GetTSFunctionPointer( LoadFileW );
exec = GetTSFunctionPointer( ExecuteWithTitanMistW ); exec = GetTSFunctionPointer( ExecuteWithTitanMistW );
set_log_callback = GetTSFunctionPointer( SetLogCallback ); set_log_callback = GetTSFunctionPointer( SetLogCallbackW );
set_log_callback(&AddLogMessage); set_log_callback(&AddLogMessageW);
} }
break; break;
@ -241,17 +240,20 @@ static bool GetFileDialog(TCHAR Buffer[MAX_PATH])
static void AddLogMessageW(const wchar_t* szLogMessage, eLogType Type) static void AddLogMessageW(const wchar_t* szLogMessage, eLogType Type)
{ {
LRESULT cSelect = SendMessage(hLogBox, LB_INSERTSTRING, (WPARAM)-1, (LPARAM)szLogMessage); if (wcslen(szLogMessage) > 0)
if (cSelect == LB_ERR)
{ {
MessageBoxW(0, L"ERROR LOG MESSAGE - LB_INSERTSTRING", L"ERROR", MB_ICONWARNING); LRESULT cSelect = SendMessage(hLogBox, LB_INSERTSTRING, (WPARAM)-1, (LPARAM)szLogMessage);
} else if (cSelect == LB_ERRSPACE) if (cSelect == LB_ERR)
{ {
MessageBoxW(0, L"ERROR LOG MESSAGE - LB_ERRSPACE - Not enough space!", L"ERROR", MB_ICONWARNING); MessageBoxW(0, L"ERROR LOG MESSAGE - LB_INSERTSTRING", L"ERROR", MB_ICONWARNING);
} } else if (cSelect == LB_ERRSPACE)
else {
{ MessageBoxW(0, L"ERROR LOG MESSAGE - LB_ERRSPACE - Not enough space!", L"ERROR", MB_ICONWARNING);
SendMessage(hLogBox, LB_SETCURSEL, cSelect, NULL); }
else
{
SendMessage(hLogBox, LB_SETCURSEL, cSelect, NULL);
}
} }
} }
@ -271,27 +273,6 @@ static bool IsValidChar(char s)
} }
} }
static void AddLogMessage(const char* szLogMessage, eLogType Type)
{
if (strlen(szLogMessage) > 0)
{
if (IsValidChar(szLogMessage[0]))
{
TCHAR * buf = (TCHAR *)calloc(strlen(szLogMessage) + 1, sizeof(TCHAR));
if (buf)
{
mbstowcs(buf, szLogMessage, strlen(szLogMessage) + 1);
AddLogMessageW(buf, Type);
free(buf);
}
}
else
{
AddLogMessageW(L"ERROR INVALID LOG MESSAGE", Type);
}
}
}
static void SettingSet(const TCHAR* name, const TCHAR* value) static void SettingSet(const TCHAR* name, const TCHAR* value)
{ {
WritePrivateProfileString(_T("Settings"), name, value, FileNameIni); WritePrivateProfileString(_T("Settings"), name, value, FileNameIni);