diff options
author | Kirill Volinsky <mataes2007@gmail.com> | 2015-05-17 17:25:51 +0000 |
---|---|---|
committer | Kirill Volinsky <mataes2007@gmail.com> | 2015-05-17 17:25:51 +0000 |
commit | 6cd9de08e7748f894d14ce1947fcd8086ad0c175 (patch) | |
tree | bfea4a74a08bc05a9a377cbd06e75b9f07066c52 /plugins/PasteIt/src/PasteToWeb.cpp | |
parent | fef36df7c49e5cbfade4ff83a1115cac7ef2b82a (diff) |
cleanup
git-svn-id: http://svn.miranda-ng.org/main/trunk@13665 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/PasteIt/src/PasteToWeb.cpp')
-rw-r--r-- | plugins/PasteIt/src/PasteToWeb.cpp | 436 |
1 files changed, 217 insertions, 219 deletions
diff --git a/plugins/PasteIt/src/PasteToWeb.cpp b/plugins/PasteIt/src/PasteToWeb.cpp index 92e84798ff..b674d55173 100644 --- a/plugins/PasteIt/src/PasteToWeb.cpp +++ b/plugins/PasteIt/src/PasteToWeb.cpp @@ -46,62 +46,62 @@ struct FromFileData bool sendFileName;
};
-INT_PTR CALLBACK DlgProcFromClipboard(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
+INT_PTR CALLBACK DlgProcFromClipboard(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
- switch (msg)
+ switch (msg)
{
- case WM_INITDIALOG:
+ case WM_INITDIALOG:
+ {
+ TranslateDialogDefault(hwndDlg);
+ FromClipboardData* data = (FromClipboardData*)lParam;
+ SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
+ int ts = 4;
+ Edit_SetTabStops(GetDlgItem(hwndDlg, IDC_CLIPBOARD_DATA), 1, &ts);
+ SetDlgItemText(hwndDlg, IDC_CLIPBOARD_DATA, data->content.c_str());
+ int sel = 0;
+ int i = 0;
+ std::wstring &defFormat = Options::instance->webOptions[data->page]->defFormatId;
+ HWND cb = GetDlgItem(hwndDlg, IDC_FORMAT);
+ for (std::list<PasteFormat>::iterator it = Options::instance->webOptions[data->page]->formats.begin(); it != Options::instance->webOptions[data->page]->formats.end(); ++it)
{
- TranslateDialogDefault(hwndDlg);
- FromClipboardData* data = (FromClipboardData*)lParam;
- SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
- int ts = 4;
- Edit_SetTabStops(GetDlgItem(hwndDlg, IDC_CLIPBOARD_DATA), 1, &ts);
- SetDlgItemText(hwndDlg, IDC_CLIPBOARD_DATA, data->content.c_str());
- int sel = 0;
- int i = 0;
- std::wstring &defFormat = Options::instance->webOptions[data->page]->defFormatId;
- HWND cb = GetDlgItem(hwndDlg, IDC_FORMAT);
- for(std::list<PasteFormat>::iterator it = Options::instance->webOptions[data->page]->formats.begin(); it != Options::instance->webOptions[data->page]->formats.end(); ++it)
- {
- ComboBox_AddString(cb, it->name.c_str());
- if(it->id == defFormat)
- sel = i;
- ++i;
- }
- if(!Options::instance->webOptions[data->page]->formats.empty())
- {
- ComboBox_SetCurSel(cb, sel);
- }
- return TRUE;
+ ComboBox_AddString(cb, it->name.c_str());
+ if (it->id == defFormat)
+ sel = i;
+ ++i;
}
- case WM_COMMAND:
+ if (!Options::instance->webOptions[data->page]->formats.empty())
+ {
+ ComboBox_SetCurSel(cb, sel);
+ }
+ return TRUE;
+ }
+ case WM_COMMAND:
+ {
+ if (HIWORD(wParam) == BN_CLICKED)
{
- if (HIWORD(wParam) == BN_CLICKED)
+ if (LOWORD(wParam) == IDOK)
{
- if (LOWORD(wParam) == IDOK)
+ FromClipboardData *clipboardData = (FromClipboardData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
+ int sel = ComboBox_GetCurSel(GetDlgItem(hwndDlg, IDC_FORMAT));
+ for (std::list<PasteFormat>::iterator it = Options::instance->webOptions[clipboardData->page]->formats.begin(); it != Options::instance->webOptions[clipboardData->page]->formats.end(); ++it)
{
- FromClipboardData *clipboardData = (FromClipboardData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
- int sel = ComboBox_GetCurSel(GetDlgItem(hwndDlg, IDC_FORMAT));
- for(std::list<PasteFormat>::iterator it = Options::instance->webOptions[clipboardData->page]->formats.begin(); it != Options::instance->webOptions[clipboardData->page]->formats.end(); ++it)
+ if (sel-- <= 0)
{
- if(sel-- <= 0)
- {
- clipboardData->format = it->id;
- break;
- }
+ clipboardData->format = it->id;
+ break;
}
-
- EndDialog(hwndDlg, IDC_BTN_OK);
- }
- else if (LOWORD(wParam) == IDCANCEL)
- {
- EndDialog(hwndDlg, IDCANCEL);
}
- }
- break;
+ EndDialog(hwndDlg, IDC_BTN_OK);
+ }
+ else if (LOWORD(wParam) == IDCANCEL)
+ {
+ EndDialog(hwndDlg, IDCANCEL);
+ }
}
+
+ break;
+ }
}
return FALSE;
@@ -109,41 +109,41 @@ INT_PTR CALLBACK DlgProcFromClipboard(HWND hwndDlg, UINT msg, WPARAM wParam, LPA void RecodeDlg(HWND hwndDlg)
{
- ShowWindow(GetDlgItem(hwndDlg,IDC_RECODE),SW_HIDE);
+ ShowWindow(GetDlgItem(hwndDlg, IDC_RECODE), SW_HIDE);
FromFileData *fromFileData = (FromFileData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
unsigned int cp = Options::GetCodepageCB(GetDlgItem(hwndDlg, IDC_CODEPAGE), false, fromFileData->codepage);
mir_free(fromFileData->contentW);
int cbLen = 0;
- if(cp == 1200 || cp == 1201)
+ if (cp == 1200 || cp == 1201)
{
// UTF-16
cbLen = fromFileData->contentLen / 2;
}
else
{
- cbLen = MultiByteToWideChar( cp, 0, fromFileData->content, fromFileData->contentLen, NULL, 0 );
+ cbLen = MultiByteToWideChar(cp, 0, fromFileData->content, fromFileData->contentLen, NULL, 0);
}
- fromFileData->contentW = ( wchar_t* )mir_alloc( sizeof( wchar_t )*(cbLen+1));
- if ( fromFileData->contentW != NULL )
+ fromFileData->contentW = (wchar_t*)mir_alloc(sizeof(wchar_t)*(cbLen + 1));
+ if (fromFileData->contentW != NULL)
{
- if(cp == 1200)
+ if (cp == 1200)
{
- memcpy_s(fromFileData->contentW, sizeof( wchar_t )*(cbLen+1), fromFileData->content, sizeof( wchar_t )*cbLen);
+ memcpy_s(fromFileData->contentW, sizeof(wchar_t)*(cbLen + 1), fromFileData->content, sizeof(wchar_t)*cbLen);
}
- else if(cp == 1201)
+ else if (cp == 1201)
{
- for(int i = 0 ; i < cbLen; ++i)
+ for (int i = 0; i < cbLen; ++i)
{
- fromFileData->contentW[i] = ((unsigned char)fromFileData->content[i*2] << 8) | (unsigned char)fromFileData->content[i*2 + 1];
+ fromFileData->contentW[i] = ((unsigned char)fromFileData->content[i * 2] << 8) | (unsigned char)fromFileData->content[i * 2 + 1];
}
}
else
{
- MultiByteToWideChar( cp, 0, fromFileData->content, fromFileData->contentLen, fromFileData->contentW, cbLen );
+ MultiByteToWideChar(cp, 0, fromFileData->content, fromFileData->contentLen, fromFileData->contentW, cbLen);
}
- fromFileData->contentW[ cbLen ] = 0;
+ fromFileData->contentW[cbLen] = 0;
SetDlgItemText(hwndDlg, IDC_FILE_DATA, fromFileData->contentW);
}
else
@@ -154,107 +154,107 @@ void RecodeDlg(HWND hwndDlg) fromFileData->codepage = cp;
}
-INT_PTR CALLBACK DlgProcFromFile(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
+INT_PTR CALLBACK DlgProcFromFile(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
- switch (msg)
+ switch (msg)
+ {
+ case WM_INITDIALOG:
+ {
+ TranslateDialogDefault(hwndDlg);
+ FromFileData *fromFileData = (FromFileData*)lParam;
+ int ts = 4;
+ Edit_SetTabStops(GetDlgItem(hwndDlg, IDC_FILE_DATA), 1, &ts);
+ SetDlgItemText(hwndDlg, IDC_FILE_DATA, fromFileData->contentW);
+ SetDlgItemText(hwndDlg, IDC_FILE_PATH, fromFileData->fileName->c_str());
+ Options::InitCodepageCB(GetDlgItem(hwndDlg, IDC_CODEPAGE), fromFileData->codepage);
+ SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
+ ShowWindow(GetDlgItem(hwndDlg, IDC_RECODE), SW_HIDE);
+
+ int sel = 0;
+ int i = 0;
+ std::wstring &defFormat = Options::instance->webOptions[fromFileData->page]->defFormatId;
+ HWND cb = GetDlgItem(hwndDlg, IDC_FORMAT);
+ for (std::list<PasteFormat>::iterator it = Options::instance->webOptions[fromFileData->page]->formats.begin(); it != Options::instance->webOptions[fromFileData->page]->formats.end(); ++it)
+ {
+ ComboBox_AddString(cb, it->name.c_str());
+ if (it->id == defFormat)
+ sel = i;
+ ++i;
+ }
+ if (!Options::instance->webOptions[fromFileData->page]->formats.empty())
+ {
+ ComboBox_SetCurSel(cb, sel);
+ }
+
+ if (Options::instance->webOptions[fromFileData->page]->isSendFileName)
+ {
+ bool sendFileName = Options::instance->webOptions[fromFileData->page]->sendFileName;
+ CheckDlgButton(hwndDlg, IDC_AUTOFORMAT, sendFileName ? BST_CHECKED : BST_UNCHECKED);
+ Button_Enable(GetDlgItem(hwndDlg, IDC_FORMAT), sendFileName ? 0 : 1);
+ Button_Enable(GetDlgItem(hwndDlg, IDC_FORMATTEXT), sendFileName ? 0 : 1);
+ }
+ else
+ Button_Enable(GetDlgItem(hwndDlg, IDC_AUTOFORMAT), FALSE);
+ return TRUE;
+ }
+ case WM_COMMAND:
{
- case WM_INITDIALOG:
+ if (HIWORD(wParam) == BN_CLICKED)
{
- TranslateDialogDefault(hwndDlg);
- FromFileData *fromFileData = (FromFileData*)lParam;
- int ts = 4;
- Edit_SetTabStops(GetDlgItem(hwndDlg, IDC_FILE_DATA), 1, &ts);
- SetDlgItemText(hwndDlg, IDC_FILE_DATA, fromFileData->contentW);
- SetDlgItemText(hwndDlg, IDC_FILE_PATH, fromFileData->fileName->c_str());
- Options::InitCodepageCB(GetDlgItem(hwndDlg, IDC_CODEPAGE), fromFileData->codepage);
- SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
- ShowWindow(GetDlgItem(hwndDlg,IDC_RECODE),SW_HIDE);
-
- int sel = 0;
- int i = 0;
- std::wstring &defFormat = Options::instance->webOptions[fromFileData->page]->defFormatId;
- HWND cb = GetDlgItem(hwndDlg, IDC_FORMAT);
- for(std::list<PasteFormat>::iterator it = Options::instance->webOptions[fromFileData->page]->formats.begin(); it != Options::instance->webOptions[fromFileData->page]->formats.end(); ++it)
+ if (LOWORD(wParam) == IDOK)
+ {
+ FromFileData *fromFileData = (FromFileData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
+ int sel = ComboBox_GetCurSel(GetDlgItem(hwndDlg, IDC_FORMAT));
+ for (std::list<PasteFormat>::iterator it = Options::instance->webOptions[fromFileData->page]->formats.begin(); it != Options::instance->webOptions[fromFileData->page]->formats.end(); ++it)
+ {
+ if (sel-- <= 0)
+ {
+ fromFileData->format = it->id;
+ break;
+ }
+ }
+
+ if (Options::instance->webOptions[fromFileData->page]->isSendFileName)
+ fromFileData->sendFileName = IsDlgButtonChecked(hwndDlg, IDC_AUTOFORMAT) ? true : false;
+ else
+ fromFileData->sendFileName = false;
+
+ EndDialog(hwndDlg, IDC_BTN_OK);
+ }
+ else if (LOWORD(wParam) == IDCANCEL)
{
- ComboBox_AddString(cb, it->name.c_str());
- if(it->id == defFormat)
- sel = i;
- ++i;
+ EndDialog(hwndDlg, IDCANCEL);
}
- if(!Options::instance->webOptions[fromFileData->page]->formats.empty())
+ else if (LOWORD(wParam) == IDC_RECODE)
{
- ComboBox_SetCurSel(cb, sel);
+ RecodeDlg(hwndDlg);
}
-
- if(Options::instance->webOptions[fromFileData->page]->isSendFileName)
+ else if (LOWORD(wParam) == IDC_AUTOFORMAT)
{
- bool sendFileName = Options::instance->webOptions[fromFileData->page]->sendFileName;
- CheckDlgButton(hwndDlg, IDC_AUTOFORMAT, sendFileName ? BST_CHECKED : BST_UNCHECKED);
+ UINT sendFileName = IsDlgButtonChecked(hwndDlg, IDC_AUTOFORMAT);
Button_Enable(GetDlgItem(hwndDlg, IDC_FORMAT), sendFileName ? 0 : 1);
Button_Enable(GetDlgItem(hwndDlg, IDC_FORMATTEXT), sendFileName ? 0 : 1);
}
- else
- Button_Enable(GetDlgItem(hwndDlg, IDC_AUTOFORMAT), FALSE);
- return TRUE;
}
- case WM_COMMAND:
+ else if (LOWORD(wParam) == IDC_CODEPAGE)
{
- if (HIWORD(wParam) == BN_CLICKED)
+ if (HIWORD(wParam) == CBN_SELCHANGE)
{
- if (LOWORD(wParam) == IDOK)
- {
- FromFileData *fromFileData = (FromFileData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
- int sel = ComboBox_GetCurSel(GetDlgItem(hwndDlg, IDC_FORMAT));
- for(std::list<PasteFormat>::iterator it = Options::instance->webOptions[fromFileData->page]->formats.begin(); it != Options::instance->webOptions[fromFileData->page]->formats.end(); ++it)
- {
- if(sel-- <= 0)
- {
- fromFileData->format = it->id;
- break;
- }
- }
-
- if(Options::instance->webOptions[fromFileData->page]->isSendFileName)
- fromFileData->sendFileName = IsDlgButtonChecked(hwndDlg, IDC_AUTOFORMAT) ? true : false;
- else
- fromFileData->sendFileName = false;
-
- EndDialog(hwndDlg, IDC_BTN_OK);
- }
- else if (LOWORD(wParam) == IDCANCEL)
- {
- EndDialog(hwndDlg, IDCANCEL);
- }
- else if(LOWORD(wParam) == IDC_RECODE)
- {
- RecodeDlg(hwndDlg);
- }
- else if(LOWORD(wParam) == IDC_AUTOFORMAT)
- {
- UINT sendFileName = IsDlgButtonChecked(hwndDlg, IDC_AUTOFORMAT);
- Button_Enable(GetDlgItem(hwndDlg, IDC_FORMAT), sendFileName ? 0 : 1);
- Button_Enable(GetDlgItem(hwndDlg, IDC_FORMATTEXT), sendFileName ? 0 : 1);
- }
+ RecodeDlg(hwndDlg);
}
- else if(LOWORD(wParam) == IDC_CODEPAGE)
+ else if (HIWORD(wParam) == CBN_EDITCHANGE)
{
- if(HIWORD(wParam) == CBN_SELCHANGE)
- {
- RecodeDlg(hwndDlg);
- }
- else if(HIWORD(wParam) == CBN_EDITCHANGE)
- {
- ShowWindow(GetDlgItem(hwndDlg,IDC_RECODE),SW_SHOW);
- }
- else if(HIWORD(wParam) == CBN_KILLFOCUS)
- {
- FromFileData *fromFileData = (FromFileData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
- Options::GetCodepageCB(GetDlgItem(hwndDlg, IDC_CODEPAGE), true, fromFileData->codepage);
- }
+ ShowWindow(GetDlgItem(hwndDlg, IDC_RECODE), SW_SHOW);
+ }
+ else if (HIWORD(wParam) == CBN_KILLFOCUS)
+ {
+ FromFileData *fromFileData = (FromFileData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
+ Options::GetCodepageCB(GetDlgItem(hwndDlg, IDC_CODEPAGE), true, fromFileData->codepage);
}
-
- break;
}
+
+ break;
+ }
}
return FALSE;
@@ -264,57 +264,57 @@ void PasteToWeb::FromClipboard() {
szFileLink[0] = 0;
error = NULL;
- std::wstring str;
+ std::wstring str;
BOOL isFile = 0;
- if(OpenClipboard(NULL))
+ if (OpenClipboard(NULL))
{
HANDLE obj = GetClipboardData(CF_UNICODETEXT);
- if(obj != NULL)
+ if (obj != NULL)
{
- LPCWSTR wStr = (LPCWSTR)GlobalLock(obj);
- str.append(wStr, wStr + wcslen(wStr));
+ LPCWSTR wStr = (LPCWSTR)GlobalLock(obj);
+ str.append(wStr, wStr + mir_wstrlen(wStr));
GlobalUnlock(obj);
// Sometimes clipboard CF_UNICODETEXT format returns only 2 characters,
// to fix this I check if CF_TEXT contains more characters,
// if this is true, this mean that CF_UNICODETEXT is invalid.
obj = GetClipboardData(CF_TEXT);
- if(obj != NULL)
+ if (obj != NULL)
{
- LPCSTR cStr = (LPCSTR)GlobalLock(obj);
- if(strlen(cStr) > str.length())
+ LPCSTR cStr = (LPCSTR)GlobalLock(obj);
+ if (strlen(cStr) > str.length())
{
str = L"";
LPWSTR wStr = mir_a2u_cp(cStr, CP_ACP);
- str.append(wStr, wStr + wcslen(wStr));
+ str.append(wStr, wStr + mir_wstrlen(wStr));
mir_free(wStr);
}
GlobalUnlock(obj);
}
}
- else
+ else
{
obj = GetClipboardData(CF_TEXT);
- if(obj != NULL)
+ if (obj != NULL)
{
- LPCSTR cStr = (LPCSTR)GlobalLock(obj);
+ LPCSTR cStr = (LPCSTR)GlobalLock(obj);
LPWSTR wStr = mir_a2u_cp(cStr, CP_ACP);
- str.append(wStr, wStr + wcslen(wStr));
+ str.append(wStr, wStr + mir_wstrlen(wStr));
mir_free(wStr);
GlobalUnlock(obj);
}
else
{
obj = GetClipboardData(CF_HDROP);
- if(obj != NULL)
+ if (obj != NULL)
{
- LPDROPFILES df = (LPDROPFILES) GlobalLock(obj);
+ LPDROPFILES df = (LPDROPFILES)GlobalLock(obj);
isFile = 1;
- if(df->fWide)
+ if (df->fWide)
{
// Unicode
WCHAR* file = (WCHAR*)((BYTE*)obj + df->pFiles);
- size_t len = wcslen(file);
- if(*(file + len + 1) == L'\0')
+ size_t len = mir_wstrlen(file);
+ if (*(file + len + 1) == L'\0')
{
str.append(file, file + len);
}
@@ -327,11 +327,11 @@ void PasteToWeb::FromClipboard() {
// ANSI
char* file = (char*)obj + df->pFiles;
- size_t len = strlen(file);
- if(*(file + len + 1) == '\0')
+ size_t len = mir_strlen(file);
+ if (*(file + len + 1) == '\0')
{
LPWSTR wStr = mir_a2u_cp(file, CP_ACP);
- str.append(wStr, wStr + wcslen(wStr));
+ str.append(wStr, wStr + mir_wstrlen(wStr));
mir_free(wStr);
}
else
@@ -347,22 +347,22 @@ void PasteToWeb::FromClipboard() CloseClipboard();
}
- if(str.length() > 0)
+ if (str.length() > 0)
{
- if(isFile)
+ if (isFile)
FromFile(str);
else
{
FromClipboardData data;
data.content = str;
data.page = pageIndex;
- if (Options::instance->confDlg && DialogBoxParam (hInst, MAKEINTRESOURCE(IDD_DLG_FROM_CLIPBOARD), 0, DlgProcFromClipboard, (LPARAM)&data) != IDC_BTN_OK)
- return;
+ if (Options::instance->confDlg && DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_DLG_FROM_CLIPBOARD), 0, DlgProcFromClipboard, (LPARAM)&data) != IDC_BTN_OK)
+ return;
SendToServer(str, L"", data.format);
}
}
- else if(error == NULL)
+ else if (error == NULL)
{
error = TranslateT("Cannot get data from clipboard");
}
@@ -373,21 +373,19 @@ void PasteToWeb::FromFile(std::wstring file) error = NULL;
szFileLink[0] = 0;
HANDLE hFile = CreateFile(file.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
- FromFileData fromFileData;
- fromFileData.content = NULL;
- fromFileData.contentLen = 0;
+ FromFileData fromFileData = { 0 };
fromFileData.fileName = &file;
- if(hFile != INVALID_HANDLE_VALUE)
+ if (hFile != INVALID_HANDLE_VALUE)
{
LARGE_INTEGER fileSize;
- if(GetFileSizeEx(hFile, &fileSize))
+ if (GetFileSizeEx(hFile, &fileSize))
{
- if(fileSize.QuadPart <= 10485760LL)
+ if (fileSize.QuadPart <= 10485760LL)
{
- if(fileSize.QuadPart > 512000LL)
+ if (fileSize.QuadPart > 512000LL)
{
mir_sntprintf(bufErr, SIZEOF(bufErr), TranslateT("File size is %d KB, do you really want to paste such a large file?"), fileSize.LowPart / 1024);
- if(MessageBox(NULL, bufErr, TranslateT("Are You sure?"), MB_YESNO | MB_ICONQUESTION) != IDYES)
+ if (MessageBox(NULL, bufErr, TranslateT("Are You sure?"), MB_YESNO | MB_ICONQUESTION) != IDYES)
{
CloseHandle(hFile);
return;
@@ -396,7 +394,7 @@ void PasteToWeb::FromFile(std::wstring file) DWORD readed;
fromFileData.contentLen = fileSize.LowPart;
fromFileData.content = (char*)mir_alloc(fromFileData.contentLen);
- if(!ReadFile(hFile, fromFileData.content, fromFileData.contentLen, &readed, NULL))
+ if (!ReadFile(hFile, fromFileData.content, fromFileData.contentLen, &readed, NULL))
{
mir_free(fromFileData.content);
fromFileData.content = NULL;
@@ -419,70 +417,70 @@ void PasteToWeb::FromFile(std::wstring file) error = bufErr;
}
- if(fromFileData.content != NULL)
+ if (fromFileData.content != NULL)
{
int cbLen = 0;
bool isDefTranslation = true;
- if(Options::instance->autoUTF)
+ if (Options::instance->autoUTF)
{
isDefTranslation = false;
fromFileData.codepage = CP_UTF8;
- cbLen = MultiByteToWideChar( fromFileData.codepage, MB_ERR_INVALID_CHARS, fromFileData.content, fromFileData.contentLen, NULL, 0 );
- if(cbLen == 0)
+ cbLen = MultiByteToWideChar(fromFileData.codepage, MB_ERR_INVALID_CHARS, fromFileData.content, fromFileData.contentLen, NULL, 0);
+ if (cbLen == 0)
{
int errorN = GetLastError();
- if(errorN == ERROR_NO_UNICODE_TRANSLATION)
+ if (errorN == ERROR_NO_UNICODE_TRANSLATION)
{
isDefTranslation = true;
}
}
}
- if(isDefTranslation)
+ if (isDefTranslation)
{
fromFileData.codepage = Options::instance->codepage;
- if(fromFileData.codepage == 1200 || fromFileData.codepage == 1201)
+ if (fromFileData.codepage == 1200 || fromFileData.codepage == 1201)
{
// UTF-16
cbLen = fromFileData.contentLen / 2;
}
else
{
- cbLen = MultiByteToWideChar( fromFileData.codepage, 0, fromFileData.content, fromFileData.contentLen, NULL, 0 );
+ cbLen = MultiByteToWideChar(fromFileData.codepage, 0, fromFileData.content, fromFileData.contentLen, NULL, 0);
}
}
- if(cbLen > 0)
+ if (cbLen > 0)
{
- fromFileData.contentW = ( wchar_t* )mir_alloc( sizeof( wchar_t )*(cbLen+1));
- if ( fromFileData.contentW != NULL )
+ fromFileData.contentW = (wchar_t*)mir_alloc(sizeof(wchar_t)*(cbLen + 1));
+ if (fromFileData.contentW != NULL)
{
- if(fromFileData.codepage == 1200)
+ if (fromFileData.codepage == 1200)
{
- memcpy_s(fromFileData.contentW, sizeof( wchar_t )*(cbLen+1), fromFileData.content, sizeof( wchar_t )*cbLen);
+ memcpy_s(fromFileData.contentW, sizeof(wchar_t)*(cbLen + 1), fromFileData.content, sizeof(wchar_t)*cbLen);
}
- else if(fromFileData.codepage == 1201)
+ else if (fromFileData.codepage == 1201)
{
- for(int i = 0 ; i < cbLen; ++i)
+ for (int i = 0; i < cbLen; ++i)
{
- fromFileData.contentW[i] = (fromFileData.content[i*2] << 8) | fromFileData.content[i*2 + 1];
+ fromFileData.contentW[i] = (fromFileData.content[i * 2] << 8) | fromFileData.content[i * 2 + 1];
}
}
else
{
- MultiByteToWideChar( fromFileData.codepage, 0, fromFileData.content, fromFileData.contentLen, fromFileData.contentW, cbLen );
+ MultiByteToWideChar(fromFileData.codepage, 0, fromFileData.content, fromFileData.contentLen, fromFileData.contentW, cbLen);
}
-
- fromFileData.contentW[ cbLen ] = 0;
+
+ fromFileData.contentW[cbLen] = 0;
fromFileData.page = pageIndex;
- if (!Options::instance->confDlg || DialogBoxParam (hInst, MAKEINTRESOURCE(IDD_DLG_FROM_FILE), 0, DlgProcFromFile, (LPARAM)&fromFileData) == IDC_BTN_OK)
+ if (!Options::instance->confDlg || DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_DLG_FROM_FILE), 0, DlgProcFromFile, (LPARAM)&fromFileData) == IDC_BTN_OK)
{
std::wstring fileName;
std::wstring::size_type pos1 = file.find_last_of(L'\\');
std::wstring::size_type pos2 = file.find_last_of(L'/');
- if(pos2 > pos1 && pos2 < file.length())
+ if (pos2 > pos1 && pos2 < file.length())
pos1 = pos2;
- if(pos1 >= 0 && pos1 + 1 < file.length())
+ if (pos1 >= 0 && pos1 + 1 < file.length())
fileName = file.substr(pos1 + 1);
else
fileName = file;
@@ -505,68 +503,68 @@ extern HANDLE g_hNetlibUser; wchar_t* PasteToWeb::SendToWeb(char* url, std::map<std::string, std::string>& headers, std::wstring content)
{
wchar_t* resCont = NULL;
- int cbLen = WideCharToMultiByte( CP_UTF8, 0, content.c_str(), -1, NULL, 0, NULL, NULL );
- char* contentBytes = ( char* )mir_alloc(cbLen);
- if ( contentBytes == NULL )
+ int cbLen = WideCharToMultiByte(CP_UTF8, 0, content.c_str(), -1, NULL, 0, NULL, NULL);
+ char* contentBytes = (char*)mir_alloc(cbLen);
+ if (contentBytes == NULL)
return resCont;
- WideCharToMultiByte( CP_UTF8, 0, content.c_str(), -1, contentBytes, cbLen, NULL, NULL );
+ WideCharToMultiByte(CP_UTF8, 0, content.c_str(), -1, contentBytes, cbLen, NULL, NULL);
--cbLen;
int nHeaders = 0;
- for(std::map<std::string, std::string>::iterator it = headers.begin(); it != headers.end(); ++it)
+ for (std::map<std::string, std::string>::iterator it = headers.begin(); it != headers.end(); ++it)
{
++nHeaders;
}
- NETLIBHTTPREQUEST nlhr={0};
+ NETLIBHTTPREQUEST nlhr = { 0 };
NETLIBHTTPHEADER* httpHeaders = new NETLIBHTTPHEADER[nHeaders];
- nlhr.cbSize=sizeof(nlhr);
- nlhr.requestType=REQUEST_POST;
- nlhr.flags=NLHRF_NODUMPSEND|NLHRF_DUMPASTEXT|NLHPIF_HTTP11;
- nlhr.szUrl=url;
+ nlhr.cbSize = sizeof(nlhr);
+ nlhr.requestType = REQUEST_POST;
+ nlhr.flags = NLHRF_NODUMPSEND | NLHRF_DUMPASTEXT | NLHPIF_HTTP11;
+ nlhr.szUrl = url;
nlhr.headers = httpHeaders;
nlhr.pData = contentBytes;
nlhr.dataLength = cbLen;
nHeaders = 0;
std::list<char*> mallBuf;
- for(std::map<std::string, std::string>::iterator it = headers.begin(); it != headers.end(); ++it)
+ for (std::map<std::string, std::string>::iterator it = headers.begin(); it != headers.end(); ++it)
{
char* b1 = new char[it->first.length() + 1];
char* b2 = new char[it->second.length() + 1];
- strcpy_s(b1, it->first.length() + 1, it->first.c_str());
- strcpy_s(b2, it->second.length() + 1, it->second.c_str());
+ mir_strncpy(b1, it->first.c_str(), it->first.length() + 1);
+ mir_strncpy(b2, it->second.c_str(), it->second.length() + 1);
httpHeaders[nHeaders].szName = b1;
httpHeaders[nHeaders].szValue = b2;
mallBuf.push_back(b1);
mallBuf.push_back(b2);
++nHeaders;
}
-
+
nlhr.headersCount = nHeaders;
- NETLIBHTTPREQUEST* nlhrReply = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION,(WPARAM)g_hNetlibUser,(LPARAM)&nlhr);
- if(nlhrReply != NULL)
+ NETLIBHTTPREQUEST* nlhrReply = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)g_hNetlibUser, (LPARAM)&nlhr);
+ if (nlhrReply != NULL)
{
- if(nlhrReply->resultCode == 200)
+ if (nlhrReply->resultCode == 200)
{
int resLen = MultiByteToWideChar(CP_UTF8, 0, nlhrReply->pData, nlhrReply->dataLength, NULL, 0);
++resLen;
- resCont = ( wchar_t* )mir_alloc(resLen * sizeof(wchar_t));
- if ( resCont != NULL )
+ resCont = (wchar_t*)mir_alloc(resLen * sizeof(wchar_t));
+ if (resCont != NULL)
{
- resLen = MultiByteToWideChar( CP_UTF8, 0, nlhrReply->pData, nlhrReply->dataLength, resCont, resLen);
+ resLen = MultiByteToWideChar(CP_UTF8, 0, nlhrReply->pData, nlhrReply->dataLength, resCont, resLen);
resCont[resLen] = 0;
}
}
- CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT,0,(LPARAM)nlhrReply);
+ CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)nlhrReply);
}
delete httpHeaders;
- for(std::list<char*>::iterator it = mallBuf.begin(); it != mallBuf.end(); ++it)
+ for (std::list<char*>::iterator it = mallBuf.begin(); it != mallBuf.end(); ++it)
{
delete *it;
}
-
+
mir_free(contentBytes);
return resCont;
}
|