From cd6972996f5645c1c3fcc55a1673499b266285e6 Mon Sep 17 00:00:00 2001
From: Alexander Gluzsky <sss123next@list.ru>
Date: Mon, 28 Jan 2013 11:31:01 +0000
Subject: added ability to export private key in key choosing dialog

git-svn-id: http://svn.miranda-ng.org/main/trunk@3315 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
---
 plugins/New_GPG/src/main.cpp | 54 ++++++++++++++++++++++++++++++++++++--------
 1 file changed, 44 insertions(+), 10 deletions(-)

(limited to 'plugins')

diff --git a/plugins/New_GPG/src/main.cpp b/plugins/New_GPG/src/main.cpp
index 5e45d04832..7282865ba1 100755
--- a/plugins/New_GPG/src/main.cpp
+++ b/plugins/New_GPG/src/main.cpp
@@ -712,16 +712,6 @@ static INT_PTR CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR
 						if(OpenClipboard(hwndDlg))
 						{
 							ListView_GetItemText(hwndList, itemnum, 0, fp, 16);
-							/*TCHAR *name = new TCHAR [64];
-							ListView_GetItemText(hwndList, itemnum, 2, name, 64);
-							{
-								if(_tcschr(name, _T('(')))
-								{
-									wstring str = name;
-									wstring::size_type p = str.find(_T("("))-1;
-									_tcscpy(name, str.substr(0, p).c_str());
-								}
-							}*/
 							string out;
 							DWORD code;
 							wstring cmd = _T("--batch -a --export ");
@@ -776,6 +766,50 @@ static INT_PTR CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR
 					}
 					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, &params));
+						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;
 
 	  }
-- 
cgit v1.2.3