From 86cafe5f5e47960cb8962fd555612aeb2d288285 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Sat, 14 Aug 2010 15:12:56 +0300 Subject: modified: main.cpp modified: messages.cpp modified: new_gpg.rc modified: resource.h --- main.cpp | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 129 insertions(+), 1 deletion(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index 1888581..09fc90f 100644 --- a/main.cpp +++ b/main.cpp @@ -30,7 +30,7 @@ void test() } -HWND hwndFirstRun = NULL, hwndSetDirs = NULL; +HWND hwndFirstRun = NULL, hwndSetDirs = NULL, hwndNewKey = NULL; int itemnum = 0; @@ -282,6 +282,64 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP return FALSE; } +static BOOL CALLBACK DlgProcNewKeyDialog(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + extern HANDLE new_key_hcnt; + void ImportKey(); + TCHAR *tmp = NULL; + switch (msg) + { + case WM_INITDIALOG: + { + TranslateDialogDefault(hwndDlg); + TCHAR *tmp = UniGetContactSettingUtf(new_key_hcnt, szModuleName, "GPGPubKey", _T("")); + SetDlgItemText(hwndDlg, IDC_MESSAGE, (_tcslen(tmp) > 0)?_T("There is existing key for contact, do you want to replace with new key ?"):_T("New public key was received, do you want to import it?")); + mir_free(tmp); + return TRUE; + } + + + case WM_COMMAND: + { + switch (LOWORD(wParam)) + { + case ID_IMPORT: + ImportKey(); + DestroyWindow(hwndDlg); + break; + case IDC_IMPORT_AND_USE: + ImportKey(); + DBWriteContactSettingByte(new_key_hcnt, szModuleName, "GPGEncryption", 1); + DestroyWindow(hwndDlg); + break; + case IDC_IGNORE_KEY: + DestroyWindow(hwndDlg); + break; + default: + break; + } + + break; + } + + case WM_NOTIFY: + { + switch (((LPNMHDR)lParam)->code) + { + } + } + break; + case WM_CLOSE: + DestroyWindow(hwndDlg); + break; + case WM_DESTROY: + hwndFirstRun = NULL; + break; + + } + return FALSE; +} + extern HINSTANCE hInst; @@ -305,6 +363,13 @@ void ShowSetDirsDialog() SetForegroundWindow(hwndSetDirs); } +void ShowNewKeyDialog() +{ + hwndNewKey = CreateDialog(hInst, MAKEINTRESOURCE(IDD_NEW_KEY), NULL, DlgProcNewKeyDialog); + SetForegroundWindow(hwndNewKey); +} + + void FirstRun() { @@ -313,3 +378,66 @@ void FirstRun() return; ShowSetDirsDialog(); } + +void ImportKey() +{ + extern wstring new_key; + extern HANDLE new_key_hcnt; + DBWriteContactSettingTString(new_key_hcnt, szModuleName, "GPGPubKey", new_key.c_str()); + { //gpg execute block + wstring cmd; + TCHAR tmp2[MAX_PATH] = {0}; + TCHAR *ptmp; + string output; + DWORD exitcode; + { + ptmp = UniGetContactSettingUtf(NULL, szModuleName, "szHomePath", _T("")); + _tcscpy(tmp2, ptmp); + mir_free(ptmp); + _tcscat(tmp2, _T("\\")); + _tcscat(tmp2, _T("temporary_exported.asc")); + wfstream f(tmp2, std::ios::out); + ptmp = UniGetContactSettingUtf(new_key_hcnt, szModuleName, "GPGPubKey", _T("")); + wstring new_key = ptmp; + mir_free(ptmp); + f<", s2); + s2++; + if(output[s] == ')') + { + DBWriteContactSettingString(new_key_hcnt, szModuleName, "KeyComment", output.substr(s2,s-s2).c_str()); + s+=3; + s2 = output.find(">", s); + DBWriteContactSettingString(new_key_hcnt, szModuleName, "KeyMainEmail", output.substr(s,s2-s).c_str()); + } + else + DBWriteContactSettingString(new_key_hcnt, szModuleName, "KeyMainEmail", output.substr(s2,s-s2).c_str()); + } + MessageBoxA(0, output.c_str(), "", MB_OK); + DeleteFile(tmp2); + } +} \ No newline at end of file -- cgit v1.2.3