From 0ad0b41c6c42e0a346a7755de39dd03d4f25142d Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 14 Feb 2019 19:50:22 +0300 Subject: PasteIt -> TinyXml --- plugins/PasteIt/src/Options.cpp | 322 ++++++++++++++++------------------ plugins/PasteIt/src/PasteIt.cpp | 5 +- plugins/PasteIt/src/PasteToWeb.cpp | 341 +++++++++++++----------------------- plugins/PasteIt/src/PasteToWeb.h | 2 +- plugins/PasteIt/src/PasteToWeb1.cpp | 55 ++---- plugins/PasteIt/src/PasteToWeb2.cpp | 206 +++++++++------------- plugins/PasteIt/src/version.h | 2 +- 7 files changed, 378 insertions(+), 555 deletions(-) (limited to 'plugins/PasteIt') diff --git a/plugins/PasteIt/src/Options.cpp b/plugins/PasteIt/src/Options.cpp index 9f6602076f..d44e6ca6ca 100644 --- a/plugins/PasteIt/src/Options.cpp +++ b/plugins/PasteIt/src/Options.cpp @@ -76,8 +76,8 @@ INT_PTR CALLBACK Options::DlgProcOptsMain(HWND hwndDlg, UINT msg, WPARAM wParam, { switch (msg) { case WM_INITDIALOG: + TranslateDialogDefault(hwndDlg); { - TranslateDialogDefault(hwndDlg); CheckDlgButton(hwndDlg, IDC_AUTOUTF, instance->autoUTF ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hwndDlg, IDC_CONFDLG, instance->confDlg ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hwndDlg, IDC_AUTOSEND, instance->autoSend ? BST_CHECKED : BST_UNCHECKED); @@ -89,35 +89,33 @@ INT_PTR CALLBACK Options::DlgProcOptsMain(HWND hwndDlg, UINT msg, WPARAM wParam, ComboBox_SetCurSel(GetDlgItem(hwndDlg, IDC_WEBLIST), instance->defWeb); InitCodepageCB(GetDlgItem(hwndDlg, IDC_CODEPAGE), instance->codepage); - return TRUE; } + return TRUE; + case WM_COMMAND: - { - if (LOWORD(wParam) == IDC_CODEPAGE) { - if (HIWORD(wParam) == CBN_KILLFOCUS) { - GetCodepageCB(GetDlgItem(hwndDlg, IDC_CODEPAGE), true, instance->codepage); - } + if (LOWORD(wParam) == IDC_CODEPAGE) { + if (HIWORD(wParam) == CBN_KILLFOCUS) { + GetCodepageCB(GetDlgItem(hwndDlg, IDC_CODEPAGE), true, instance->codepage); } - - if (HIWORD(wParam) == BN_CLICKED || HIWORD(wParam) == CBN_SELCHANGE || HIWORD(wParam) == CBN_EDITCHANGE) - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - return TRUE; } + + if (HIWORD(wParam) == BN_CLICKED || HIWORD(wParam) == CBN_SELCHANGE || HIWORD(wParam) == CBN_EDITCHANGE) + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + return TRUE; + case WM_NOTIFY: - { - if (((LPNMHDR)lParam)->code == PSN_APPLY) { - instance->codepage = GetCodepageCB(GetDlgItem(hwndDlg, IDC_CODEPAGE), false, instance->codepage); - instance->autoUTF = IsDlgButtonChecked(hwndDlg, IDC_AUTOUTF) ? true : false; - instance->confDlg = IsDlgButtonChecked(hwndDlg, IDC_CONFDLG) ? true : false; - instance->autoSend = IsDlgButtonChecked(hwndDlg, IDC_AUTOSEND) ? true : false; - instance->defWeb = ComboBox_GetCurSel(GetDlgItem(hwndDlg, IDC_WEBLIST)); + if (((LPNMHDR)lParam)->code == PSN_APPLY) { + instance->codepage = GetCodepageCB(GetDlgItem(hwndDlg, IDC_CODEPAGE), false, instance->codepage); + instance->autoUTF = IsDlgButtonChecked(hwndDlg, IDC_AUTOUTF) ? true : false; + instance->confDlg = IsDlgButtonChecked(hwndDlg, IDC_CONFDLG) ? true : false; + instance->autoSend = IsDlgButtonChecked(hwndDlg, IDC_AUTOSEND) ? true : false; + instance->defWeb = ComboBox_GetCurSel(GetDlgItem(hwndDlg, IDC_WEBLIST)); - DefWebPageChanged(); + DefWebPageChanged(); - Options::instance->Save(); - } - return TRUE; + Options::instance->Save(); } + return TRUE; } return FALSE; @@ -171,9 +169,9 @@ void ReloadFormatsCombo(HWND hWnd, WebOptions* wo) sel = i; ++i; } - if (!wo->formats.empty()) { + + if (!wo->formats.empty()) ComboBox_SetCurSel(hWnd, sel); - } } void GetPagesSettings(HWND hwndDlg, OptsPagesData* optsPagesData) @@ -204,6 +202,7 @@ void GetPagesSettings(HWND hwndDlg, OptsPagesData* optsPagesData) } } } + if (optsPagesData->webOptions[selected]->isPublicPaste) { if (IsDlgButtonChecked(hwndDlg, IDC_GUEST)) { optsPagesData->webOptions[selected]->pastebinUserKey = L""; @@ -220,20 +219,18 @@ INT_PTR CALLBACK Options::DlgProcOptsPages(HWND hwndDlg, UINT msg, WPARAM wParam { switch (msg) { case WM_INITDIALOG: + TranslateDialogDefault(hwndDlg); { - TranslateDialogDefault(hwndDlg); OptsPagesData* optsPagesData = new OptsPagesData(); SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)optsPagesData); HWND btnhwnd = GetDlgItem(hwndDlg, IDC_PASTEBIN_LOGIN); int btSize = Button_GetTextLength(btnhwnd); - if (btSize > 20) { + if (btSize > 20) SetWindowPos(btnhwnd, nullptr, 0, 0, 115, 34, SWP_NOZORDER | SWP_NOMOVE | SWP_NOREPOSITION | SWP_NOACTIVATE | SWP_NOREDRAW); - } - for (int i = 0; i < PasteToWeb::pages; ++i) { + for (int i = 0; i < PasteToWeb::pages; ++i) ComboBox_AddString(GetDlgItem(hwndDlg, IDC_WEBPAGE), pasteToWebs[i]->GetName()); - } ComboBox_SetCurSel(GetDlgItem(hwndDlg, IDC_WEBPAGE), 0); ReloadFormatsCombo(GetDlgItem(hwndDlg, IDC_DEFFORMAT), optsPagesData->webOptions[0]); @@ -275,9 +272,7 @@ INT_PTR CALLBACK Options::DlgProcOptsPages(HWND hwndDlg, UINT msg, WPARAM wParam Static_Enable(GetDlgItem(hwndDlg, IDC_PASTEBIN_KEY_DESC), FALSE); Button_Enable(GetDlgItem(hwndDlg, IDC_PASTEBIN_LOGIN), FALSE); } - else { - Edit_SetText(GetDlgItem(hwndDlg, IDC_PASTEBIN_KEY), pastebinUserKey.c_str()); - } + else Edit_SetText(GetDlgItem(hwndDlg, IDC_PASTEBIN_KEY), pastebinUserKey.c_str()); } else { ShowWindow(GetDlgItem(hwndDlg, IDC_GUEST), SW_HIDE); @@ -287,8 +282,9 @@ INT_PTR CALLBACK Options::DlgProcOptsPages(HWND hwndDlg, UINT msg, WPARAM wParam } optsPagesData->init = true; - return TRUE; } + return TRUE; + case WM_COMMAND: { OptsPagesData* optsPagesData = (OptsPagesData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); @@ -326,15 +322,13 @@ INT_PTR CALLBACK Options::DlgProcOptsPages(HWND hwndDlg, UINT msg, WPARAM wParam ShowWindow(GetDlgItem(hwndDlg, IDC_AUTOFORMAT), SW_SHOW); CheckDlgButton(hwndDlg, IDC_AUTOFORMAT, optsPagesData->webOptions[optsPagesData->lastPage]->sendFileName ? BST_CHECKED : BST_UNCHECKED); } - else - ShowWindow(GetDlgItem(hwndDlg, IDC_AUTOFORMAT), SW_HIDE); + else ShowWindow(GetDlgItem(hwndDlg, IDC_AUTOFORMAT), SW_HIDE); if (optsPagesData->webOptions[optsPagesData->lastPage]->isPublicPaste) { ShowWindow(GetDlgItem(hwndDlg, IDC_PUBLICPASTE), SW_SHOW); CheckDlgButton(hwndDlg, IDC_PUBLICPASTE, optsPagesData->webOptions[optsPagesData->lastPage]->publicPaste ? BST_CHECKED : BST_UNCHECKED); } - else - ShowWindow(GetDlgItem(hwndDlg, IDC_PUBLICPASTE), SW_HIDE); + else ShowWindow(GetDlgItem(hwndDlg, IDC_PUBLICPASTE), SW_HIDE); if (optsPagesData->webOptions[optsPagesData->lastPage]->isCombo1) { ShowWindow(GetDlgItem(hwndDlg, IDC_COMBO1), SW_SHOW); @@ -358,7 +352,6 @@ INT_PTR CALLBACK Options::DlgProcOptsPages(HWND hwndDlg, UINT msg, WPARAM wParam ShowWindow(GetDlgItem(hwndDlg, IDC_COMBO1_DESC), SW_HIDE); } - if (optsPagesData->webOptions[optsPagesData->lastPage]->isPastebin) { ShowWindow(GetDlgItem(hwndDlg, IDC_GUEST), SW_SHOW); ShowWindow(GetDlgItem(hwndDlg, IDC_PASTEBIN_KEY), SW_SHOW); @@ -392,28 +385,26 @@ INT_PTR CALLBACK Options::DlgProcOptsPages(HWND hwndDlg, UINT msg, WPARAM wParam if (optsPagesData->init && ((HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) != IDC_CONFIGURE && LOWORD(wParam) != IDC_PASTEBIN_LOGIN) || (HIWORD(wParam) == CBN_SELCHANGE && LOWORD(wParam) != IDC_WEBPAGE) || HIWORD(wParam) == EN_CHANGE)) SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - return TRUE; } - case WM_NOTIFY: - { - if (((LPNMHDR)lParam)->code == PSN_APPLY) { - OptsPagesData* optsPagesData = (OptsPagesData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - GetPagesSettings(hwndDlg, optsPagesData); - for (int i = 0; i < PasteToWeb::pages; ++i) { - *Options::instance->webOptions[i] = *optsPagesData->webOptions[i]; - } + return TRUE; - Options::instance->Save(); + case WM_NOTIFY: + if (((LPNMHDR)lParam)->code == PSN_APPLY) { + OptsPagesData* optsPagesData = (OptsPagesData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + GetPagesSettings(hwndDlg, optsPagesData); + for (int i = 0; i < PasteToWeb::pages; ++i) { + *Options::instance->webOptions[i] = *optsPagesData->webOptions[i]; } - return TRUE; + + Options::instance->Save(); } + return TRUE; + case WM_CLOSE: - { - OptsPagesData *optsPagesData = (OptsPagesData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - delete optsPagesData; - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0); - break; - } + OptsPagesData *optsPagesData = (OptsPagesData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + delete optsPagesData; + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0); + break; } return FALSE; @@ -443,8 +434,8 @@ INT_PTR CALLBACK Options::DlgProcOptsConfigure(HWND hwndDlg, UINT msg, WPARAM wP { switch (msg) { case WM_INITDIALOG: + TranslateDialogDefault(hwndDlg); { - TranslateDialogDefault(hwndDlg); OptsConfigureData* optsConfigureData = (OptsConfigureData*)lParam; SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); @@ -454,116 +445,115 @@ INT_PTR CALLBACK Options::DlgProcOptsConfigure(HWND hwndDlg, UINT msg, WPARAM wP } SelectLbConfigure(hwndDlg, -1, optsConfigureData); - return TRUE; } + return TRUE; + case WM_COMMAND: - { - if (HIWORD(wParam) == BN_CLICKED) { - if (LOWORD(wParam) == IDOK) { - EndDialog(hwndDlg, IDOK); - } - else if (LOWORD(wParam) == IDCANCEL) { - EndDialog(hwndDlg, IDCANCEL); - } - else if (LOWORD(wParam) == IDC_DELETE) { - HWND lb = GetDlgItem(hwndDlg, IDC_FORMATTING); - OptsConfigureData* optsConfigureData = (OptsConfigureData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - int sel = ListBox_GetCurSel(lb); - if (sel >= 0) { - ListBox_DeleteString(lb, sel); - int i = sel; - for (std::list::iterator it = optsConfigureData->tempFormats.begin(); it != optsConfigureData->tempFormats.end(); ++it) { - if (i-- <= 0) { - optsConfigureData->tempFormats.erase(it); - ListBox_SetCurSel(lb, sel); - SelectLbConfigure(hwndDlg, sel, optsConfigureData); - break; - } - } - } - } - else if (LOWORD(wParam) == IDC_UP) { - HWND lb = GetDlgItem(hwndDlg, IDC_FORMATTING); - OptsConfigureData* optsConfigureData = (OptsConfigureData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - int sel = ListBox_GetCurSel(lb); - if (sel > 0) { - int i = sel; - for (std::list::iterator it = optsConfigureData->tempFormats.begin(); it != optsConfigureData->tempFormats.end(); ++it) { - if (i-- <= 0) { - PasteFormat pf = *it; - std::list::iterator prevIt = it; - --prevIt; - optsConfigureData->tempFormats.erase(it); - optsConfigureData->tempFormats.insert(prevIt, pf); - ListBox_DeleteString(lb, sel--); - ListBox_InsertString(lb, sel, pf.name.c_str()); - ListBox_SetCurSel(lb, sel); - SelectLbConfigure(hwndDlg, sel, optsConfigureData); - break; - } + if (HIWORD(wParam) == BN_CLICKED) { + if (LOWORD(wParam) == IDOK) { + EndDialog(hwndDlg, IDOK); + } + else if (LOWORD(wParam) == IDCANCEL) { + EndDialog(hwndDlg, IDCANCEL); + } + else if (LOWORD(wParam) == IDC_DELETE) { + HWND lb = GetDlgItem(hwndDlg, IDC_FORMATTING); + OptsConfigureData* optsConfigureData = (OptsConfigureData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + int sel = ListBox_GetCurSel(lb); + if (sel >= 0) { + ListBox_DeleteString(lb, sel); + int i = sel; + for (std::list::iterator it = optsConfigureData->tempFormats.begin(); it != optsConfigureData->tempFormats.end(); ++it) { + if (i-- <= 0) { + optsConfigureData->tempFormats.erase(it); + ListBox_SetCurSel(lb, sel); + SelectLbConfigure(hwndDlg, sel, optsConfigureData); + break; } } } - else if (LOWORD(wParam) == IDC_DOWN) { - HWND lb = GetDlgItem(hwndDlg, IDC_FORMATTING); - OptsConfigureData* optsConfigureData = (OptsConfigureData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - int sel = ListBox_GetCurSel(lb); - if (sel >= 0 && sel + 1 < (int)optsConfigureData->tempFormats.size()) { - int i = sel; - for (std::list::iterator it = optsConfigureData->tempFormats.begin(); it != optsConfigureData->tempFormats.end(); ++it) { - if (i-- <= 0) { - PasteFormat pf = *it; - std::list::iterator nextIt = it; - ++(++nextIt); - optsConfigureData->tempFormats.erase(it); - optsConfigureData->tempFormats.insert(nextIt, pf); - ListBox_DeleteString(lb, sel++); - ListBox_InsertString(lb, sel, pf.name.c_str()); - ListBox_SetCurSel(lb, sel); - SelectLbConfigure(hwndDlg, sel, optsConfigureData); - break; - } + } + else if (LOWORD(wParam) == IDC_UP) { + HWND lb = GetDlgItem(hwndDlg, IDC_FORMATTING); + OptsConfigureData* optsConfigureData = (OptsConfigureData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + int sel = ListBox_GetCurSel(lb); + if (sel > 0) { + int i = sel; + for (std::list::iterator it = optsConfigureData->tempFormats.begin(); it != optsConfigureData->tempFormats.end(); ++it) { + if (i-- <= 0) { + PasteFormat pf = *it; + std::list::iterator prevIt = it; + --prevIt; + optsConfigureData->tempFormats.erase(it); + optsConfigureData->tempFormats.insert(prevIt, pf); + ListBox_DeleteString(lb, sel--); + ListBox_InsertString(lb, sel, pf.name.c_str()); + ListBox_SetCurSel(lb, sel); + SelectLbConfigure(hwndDlg, sel, optsConfigureData); + break; } } } - else if (LOWORD(wParam) == IDC_DOWNLOAD) { - OptsConfigureData* optsConfigureData = (OptsConfigureData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - HWND lb = GetDlgItem(hwndDlg, IDC_FORMATTING); - while (ListBox_DeleteString(lb, 0) > 0); - SelectLbConfigure(hwndDlg, -1, optsConfigureData); - optsConfigureData->tempFormats = pasteToWebs[optsConfigureData->page]->GetFormats(); + } + else if (LOWORD(wParam) == IDC_DOWN) { + HWND lb = GetDlgItem(hwndDlg, IDC_FORMATTING); + OptsConfigureData* optsConfigureData = (OptsConfigureData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + int sel = ListBox_GetCurSel(lb); + if (sel >= 0 && sel + 1 < (int)optsConfigureData->tempFormats.size()) { + int i = sel; for (std::list::iterator it = optsConfigureData->tempFormats.begin(); it != optsConfigureData->tempFormats.end(); ++it) { - ListBox_AddString(lb, it->name.c_str()); + if (i-- <= 0) { + PasteFormat pf = *it; + std::list::iterator nextIt = it; + ++(++nextIt); + optsConfigureData->tempFormats.erase(it); + optsConfigureData->tempFormats.insert(nextIt, pf); + ListBox_DeleteString(lb, sel++); + ListBox_InsertString(lb, sel, pf.name.c_str()); + ListBox_SetCurSel(lb, sel); + SelectLbConfigure(hwndDlg, sel, optsConfigureData); + break; + } } } - else if (LOWORD(wParam) == IDC_RESTORE) { - OptsConfigureData* optsConfigureData = (OptsConfigureData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - HWND lb = GetDlgItem(hwndDlg, IDC_FORMATTING); - while (ListBox_DeleteString(lb, 0) > 0); - SelectLbConfigure(hwndDlg, -1, optsConfigureData); - optsConfigureData->tempFormats = pasteToWebs[optsConfigureData->page]->GetDefFormats(); - for (std::list::iterator it = optsConfigureData->tempFormats.begin(); it != optsConfigureData->tempFormats.end(); ++it) { - ListBox_AddString(lb, it->name.c_str()); - } + } + else if (LOWORD(wParam) == IDC_DOWNLOAD) { + OptsConfigureData* optsConfigureData = (OptsConfigureData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + HWND lb = GetDlgItem(hwndDlg, IDC_FORMATTING); + while (ListBox_DeleteString(lb, 0) > 0); + SelectLbConfigure(hwndDlg, -1, optsConfigureData); + optsConfigureData->tempFormats = pasteToWebs[optsConfigureData->page]->GetFormats(); + for (std::list::iterator it = optsConfigureData->tempFormats.begin(); it != optsConfigureData->tempFormats.end(); ++it) { + ListBox_AddString(lb, it->name.c_str()); } } - else if (HIWORD(wParam) == LBN_SELCHANGE && LOWORD(wParam) == IDC_FORMATTING) { + else if (LOWORD(wParam) == IDC_RESTORE) { OptsConfigureData* optsConfigureData = (OptsConfigureData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - int sel = ListBox_GetCurSel(GetDlgItem(hwndDlg, IDC_FORMATTING)); - SelectLbConfigure(hwndDlg, sel, optsConfigureData); + HWND lb = GetDlgItem(hwndDlg, IDC_FORMATTING); + while (ListBox_DeleteString(lb, 0) > 0); + SelectLbConfigure(hwndDlg, -1, optsConfigureData); + optsConfigureData->tempFormats = pasteToWebs[optsConfigureData->page]->GetDefFormats(); + for (std::list::iterator it = optsConfigureData->tempFormats.begin(); it != optsConfigureData->tempFormats.end(); ++it) { + ListBox_AddString(lb, it->name.c_str()); + } } - return TRUE; } + else if (HIWORD(wParam) == LBN_SELCHANGE && LOWORD(wParam) == IDC_FORMATTING) { + OptsConfigureData* optsConfigureData = (OptsConfigureData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + int sel = ListBox_GetCurSel(GetDlgItem(hwndDlg, IDC_FORMATTING)); + SelectLbConfigure(hwndDlg, sel, optsConfigureData); + } + return TRUE; + case WM_VKEYTOITEM: if (LOWORD(wParam) == VK_DELETE && (HWND)lParam == GetDlgItem(hwndDlg, IDC_FORMATTING)) { DlgProcOptsConfigure(hwndDlg, WM_COMMAND, MAKELONG(IDC_DELETE, BN_CLICKED), NULL); return -2; } return -1; + case WM_NOTIFY: - { - return TRUE; - } + return TRUE; } return FALSE; @@ -573,35 +563,31 @@ INT_PTR CALLBACK Options::DlgProcOptsLogin(HWND hwndDlg, UINT msg, WPARAM wParam { switch (msg) { case WM_INITDIALOG: - { - TranslateDialogDefault(hwndDlg); - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); - Edit_LimitText(GetDlgItem(hwndDlg, IDC_PASTEBIN_USER), 99); - Edit_LimitText(GetDlgItem(hwndDlg, IDC_PASTEBIN_PASSWORD), 99); - return TRUE; - } + TranslateDialogDefault(hwndDlg); + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); + Edit_LimitText(GetDlgItem(hwndDlg, IDC_PASTEBIN_USER), 99); + Edit_LimitText(GetDlgItem(hwndDlg, IDC_PASTEBIN_PASSWORD), 99); + return TRUE; + case WM_COMMAND: - { - if (HIWORD(wParam) == BN_CLICKED) { - if (LOWORD(wParam) == IDOK) { - wchar_t buf[100]; - OptsLoginData* optsLoginData = (OptsLoginData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - Edit_GetText(GetDlgItem(hwndDlg, IDC_PASTEBIN_USER), buf, 100); - optsLoginData->user = buf; - Edit_GetText(GetDlgItem(hwndDlg, IDC_PASTEBIN_PASSWORD), buf, 100); - optsLoginData->password = buf; - EndDialog(hwndDlg, IDOK); - } - else if (LOWORD(wParam) == IDCANCEL) { - EndDialog(hwndDlg, IDCANCEL); - } + if (HIWORD(wParam) == BN_CLICKED) { + if (LOWORD(wParam) == IDOK) { + wchar_t buf[100]; + OptsLoginData* optsLoginData = (OptsLoginData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + Edit_GetText(GetDlgItem(hwndDlg, IDC_PASTEBIN_USER), buf, 100); + optsLoginData->user = buf; + Edit_GetText(GetDlgItem(hwndDlg, IDC_PASTEBIN_PASSWORD), buf, 100); + optsLoginData->password = buf; + EndDialog(hwndDlg, IDOK); + } + else if (LOWORD(wParam) == IDCANCEL) { + EndDialog(hwndDlg, IDCANCEL); } - return TRUE; } + return TRUE; + case WM_NOTIFY: - { - return TRUE; - } + return TRUE; } return FALSE; diff --git a/plugins/PasteIt/src/PasteIt.cpp b/plugins/PasteIt/src/PasteIt.cpp index 0b538f5cae..295466b993 100644 --- a/plugins/PasteIt/src/PasteIt.cpp +++ b/plugins/PasteIt/src/PasteIt.cpp @@ -29,7 +29,7 @@ HGENMENU hWebPageMenus[PasteToWeb::pages]; HANDLE hOptionsInit; HANDLE hWindowEvent = nullptr; -static IconItem iconList[] = +static IconItem iconList[] = { { LPGEN("Paste It"), "PasteIt_main", IDI_MENU } }; @@ -59,7 +59,8 @@ PLUGININFOEX pluginInfoEx = CMPlugin::CMPlugin() : PLUGIN(MODULENAME, pluginInfoEx) -{} +{ +} ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/plugins/PasteIt/src/PasteToWeb.cpp b/plugins/PasteIt/src/PasteToWeb.cpp index 358564bdb6..7a98dcf5b8 100644 --- a/plugins/PasteIt/src/PasteToWeb.cpp +++ b/plugins/PasteIt/src/PasteToWeb.cpp @@ -22,7 +22,6 @@ PasteToWeb::PasteToWeb() { } - PasteToWeb::~PasteToWeb() { } @@ -48,45 +47,38 @@ struct FromFileData INT_PTR CALLBACK DlgProcFromClipboard(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - switch (msg) - { + switch (msg) { 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::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); + 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::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; - } + case WM_COMMAND: - { - if (HIWORD(wParam) == BN_CLICKED) - { - if (LOWORD(wParam) == IDOK) - { + if (HIWORD(wParam) == BN_CLICKED) { + if (LOWORD(wParam) == IDOK) { FromClipboardData *clipboardData = (FromClipboardData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); int sel = ComboBox_GetCurSel(GetDlgItem(hwndDlg, IDC_FORMAT)); - for (std::list::iterator it = Options::instance->webOptions[clipboardData->page]->formats.begin(); it != Options::instance->webOptions[clipboardData->page]->formats.end(); ++it) - { - if (sel-- <= 0) - { + for (std::list::iterator it = Options::instance->webOptions[clipboardData->page]->formats.begin(); it != Options::instance->webOptions[clipboardData->page]->formats.end(); ++it) { + if (sel-- <= 0) { clipboardData->format = it->id; break; } @@ -94,15 +86,13 @@ INT_PTR CALLBACK DlgProcFromClipboard(HWND hwndDlg, UINT msg, WPARAM wParam, LPA EndDialog(hwndDlg, IDC_BTN_OK); } - else if (LOWORD(wParam) == IDCANCEL) - { + else if (LOWORD(wParam) == IDCANCEL) { EndDialog(hwndDlg, IDCANCEL); } } break; } - } return FALSE; } @@ -114,101 +104,75 @@ void RecodeDlg(HWND hwndDlg) unsigned int cp = Options::GetCodepageCB(GetDlgItem(hwndDlg, IDC_CODEPAGE), false, fromFileData->codepage); mir_free(fromFileData->contentW); int cbLen = 0; - if (cp == 1200 || cp == 1201) - { - // UTF-16 + if (cp == 1200 || cp == 1201) // UTF-16 cbLen = fromFileData->contentLen / 2; - } else - { cbLen = MultiByteToWideChar(cp, 0, fromFileData->content, fromFileData->contentLen, nullptr, 0); - } fromFileData->contentW = (wchar_t*)mir_alloc(sizeof(wchar_t)*(cbLen + 1)); - if (fromFileData->contentW != nullptr) - { + if (fromFileData->contentW != nullptr) { if (cp == 1200) - { 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) - { 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); } + else MultiByteToWideChar(cp, 0, fromFileData->content, fromFileData->contentLen, fromFileData->contentW, cbLen); fromFileData->contentW[cbLen] = 0; SetDlgItemText(hwndDlg, IDC_FILE_DATA, fromFileData->contentW); } - else - { - SetDlgItemText(hwndDlg, IDC_FILE_DATA, L""); - } + else SetDlgItemText(hwndDlg, IDC_FILE_DATA, L""); fromFileData->codepage = cp; } 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::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); - } + 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::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]->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); + 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); } - else - Button_Enable(GetDlgItem(hwndDlg, IDC_AUTOFORMAT), FALSE); return TRUE; - } + case WM_COMMAND: - { - if (HIWORD(wParam) == BN_CLICKED) - { - if (LOWORD(wParam) == IDOK) - { + if (HIWORD(wParam) == BN_CLICKED) { + if (LOWORD(wParam) == IDOK) { FromFileData *fromFileData = (FromFileData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); int sel = ComboBox_GetCurSel(GetDlgItem(hwndDlg, IDC_FORMAT)); - for (std::list::iterator it = Options::instance->webOptions[fromFileData->page]->formats.begin(); it != Options::instance->webOptions[fromFileData->page]->formats.end(); ++it) - { - if (sel-- <= 0) - { + for (std::list::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; } @@ -221,33 +185,26 @@ INT_PTR CALLBACK DlgProcFromFile(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l EndDialog(hwndDlg, IDC_BTN_OK); } - else if (LOWORD(wParam) == IDCANCEL) - { + else if (LOWORD(wParam) == IDCANCEL) { EndDialog(hwndDlg, IDCANCEL); } - else if (LOWORD(wParam) == IDC_RECODE) - { + else if (LOWORD(wParam) == IDC_RECODE) { RecodeDlg(hwndDlg); } - else if (LOWORD(wParam) == IDC_AUTOFORMAT) - { + 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); } } - else if (LOWORD(wParam) == IDC_CODEPAGE) - { - if (HIWORD(wParam) == CBN_SELCHANGE) - { + else if (LOWORD(wParam) == IDC_CODEPAGE) { + if (HIWORD(wParam) == CBN_SELCHANGE) { RecodeDlg(hwndDlg); } - else if (HIWORD(wParam) == CBN_EDITCHANGE) - { + else if (HIWORD(wParam) == CBN_EDITCHANGE) { ShowWindow(GetDlgItem(hwndDlg, IDC_RECODE), SW_SHOW); } - else if (HIWORD(wParam) == CBN_KILLFOCUS) - { + else if (HIWORD(wParam) == CBN_KILLFOCUS) { FromFileData *fromFileData = (FromFileData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); Options::GetCodepageCB(GetDlgItem(hwndDlg, IDC_CODEPAGE), true, fromFileData->codepage); } @@ -255,7 +212,6 @@ INT_PTR CALLBACK DlgProcFromFile(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l break; } - } return FALSE; } @@ -266,11 +222,9 @@ void PasteToWeb::FromClipboard() error = nullptr; std::wstring str; BOOL isFile = 0; - if (OpenClipboard(nullptr)) - { + if (OpenClipboard(nullptr)) { HANDLE obj = GetClipboardData(CF_UNICODETEXT); - if (obj != nullptr) - { + if (obj != nullptr) { LPCWSTR wStr = (LPCWSTR)GlobalLock(obj); str.append(wStr, wStr + mir_wstrlen(wStr)); GlobalUnlock(obj); @@ -278,11 +232,9 @@ void PasteToWeb::FromClipboard() // 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 != nullptr) - { + if (obj != nullptr) { LPCSTR cStr = (LPCSTR)GlobalLock(obj); - if (mir_strlen(cStr) > str.length()) - { + if (mir_strlen(cStr) > str.length()) { str = L""; LPWSTR p = mir_a2u_cp(cStr, CP_ACP); str.append(p, p + mir_wstrlen(p)); @@ -291,51 +243,41 @@ void PasteToWeb::FromClipboard() GlobalUnlock(obj); } } - else - { + else { obj = GetClipboardData(CF_TEXT); - if (obj != nullptr) - { + if (obj != nullptr) { LPCSTR cStr = (LPCSTR)GlobalLock(obj); LPWSTR wStr = mir_a2u_cp(cStr, CP_ACP); str.append(wStr, wStr + mir_wstrlen(wStr)); mir_free(wStr); GlobalUnlock(obj); } - else - { + else { obj = GetClipboardData(CF_HDROP); - if (obj != nullptr) - { + if (obj != nullptr) { LPDROPFILES df = (LPDROPFILES)GlobalLock(obj); isFile = 1; - if (df->fWide) - { + if (df->fWide) { // Unicode WCHAR* file = (WCHAR*)((BYTE*)obj + df->pFiles); size_t len = mir_wstrlen(file); - if (*(file + len + 1) == L'\0') - { + if (*(file + len + 1) == L'\0') { str.append(file, file + len); } - else - { + else { error = TranslateT("You can only paste 1 file"); } } - else - { + else { // ANSI char* file = (char*)obj + df->pFiles; size_t len = mir_strlen(file); - if (*(file + len + 1) == '\0') - { + if (*(file + len + 1) == '\0') { LPWSTR wStr = mir_a2u_cp(file, CP_ACP); str.append(wStr, wStr + mir_wstrlen(wStr)); mir_free(wStr); } - else - { + else { error = TranslateT("You can only paste 1 file"); } } @@ -347,12 +289,10 @@ void PasteToWeb::FromClipboard() CloseClipboard(); } - if (str.length() > 0) - { + if (str.length() > 0) { if (isFile) FromFile(str); - else - { + else { FromClipboardData data; data.content = str; data.page = pageIndex; @@ -362,8 +302,7 @@ void PasteToWeb::FromClipboard() SendToServer(str, L"", data.format); } } - else if (error == nullptr) - { + else if (error == nullptr) { error = TranslateT("Cannot get data from clipboard"); } } @@ -375,18 +314,13 @@ void PasteToWeb::FromFile(std::wstring file) HANDLE hFile = CreateFile(file.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, 0, nullptr); FromFileData fromFileData = {}; fromFileData.fileName = &file; - if (hFile != INVALID_HANDLE_VALUE) - { + if (hFile != INVALID_HANDLE_VALUE) { LARGE_INTEGER fileSize; - if (GetFileSizeEx(hFile, &fileSize)) - { - if (fileSize.QuadPart <= 10485760LL) - { - if (fileSize.QuadPart > 512000LL) - { + if (GetFileSizeEx(hFile, &fileSize)) { + if (fileSize.QuadPart <= 10485760LL) { + if (fileSize.QuadPart > 512000LL) { mir_snwprintf(bufErr, TranslateT("File size is %d KB, do you really want to paste such a large file?"), fileSize.LowPart / 1024); - if (MessageBox(nullptr, bufErr, TranslateT("Are You sure?"), MB_YESNO | MB_ICONQUESTION) != IDYES) - { + if (MessageBox(nullptr, bufErr, TranslateT("Are You sure?"), MB_YESNO | MB_ICONQUESTION) != IDYES) { CloseHandle(hFile); return; } @@ -394,8 +328,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, nullptr)) - { + if (!ReadFile(hFile, fromFileData.content, fromFileData.contentLen, &readed, nullptr)) { mir_free(fromFileData.content); fromFileData.content = nullptr; fromFileData.contentLen = 0; @@ -403,78 +336,62 @@ void PasteToWeb::FromFile(std::wstring file) error = bufErr; } } - else - { + else { error = TranslateT("File size is larger then 10 MB, cannot be sent"); } } CloseHandle(hFile); } - else - { + else { mir_snwprintf(bufErr, TranslateT("Cannot open file '%s'"), file.c_str()); error = bufErr; } - if (fromFileData.content != nullptr) - { + if (fromFileData.content != nullptr) { 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, nullptr, 0); - if (cbLen == 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 - { + else { cbLen = MultiByteToWideChar(fromFileData.codepage, 0, fromFileData.content, fromFileData.contentLen, nullptr, 0); } } - if (cbLen > 0) - { + if (cbLen > 0) { fromFileData.contentW = (wchar_t*)mir_alloc(sizeof(wchar_t)*(cbLen + 1)); - if (fromFileData.contentW != nullptr) - { - if (fromFileData.codepage == 1200) - { + if (fromFileData.contentW != nullptr) { + if (fromFileData.codepage == 1200) { memcpy_s(fromFileData.contentW, sizeof(wchar_t)*(cbLen + 1), fromFileData.content, sizeof(wchar_t)*cbLen); } - else if (fromFileData.codepage == 1201) - { - for (int i = 0; i < cbLen; ++i) - { + else if (fromFileData.codepage == 1201) { + for (int i = 0; i < cbLen; ++i) { fromFileData.contentW[i] = (fromFileData.content[i * 2] << 8) | fromFileData.content[i * 2 + 1]; } } - else - { + else { MultiByteToWideChar(fromFileData.codepage, 0, fromFileData.content, fromFileData.contentLen, fromFileData.contentW, cbLen); } fromFileData.contentW[cbLen] = 0; fromFileData.page = pageIndex; - if (!Options::instance->confDlg || DialogBoxParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_DLG_FROM_FILE), nullptr, DlgProcFromFile, (LPARAM)&fromFileData) == IDC_BTN_OK) - { + if (!Options::instance->confDlg || DialogBoxParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_DLG_FROM_FILE), nullptr, 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'/'); @@ -489,8 +406,7 @@ void PasteToWeb::FromFile(std::wstring file) mir_free(fromFileData.contentW); } } - else - { + else { mir_snwprintf(bufErr, TranslateT("File '%s' is empty"), file.c_str()); error = bufErr; } @@ -500,24 +416,22 @@ void PasteToWeb::FromFile(std::wstring file) extern HNETLIBUSER g_hNetlibUser; -wchar_t* PasteToWeb::SendToWeb(char* url, std::map& headers, std::wstring content) +char* PasteToWeb::SendToWeb(char* url, std::map& headers, std::wstring content) { - wchar_t* resCont = nullptr; int cbLen = WideCharToMultiByte(CP_UTF8, 0, content.c_str(), -1, nullptr, 0, nullptr, nullptr); char* contentBytes = (char*)mir_alloc(cbLen); if (contentBytes == nullptr) - return resCont; + return nullptr; WideCharToMultiByte(CP_UTF8, 0, content.c_str(), -1, contentBytes, cbLen, nullptr, nullptr); --cbLen; int nHeaders = 0; - for (std::map::iterator it = headers.begin(); it != headers.end(); ++it) - { + for (std::map::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; @@ -528,8 +442,7 @@ wchar_t* PasteToWeb::SendToWeb(char* url, std::map& he nlhr.dataLength = cbLen; nHeaders = 0; std::list mallBuf; - for (std::map::iterator it = headers.begin(); it != headers.end(); ++it) - { + for (std::map::iterator it = headers.begin(); it != headers.end(); ++it) { char* b1 = new char[it->first.length() + 1]; char* b2 = new char[it->second.length() + 1]; mir_strncpy(b1, it->first.c_str(), it->first.length() + 1); @@ -541,29 +454,21 @@ wchar_t* PasteToWeb::SendToWeb(char* url, std::map& he ++nHeaders; } + char *resCont = nullptr; nlhr.headersCount = nHeaders; NETLIBHTTPREQUEST* nlhrReply = Netlib_HttpTransaction(g_hNetlibUser, &nlhr); - if (nlhrReply != nullptr) - { - if (nlhrReply->resultCode == 200) - { - int resLen = MultiByteToWideChar(CP_UTF8, 0, nlhrReply->pData, nlhrReply->dataLength, nullptr, 0); - ++resLen; - resCont = (wchar_t*)mir_alloc(resLen * sizeof(wchar_t)); - if (resCont != nullptr) - { - resLen = MultiByteToWideChar(CP_UTF8, 0, nlhrReply->pData, nlhrReply->dataLength, resCont, resLen); - resCont[resLen] = 0; - } + if (nlhrReply != nullptr) { + if (nlhrReply->resultCode == 200) { + resCont = nlhrReply->pData; + nlhrReply->pData = 0; } Netlib_FreeHttpRequest(nlhrReply); } + delete[] httpHeaders; for (std::list::iterator it = mallBuf.begin(); it != mallBuf.end(); ++it) - { delete *it; - } mir_free(contentBytes); return resCont; diff --git a/plugins/PasteIt/src/PasteToWeb.h b/plugins/PasteIt/src/PasteToWeb.h index fdedc388ac..aa94015b3a 100644 --- a/plugins/PasteIt/src/PasteToWeb.h +++ b/plugins/PasteIt/src/PasteToWeb.h @@ -28,7 +28,7 @@ class PasteToWeb { protected: virtual void SendToServer(std::wstring str, std::wstring fileName, std::wstring format) = 0; - wchar_t* SendToWeb(char* url, std::map& headers, std::wstring content); + char* SendToWeb(char* url, std::map& headers, std::wstring content); PasteToWeb(); wchar_t bufErr[1024]; public: diff --git a/plugins/PasteIt/src/PasteToWeb1.cpp b/plugins/PasteIt/src/PasteToWeb1.cpp index b725c12f52..706f6c2171 100644 --- a/plugins/PasteIt/src/PasteToWeb1.cpp +++ b/plugins/PasteIt/src/PasteToWeb1.cpp @@ -273,52 +273,37 @@ void PasteToWeb1::SendToServer(std::wstring str, std::wstring fileName, std::wst content += Options::instance->webOptions[pageIndex]->combo1.empty() ? L"1M" : Options::instance->webOptions[pageIndex]->combo1; content += L"&api_dev_key=dcba056bf9cc71729fdad76dddcb0dcd&api_paste_format="; content += format; - if (!Options::instance->webOptions[pageIndex]->pastebinUserKey.empty()) - { + if (!Options::instance->webOptions[pageIndex]->pastebinUserKey.empty()) { content += L"&api_user_key="; content += Options::instance->webOptions[pageIndex]->pastebinUserKey; } content += L"&api_paste_code="; - for (std::wstring::iterator it = str.begin(); it != str.end(); ++it) - { - if (*it == L'%') - { + for (std::wstring::iterator it = str.begin(); it != str.end(); ++it) { + if (*it == L'%') { content += L"%25"; } - else if (*it == L'&') - { + else if (*it == L'&') { content += L"%26"; } - else if (*it == L'=') - { + else if (*it == L'=') { content += L"%3D"; } - else - { + else { content += *it; } } - wchar_t* resCont = SendToWeb("http://pastebin.com/api/api_post.php", headers, content); - if (resCont != nullptr) - { - if (memcmp(L"Bad API request, ", resCont, 17 * sizeof(wchar_t)) == 0) - { - mir_snwprintf(bufErr, TranslateT("Error during sending text to web page: %s"), resCont + 17); + char *resCont = SendToWeb("http://pastebin.com/api/api_post.php", headers, content); + if (resCont != nullptr) { + if (memcmp("Bad API request, ", resCont, 17) == 0) { + mir_snwprintf(bufErr, TranslateT("Error during sending text to web page: %S"), resCont + 17); error = bufErr; } - else - { - char* s = mir_u2a_cp(resCont, CP_ACP); - mir_strncpy(szFileLink, s, _countof(szFileLink)); - mir_free(s); - } + else mir_strncpy(szFileLink, resCont, _countof(szFileLink)); + mir_free(resCont); } - else - { - error = TranslateT("Error during sending text to web page"); - } + else error = TranslateT("Error during sending text to web page"); } std::wstring PasteToWeb1::GetUserKey(std::wstring& user, std::wstring& password) @@ -330,17 +315,14 @@ std::wstring PasteToWeb1::GetUserKey(std::wstring& user, std::wstring& password) content += L"&api_user_password="; content += password; content += L"&api_dev_key=dcba056bf9cc71729fdad76dddcb0dcd"; - wchar_t* resCont = SendToWeb("http://pastebin.com/api/api_login.php", headers, content); + char *resCont = SendToWeb("http://pastebin.com/api/api_login.php", headers, content); std::wstring toRet; - if (resCont != nullptr) - { - if (memcmp(L"Bad API request, ", resCont, 17 * sizeof(wchar_t)) == 0) - { - mir_snwprintf(bufErr, TranslateT("Error during getting user key from web page: %s"), resCont + 17); + if (resCont != nullptr) { + if (memcmp("Bad API request, ", resCont, 17) == 0) { + mir_snwprintf(bufErr, TranslateT("Error during getting user key from web page: %S"), resCont + 17); MessageBox(nullptr, bufErr, TranslateT("Error"), MB_OK | MB_ICONERROR); } - else - toRet = resCont; + else toRet = Utf2T(resCont).get(); mir_free(resCont); } @@ -388,4 +370,3 @@ void PasteToWeb1::ConfigureSettings() Options::instance->webOptions[pageIndex]->combo1 = L"1M"; Options::instance->webOptions[pageIndex]->isPastebin = true; } - diff --git a/plugins/PasteIt/src/PasteToWeb2.cpp b/plugins/PasteIt/src/PasteToWeb2.cpp index 17b3ca116f..e77def7eb0 100644 --- a/plugins/PasteIt/src/PasteToWeb2.cpp +++ b/plugins/PasteIt/src/PasteToWeb2.cpp @@ -55,80 +55,53 @@ void PasteToWeb2::SendToServer(std::wstring str, std::wstring fileName, std::wst std::map headers; headers["Content-Type"] = "text/xml"; std::wstring content = L"\r\ncreate_paste"; - if (fileName == L"") - { + if (fileName == L"") { content += format; content += L""; } - else - { - content += L""; - } - for (std::wstring::iterator it = str.begin(); it != str.end(); ++it) - { - if (*it == L'&') - { + else content += L""; + + for (std::wstring::iterator it = str.begin(); it != str.end(); ++it) { + if (*it == L'&') { content += L"&"; } - else if (*it == L'<') - { + else if (*it == L'<') { content += L"<"; } - else - { + else { content += *it; } } content += L""; - if (fileName != L"") - { - for (std::wstring::iterator it = fileName.begin(); it != fileName.end(); ++it) - { - if (*it == L'&') - { + if (fileName != L"") { + for (std::wstring::iterator it = fileName.begin(); it != fileName.end(); ++it) { + if (*it == L'&') { content += L"&"; } - else if (*it == L'<') - { + else if (*it == L'<') { content += L"<"; } - else - { + else { content += *it; } } } content += L"1.5"; - wchar_t* resCont = SendToWeb("http://wklej.to/api/", headers, content); + char *resCont = SendToWeb("http://wklej.to/api/", headers, content); error = TranslateT("Error during sending text to web page"); - if (resCont != nullptr) - { - HXML hXml = xmlParseString(resCont, nullptr, L"methodResponse"); - if (hXml != nullptr) - { - HXML node = xmlGetChildByPath(hXml, L"params/param/value/array/data/value/int", 0); - if (node != nullptr && !mir_wstrcmp(xmlGetText(node), L"1")) - { - node = xmlGetChildByPath(hXml, L"params/param/value/array/data", 0); - if (node != nullptr) - { - node = xmlGetNthChild(node, L"value", 1); - if (node != nullptr) - { - node = xmlGetChildByPath(node, L"string", 0); - if (node != nullptr) - { - char* s = mir_u2a_cp(xmlGetText(node), CP_ACP); - mir_strncpy(szFileLink, s, _countof(szFileLink)); - mir_free(s); - error = nullptr; - } - } + if (resCont != nullptr) { + TiXmlDocument doc; + if (0 == doc.Parse(resCont)) { + auto *pData = TiXmlConst(&doc)["methodResponse"]["params"]["param"]["value"]["array"]["data"].ToElement(); + for (auto *it : TiXmlFilter(pData, "value")) { + auto *pString = it->FirstChildElement("string"); + if (pString) { + mir_strncpy(szFileLink, pString->GetText(), _countof(szFileLink)); + error = nullptr; } } - xmlDestroyNode(hXml); } mir_free(resCont); } @@ -142,90 +115,67 @@ std::list PasteToWeb2::GetFormats() headers["Content-Type"] = "text/xml"; std::wstring content = L"\r\ntypes"; - wchar_t* resCont = SendToWeb("http://wklej.to/api/", headers, content); - if (resCont != nullptr) - { - HXML hXml = xmlParseString(resCont, nullptr, L"methodResponse"); - if (hXml != nullptr) - { - HXML node = xmlGetChildByPath(hXml, L"params/param/value/array/data/value/int", 0); - if (node != nullptr && !mir_wstrcmp(xmlGetText(node), L"1")) - { - node = xmlGetChildByPath(hXml, L"params/param/value/array/data", 0); - if (node != nullptr) + char* resCont = SendToWeb("http://wklej.to/api/", headers, content); + if (resCont != nullptr) { + TiXmlDocument doc; + if (0 == doc.Parse(resCont)) { + auto *pData = TiXmlConst(&doc)["methodResponse"]["params"]["param"]["value"]["array"]["data"].ToElement(); + for (auto *it : TiXmlFilter(pData, "value")) { + auto *pString = it->FirstChildElement("string"); + if (pString == nullptr) + continue; + + std::wstring str = Utf2T(pString->GetText()).get(); + std::wstring::size_type pos = str.find(L'\n'); + if (pos < str.length()) { + str = str.substr(pos + 1); + } + pos = str.find(L'\n'); + if (pos < str.length()) { + str = str.substr(pos + 1); + } + pos = str.find(L'\n'); + while (pos < str.length()) { + std::wstring line = str.substr(0, pos); + std::wstring::size_type sep = line.find(L':'); + if (sep < line.length()) { + PasteFormat pf; + pf.name = line.substr(0, sep); + std::wstring::size_type sep2 = line.find(L','); + if (sep2 < line.length()) { + pf.id = line.substr(sep + 2, sep2 - sep - 2); + } + else { + pf.id = line.substr(sep + 2); + } + ret.push_back(pf); + } + + if (pos < str.length() - 1) { + str = str.substr(pos + 1); + } + else { + str = L""; + } + pos = str.find(L'\n'); + } { - node = xmlGetNthChild(node, L"value", 1); - if (node != nullptr) - { - node = xmlGetChildByPath(node, L"string", 0); - if (node != nullptr) - { - std::wstring str = xmlGetText(node); - std::wstring::size_type pos = str.find(L'\n'); - if (pos < str.length()) - { - str = str.substr(pos + 1); - } - pos = str.find(L'\n'); - if (pos < str.length()) - { - str = str.substr(pos + 1); - } - pos = str.find(L'\n'); - while (pos < str.length()) - { - std::wstring line = str.substr(0, pos); - std::wstring::size_type sep = line.find(L':'); - if (sep < line.length()) - { - PasteFormat pf; - pf.name = line.substr(0, sep); - std::wstring::size_type sep2 = line.find(L','); - if (sep2 < line.length()) - { - pf.id = line.substr(sep + 2, sep2 - sep - 2); - } - else - { - pf.id = line.substr(sep + 2); - } - ret.push_back(pf); - } - - if (pos < str.length() - 1) - { - str = str.substr(pos + 1); - } - else - { - str = L""; - } - pos = str.find(L'\n'); - } - { - std::wstring line = str; - std::wstring::size_type sep = line.find(L':'); - if (sep < line.length()) - { - PasteFormat pf; - pf.name = line.substr(0, sep); - std::wstring::size_type sep2 = line.find(L','); - if (sep2 < line.length()) - { - pf.id = line.substr(sep + 2, sep2 - sep - 2); - } - else - { - pf.id = line.substr(sep + 2); - } - ret.push_back(pf); - } - } + std::wstring line = str; + std::wstring::size_type sep = line.find(L':'); + if (sep < line.length()) { + PasteFormat pf; + pf.name = line.substr(0, sep); + std::wstring::size_type sep2 = line.find(L','); + if (sep2 < line.length()) { + pf.id = line.substr(sep + 2, sep2 - sep - 2); + } + else { + pf.id = line.substr(sep + 2); } + ret.push_back(pf); } } } - xmlDestroyNode(hXml); } mir_free(resCont); } diff --git a/plugins/PasteIt/src/version.h b/plugins/PasteIt/src/version.h index bea6149880..a505d64a79 100644 --- a/plugins/PasteIt/src/version.h +++ b/plugins/PasteIt/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 1 #define __MINOR_VERSION 0 #define __RELEASE_NUM 0 -#define __BUILD_NUM 3 +#define __BUILD_NUM 4 #include -- cgit v1.2.3