diff options
Diffstat (limited to 'src')
-rwxr-xr-x | src/main.cpp | 113 | ||||
-rwxr-xr-x | src/options.cpp | 3 | ||||
-rwxr-xr-x | src/resource.h | 4 |
3 files changed, 113 insertions, 7 deletions
diff --git a/src/main.cpp b/src/main.cpp index 87edd03..495f025 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -42,6 +42,8 @@ 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);
col.pszText = _T("Key ID"); col.mask = LVCF_TEXT | LVCF_WIDTH; col.fmt = LVCFMT_LEFT; @@ -321,10 +323,7 @@ static INT_PTR CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR if(result == pxNotFound) break; string::size_type s = 0; - while((s = out.find("\r", s)) != string::npos) - { - out.erase(s, 1); - } + boost::algorithm::erase_all(out, "\r");
{ char buf[64]; GetDlgItemTextA(hwndDlg, IDC_ACCOUNT, buf, 63); @@ -708,6 +707,110 @@ 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;
+ wstring cmd = _T("--batch -a --export ");
+ cmd += fp;
+ gpg_execution_params params;
+ pxResult result;
+ params.cmd = &cmd;
+ params.useless = "";
+ params.out = &out;
+ params.code = &code;
+ params.result = &result;
+ boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms));
+ if(!gpg_thread.timed_join(boost::posix_time::seconds(10)))
+ {
+ gpg_thread.~thread();
+ TerminateProcess(params.hProcess, 1);
+ params.hProcess = NULL;
+ if(bDebugLog)
+ debuglog<<std::string(time_str()+": GPG execution timed out, aborted");
+ break;
+ }
+ if(result == pxNotFound)
+ break;
+ boost::algorithm::erase_all(out, "\r");
+ HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, out.size() +1); + if(!hMem) + { + MessageBox(0, TranslateT("Failed to alocate memory"), TranslateT("Error"), MB_OK); + break; + } + char *szKey = (char*)GlobalLock(hMem); + if(!szKey) + { + char msg[64]; + mir_snprintf(msg, 127, "Failed to lock memory with error %d", GetLastError()); + MessageBoxA(0, msg, "Error", MB_OK); + GlobalFree(hMem); + } + memcpy(szKey, out.c_str(), out.size()); + szKey[out.size()] = '\0'; + EmptyClipboard(); + GlobalUnlock(hMem); + if(!SetClipboardData(CF_OEMTEXT, hMem)) + { + GlobalFree(hMem); + char msg[64]; + mir_snprintf(msg, 127, "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;
+ wstring cmd = _T("--batch -a --export-secret-keys ");
+ cmd += fp;
+ gpg_execution_params params;
+ pxResult result;
+ params.cmd = &cmd;
+ params.useless = "";
+ params.out = &out;
+ params.code = &code;
+ params.result = &result;
+ boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms));
+ if(!gpg_thread.timed_join(boost::posix_time::seconds(10)))
+ {
+ gpg_thread.~thread();
+ TerminateProcess(params.hProcess, 1);
+ params.hProcess = NULL;
+ if(bDebugLog)
+ debuglog<<std::string(time_str()+": GPG execution timed out, aborted");
+ break;
+ }
+ if(result == pxNotFound)
+ break;
+ boost::algorithm::erase_all(out, "\r");
+ file<<out;
+ if(file.is_open())
+ file.close();
+ }
+ break;
} break; @@ -720,6 +823,8 @@ static INT_PTR CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR if(hdr->hdr.code == NM_CLICK) { EnableWindow(GetDlgItem(hwndDlg, ID_OK), 1); + EnableWindow(GetDlgItem(hwndDlg, IDC_COPY_PUBKEY), 1);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_EXPORT_PRIVATE), 1);
itemnum = hdr->iItem; } } diff --git a/src/options.cpp b/src/options.cpp index d635302..ab54404 100755 --- a/src/options.cpp +++ b/src/options.cpp @@ -381,8 +381,7 @@ static INT_PTR CALLBACK DlgProcGpgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP char *szKey = UniGetContactSettingUtf(NULL, szGPGModuleName, "GPGPubKey", "");
std::string str = szKey;;
mir_free(szKey);
- for(std::string::size_type i = str.find("\n"); i != std::string::npos; i = str.find("\n", i+2))
- str.replace(i, 1, "\r\n");
+ boost::algorithm::replace_all(str, "\n", "\r\n"); HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, str.size() +1);
if(!hMem)
{
diff --git a/src/resource.h b/src/resource.h index 7ffd83c..38f790f 100755 --- a/src/resource.h +++ b/src/resource.h @@ -82,6 +82,7 @@ #define IDC_AUT_EXCHANGE 1065
#define IDC_BUTTON3 1066
#define IDC_COPY_KEY 1066
+#define IDC_COPY_PUBKEY 1066
#define IDC_STRIP_TAGS 1067
#define IDC_CHECK1 1068
#define IDC_PRESCENSE_SUBSCRIPTION 1068
@@ -95,6 +96,7 @@ #define IDC_PUBLIC 1073
#define IDC_PRIVATE 1074
#define IDC_ALL 1075
+#define IDC_EXPORT_PRIVATE 1076
// Next default values for new objects
//
@@ -102,7 +104,7 @@ #ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 115
#define _APS_NEXT_COMMAND_VALUE 40001
-#define _APS_NEXT_CONTROL_VALUE 1076
+#define _APS_NEXT_CONTROL_VALUE 1077
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
|