From fb9e64ea76b6363b57a4a82d47da0280bb0a1429 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Mon, 1 Nov 2010 15:35:20 +0200 Subject: modified: gpg_wrapper.cpp modified: main.cpp modified: new_gpg.rc --- main.cpp | 191 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 189 insertions(+), 2 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index 197623f..dd3b39f 100644 --- a/main.cpp +++ b/main.cpp @@ -463,7 +463,6 @@ static BOOL CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM SetWindowText(hwndCurKey_p, path.c_str()); } } - bAutoExchange = CheckStateStoreDB(hwndDlg, IDC_AUTO_EXCHANGE, "bAutoExchange"); DestroyWindow(hwndDlg); break; } @@ -574,9 +573,11 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP params.out = &out; params.code = &code; params.result = &result; + gpg_configured = true; boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) gpg_thread.~thread(); + gpg_configured = false; DBDeleteContactSetting(NULL, szGPGModuleName, "szGpgBinPath"); string::size_type p1 = out.find("(GnuPG) "); if(p1 != string::npos) @@ -685,9 +686,11 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP params.out = &out; params.code = &code; params.result = &result; + gpg_configured = true; boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) gpg_thread.~thread(); + gpg_configured = false; DBDeleteContactSetting(NULL, szGPGModuleName, "szGpgBinPath"); string::size_type p1 = out.find("(GnuPG) "); if(p1 != string::npos) @@ -724,11 +727,195 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP } mir_free(path); } + gpg_configured = true; DestroyWindow(hwndDlg); ShowFirstRunDialog(); - break; } + break; + case IDC_GENERATE_RANDOM: + { + TCHAR tmp[512]; + GetDlgItemText(hwndDlg, IDC_BIN_PATH, tmp, 512); + if(tmp[0]) + { + char *mir_path = new char [MAX_PATH]; + CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)"\\", (LPARAM)mir_path); + SetCurrentDirectoryA(mir_path); + delete [] mir_path; + if(_waccess(tmp, 0) == -1) + { + if(errno == ENOENT) + { + MessageBox(0, _T("gpg binary does not exists.\nplease choose another location"), _T("Warning"), MB_OK); + break; + } + } + } + else + { + MessageBox(0, _T("please choose gpg binary location"), _T("Warning"), MB_OK); + break; + } + { + bool bad_version = false; + DBWriteContactSettingTString(NULL, szGPGModuleName, "szGpgBinPath", tmp); + string out; + DWORD code; + wstring cmd = _T("--version"); + gpg_execution_params params; + pxResult result; + params.cmd = &cmd; + params.useless = ""; + params.out = &out; + params.code = &code; + params.result = &result; + gpg_configured = true; + boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); + if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) + gpg_thread.~thread(); + gpg_configured = false; + DBDeleteContactSetting(NULL, szGPGModuleName, "szGpgBinPath"); + string::size_type p1 = out.find("(GnuPG) "); + if(p1 != string::npos) + { + p1 += strlen("(GnuPG) "); + if(out[p1] != '1') + bad_version = true; + } + else + { + bad_version = false; + MessageBox(0, _T("This is not gnupg binary !\nrecommended to use GnuPG v1.x.x with this plugn."), _T("Warning"), MB_OK); + } + if(bad_version) + MessageBox(0, _T("Unsupported gnupg version found, use at you own risk!\nrecommended to use GnuPG v1.x.x with this plugn."), _T("Warning"), MB_OK); + } + DBWriteContactSettingTString(NULL, szGPGModuleName, "szGpgBinPath", tmp); + GetDlgItemText(hwndDlg, IDC_HOME_DIR, tmp, 512); + while(tmp[_tcslen(tmp)-1] == '\\') + tmp[_tcslen(tmp)-1] = '\0'; + if(!tmp[0]) + { + MessageBox(0, _T("please set keyring's home directory"), _T("Warning"), MB_OK); + break; + } + DBWriteContactSettingTString(NULL, szGPGModuleName, "szHomePath", tmp); + { + TCHAR *path = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); + DWORD dwFileAttr = GetFileAttributes(path); + if (dwFileAttr != INVALID_FILE_ATTRIBUTES) + { + dwFileAttr &=~ FILE_ATTRIBUTE_READONLY; + SetFileAttributes(path, dwFileAttr); + } + mir_free(path); + } + } + { + wstring path; + { //generating key file + TCHAR *tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); + path = tmp; + mir_free(tmp); + path.append(_T("\\new_key")); + wfstream f(path.c_str(), std::ios::out); + if(!f.is_open()) + { + MessageBox(0, _T("Failed to open file"), _T("Error"), MB_OK); + break; + } + f<<"Key-Type: RSA"; + f<<"\n"; + f<<"Key-Length: 2048"; + f<<"\n"; + f<<"Subkey-Type: RSA"; + f<<"\n"; + f<<"Name-Real: "; + f<