BOOL XFile::WriteAsUTF8(CTSTR lpBuffer, DWORD dwElements) { DWORD retVal = 0; if(!lpBuffer) return false; if (!hFile) return false; if (!lpBuffer[0]) return true; if(!dwElements) dwElements = slen(lpBuffer); #ifdef UNICODE DWORD dwBytes = (DWORD)wchar_to_utf8_len(lpBuffer, dwElements, 0); LPSTR lpDest = (LPSTR)Allocate(dwBytes+1); if (wchar_to_utf8(lpBuffer, dwElements, lpDest, dwBytes, 0)) retVal = (Write(lpDest, dwBytes) == dwBytes); else Log(TEXT("XFile::WriteAsUTF8: wchar_to_utf8 failed: %d"), GetLastError()); Free(lpDest); #else DWORD retVal = (Write(lpBuffer, dwElements) == dwBytes); #endif return retVal; }
DWORD XFile::WriteAsUTF8(CTSTR lpBuffer, DWORD dwElements) { traceInFast(XFile::WriteAsUTF8); if(!lpBuffer) return 0; if(!hFile) return XFILE_ERROR; if(!dwElements) dwElements = slen(lpBuffer); DWORD dwBytes = (DWORD)wchar_to_utf8_len(lpBuffer, dwElements, 0); LPSTR lpDest = (LPSTR)Allocate(dwBytes+1); wchar_to_utf8(lpBuffer, dwElements, lpDest, dwBytes, 0); DWORD retVal = Write(lpDest, dwBytes); Free(lpDest); return retVal; traceOutFast; }
String::String(CWSTR str) { #ifdef UNICODE if(!str) { curLength = 0; lpString = NULL; return; } curLength = slen(str); if(curLength) { lpString = (TSTR)Allocate((curLength+1)*sizeof(TCHAR)); scpy(lpString, str); } else lpString = NULL; #else if(!str) { curLength = 0; lpString = NULL; return; } size_t wideLen = wcslen(str); curLength = (UINT)wchar_to_utf8_len(str, wideLen, 0); if(curLength) { lpString = (TSTR)Allocate(curLength+1); wchar_to_utf8(str, wideLen+1, lpString, curLength+1, 0); } else lpString = NULL; #endif }
json_t* json_string_wchar(CTSTR str) { if(!str) { return NULL; } size_t wcharLen = slen(str); size_t curLength = (UINT)wchar_to_utf8_len(str, wcharLen, 0); if(curLength) { char *out = (char *) malloc((curLength+1)); wchar_to_utf8(str,wcharLen, out, curLength + 1, 0); out[curLength] = 0; json_t* ret = json_string(out); free(out); return ret; } else { return NULL; } }
INT_PTR CALLBACK ConfigDialogProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static bool edited = false; switch(message) { case WM_INITDIALOG: { Config* _config = getRemoteConfig(); HWND checkBox = GetDlgItem(hwnd, ID_USEPASSWORDAUTH); SendMessage(checkBox, BM_SETCHECK, (_config->useAuth)?BST_CHECKED:BST_UNCHECKED, 0); HWND editBox = GetDlgItem(hwnd, IDC_AUTH_EDIT); EnableWindow(editBox, _config->useAuth); SetWindowText(editBox, DEFAULT_PASS_TEXT); HWND okButton = GetDlgItem(hwnd, IDOK); EnableWindow(okButton, false); edited = false; } case WM_COMMAND: switch(LOWORD(wParam)) { case IDOK: { TCHAR buff[1024]; HWND editBox = GetDlgItem(hwnd, IDC_AUTH_EDIT); GetWindowText(editBox, buff, 1024); HWND checkBox = GetDlgItem(hwnd, ID_USEPASSWORDAUTH); bool useAuth = SendMessage(checkBox, BM_GETCHECK, 0, 0) == BST_CHECKED; Config* _config = getRemoteConfig(); if(!useAuth || edited) { size_t wcharLen = slen(buff); size_t curLength = (UINT)wchar_to_utf8_len(buff, wcharLen, 0); char *utf8Pass = (char *) malloc((curLength+1)); wchar_to_utf8(buff,wcharLen, utf8Pass, curLength + 1, 0); utf8Pass[curLength] = 0; Config* _config = getRemoteConfig(); _config->setAuth(useAuth, utf8Pass); _config->save(getPluginConfigPath()); free(utf8Pass); } edited = false; EndDialog(hwnd, LOWORD(wParam)); } break; case IDCANCEL: EndDialog(hwnd, LOWORD(wParam)); break; case ID_USEPASSWORDAUTH: { if(HIWORD(wParam) == BN_CLICKED) { bool useAuth = SendMessage((HWND)lParam, BM_GETCHECK, 0, 0) == BST_CHECKED; HWND editBox = GetDlgItem(hwnd, IDC_AUTH_EDIT); EnableWindow(editBox, useAuth); HWND okButton = GetDlgItem(hwnd, IDOK); EnableWindow(okButton, (edited && useAuth) || (!useAuth && useAuth != getRemoteConfig()->useAuth)); } } break; case IDC_AUTH_EDIT: { if(HIWORD(wParam) == EN_CHANGE) { if(!edited) { edited = true; HWND okButton = GetDlgItem(hwnd, IDOK); EnableWindow(okButton, true); } } break; } } break; case WM_CLOSE: EndDialog(hwnd, IDCANCEL); break; } return 0; };