Unicode bugfixes

This commit is contained in:
NtQuery 2014-03-13 21:06:51 +01:00
parent 7d3ebc9405
commit b57abe7775
1 changed files with 31 additions and 10 deletions

View File

@ -19,6 +19,7 @@ static TCHAR FileNameIni[MAX_PATH] = {};
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 AddLogMessage(const char* 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);
static bool FileExists(LPCTSTR szPath); static bool FileExists(LPCTSTR szPath);
@ -81,11 +82,11 @@ INT_PTR CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
//make sure TitanScript is available //make sure TitanScript is available
if ( !ExtensionManagerIsPluginLoaded( "TitanScript" ) || !ExtensionManagerIsPluginEnabled( "TitanScript" ) ) if ( !ExtensionManagerIsPluginLoaded( "TitanScript" ) || !ExtensionManagerIsPluginEnabled( "TitanScript" ) )
{ {
AddLogMessage("TitanScript failed to load", TS_LOG_ERROR); AddLogMessageW(L"TitanScript failed to load", TS_LOG_ERROR);
#ifdef _WIN64 #ifdef _WIN64
AddLogMessage("Ensure plugins\\x64\\TitanScript.dll exists !", TS_LOG_ERROR); AddLogMessageW(L"Ensure plugins\\x64\\TitanScript.dll exists !", TS_LOG_ERROR);
#else #else
AddLogMessage("Ensure plugins\\x86\\TitanScript.dll exists !", TS_LOG_ERROR); AddLogMessageW(L"Ensure plugins\\x86\\TitanScript.dll exists !", TS_LOG_ERROR);
#endif //_WIN64 #endif //_WIN64
EnableWindow(GetDlgItem(hWnd, IDC_RUN ), FALSE); EnableWindow(GetDlgItem(hWnd, IDC_RUN ), FALSE);
} }
@ -211,12 +212,32 @@ static bool GetFileDialog(TCHAR Buffer[MAX_PATH])
return (TRUE == GetOpenFileName(&sOpenFileName)); return (TRUE == GetOpenFileName(&sOpenFileName));
} }
static void AddLogMessageW(const wchar_t* szLogMessage, eLogType Type)
{
LRESULT cSelect = SendMessage(hLogBox, LB_INSERTSTRING, (WPARAM)-1, (LPARAM)szLogMessage);
if (cSelect == LB_ERR)
{
MessageBoxW(0, L"ERROR LOG MESSAGE - LB_INSERTSTRING", L"ERROR", MB_ICONWARNING);
} else if (cSelect == LB_ERRSPACE)
{
MessageBoxW(0, L"ERROR LOG MESSAGE - LB_ERRSPACE - Not enough space!", L"ERROR", MB_ICONWARNING);
}
else
{
SendMessage(hLogBox, LB_SETCURSEL, cSelect, NULL);
}
}
static void AddLogMessage(const char* szLogMessage, eLogType Type) static void AddLogMessage(const char* szLogMessage, eLogType Type)
{ {
TCHAR buf[MAX_LOG_LINE_LENGTH] = {0}; TCHAR * buf = (TCHAR *)calloc(strlen(szLogMessage) + 1, sizeof(TCHAR));
mbstowcs(buf, szLogMessage, _countof(buf)); if (buf)
LRESULT cSelect = SendMessage(hLogBox, LB_INSERTSTRING, (WPARAM)-1, (LPARAM)buf); {
SendMessage(hLogBox, LB_SETCURSEL, cSelect, NULL); mbstowcs(buf, szLogMessage, strlen(szLogMessage) + 1);
AddLogMessageW(buf, Type);
free(buf);
}
} }
static void SettingSet(const TCHAR* name, const TCHAR* value) static void SettingSet(const TCHAR* name, const TCHAR* value)
@ -253,17 +274,17 @@ static DWORD WINAPI TitanScriptExecThread(LPVOID lpParam)
{ {
if(!load_file(FileNameScript)) if(!load_file(FileNameScript))
{ {
AddLogMessage("Script failed to load", TS_LOG_ERROR); AddLogMessageW(L"Script failed to load", TS_LOG_ERROR);
return 0; return 0;
} }
SetWindowText(hRunBtn, _T("Stop")); SetWindowText(hRunBtn, _T("Stop"));
bRunning = true; bRunning = true;
if(!exec(FileNameTarget, L"")) //TitanScript will generate the output filename if(!exec(FileNameTarget, L"")) //TitanScript will generate the output filename
{ {
AddLogMessage("Failed to execute", TS_LOG_ERROR); AddLogMessageW(L"Failed to execute", TS_LOG_ERROR);
} }
else else
AddLogMessage("Debugging stopped", TS_LOG_NORMAL); AddLogMessageW(L"Debugging stopped", TS_LOG_NORMAL);
bRunning = false; bRunning = false;
SetWindowText(hRunBtn, _T("Run")); SetWindowText(hRunBtn, _T("Run"));
return 0; return 0;