diff options
Diffstat (limited to 'plugins/New_GPG')
-rw-r--r-- | plugins/New_GPG/res/new_gpg.rc | 6 | ||||
-rwxr-xr-x | plugins/New_GPG/src/log.cpp | 2 | ||||
-rw-r--r-- | plugins/New_GPG/src/log.h | 2 | ||||
-rwxr-xr-x | plugins/New_GPG/src/options.cpp | 11 | ||||
-rw-r--r-- | plugins/New_GPG/src/resource.h | 2 | ||||
-rwxr-xr-x | plugins/New_GPG/src/ui.cpp | 17 | ||||
-rwxr-xr-x | plugins/New_GPG/src/utilities.cpp | 63 |
7 files changed, 37 insertions, 66 deletions
diff --git a/plugins/New_GPG/res/new_gpg.rc b/plugins/New_GPG/res/new_gpg.rc index 41f1b30c0f..30a25c0fc5 100644 --- a/plugins/New_GPG/res/new_gpg.rc +++ b/plugins/New_GPG/res/new_gpg.rc @@ -192,12 +192,12 @@ CAPTION "Choose which keys to export" FONT 8, "MS Shell Dlg", 400, 0, 0x1 BEGIN GROUPBOX "Static",IDC_STATIC,7,7,267,63 - PUSHBUTTON "OK",IDC_OK,7,71,50,14 - PUSHBUTTON "Cancel",IDC_CANCEL,224,71,50,14 CONTROL "Export public keys (only set for contacts)",IDC_PUBLIC, "Button",BS_AUTORADIOBUTTON,15,23,248,10 CONTROL "Export all private keys",IDC_PRIVATE,"Button",BS_AUTORADIOBUTTON,15,36,246,10 CONTROL "Export public and private keys",IDC_ALL,"Button",BS_AUTORADIOBUTTON,15,50,248,10 + PUSHBUTTON "OK",IDOK,7,71,50,14 + PUSHBUTTON "Cancel",IDCANCEL,224,71,50,14 END IDD_CHANGE_PASSWD DIALOGEX 0, 0, 256, 74 @@ -210,7 +210,7 @@ BEGIN EDITTEXT IDC_NEW_PASSWD2,81,50,157,14,ES_PASSWORD | ES_AUTOHSCROLL LTEXT "Current password:",IDC_STATIC,7,17,61,8 LTEXT "New password twice:",IDC_STATIC,7,32,69,8 - PUSHBUTTON "OK",IDC_OK,7,55,50,14 + PUSHBUTTON "OK",IDOK,7,55,50,14 END IDD_OPT_GPG DIALOGEX 0, 0, 286, 220 diff --git a/plugins/New_GPG/src/log.cpp b/plugins/New_GPG/src/log.cpp index 24f6af9c1a..8f198c8561 100755 --- a/plugins/New_GPG/src/log.cpp +++ b/plugins/New_GPG/src/log.cpp @@ -64,7 +64,7 @@ logtofile& logtofile::operator<<(wstring buf) mir_cslock l(csLock); log.open(path, std::ios::app | std::ios::ate); - log << buf; + log << T2Utf(buf.c_str()); log << "\n"; log.close(); return *this; diff --git a/plugins/New_GPG/src/log.h b/plugins/New_GPG/src/log.h index 86da7b3376..56847943cc 100644 --- a/plugins/New_GPG/src/log.h +++ b/plugins/New_GPG/src/log.h @@ -28,7 +28,7 @@ public: logtofile(); private: - wfstream log; + fstream log; CMStringW path; bool _bDebugLog; mir_cs csLock; diff --git a/plugins/New_GPG/src/options.cpp b/plugins/New_GPG/src/options.cpp index 6728343fe5..c907cf2165 100755 --- a/plugins/New_GPG/src/options.cpp +++ b/plugins/New_GPG/src/options.cpp @@ -243,13 +243,12 @@ public: void onClick_SAVE_KEY_BUTTON(CCtrlButton*) { - wchar_t *tmp = GetFilePath(TranslateT("Export public key"), L"*", TranslateT(".asc pubkey file"), true); + ptrW tmp(GetFilePath(TranslateT("Export public key"), L"*", TranslateT(".asc pubkey file"), true)); if (tmp) { CMStringW str(g_plugin.getMStringW(globals.user_data[item_num + 1], "GPGPubKey")); str.Replace(L"\r", L""); wfstream f(tmp, std::ios::out); - delete[] tmp; f << str.c_str(); f.close(); } @@ -953,14 +952,13 @@ public: this->Close(); } - void onClick_LOAD_FROM_FILE(CCtrlButton*) + void onClick_LOAD_FROM_FILE(CCtrlButton *) { - wchar_t *tmp = GetFilePath(TranslateT("Set file containing GPG public key"), L"*", TranslateT("GPG public key file")); + ptrW tmp(GetFilePath(TranslateT("Set file containing GPG public key"), L"*", TranslateT("GPG public key file"))); if (!tmp) return; wfstream f(tmp, std::ios::in | std::ios::ate | std::ios::binary); - delete[] tmp; if (!f.is_open()) { MessageBox(nullptr, TranslateT("Failed to open file"), TranslateT("Error"), MB_OK); return; @@ -995,7 +993,8 @@ public: edit_PUBLIC_KEY_EDIT.SetText(key_buf.substr(ws1, ws2 - ws1).c_str()); key_buf.clear(); } - void onClick_IMPORT(CCtrlButton*) + + void onClick_IMPORT(CCtrlButton *) { CDlgImportKey *d = new CDlgImportKey(hContact); d->Show(); diff --git a/plugins/New_GPG/src/resource.h b/plugins/New_GPG/src/resource.h index b57e346c05..8132179de6 100644 --- a/plugins/New_GPG/src/resource.h +++ b/plugins/New_GPG/src/resource.h @@ -42,7 +42,6 @@ #define IDC_SELECT_EXISTING 1026 #define IDC_KEY_EMAIL 1026 #define IDC_IGNORE 1026 -#define IDC_OK 1026 #define IDC_EXPORT 1026 #define IDC_DELETE_KEY_BUTTON 1027 #define IDC_IN_CLOSE_TAG 1027 @@ -65,7 +64,6 @@ #define IDC_LOG_FILE_SET 1046 #define IDC_IMPORT 1046 #define IDC_DECRYPT 1046 -#define IDC_CANCEL 1046 #define IDC_SAVE_PASSWORD 1047 #define IDC_DEBUG_LOG 1048 #define IDC_JABBER_API 1049 diff --git a/plugins/New_GPG/src/ui.cpp b/plugins/New_GPG/src/ui.cpp index c3147444ba..04c308410e 100755 --- a/plugins/New_GPG/src/ui.cpp +++ b/plugins/New_GPG/src/ui.cpp @@ -278,19 +278,16 @@ void CDlgFirstRun::onClick_EXPORT_PRIVATE(CCtrlButton*) int i = list_KEY_LIST.GetSelectionMark(); if (i == -1) return; - wchar_t *p = GetFilePath(L"Choose file to export key", L"*", L"Any file", true); - if (!p || !p[0]) { - delete[] p; - //TODO: handle error + + ptrW p(GetFilePath(L"Choose file to export key", L"*", L"Any file", true)); + if (!p || !p[0]) return; - } - char *path = mir_u2a(p); - delete[] p; + std::ofstream file; - file.open(path, std::ios::trunc | std::ios::out); - mir_free(path); + file.open(p, std::ios::trunc | std::ios::out); if (!file.is_open()) return; //TODO: handle error + list_KEY_LIST.GetItemText(i, 0, fp, _countof(fp)); string out; DWORD code; @@ -310,7 +307,7 @@ void CDlgFirstRun::onClick_EXPORT_PRIVATE(CCtrlButton*) if (result == pxNotFound) return; boost::algorithm::erase_all(out, "\r"); - file << out; + file << out.c_str(); if (file.is_open()) file.close(); } diff --git a/plugins/New_GPG/src/utilities.cpp b/plugins/New_GPG/src/utilities.cpp index ea0c57540b..cef68df7e3 100755 --- a/plugins/New_GPG/src/utilities.cpp +++ b/plugins/New_GPG/src/utilities.cpp @@ -18,13 +18,12 @@ #include "utf8.h" -void ShowExportKeysDlg(); void ShowLoadPublicKeyDialog(bool = false); void GetFilePath(wchar_t *WindowTittle, char *szSetting, wchar_t *szExt, wchar_t *szExtDesc) { wchar_t str[MAX_PATH + 2] = {}; - OPENFILENAME ofn = { 0 }; + OPENFILENAME ofn = {}; wchar_t filter[512], *pfilter; ofn.lStructSize = CDSIZEOF_STRUCT(OPENFILENAME, lpTemplateName); ofn.Flags = OFN_EXPLORER; @@ -41,15 +40,14 @@ void GetFilePath(wchar_t *WindowTittle, char *szSetting, wchar_t *szExt, wchar_t ofn.lpstrFile = str; ofn.nMaxFile = _MAX_PATH; ofn.nMaxFileTitle = MAX_PATH; - if (!GetOpenFileName(&ofn)) - return; - g_plugin.setWString(szSetting, str); + if (GetOpenFileName(&ofn)) + g_plugin.setWString(szSetting, str); } wchar_t* GetFilePath(wchar_t *WindowTittle, wchar_t *szExt, wchar_t *szExtDesc, bool save_file) { - wchar_t *str = new wchar_t[MAX_PATH + 2]; - OPENFILENAME ofn = { 0 }; + wchar_t str[MAX_PATH + 1]; + OPENFILENAME ofn = {}; wchar_t filter[512], *pfilter; ofn.lStructSize = CDSIZEOF_STRUCT(OPENFILENAME, lpTemplateName); ofn.Flags = OFN_EXPLORER; @@ -67,18 +65,14 @@ wchar_t* GetFilePath(wchar_t *WindowTittle, wchar_t *szExt, wchar_t *szExtDesc, ofn.nMaxFile = _MAX_PATH; ofn.nMaxFileTitle = MAX_PATH; if (!save_file) { - if (!GetOpenFileName(&ofn)) { - delete[] str; + if (!GetOpenFileName(&ofn)) return nullptr; - } } else { - if (!GetSaveFileName(&ofn)) { - delete[] str; + if (!GetSaveFileName(&ofn)) return nullptr; - } } - return str; + return mir_wstrdup(str); } void GetFolderPath(wchar_t *WindowTittle) @@ -1128,20 +1122,16 @@ bool isTabsrmmUsed() void ExportGpGKeysFunc(int type) { - wchar_t *p = GetFilePath(L"Choose file to export keys", L"*", L"Any file", true); - if (!p || !p[0]) { - delete[] p; - //TODO: handle error + ptrW p(GetFilePath(L"Choose file to export keys", L"*", L"Any file", true)); + if (!p || !p[0]) return; - } - char *path = mir_u2a(p); - delete[] p; + std::ofstream file; - file.open(path, std::ios::trunc | std::ios::out); - mir_free(path); - int exported_keys = 0; + file.open(p, std::ios::trunc | std::ios::out); if (!file.is_open()) return; //TODO: handle error + + int exported_keys = 0; if (!type || type == 2) { for (auto &hContact : Contacts()) { CMStringA key = g_plugin.getMStringA(hContact, "GPGPubKey"); @@ -1278,7 +1268,7 @@ void ExportGpGKeysFunc(int type) params.result = &result; gpg_launcher(params); //TODO: handle errors { - file << out; + file << out.c_str(); file << std::endl; } } @@ -1296,25 +1286,18 @@ void ExportGpGKeysFunc(int type) INT_PTR ExportGpGKeys(WPARAM, LPARAM) { - ShowExportKeysDlg(); + (new CDlgExportKeysMsgBox())->Show(); return 0; } INT_PTR ImportGpGKeys(WPARAM, LPARAM) { - wchar_t *p = GetFilePath(L"Choose file to import keys from", L"*", L"Any file"); - if (!p || !p[0]) { - delete[] p; - //TODO: handle error + ptrW p(GetFilePath(L"Choose file to import keys from", L"*", L"Any file")); + if (!p || !p[0]) return 1; - } - std::ifstream file; - { - ptrA szPath(mir_u2a(p)); - delete[] p; - file.open(szPath, std::ios::in); - } + std::ifstream file; + file.open(p, std::ios::in); if (!file.is_open()) return 1; //TODO: handle error @@ -1671,12 +1654,6 @@ void ShowEncryptedFileMsgBox() d->DoModal(); } -void ShowExportKeysDlg() -{ - CDlgExportKeysMsgBox *d = new CDlgExportKeysMsgBox; - d->Show(); -} - void ShowChangePasswdDlg() { CDlgChangePasswdMsgBox *d = new CDlgChangePasswdMsgBox; |