From 2db81bed3b59b2c48bac5cbd97b511e79a9f23ca Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Thu, 10 Oct 2013 12:55:59 +0300 Subject: merged some of critical fixes from miranda ng main repo --- main.cpp | 1119 +++++++++++++++++++++++++++++++------------------------------- 1 file changed, 563 insertions(+), 556 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index be2fe51..aaf82d3 100755 --- a/main.cpp +++ b/main.cpp @@ -27,8 +27,8 @@ int itemnum = 0; HWND hwndList_g = NULL; BOOL CheckStateStoreDB(HWND hwndDlg, int idCtrl, const char* szSetting); -TCHAR key_id_global[17] = {0}; - +TCHAR key_id_global[17] = {0}; + static INT_PTR CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam) { HWND hwndList=GetDlgItem(hwndDlg, IDC_KEY_LIST); @@ -44,9 +44,9 @@ static INT_PTR CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR SetWindowPos(hwndDlg, 0, firstrun_rect.left, firstrun_rect.top, 0, 0, SWP_NOSIZE|SWP_SHOWWINDOW); TranslateDialogDefault(hwndDlg); SetWindowText(hwndDlg, TranslateT("Set own key")); - EnableWindow(GetDlgItem(hwndDlg, IDC_COPY_PUBKEY), 0); - EnableWindow(GetDlgItem(hwndDlg, IDC_EXPORT_PRIVATE), 0); - EnableWindow(GetDlgItem(hwndDlg, IDC_CHANGE_PASSWD), 0); + EnableWindow(GetDlgItem(hwndDlg, IDC_COPY_PUBKEY), 0); + EnableWindow(GetDlgItem(hwndDlg, IDC_EXPORT_PRIVATE), 0); + EnableWindow(GetDlgItem(hwndDlg, IDC_CHANGE_PASSWD), 0); col.pszText = _T("Key ID"); col.mask = LVCF_TEXT | LVCF_WIDTH; col.fmt = LVCFMT_LEFT; @@ -71,23 +71,23 @@ static INT_PTR CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR col.cx = 30; ListView_InsertColumn(hwndList, 3, &col); ZeroMemory(&col,sizeof(col)); - col.pszText = TranslateT("Expire date"); + col.pszText = TranslateT("Expire date"); col.mask = LVCF_TEXT | LVCF_WIDTH; col.fmt = LVCFMT_LEFT; col.cx = 30; ListView_InsertColumn(hwndList, 4, &col); - ZeroMemory(&col,sizeof(col)); - col.pszText = TranslateT("Key length"); - col.mask = LVCF_TEXT | LVCF_WIDTH; - col.fmt = LVCFMT_LEFT; - col.cx = 30; - ListView_InsertColumn(hwndList, 5, &col); - ZeroMemory(&col,sizeof(col)); - col.pszText = TranslateT("Accounts"); - col.mask = LVCF_TEXT | LVCF_WIDTH; - col.fmt = LVCFMT_LEFT; - col.cx = 30; - ListView_InsertColumn(hwndList, 6, &col); + ZeroMemory(&col,sizeof(col)); + col.pszText = TranslateT("Key length"); + col.mask = LVCF_TEXT | LVCF_WIDTH; + col.fmt = LVCFMT_LEFT; + col.cx = 30; + ListView_InsertColumn(hwndList, 5, &col); + ZeroMemory(&col,sizeof(col)); + col.pszText = TranslateT("Accounts"); + col.mask = LVCF_TEXT | LVCF_WIDTH; + col.fmt = LVCFMT_LEFT; + col.cx = 30; + ListView_InsertColumn(hwndList, 6, &col); ListView_SetExtendedListViewStyleEx(hwndList, 0, LVS_EX_FULLROWSELECT); int i = 1, iRow = 0; { @@ -101,14 +101,14 @@ static INT_PTR CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR pxResult result; wstring::size_type p = 0, p2 = 0, stop = 0; { - std::vector cmd; - cmd.push_back(L"--batch"); - cmd.push_back(L"--list-secret-keys"); - gpg_execution_params params(cmd); + std::vector cmd; + cmd.push_back(L"--batch"); + cmd.push_back(L"--list-secret-keys"); + gpg_execution_params params(cmd); params.out = &out; params.code = &code; params.result = &result; - if(!gpg_launcher(params)) + if(!gpg_launcher(params)) { break; } @@ -124,85 +124,85 @@ static INT_PTR CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR break; stop = p; p2 = out.find("/", p) - 1; - TCHAR *key_len = mir_wstrdup(toUTF16(out.substr(p,p2-p)).c_str()), *creation_date = NULL, *expire_date = NULL; + TCHAR *key_len = mir_wstrdup(toUTF16(out.substr(p,p2-p)).c_str()), *creation_date = NULL, *expire_date = NULL; p2+=2; p = out.find(" ", p2); - std::wstring key_id = toUTF16(out.substr(p2,p-p2)); - p += 1; - p2 = out.find(" ", p); - std::string::size_type p3 = out.find("\n", p); - if((p2 != std::string::npos) && (p3 < p2)) - { - p2 = p3; - creation_date = mir_wstrdup(toUTF16(out.substr(p,p2-p-1)).c_str()); - } - else - { - creation_date = mir_wstrdup(toUTF16(out.substr(p,p2-p)).c_str()); - p2 = out.find("[", p2); - p2 = out.find("expires:", p2); - p2 += strlen("expires:"); - if(p2 != std::string::npos) - { - p2++; - p = p2; - p2 = out.find("]", p); - expire_date = mir_wstrdup(toUTF16(out.substr(p,p2-p)).c_str()); - //check expiration - bool expired = false; - { - boost::posix_time::ptime now = boost::posix_time::second_clock::local_time(); - TCHAR buf[5]; - mir_sntprintf(buf, 5, _T("%s"), expire_date); - int year = _ttoi(buf); - if(year < now.date().year()) - expired = true; - else if(year == now.date().year()) - { - mir_sntprintf(buf, 3, _T("%s"), expire_date+5); - int month = _ttoi(buf); - if(month < now.date().month()) - expired = true; - else if(month == now.date().month()) - { - mir_sntprintf(buf, 3, _T("%s"), expire_date+8); - unsigned day = _ttoi(buf); - if(day <= now.date().day_number()) - expired = true; - } - } - } - if(expired) - { - mir_free(key_len); - mir_free(creation_date); - mir_free(expire_date); - //mimic normal behaviour - p = out.find("uid ", p); - p2 = out.find_first_not_of(" ", p+5); - p = out.find("<", p2); - p++; - p2 = out.find(">", p); - // - continue; //does not add to key list - } - } - } - iRow = ListView_InsertItem(hwndList, &item); - ListView_SetItemText(hwndList, iRow, 3, creation_date); - mir_free(creation_date); - if(expire_date) - { - ListView_SetItemText(hwndList, iRow, 4, expire_date); - mir_free(expire_date); - } - ListView_SetItemText(hwndList, iRow, 5, key_len); - mir_free(key_len); - ListView_SetItemText(hwndList, iRow, 0, (TCHAR*)key_id.c_str()); + std::wstring key_id = toUTF16(out.substr(p2,p-p2)); + p += 1; + p2 = out.find(" ", p); + std::string::size_type p3 = out.find("\n", p); + if((p2 != std::string::npos) && (p3 < p2)) + { + p2 = p3; + creation_date = mir_wstrdup(toUTF16(out.substr(p,p2-p-1)).c_str()); + } + else + { + creation_date = mir_wstrdup(toUTF16(out.substr(p,p2-p)).c_str()); + p2 = out.find("[", p2); + p2 = out.find("expires:", p2); + p2 += strlen("expires:"); + if(p2 != std::string::npos) + { + p2++; + p = p2; + p2 = out.find("]", p); + expire_date = mir_wstrdup(toUTF16(out.substr(p,p2-p)).c_str()); + //check expiration + bool expired = false; + { + boost::posix_time::ptime now = boost::posix_time::second_clock::local_time(); + TCHAR buf[5]; + mir_sntprintf(buf, 5, _T("%s"), expire_date); + int year = _ttoi(buf); + if(year < now.date().year()) + expired = true; + else if(year == now.date().year()) + { + mir_sntprintf(buf, 3, _T("%s"), expire_date+5); + int month = _ttoi(buf); + if(month < now.date().month()) + expired = true; + else if(month == now.date().month()) + { + mir_sntprintf(buf, 3, _T("%s"), expire_date+8); + unsigned day = _ttoi(buf); + if(day <= now.date().day_number()) + expired = true; + } + } + } + if(expired) + { + mir_free(key_len); + mir_free(creation_date); + mir_free(expire_date); + //mimic normal behaviour + p = out.find("uid ", p); + p2 = out.find_first_not_of(" ", p+5); + p = out.find("<", p2); + p++; + p2 = out.find(">", p); + // + continue; //does not add to key list + } + } + } + iRow = ListView_InsertItem(hwndList, &item); + ListView_SetItemText(hwndList, iRow, 3, creation_date); + mir_free(creation_date); + if(expire_date) + { + ListView_SetItemText(hwndList, iRow, 4, expire_date); + mir_free(expire_date); + } + ListView_SetItemText(hwndList, iRow, 5, key_len); + mir_free(key_len); + ListView_SetItemText(hwndList, iRow, 0, (TCHAR*)key_id.c_str()); p = out.find("uid ", p); p2 = out.find_first_not_of(" ", p+5); p = out.find("<", p2); - TCHAR *tmp = mir_wstrdup(toUTF16(out.substr(p2,p-p2)).c_str()); + TCHAR *tmp = mir_wstrdup(toUTF16(out.substr(p2,p-p2)).c_str()); ListView_SetItemText(hwndList, iRow, 2, tmp); mir_free(tmp); p++; @@ -210,41 +210,42 @@ static INT_PTR CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR tmp = mir_wstrdup(toUTF16(out.substr(p,p2-p)).c_str()); ListView_SetItemText(hwndList, iRow, 1, tmp); mir_free(tmp); - { //get accounts - int count = 0; - PROTOACCOUNT **accounts; - ProtoEnumAccounts(&count, &accounts); - std::wstring accs; - for(int i = 0; i < count; i++) - { - std::string setting = toUTF8(accounts[i]->tszAccountName); - setting += "("; - setting += accounts[i]->szModuleName; - setting += ")" ; - setting += "_KeyID"; - TCHAR *str = UniGetContactSettingUtf(NULL, szGPGModuleName, setting.c_str(), _T("")); - if(key_id == str) - { - if(accs.empty()) - accs += accounts[i]->tszAccountName; - else - { - accs += _T(","); - accs += accounts[i]->tszAccountName; - } - } - } - ListView_SetItemText(hwndList, iRow, 6, (TCHAR*)accs.c_str()); - } + { //get accounts + int count = 0; + PROTOACCOUNT **accounts; + ProtoEnumAccounts(&count, &accounts); + std::wstring accs; + for(int i = 0; i < count; i++) + { + std::string setting = toUTF8(accounts[i]->tszAccountName); + setting += "("; + setting += accounts[i]->szModuleName; + setting += ")" ; + setting += "_KeyID"; + TCHAR *str = UniGetContactSettingUtf(NULL, szGPGModuleName, setting.c_str(), _T("")); + if(key_id == str) + { + if(accs.empty()) + accs += accounts[i]->tszAccountName; + else + { + accs += _T(","); + accs += accounts[i]->tszAccountName; + } + } + mir_free(str); + } + ListView_SetItemText(hwndList, iRow, 6, (TCHAR*)accs.c_str()); + } i++; } - ListView_SetColumnWidth(hwndList, 0, LVSCW_AUTOSIZE); - ListView_SetColumnWidth(hwndList, 1, LVSCW_AUTOSIZE); - ListView_SetColumnWidth(hwndList, 2, LVSCW_AUTOSIZE); - ListView_SetColumnWidth(hwndList, 3, LVSCW_AUTOSIZE); - ListView_SetColumnWidth(hwndList, 4, LVSCW_AUTOSIZE); - ListView_SetColumnWidth(hwndList, 5, LVSCW_AUTOSIZE); - ListView_SetColumnWidth(hwndList, 6, LVSCW_AUTOSIZE); + ListView_SetColumnWidth(hwndList, 0, LVSCW_AUTOSIZE); + ListView_SetColumnWidth(hwndList, 1, LVSCW_AUTOSIZE); + ListView_SetColumnWidth(hwndList, 2, LVSCW_AUTOSIZE); + ListView_SetColumnWidth(hwndList, 3, LVSCW_AUTOSIZE); + ListView_SetColumnWidth(hwndList, 4, LVSCW_AUTOSIZE); + ListView_SetColumnWidth(hwndList, 5, LVSCW_AUTOSIZE); + ListView_SetColumnWidth(hwndList, 6, LVSCW_AUTOSIZE); } } { @@ -300,24 +301,24 @@ static INT_PTR CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR } string out; DWORD code; - std::vector cmd; - cmd.push_back(L"--batch"); - cmd.push_back(L"-a"); - cmd.push_back(L"--export"); - cmd.push_back(fp); - gpg_execution_params params(cmd); + std::vector cmd; + cmd.push_back(L"--batch"); + cmd.push_back(L"-a"); + cmd.push_back(L"--export"); + cmd.push_back(fp); + gpg_execution_params params(cmd); pxResult result; params.out = &out; params.code = &code; params.result = &result; - if(!gpg_launcher(params)) + if(!gpg_launcher(params)) { break; } if(result == pxNotFound) break; string::size_type s = 0; - boost::algorithm::erase_all(out, "\r"); + boost::algorithm::erase_all(out, "\r"); { char buf[64]; GetDlgItemTextA(hwndDlg, IDC_ACCOUNT, buf, 63); @@ -386,15 +387,15 @@ static INT_PTR CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR DWORD code; wstring::size_type p = 0, p2 = 0, stop = 0; { - std::vector cmd; - cmd.push_back(L"--batch"); - cmd.push_back(L"--list-secret-keys"); - gpg_execution_params params(cmd); + std::vector cmd; + cmd.push_back(L"--batch"); + cmd.push_back(L"--list-secret-keys"); + gpg_execution_params params(cmd); pxResult result; params.out = &out; params.code = &code; params.result = &result; - if(!gpg_launcher(params)) + if(!gpg_launcher(params)) { break; } @@ -453,16 +454,16 @@ static INT_PTR CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR { string out; DWORD code; - std::vector cmd; - cmd.push_back(L"--batch"); - cmd.push_back(L"--fingerprint"); - cmd.push_back(fp); - gpg_execution_params params(cmd); + std::vector cmd; + cmd.push_back(L"--batch"); + cmd.push_back(L"--fingerprint"); + cmd.push_back(fp); + gpg_execution_params params(cmd); pxResult result; params.out = &out; params.code = &code; params.result = &result; - if(!gpg_launcher(params)) + if(!gpg_launcher(params)) { break; } @@ -483,12 +484,12 @@ static INT_PTR CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR } cmd.clear(); out.clear(); - cmd.push_back(L"--batch"); - cmd.push_back(L"--delete-secret-and-public-key"); - cmd.push_back(L"--fingerprint"); - cmd.push_back(fp); + cmd.push_back(L"--batch"); + cmd.push_back(L"--delete-secret-and-public-key"); + cmd.push_back(L"--fingerprint"); + cmd.push_back(fp); mir_free(fp); - if(!gpg_launcher(params)) + if(!gpg_launcher(params)) { break; } @@ -566,32 +567,32 @@ static INT_PTR CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR { //gpg execution DWORD code; string out; - std::vector cmd; - cmd.push_back(L"--batch"); - cmd.push_back(L"--yes"); - cmd.push_back(L"--gen-key"); - cmd.push_back(path); - gpg_execution_params params(cmd); + std::vector cmd; + cmd.push_back(L"--batch"); + cmd.push_back(L"--yes"); + cmd.push_back(L"--gen-key"); + cmd.push_back(path); + gpg_execution_params params(cmd); pxResult result; params.out = &out; params.code = &code; params.result = &result; - extern HFONT bold_font; - SendMessage(GetDlgItem(hwndDlg, IDC_GENERATING_KEY), WM_SETFONT, (WPARAM)bold_font, true); + extern HFONT bold_font; + SendMessage(GetDlgItem(hwndDlg, IDC_GENERATING_KEY), WM_SETFONT, (WPARAM)bold_font, true); SetWindowTextA(GetDlgItem(hwndDlg, IDC_GENERATING_KEY), Translate("Generating new random key, please wait")); EnableWindow(GetDlgItem(hwndDlg, IDC_GENERATE_KEY), 0); EnableWindow(GetDlgItem(hwndDlg, IDC_OTHER), 0); EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE_KEY), 0); EnableWindow(GetDlgItem(hwndDlg, IDC_KEY_LIST), 0); EnableWindow(GetDlgItem(hwndDlg, IDC_GENERATE_RANDOM), 0); - if(!gpg_launcher(params, boost::posix_time::minutes(10))) + if(!gpg_launcher(params, boost::posix_time::minutes(10))) { break; } if(result == pxNotFound) break; - boost::filesystem::remove(path); + boost::filesystem::remove(path); string::size_type p1 = 0; if((p1 = out.find("key ")) != string::npos) path = toUTF16(out.substr(p1+4, 8)); @@ -602,17 +603,17 @@ static INT_PTR CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR { string out; DWORD code; - std::vector cmd; - cmd.push_back(L"--batch"); - cmd.push_back(L"-a"); - cmd.push_back(L"--export"); - cmd.push_back(path); - gpg_execution_params params(cmd); + std::vector cmd; + cmd.push_back(L"--batch"); + cmd.push_back(L"-a"); + cmd.push_back(L"--export"); + cmd.push_back(path); + gpg_execution_params params(cmd); pxResult result; params.out = &out; params.code = &code; params.result = &result; - if(!gpg_launcher(params)) + if(!gpg_launcher(params)) { break; } @@ -673,30 +674,30 @@ static INT_PTR CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR } } break; - case IDC_COPY_PUBKEY: - { - if(OpenClipboard(hwndDlg)) - { - ListView_GetItemText(hwndList, itemnum, 0, fp, 16); - string out; - DWORD code; - std::vector cmd; - cmd.push_back(L"--batch"); - cmd.push_back(L"-a"); - cmd.push_back(L"--export"); - cmd.push_back(fp); - gpg_execution_params params(cmd); - pxResult result; - params.out = &out; - params.code = &code; - params.result = &result; - if(!gpg_launcher(params)) - { - break; - } - if(result == pxNotFound) - break; - boost::algorithm::erase_all(out, "\r"); + case IDC_COPY_PUBKEY: + { + if(OpenClipboard(hwndDlg)) + { + ListView_GetItemText(hwndList, itemnum, 0, fp, 16); + string out; + DWORD code; + std::vector cmd; + cmd.push_back(L"--batch"); + cmd.push_back(L"-a"); + cmd.push_back(L"--export"); + cmd.push_back(fp); + gpg_execution_params params(cmd); + pxResult result; + params.out = &out; + params.code = &code; + params.result = &result; + if(!gpg_launcher(params)) + { + break; + } + if(result == pxNotFound) + break; + boost::algorithm::erase_all(out, "\r"); HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, out.size() +1); if(!hMem) { @@ -707,7 +708,7 @@ static INT_PTR CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR if(!szKey) { char msg[64]; - mir_snprintf(msg, 127, "Failed to lock memory with error %d", GetLastError()); + mir_snprintf(msg, 64, "Failed to lock memory with error %d", GetLastError()); MessageBoxA(0, msg, "Error", MB_OK); GlobalFree(hMem); } @@ -719,87 +720,87 @@ static INT_PTR CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR { GlobalFree(hMem); char msg[64]; - mir_snprintf(msg, 127, "Failed write to clipboard with error %d", GetLastError()); + mir_snprintf(msg, 64, "Failed write to clipboard with error %d", GetLastError()); MessageBoxA(0, msg, "Error", MB_OK); } CloseClipboard(); - } - } - break; - case IDC_EXPORT_PRIVATE: - { - TCHAR *p = GetFilePath(_T("Choose file to export key"), _T("*"), _T("Any file"), true); - if(!p || !p[0]) - { - delete [] p; - //TODO: handle error - break; - } - char *path = mir_t2a(p); - delete [] p; - std::ofstream file; - file.open(path, std::ios::trunc | std::ios::out); - mir_free(path); - if(!file.is_open()) - break; //TODO: handle error - ListView_GetItemText(hwndList, itemnum, 0, fp, 16); - string out; - DWORD code; - std::vector cmd; - cmd.push_back(L"--batch"); - cmd.push_back(L"-a"); - cmd.push_back(L"--export-secret-keys"); - cmd.push_back(fp); - gpg_execution_params params(cmd); - pxResult result; - params.out = &out; - params.code = &code; - params.result = &result; - if(!gpg_launcher(params)) - { - break; - } - if(result == pxNotFound) - break; - boost::algorithm::erase_all(out, "\r"); - file< cmd; - std::string old_pass, new_pass; - TCHAR tmp2[MAX_PATH] = {0}; - string output; - DWORD exitcode; - cmd.push_back(L"--edit-key"); - cmd.push_back(key_id_global); - cmd.push_back(L"passwd"); - gpg_execution_params_pass params(cmd, old_pass, new_pass); - pxResult result; - params.out = &output; - params.code = &exitcode; - params.result = &result; - boost::thread gpg_thread(boost::bind(&pxEexcute_passwd_change_thread, ¶ms)); - if(!gpg_thread.timed_join(boost::posix_time::minutes(10))) - { - gpg_thread.~thread(); - if(params.child) - boost::process::terminate(*(params.child)); - if(bDebugLog) - debuglog< cmd; + cmd.push_back(L"--batch"); + cmd.push_back(L"-a"); + cmd.push_back(L"--export-secret-keys"); + cmd.push_back(fp); + gpg_execution_params params(cmd); + pxResult result; + params.out = &out; + params.code = &code; + params.result = &result; + if(!gpg_launcher(params)) + { + break; + } + if(result == pxNotFound) + break; + boost::algorithm::erase_all(out, "\r"); + file< cmd; + std::string old_pass, new_pass; + TCHAR tmp2[MAX_PATH] = {0}; + string output; + DWORD exitcode; + cmd.push_back(L"--edit-key"); + cmd.push_back(key_id_global); + cmd.push_back(L"passwd"); + gpg_execution_params_pass params(cmd, old_pass, new_pass); + pxResult result; + params.out = &output; + params.code = &exitcode; + params.result = &result; + boost::thread gpg_thread(boost::bind(&pxEexcute_passwd_change_thread, ¶ms)); + if(!gpg_thread.timed_join(boost::posix_time::minutes(10))) + { + gpg_thread.~thread(); + if(params.child) + boost::process::terminate(*(params.child)); + if(bDebugLog) + debuglog<hdr.code == NM_CLICK) { EnableWindow(GetDlgItem(hwndDlg, ID_OK), 1); - EnableWindow(GetDlgItem(hwndDlg, IDC_COPY_PUBKEY), 1); - EnableWindow(GetDlgItem(hwndDlg, IDC_EXPORT_PRIVATE), 1); - EnableWindow(GetDlgItem(hwndDlg, IDC_CHANGE_PASSWD), 1); + EnableWindow(GetDlgItem(hwndDlg, IDC_COPY_PUBKEY), 1); + EnableWindow(GetDlgItem(hwndDlg, IDC_EXPORT_PRIVATE), 1); + EnableWindow(GetDlgItem(hwndDlg, IDC_CHANGE_PASSWD), 1); itemnum = hdr->iItem; } } @@ -856,30 +857,30 @@ static INT_PTR CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, case WM_INITDIALOG: { TranslateDialogDefault(hwndDlg); - TCHAR *path = (TCHAR*)mir_alloc(sizeof(TCHAR) * MAX_PATH); + TCHAR *path = (TCHAR*)mir_alloc(sizeof(TCHAR) * MAX_PATH); bool gpg_exists = false, lang_exists = false; { - char *mir_path = (char*)mir_alloc(sizeof(char) * MAX_PATH); + char *mir_path = (char*)mir_alloc(sizeof(char) * MAX_PATH); CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)"\\", (LPARAM)mir_path); SetCurrentDirectoryA(mir_path); tmp = mir_a2t(mir_path); mir_free(mir_path); mir_realloc(path, (_tcslen(path)+128)*sizeof(TCHAR)); - TCHAR *gpg_path = (TCHAR*)mir_alloc(sizeof(TCHAR) * MAX_PATH), *gpg_lang_path = (TCHAR*)mir_alloc(sizeof(TCHAR) * MAX_PATH); + TCHAR *gpg_path = (TCHAR*)mir_alloc(sizeof(TCHAR) * MAX_PATH), *gpg_lang_path = (TCHAR*)mir_alloc(sizeof(TCHAR) * MAX_PATH); _tcscpy(gpg_path, tmp); _tcscat(gpg_path, _T("\\GnuPG\\gpg.exe")); _tcscpy(gpg_lang_path, tmp); _tcscat(gpg_lang_path, _T("\\GnuPG\\gnupg.nls\\en@quot.mo")); mir_free(tmp); - if(boost::filesystem::exists(gpg_path)) + if(boost::filesystem::exists(gpg_path)) { gpg_exists = true; _tcscpy(path, _T("GnuPG\\gpg.exe")); } - if(boost::filesystem::exists(gpg_lang_path)) + if(boost::filesystem::exists(gpg_lang_path)) lang_exists = true; - if(gpg_exists && !lang_exists) - MessageBox(0, TranslateT("gpg binary found in miranda folder, but english locale does not exists.\nit's highly recommended to place \\gnupg.nls\\en@quot.mo in gnupg folder under miranda root.\nwithout this file you may expirense many problem with gpg output on non english systems.\nand plugin may completely do not work.\nyou have beed warned."), TranslateT("Warning"), MB_OK); + if(gpg_exists && !lang_exists) + MessageBox(0, TranslateT("GPG binary found in Miranda folder, but English locale does not exist.\nIt's highly recommended to place \\gnupg.nls\\en@quot.mo in GnuPG folder under Miranda root.\nWithout this file you may experience many problems with GPG output on non-English systems\nand plugin may completely not work.\nYou have been warned."), TranslateT("Warning"), MB_OK); mir_free(gpg_path); mir_free(gpg_lang_path); } @@ -888,28 +889,29 @@ static INT_PTR CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, { tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szGpgBinPath", (SHGetValue(HKEY_CURRENT_USER, _T("Software\\GNU\\GnuPG"), _T("gpgProgram"), 0, path, &len) == ERROR_SUCCESS)?path:_T("")); if(tmp[0]) - if(!boost::filesystem::exists(tmp)) - MessageBox(0, TranslateT("wrong gpg binary location found in system.\nplease choose another location"), TranslateT("Warning"), MB_OK); + if(!boost::filesystem::exists(tmp)) + MessageBox(0, TranslateT("Wrong GPG binary location found in system.\nPlease choose another location"), TranslateT("Warning"), MB_OK); } - else tmp = mir_wstrdup(path); - mir_free(path); + else + tmp = mir_wstrdup(path); + mir_free(path); SetDlgItemText(hwndDlg, IDC_BIN_PATH, tmp); bool bad_version = false; - if(gpg_exists/* && lang_exists*/) + if(gpg_exists/* && lang_exists*/) { DBWriteContactSettingTString(NULL, szGPGModuleName, "szGpgBinPath", tmp); string out; DWORD code; - std::vector cmd; - cmd.push_back(L"--version"); - gpg_execution_params params(cmd); + std::vector cmd; + cmd.push_back(L"--version"); + gpg_execution_params params(cmd); pxResult result; params.out = &out; params.code = &code; params.result = &result; gpg_valid = true; - gpg_launcher(params); + gpg_launcher(params); gpg_valid = false; DBDeleteContactSetting(NULL, szGPGModuleName, "szGpgBinPath"); string::size_type p1 = out.find("(GnuPG) "); @@ -922,36 +924,36 @@ static INT_PTR CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, else { bad_version = false; - MessageBox(0, TranslateT("This is not gnupg binary !\nrecommended to use GnuPG v1.x.x with this plugn."), TranslateT("Error"), MB_OK); + MessageBox(0, TranslateT("This is not GnuPG binary!\nIt is recommended to use GnuPG v1.x.x with this plugin."), TranslateT("Error"), MB_OK); } if(bad_version) - MessageBox(0, TranslateT("Unsupported gnupg version found, use at you own risk!\nrecommended to use GnuPG v1.x.x with this plugn."), TranslateT("Warning"), MB_OK); + MessageBox(0, TranslateT("Unsupported GnuPG version found, use at you own risk!\nIt is recommended to use GnuPG v1.x.x with this plugin."), TranslateT("Warning"), MB_OK); } mir_free(tmp); { - tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); - if(!tmp[0]) - { - mir_free(tmp); - char *mir_path = (char*)mir_alloc(sizeof(char) * MAX_PATH); - CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)"\\", (LPARAM)mir_path); - strcat(mir_path, "\\gpg"); - if(_access(mir_path, 0) != -1) - { - tmp = mir_wstrdup(toUTF16(mir_path).c_str()); - MessageBox(0, TranslateT("found \"gpg\" directory in MIranda root.\nassuming it's gpg home directory.\ngpg home directory set."), TranslateT("Info"), MB_OK); - } - else - { - wstring path_ = _wgetenv(_T("APPDATA")); - path_ += _T("\\GnuPG"); - tmp = mir_wstrdup(path_.c_str()); - } - } - SetDlgItemText(hwndDlg, IDC_HOME_DIR, !gpg_exists?tmp:_T("gpg")); - mir_free(tmp); + tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); + if(!tmp[0]) + { + mir_free(tmp); + char *mir_path = (char*)mir_alloc(sizeof(char) * MAX_PATH); + CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)"\\", (LPARAM)mir_path); + strcat(mir_path, "\\gpg"); + if(_access(mir_path, 0) != -1) + { + tmp = mir_wstrdup(toUTF16(mir_path).c_str()); + MessageBox(0, TranslateT("\"GPG\" directory found in Miranda root.\nAssuming it's GPG home directory.\nGPG home directory set."), TranslateT("Info"), MB_OK); + } + else + { + wstring path_ = _wgetenv(_T("APPDATA")); + path_ += _T("\\GnuPG"); + tmp = mir_wstrdup(path_.c_str()); + } + } + SetDlgItemText(hwndDlg, IDC_HOME_DIR, !gpg_exists?tmp:_T("gpg")); + mir_free(tmp); } - //TODO: additional check for write access + //TODO: additional check for write access if(gpg_exists && lang_exists && !bad_version) MessageBox(0, TranslateT("Your GPG version is supported. The language file was found.\nGPG plugin should work fine.\nPress OK to continue."), TranslateT("Info"), MB_OK); extern bool bIsMiranda09; @@ -1010,10 +1012,10 @@ static INT_PTR CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)"\\", (LPARAM)mir_path); SetCurrentDirectoryA(mir_path); delete [] mir_path; - if(!boost::filesystem::exists(tmp)) + if(!boost::filesystem::exists(tmp)) { - MessageBox(0, TranslateT("gpg binary does not exists.\nplease choose another location"), TranslateT("Warning"), MB_OK); - break; + MessageBox(0, TranslateT("gpg binary does not exists.\nplease choose another location"), TranslateT("Warning"), MB_OK); + break; } } else @@ -1026,15 +1028,15 @@ static INT_PTR CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, DBWriteContactSettingTString(NULL, szGPGModuleName, "szGpgBinPath", tmp); string out; DWORD code; - std::vector cmd; - cmd.push_back(L"--version"); - gpg_execution_params params(cmd); + std::vector cmd; + cmd.push_back(L"--version"); + gpg_execution_params params(cmd); pxResult result; params.out = &out; params.code = &code; params.result = &result; gpg_valid = true; - gpg_launcher(params); + gpg_launcher(params); gpg_valid = false; DBDeleteContactSetting(NULL, szGPGModuleName, "szGpgBinPath"); string::size_type p1 = out.find("(GnuPG) "); @@ -1047,10 +1049,10 @@ static INT_PTR CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, else { bad_version = false; - MessageBox(0, TranslateT("This is not gnupg binary !\nrecommended to use GnuPG v1.x.x with this plugn."), TranslateT("Warning"), MB_OK); + MessageBox(0, TranslateT("This is not GnuPG binary!\nIt is recommended to use GnuPG v1.x.x with this plugin."), TranslateT("Warning"), MB_OK); } if(bad_version) - MessageBox(0, TranslateT("Unsupported gnupg version found, use at you own risk!\nrecommended to use GnuPG v1.x.x with this plugn."), TranslateT("Warning"), MB_OK); + MessageBox(0, TranslateT("Unsupported GnuPG version found, use at you own risk!\nIt is recommended to use GnuPG v1.x.x with this plugin."), TranslateT("Warning"), MB_OK); } DBWriteContactSettingTString(NULL, szGPGModuleName, "szGpgBinPath", tmp); GetDlgItemText(hwndDlg, IDC_HOME_DIR, tmp, 512); @@ -1088,10 +1090,10 @@ static INT_PTR CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)"\\", (LPARAM)mir_path); SetCurrentDirectoryA(mir_path); delete [] mir_path; - if(!boost::filesystem::exists(tmp)) + if(!boost::filesystem::exists(tmp)) { - MessageBox(0, TranslateT("gpg binary does not exists.\nplease choose another location"), TranslateT("Warning"), MB_OK); - break; + MessageBox(0, TranslateT("GPG binary does not exist.\nPlease choose another location"), TranslateT("Warning"), MB_OK); + break; } } else @@ -1104,15 +1106,15 @@ static INT_PTR CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, DBWriteContactSettingTString(NULL, szGPGModuleName, "szGpgBinPath", tmp); string out; DWORD code; - std::vector cmd; - cmd.push_back(L"--version"); - gpg_execution_params params(cmd); + std::vector cmd; + cmd.push_back(L"--version"); + gpg_execution_params params(cmd); pxResult result; params.out = &out; params.code = &code; params.result = &result; gpg_valid = true; - gpg_launcher(params); + gpg_launcher(params); gpg_valid = false; DBDeleteContactSetting(NULL, szGPGModuleName, "szGpgBinPath"); string::size_type p1 = out.find("(GnuPG) "); @@ -1125,10 +1127,10 @@ static INT_PTR CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, else { bad_version = false; - MessageBox(0, TranslateT("This is not gnupg binary !\nrecommended to use GnuPG v1.x.x with this plugn."), TranslateT("Warning"), MB_OK); + MessageBox(0, TranslateT("This is not GnuPG binary!\nIt is recommended to use GnuPG v1.x.x with this plugin."), TranslateT("Warning"), MB_OK); } if(bad_version) - MessageBox(0, TranslateT("Unsupported gnupg version found, use at you own risk!\nrecommended to use GnuPG v1.x.x with this plugn."), TranslateT("Warning"), MB_OK); + MessageBox(0, TranslateT("Unsupported GnuPG version found, use at you own risk!\nIt is recommended to use GnuPG v1.x.x with this plugin."), TranslateT("Warning"), MB_OK); } DBWriteContactSettingTString(NULL, szGPGModuleName, "szGpgBinPath", tmp); GetDlgItemText(hwndDlg, IDC_HOME_DIR, tmp, 512); @@ -1185,18 +1187,18 @@ static INT_PTR CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, { //gpg execution DWORD code; string out; - std::vector cmd; - cmd.push_back(L"--batch"); - cmd.push_back(L"--yes"); - cmd.push_back(L"--gen-key"); - cmd.push_back(path); - gpg_execution_params params(cmd); + std::vector cmd; + cmd.push_back(L"--batch"); + cmd.push_back(L"--yes"); + cmd.push_back(L"--gen-key"); + cmd.push_back(path); + gpg_execution_params params(cmd); pxResult result; params.out = &out; params.code = &code; params.result = &result; gpg_valid = true; - if(!gpg_launcher(params, boost::posix_time::minutes(10))) + if(!gpg_launcher(params, boost::posix_time::minutes(10))) { gpg_valid = false; break; @@ -1204,7 +1206,7 @@ static INT_PTR CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, gpg_valid = false; if(result == pxNotFound) break; - boost::filesystem::remove(path); + boost::filesystem::remove(path); string::size_type p1 = 0; if((p1 = out.find("key ")) != string::npos) path = toUTF16(out.substr(p1+4, 8)); @@ -1215,18 +1217,18 @@ static INT_PTR CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, { string out; DWORD code; - std::vector cmd; - cmd.push_back(L"--batch"); - cmd.push_back(L"-a"); - cmd.push_back(L"--export"); - cmd.push_back(path); - gpg_execution_params params(cmd); + std::vector cmd; + cmd.push_back(L"--batch"); + cmd.push_back(L"-a"); + cmd.push_back(L"--export"); + cmd.push_back(path); + gpg_execution_params params(cmd); pxResult result; params.out = &out; params.code = &code; params.result = &result; gpg_valid = true; - if(!gpg_launcher(params)) + if(!gpg_launcher(params)) { gpg_valid = false; break; @@ -1271,8 +1273,8 @@ static INT_PTR CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, break; case WM_DESTROY: hwndSetDirs = NULL; - void InitCheck(); - InitCheck(); + void InitCheck(); + InitCheck(); break; } @@ -1291,7 +1293,7 @@ static INT_PTR CALLBACK DlgProcNewKeyDialog(HWND hwndDlg, UINT msg, WPARAM wPara case WM_INITDIALOG: { hContact = new_key_hcnt; - //new_key_hcnt_mutex.unlock(); + //new_key_hcnt_mutex.unlock(); SetWindowPos(hwndDlg, 0, new_key_rect.left, new_key_rect.top, 0, 0, SWP_NOSIZE|SWP_SHOWWINDOW); TranslateDialogDefault(hwndDlg); TCHAR *tmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "GPGPubKey", _T("")); @@ -1393,7 +1395,7 @@ static INT_PTR CALLBACK DlgProcKeyGenDialog(HWND hwndDlg, UINT msg, WPARAM wPara if(_tcslen(tmp) < 3) { mir_free(tmp); tmp = NULL; - MessageBox(0, TranslateT("You must set encryption algorythm first"), TranslateT("Error"), MB_OK); + MessageBox(0, TranslateT("You must set encryption algorithm first"), TranslateT("Error"), MB_OK); break; } if(tmp) @@ -1532,18 +1534,18 @@ static INT_PTR CALLBACK DlgProcKeyGenDialog(HWND hwndDlg, UINT msg, WPARAM wPara { //gpg execution DWORD code; string out; - std::vector cmd; - cmd.push_back(L"--batch"); - cmd.push_back(L"--yes"); - cmd.push_back(L"--gen-key"); - cmd.push_back(path); - gpg_execution_params params(cmd); + std::vector cmd; + cmd.push_back(L"--batch"); + cmd.push_back(L"--yes"); + cmd.push_back(L"--gen-key"); + cmd.push_back(path); + gpg_execution_params params(cmd); pxResult result; params.out = &out; params.code = &code; params.result = &result; - extern HFONT bold_font; - SendMessage(GetDlgItem(hwndDlg, IDC_GENERATING_TEXT), WM_SETFONT, (WPARAM)bold_font, true); + extern HFONT bold_font; + SendMessage(GetDlgItem(hwndDlg, IDC_GENERATING_TEXT), WM_SETFONT, (WPARAM)bold_font, true); SetWindowTextA(GetDlgItem(hwndDlg, IDC_GENERATING_TEXT), Translate("Generating new key, please wait...")); EnableWindow(GetDlgItem(hwndDlg, IDCANCEL), 0); EnableWindow(GetDlgItem(hwndDlg, IDOK), 0); @@ -1554,12 +1556,12 @@ static INT_PTR CALLBACK DlgProcKeyGenDialog(HWND hwndDlg, UINT msg, WPARAM wPara EnableWindow(GetDlgItem(hwndDlg, IDC_KEY_EMAIL), 0); EnableWindow(GetDlgItem(hwndDlg, IDC_KEY_COMMENT), 0); EnableWindow(GetDlgItem(hwndDlg, IDC_KEY_EXPIRE_DATE), 0); - if(!gpg_launcher(params, boost::posix_time::minutes(10))) + if(!gpg_launcher(params, boost::posix_time::minutes(10))) break; if(result == pxNotFound) break; } - boost::filesystem::remove(path); + boost::filesystem::remove(path); DestroyWindow(hwndDlg); {//parse gpg output LVITEM item = {0}; @@ -1572,14 +1574,14 @@ static INT_PTR CALLBACK DlgProcKeyGenDialog(HWND hwndDlg, UINT msg, WPARAM wPara DWORD code; string::size_type p = 0, p2 = 0, stop = 0; { - std::vector cmd; - cmd.push_back(L"--list-secret-keys"); - gpg_execution_params params(cmd); + std::vector cmd; + cmd.push_back(L"--list-secret-keys"); + gpg_execution_params params(cmd); pxResult result; params.out = &out; params.code = &code; params.result = &result; - if(!gpg_launcher(params)) + if(!gpg_launcher(params)) break; if(result == pxNotFound) break; @@ -1726,15 +1728,15 @@ static INT_PTR CALLBACK DlgProcLoadExistingKey(HWND hwndDlg,UINT msg,WPARAM wPar DWORD code; string::size_type p = 0, p2 = 0, stop = 0; { - std::vector cmd; - cmd.push_back(L"--batch"); - cmd.push_back(L"--list-keys"); - gpg_execution_params params(cmd); + std::vector cmd; + cmd.push_back(L"--batch"); + cmd.push_back(L"--list-keys"); + gpg_execution_params params(cmd); pxResult result; params.out = &out; params.code = &code; params.result = &result; - if(!gpg_launcher(params)) + if(!gpg_launcher(params)) break; if(result == pxNotFound) break; @@ -1827,17 +1829,17 @@ static INT_PTR CALLBACK DlgProcLoadExistingKey(HWND hwndDlg,UINT msg,WPARAM wPar extern HWND hPubKeyEdit; string out; DWORD code; - std::vector cmd; - cmd.push_back(L"--batch"); - cmd.push_back(L"-a"); - cmd.push_back(L"--export"); - cmd.push_back(id); - gpg_execution_params params(cmd); + std::vector cmd; + cmd.push_back(L"--batch"); + cmd.push_back(L"-a"); + cmd.push_back(L"--export"); + cmd.push_back(id); + gpg_execution_params params(cmd); pxResult result; params.out = &out; params.code = &code; params.result = &result; - if(!gpg_launcher(params)) + if(!gpg_launcher(params)) break; if(result == pxNotFound) break; @@ -1939,24 +1941,24 @@ static INT_PTR CALLBACK DlgProcImportKeyDialog(HWND hwndDlg, UINT msg, WPARAM wP { string out; DWORD code; - std::vector cmd; - cmd.push_back(L"--keyserver"); + std::vector cmd; + cmd.push_back(L"--keyserver"); TCHAR *server= new TCHAR [128]; GetDlgItemText(hwndDlg, IDC_KEYSERVER, server, 128); - cmd.push_back(server); + cmd.push_back(server); delete [] server; - cmd.push_back(L"--recv-keys"); + cmd.push_back(L"--recv-keys"); // char *tmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyID_Prescense", ""); // TCHAR *tmp2 = mir_a2t(tmp); // mir_free(tmp); - cmd.push_back(toUTF16(hcontact_data[hContact].key_in_prescense)); + cmd.push_back(toUTF16(hcontact_data[hContact].key_in_prescense)); // mir_free(tmp2); - gpg_execution_params params(cmd); + gpg_execution_params params(cmd); pxResult result; params.out = &out; params.code = &code; params.result = &result; - gpg_launcher(params); + gpg_launcher(params); MessageBoxA(0, out.c_str(), "GPG output", MB_OK); } break; @@ -2071,7 +2073,7 @@ void InitCheck() if(test_file.good()) home_dir_access = true; test_file.close(); - boost::filesystem::remove(test_path); + boost::filesystem::remove(test_path); } home_dir = _tgetenv(_T("TEMP")); test_path = home_dir; @@ -2084,16 +2086,16 @@ void InitCheck() if(test_file.good()) temp_access = true; test_file.close(); - boost::filesystem::remove(test_path); + boost::filesystem::remove(test_path); } if(!home_dir_access || !temp_access || !gpg_valid) { char buf[4096]; - strcpy(buf, gpg_valid?Translate("GPG binary is set and valid (this is good).\n"):Translate("GPG binary unset or invalid (plugin will not work).\n")); - strcat(buf, home_dir_access?Translate("Home dir write access granted (this is good).\n"):Translate("Home dir have not write access (plugin most probably will not work).\n")); - strcat(buf, temp_access?Translate("Temp dir write access granted (this is good).\n"):Translate("Temp dir have not write access (plugin should work, but may have some problems, filetransfers will not work).")); + strcpy(buf, gpg_valid?Translate("GPG binary is set and valid (This is good).\n"):Translate("GPG binary unset or invalid (Plugin will not work).\n")); + strcat(buf, home_dir_access?Translate("Home dir write access granted (This is good).\n"):Translate("Home dir has no write access (Plugin most probably will not work).\n")); + strcat(buf, temp_access?Translate("Temp dir write access granted (This is good).\n"):Translate("Temp dir has no write access (Plugin should work, but may have some problems, file transfers will not work).")); if(!gpg_valid) - strcat(buf, Translate("\nGPG will be disabled until you solve this problems")); + strcat(buf, Translate("\nGPG will be disabled until you solve these problems")); MessageBoxA(0, buf, Translate("GPG plugin problems"), MB_OK); } if(!gpg_valid) @@ -2104,14 +2106,14 @@ void InitCheck() pxResult result; wstring::size_type p = 0, p2 = 0, stop = 0; { - std::vector cmd; - cmd.push_back(L"--batch"); - cmd.push_back(L"--list-secret-keys"); - gpg_execution_params params(cmd); + std::vector cmd; + cmd.push_back(L"--batch"); + cmd.push_back(L"--list-secret-keys"); + gpg_execution_params params(cmd); params.out = &out; params.code = &code; params.result = &result; - if(!gpg_launcher(params)) + if(!gpg_launcher(params)) return; if(result == pxNotFound) return; @@ -2121,145 +2123,150 @@ void InitCheck() mir_free(home_dir); tmp_dir += _T("\\tmp"); _wmkdir(tmp_dir.c_str()); - int count = 0; - PROTOACCOUNT **accounts; - ProtoEnumAccounts(&count, &accounts); - string question; - char *keyid, *key; - for(int i = 0; i < count; i++) - { - if(StriStr(accounts[i]->szModuleName, "metacontacts")) - continue; - if(StriStr(accounts[i]->szModuleName, "weather")) - continue; - std::string acc = toUTF8(accounts[i]->tszAccountName); - acc += "("; - acc += accounts[i]->szModuleName; - acc += ")"; - acc += "_KeyID"; - keyid = UniGetContactSettingUtf(NULL, szGPGModuleName, acc.c_str(), ""); - if(keyid[0]) - { - question = Translate("Your secret key whith id: "); - keyid = UniGetContactSettingUtf(NULL, szGPGModuleName, "KeyID", ""); - key = UniGetContactSettingUtf(NULL, szGPGModuleName, "GPGPubKey", ""); - void ShowFirstRunDialog(); - if((p = out.find(keyid)) == string::npos) - { - question += keyid; - question += Translate(" for account "); - question += toUTF8(accounts[i]->tszAccountName); - question += Translate(" deleted from gpg secret keyring\nDo you want to set another key ?"); - if(MessageBoxA(0, question.c_str(), Translate("Own secret key warning"), MB_YESNO) == IDYES) - ShowFirstRunDialog(); - } - p2 = p; - p = out.find("[", p); - p2 = out.find("\n", p2); - if((p != std::string::npos) && (p < p2)) - { - p = out.find("expires:", p); - p += strlen("expires:"); - p++; - p2 = out.find("]", p); - TCHAR *expire_date = mir_wstrdup(toUTF16(out.substr(p,p2-p)).c_str()); - bool expired = false; - { - boost::posix_time::ptime now = boost::posix_time::second_clock::local_time(); - TCHAR buf[5]; - mir_sntprintf(buf, 5, _T("%s"), expire_date); - int year = _ttoi(buf); - if(year < now.date().year()) - expired = true; - else if(year == now.date().year()) - { - mir_sntprintf(buf, 3, _T("%s"), expire_date+5); - int month = _ttoi(buf); - if(month < now.date().month()) - expired = true; - else if(month == now.date().month()) - { - mir_sntprintf(buf, 3, _T("%s"), expire_date+8); - unsigned day = _ttoi(buf); - if(day <= now.date().day_number()) - expired = true; - } - } - } - if(expired) - { - question += keyid; - question += Translate(" for account "); - question += toUTF8(accounts[i]->tszAccountName); - question += Translate(" expired and will not work\nDo you want to set another key ?"); - if(MessageBoxA(0, question.c_str(), Translate("Own secret key warning"), MB_YESNO) == IDYES) - ShowFirstRunDialog(); - } - mir_free(expire_date); - } - } - mir_free(keyid); - } - question = Translate("Your secret key whith id: "); - keyid = UniGetContactSettingUtf(NULL, szGPGModuleName, "KeyID", ""); - key = UniGetContactSettingUtf(NULL, szGPGModuleName, "GPGPubKey", ""); + int count = 0; + PROTOACCOUNT **accounts; + ProtoEnumAccounts(&count, &accounts); + string question; + char *keyid = nullptr, *key = nullptr; + for(int i = 0; i < count; i++) + { + if(StriStr(accounts[i]->szModuleName, "metacontacts")) + continue; + if(StriStr(accounts[i]->szModuleName, "weather")) + continue; + std::string acc = toUTF8(accounts[i]->tszAccountName); + acc += "("; + acc += accounts[i]->szModuleName; + acc += ")"; + acc += "_KeyID"; + keyid = UniGetContactSettingUtf(NULL, szGPGModuleName, acc.c_str(), ""); + if(keyid[0]) + { + question = Translate("Your secret key with id: "); + mir_free(keyid); + keyid = UniGetContactSettingUtf(NULL, szGPGModuleName, "KeyID", ""); + key = UniGetContactSettingUtf(NULL, szGPGModuleName, "GPGPubKey", ""); + void ShowFirstRunDialog(); + if((p = out.find(keyid)) == string::npos) + { + question += keyid; + question += Translate(" for account "); + question += toUTF8(accounts[i]->tszAccountName); + question += Translate(" deleted from GPG secret keyring.\nDo you want to set another key?"); + if(MessageBoxA(0, question.c_str(), Translate("Own secret key warning"), MB_YESNO) == IDYES) + ShowFirstRunDialog(); + } + p2 = p; + p = out.find("[", p); + p2 = out.find("\n", p2); + if((p != std::string::npos) && (p < p2)) + { + p = out.find("expires:", p); + p += strlen("expires:"); + p++; + p2 = out.find("]", p); + TCHAR *expire_date = mir_wstrdup(toUTF16(out.substr(p,p2-p)).c_str()); + bool expired = false; + { + boost::posix_time::ptime now = boost::posix_time::second_clock::local_time(); + TCHAR buf[5]; + mir_sntprintf(buf, 5, _T("%s"), expire_date); + int year = _ttoi(buf); + if(year < now.date().year()) + expired = true; + else if(year == now.date().year()) + { + mir_sntprintf(buf, 3, _T("%s"), expire_date+5); + int month = _ttoi(buf); + if(month < now.date().month()) + expired = true; + else if(month == now.date().month()) + { + mir_sntprintf(buf, 3, _T("%s"), expire_date+8); + unsigned day = _ttoi(buf); + if(day <= now.date().day_number()) + expired = true; + } + } + } + if(expired) + { + question += keyid; + question += Translate(" for account "); + question += toUTF8(accounts[i]->tszAccountName); + question += Translate(" expired and will not work.\nDo you want to set another key?"); + if(MessageBoxA(0, question.c_str(), Translate("Own secret key warning"), MB_YESNO) == IDYES) + ShowFirstRunDialog(); + } + mir_free(expire_date); + } + } + if(keyid) + { + mir_free(keyid); + keyid = nullptr; + } + } + question = Translate("Your secret key with id: "); + keyid = UniGetContactSettingUtf(NULL, szGPGModuleName, "KeyID", ""); + key = UniGetContactSettingUtf(NULL, szGPGModuleName, "GPGPubKey", ""); void ShowFirstRunDialog(); if(!DBGetContactSettingByte(NULL, szGPGModuleName, "FirstRun", 1) && (!keyid[0] || !key[0])) { - question = Translate("You didn't set a private key.\nWould you like to set it now?"); - if(MessageBoxA(0, question.c_str(), Translate("Own private key warning"), MB_YESNO) == IDYES) + question = Translate("You didn't set a private key.\nWould you like to set it now?"); + if(MessageBoxA(0, question.c_str(), Translate("Own private key warning"), MB_YESNO) == IDYES) ShowFirstRunDialog(); } - if((p = out.find(keyid)) == string::npos) + if((p = out.find(keyid)) == string::npos) { question += keyid; - question += Translate(" deleted from gpg secret keyring\nDo you want to set another key ?"); + question += Translate(" deleted from GPG secret keyring.\nDo you want to set another key?"); if(MessageBoxA(0, question.c_str(), Translate("Own secret key warning"), MB_YESNO) == IDYES) ShowFirstRunDialog(); } - p2 = p; - p = out.find("[", p); - p2 = out.find("\n", p2); - if((p != std::string::npos) && (p < p2)) - { - p = out.find("expires:", p); - p += strlen("expires:"); - p++; - p2 = out.find("]", p); - TCHAR *expire_date = mir_wstrdup(toUTF16(out.substr(p,p2-p)).c_str()); - bool expired = false; - { - boost::posix_time::ptime now = boost::posix_time::second_clock::local_time(); - TCHAR buf[5]; - mir_sntprintf(buf, 5, _T("%s"), expire_date); - int year = _ttoi(buf); - if(year < now.date().year()) - expired = true; - else if(year == now.date().year()) - { - mir_sntprintf(buf, 3, _T("%s"), expire_date+5); - int month = _ttoi(buf); - if(month < now.date().month()) - expired = true; - else if(month == now.date().month()) - { - mir_sntprintf(buf, 3, _T("%s"), expire_date+8); - unsigned day = _ttoi(buf); - if(day <= now.date().day_number()) - expired = true; - } - } - } - if(expired) - { - question += keyid; - question += Translate(" expired and will not work\nDo you want to set another key ?"); - if(MessageBoxA(0, question.c_str(), Translate("Own secret key warning"), MB_YESNO) == IDYES) - ShowFirstRunDialog(); - } - mir_free(expire_date); - } - //TODO: check for expired key + p2 = p; + p = out.find("[", p); + p2 = out.find("\n", p2); + if((p != std::string::npos) && (p < p2)) + { + p = out.find("expires:", p); + p += strlen("expires:"); + p++; + p2 = out.find("]", p); + TCHAR *expire_date = mir_wstrdup(toUTF16(out.substr(p,p2-p)).c_str()); + bool expired = false; + { + boost::posix_time::ptime now = boost::posix_time::second_clock::local_time(); + TCHAR buf[5]; + mir_sntprintf(buf, 5, _T("%s"), expire_date); + int year = _ttoi(buf); + if(year < now.date().year()) + expired = true; + else if(year == now.date().year()) + { + mir_sntprintf(buf, 3, _T("%s"), expire_date+5); + int month = _ttoi(buf); + if(month < now.date().month()) + expired = true; + else if(month == now.date().month()) + { + mir_sntprintf(buf, 3, _T("%s"), expire_date+8); + unsigned day = _ttoi(buf); + if(day <= now.date().day_number()) + expired = true; + } + } + } + if(expired) + { + question += keyid; + question += Translate(" expired and will not work.\nDo you want to set another key?"); + if(MessageBoxA(0, question.c_str(), Translate("Own secret key warning"), MB_YESNO) == IDYES) + ShowFirstRunDialog(); + } + mir_free(expire_date); + } + //TODO: check for expired key mir_free(keyid); mir_free(key); } @@ -2294,26 +2301,26 @@ void InitCheck() CallService(svc, 0, (LPARAM)&cap); } } - if(bFileTransfers) - { - int count = 0; - PROTOACCOUNT **accounts; - ProtoEnumAccounts(&count, &accounts); - ICQ_CUSTOMCAP cap; - cap.cbSize = sizeof(ICQ_CUSTOMCAP); - cap.hIcon = 0; - strcpy(cap.name, "GPG Encrypted FileTransfers"); - strcpy(cap.caps, "GPG FileTransfer"); - - for(int i = 0; i < count; i++) - { - char svc[64]; - strcpy(svc, accounts[i]->szProtoName); - strcat(svc, PS_ICQ_ADDCAPABILITY); - if(ServiceExists(svc)) - CallService(svc, 0, (LPARAM)&cap); - } - } + if(bFileTransfers) + { + int count = 0; + PROTOACCOUNT **accounts; + ProtoEnumAccounts(&count, &accounts); + ICQ_CUSTOMCAP cap; + cap.cbSize = sizeof(ICQ_CUSTOMCAP); + cap.hIcon = 0; + strcpy(cap.name, "GPG Encrypted FileTransfers"); + strcpy(cap.caps, "GPG FileTransfer"); + + for(int i = 0; i < count; i++) + { + char svc[64]; + strcpy(svc, accounts[i]->szProtoName); + strcat(svc, PS_ICQ_ADDCAPABILITY); + if(ServiceExists(svc)) + CallService(svc, 0, (LPARAM)&cap); + } + } } void ImportKey() @@ -2325,7 +2332,7 @@ void ImportKey() new_key_hcnt_mutex.unlock(); bool for_all_sub = false; if(metaIsProtoMetaContacts(hContact)) - if(MessageBox(0, TranslateT("Do you want load key for all subcontacts ?"), TranslateT("Metacontact detected"), MB_YESNO) == IDYES) + if(MessageBox(0, TranslateT("Do you want to load key for all subcontacts?"), TranslateT("Metacontact detected"), MB_YESNO) == IDYES) for_all_sub = true; if(metaIsProtoMetaContacts(hContact)) { @@ -2347,7 +2354,7 @@ void ImportKey() DBWriteContactSettingTString(hContact, szGPGModuleName, "GPGPubKey", new_key.c_str()); new_key.clear(); { //gpg execute block - std::vector cmd; + std::vector cmd; TCHAR tmp2[MAX_PATH] = {0}; TCHAR *ptmp; string output; @@ -2358,7 +2365,7 @@ void ImportKey() mir_free(ptmp); _tcscat(tmp2, _T("\\")); _tcscat(tmp2, _T("temporary_exported.asc")); - boost::filesystem::remove(tmp2); + boost::filesystem::remove(tmp2); wfstream f(tmp2, std::ios::out); if(metaIsProtoMetaContacts(hContact)) ptmp = UniGetContactSettingUtf(metaGetMostOnline(hContact), szGPGModuleName, "GPGPubKey", _T("")); @@ -2368,16 +2375,16 @@ void ImportKey() mir_free(ptmp); f<