diff options
Diffstat (limited to 'main.cpp')
-rwxr-xr-x | main.cpp | 367 |
1 files changed, 83 insertions, 284 deletions
@@ -1,4 +1,4 @@ -// Copyright © 2010-2012 sss +// Copyright © 2010-2011 sss // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -148,27 +148,7 @@ static BOOL CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM } } } - { - SendMessageA(GetDlgItem(hwndDlg, IDC_ACCOUNT), CB_ADDSTRING, 0, (LPARAM)Translate("Default")); - int count = 0; - PROTOACCOUNT **accounts; - ProtoEnumAccounts(&count, &accounts); - for(int i = 0; i < count; i++) - { - if(StriStr(accounts[i]->szModuleName, "metacontacts")) - continue; - if(StriStr(accounts[i]->szModuleName, "weather")) - continue; - SendMessageA(GetDlgItem(hwndDlg, IDC_ACCOUNT), CB_ADDSTRING, 0, (LPARAM)accounts[i]->szModuleName); - } - SendMessageA(GetDlgItem(hwndDlg, IDC_ACCOUNT), CB_SELECTSTRING, 0, (LPARAM)Translate("Default")); - string keyinfo = Translate("key id"); - keyinfo += ": "; - char *keyid = UniGetContactSettingUtf(NULL, szGPGModuleName, "KeyID", ""); - keyinfo += (strlen(keyid) > 0)?keyid:Translate("not set"); - mir_free(keyid); - SetDlgItemTextA(hwndDlg, IDC_KEY_ID, keyinfo.c_str()); - } + return TRUE; } @@ -222,29 +202,9 @@ static BOOL CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM { out.erase(s, 1); } - { - char buf[64]; - GetDlgItemTextA(hwndDlg, IDC_ACCOUNT, buf, 63); - if(!strcmp(buf, Translate("Default"))) - { - DBWriteContactSettingString(NULL, szGPGModuleName, "GPGPubKey", out.c_str()); - DBWriteContactSettingTString(NULL, szGPGModuleName, "KeyMainName", name); - DBWriteContactSettingTString(NULL, szGPGModuleName, "KeyID", fp); - } - else - { - char setting[64]; - strcpy(setting, buf); - strcat(setting, "_GPGPubKey"); - DBWriteContactSettingString(NULL, szGPGModuleName, setting, out.c_str()); - strcpy(setting, buf); - strcat(setting, "_KeyMainName"); - DBWriteContactSettingTString(NULL, szGPGModuleName, setting, name); - strcpy(setting, buf); - strcat(setting, "_KeyID"); - DBWriteContactSettingTString(NULL, szGPGModuleName, setting, fp); - } - } + DBWriteContactSettingString(NULL, szGPGModuleName, "GPGPubKey", out.c_str()); + DBWriteContactSettingTString(NULL, szGPGModuleName, "KeyMainName", name); + DBWriteContactSettingTString(NULL, szGPGModuleName, "KeyID", fp); TCHAR passwd[64]; GetDlgItemText(hwndDlg, IDC_KEY_PASSWORD, passwd, 64); if(passwd[0]) @@ -257,8 +217,7 @@ static BOOL CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM DBWriteContactSettingTString(NULL, szGPGModuleName, dbsetting.c_str(), passwd); } { - wstring keyinfo = TranslateT("Default private key id"); - keyinfo += _T(": "); + wstring keyinfo = _T("Current private key id: "); keyinfo += (fp[0])?fp:_T("not set"); extern HWND hwndCurKey_p; SetWindowText(hwndCurKey_p, keyinfo.c_str()); @@ -266,8 +225,7 @@ static BOOL CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM delete [] name; } bAutoExchange = CheckStateStoreDB(hwndDlg, IDC_AUTO_EXCHANGE, "bAutoExchange"); - gpg_valid = isGPGValid(); - gpg_keyexist = isGPGKeyExist(); + gpg_configured = isGPGConfigured(); DestroyWindow(hwndDlg); break; case IDC_OTHER: @@ -412,41 +370,12 @@ static BOOL CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM if(result == pxNotFound) break; } - { - char buf[64]; - GetDlgItemTextA(hwndDlg, IDC_ACCOUNT, buf, 63); - if(!strcmp(buf, Translate("Default"))) - { - DBDeleteContactSetting(NULL, szGPGModuleName, "GPGPubKey"); - DBDeleteContactSetting(NULL, szGPGModuleName, "KeyID"); - DBDeleteContactSetting(NULL, szGPGModuleName, "KeyComment"); - DBDeleteContactSetting(NULL, szGPGModuleName, "KeyMainName"); - DBDeleteContactSetting(NULL, szGPGModuleName, "KeyMainEmail"); - DBDeleteContactSetting(NULL, szGPGModuleName, "KeyType"); - } - else - { - char setting[64]; - strcpy(setting, buf); - strcat(setting, "_GPGPubKey"); - DBDeleteContactSetting(NULL, szGPGModuleName, setting); - strcpy(setting, buf); - strcat(setting, "_KeyMainName"); - DBDeleteContactSetting(NULL, szGPGModuleName, setting); - strcpy(setting, buf); - strcat(setting, "_KeyID"); - DBDeleteContactSetting(NULL, szGPGModuleName, setting); - strcpy(setting, buf); - strcat(setting, "_KeyComment"); - DBDeleteContactSetting(NULL, szGPGModuleName, setting); - strcpy(setting, buf); - strcat(setting, "_KeyMainEmail"); - DBDeleteContactSetting(NULL, szGPGModuleName, setting); - strcpy(setting, buf); - strcat(setting, "_KeyType"); - DBDeleteContactSetting(NULL, szGPGModuleName, setting); - } - } + DBDeleteContactSetting(NULL, szGPGModuleName, "GPGPubKey"); + DBDeleteContactSetting(NULL, szGPGModuleName, "KeyID"); + DBDeleteContactSetting(NULL, szGPGModuleName, "KeyComment"); + DBDeleteContactSetting(NULL, szGPGModuleName, "KeyMainName"); + DBDeleteContactSetting(NULL, szGPGModuleName, "KeyMainEmail"); + DBDeleteContactSetting(NULL, szGPGModuleName, "KeyType"); ListView_DeleteItem(hwndList, itemnum); break; case IDC_GENERATE_RANDOM: @@ -460,12 +389,12 @@ static BOOL CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM wfstream f(path.c_str(), std::ios::out); if(!f.is_open()) { - MessageBox(0, TranslateT("Failed to open file"), TranslateT("Error"), MB_OK); + MessageBox(0, _T("Failed to open file"), _T("Error"), MB_OK); break; } f<<"Key-Type: RSA"; f<<"\n"; - f<<"Key-Length: 4096"; + f<<"Key-Length: 2048"; f<<"\n"; f<<"Subkey-Type: RSA"; f<<"\n"; @@ -495,12 +424,6 @@ static BOOL CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM params.out = &out; params.code = &code; params.result = &result; - 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); boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); if(!gpg_thread.timed_join(boost::posix_time::minutes(10))) { @@ -549,59 +472,14 @@ static BOOL CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM { out.erase(s, 1); } - { - char buf[64]; - GetDlgItemTextA(hwndDlg, IDC_ACCOUNT, buf, 63); - if(!strcmp(buf, Translate("Default"))) - { - DBWriteContactSettingString(NULL, szGPGModuleName, "GPGPubKey", out.c_str()); - DBWriteContactSettingTString(NULL, szGPGModuleName, "KeyID", fp); - } - else - { - char setting[64]; - strcpy(setting, buf); - strcat(setting, "_GPGPubKey"); - DBWriteContactSettingString(NULL, szGPGModuleName, setting, out.c_str()); - strcpy(setting, buf); - strcat(setting, "_KeyID"); - DBWriteContactSettingTString(NULL, szGPGModuleName, setting, fp); - } - } + DBWriteContactSettingString(NULL, szGPGModuleName, "GPGPubKey", out.c_str()); + DBWriteContactSettingTString(NULL, szGPGModuleName, "KeyID", path.c_str()); extern HWND hwndCurKey_p; SetWindowText(hwndCurKey_p, path.c_str()); } } DestroyWindow(hwndDlg); break; - case IDC_ACCOUNT: - { - char buf[64]; - GetDlgItemTextA(hwndDlg, IDC_ACCOUNT, buf, 63); - if(!strcmp(buf, Translate("Default"))) - { - string keyinfo = Translate("key id"); - keyinfo += ": "; - char *keyid = UniGetContactSettingUtf(NULL, szGPGModuleName, "KeyID", ""); - keyinfo += (strlen(keyid) > 0)?keyid:Translate("not set"); - mir_free(keyid); - SetDlgItemTextA(hwndDlg, IDC_KEY_ID, keyinfo.c_str()); - } - else - { - string keyinfo = Translate("key id"); - keyinfo += ": "; - char setting[64]; - strcpy(setting, buf); - strcat(setting, "_KeyID"); - char *keyid = UniGetContactSettingUtf(NULL, szGPGModuleName, setting, ""); - keyinfo += (strlen(keyid) > 0)?keyid:Translate("not set"); - mir_free(keyid); - SetDlgItemTextA(hwndDlg, IDC_KEY_ID, keyinfo.c_str()); - } - } - break; - } break; } @@ -616,16 +494,12 @@ static BOOL CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM itemnum = hdr->iItem; } } -/* switch(LOWORD(wParam)) - { - default: - break; - }; */ -/* switch (((LPNMHDR)lParam)->code) - { - default: - break; - } */ +// switch (((LPNMHDR)lParam)->code) + // { +// default: +// break; + +// } } break; case WM_CLOSE: @@ -678,7 +552,7 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP if(_waccess(gpg_lang_path, 0) != -1) lang_exists = true; if(gpg_exists && !lang_exists) //TODO: check gpg version - 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); + MessageBox(0, _T("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."), _T("Warning"), MB_OK); mir_free(gpg_path); mir_free(gpg_lang_path); } @@ -695,7 +569,9 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP if(_waccess(tmp, 0) == -1) { if(errno == ENOENT) - MessageBox(0, TranslateT("wrong gpg binary location found in system.\nplease choose another location"), TranslateT("Warning"), MB_OK); + { + MessageBox(0, _T("wrong gpg binary location found in system.\nplease choose another location"), _T("Warning"), MB_OK); + } } } } @@ -717,7 +593,7 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP params.out = &out; params.code = &code; params.result = &result; - gpg_valid = true; + gpg_configured = true; boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) { @@ -726,7 +602,7 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP params.hProcess = NULL; debuglog<<time_str()<<": GPG execution timed out, aborted\n"; } - gpg_valid = false; + gpg_configured = false; DBDeleteContactSetting(NULL, szGPGModuleName, "szGpgBinPath"); string::size_type p1 = out.find("(GnuPG) "); if(p1 != string::npos) @@ -738,10 +614,10 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP 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, _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, 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, _T("Unsupported gnupg version found, use at you own risk!\nrecommended to use GnuPG v1.x.x with this plugn."), _T("Warning"), MB_OK); } mir_free(tmp); if(!gpg_exists) @@ -753,7 +629,7 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP SetDlgItemText(hwndDlg, IDC_HOME_DIR, !gpg_exists?tmp:_T("gpg")); mir_free(tmp); 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); + MessageBox(0, _T("You have supported version of gpg binary, and gpg language file in place!\ngpg plugin should work fine on your installation!\njust press ok in wollowing diallog."), _T("Info"), MB_OK); extern bool bIsMiranda09; EnableWindow(GetDlgItem(hwndDlg, IDC_AUTO_EXCHANGE), bIsMiranda09); return TRUE; @@ -814,14 +690,14 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP { if(errno == ENOENT) { - MessageBox(0, TranslateT("gpg binary does not exists.\nplease choose another location"), TranslateT("Warning"), MB_OK); + MessageBox(0, _T("gpg binary does not exists.\nplease choose another location"), _T("Warning"), MB_OK); break; } } } else { - MessageBox(0, TranslateT("please choose gpg binary location"), TranslateT("Warning"), MB_OK); + MessageBox(0, _T("please choose gpg binary location"), _T("Warning"), MB_OK); break; } { @@ -837,7 +713,7 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP params.out = &out; params.code = &code; params.result = &result; - gpg_valid = true; + gpg_configured = true; boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) { @@ -846,7 +722,7 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP gpg_thread.~thread(); debuglog<<time_str()<<": GPG execution timed out, aborted\n"; } - gpg_valid = false; + gpg_configured = false; DBDeleteContactSetting(NULL, szGPGModuleName, "szGpgBinPath"); string::size_type p1 = out.find("(GnuPG) "); if(p1 != string::npos) @@ -858,10 +734,10 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP 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, _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, 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, _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); @@ -869,7 +745,7 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP tmp[_tcslen(tmp)-1] = '\0'; if(!tmp[0]) { - MessageBox(0, TranslateT("please set keyring's home directory"), TranslateT("Warning"), MB_OK); + MessageBox(0, _T("please set keyring's home directory"), _T("Warning"), MB_OK); break; } DBWriteContactSettingTString(NULL, szGPGModuleName, "szHomePath", tmp); @@ -883,7 +759,7 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP } mir_free(path); } - gpg_valid = true; + gpg_configured = true; DBWriteContactSettingByte(NULL, szGPGModuleName, "FirstRun", 0); DestroyWindow(hwndDlg); ShowFirstRunDialog(); @@ -903,14 +779,14 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP { if(errno == ENOENT) { - MessageBox(0, TranslateT("gpg binary does not exists.\nplease choose another location"), TranslateT("Warning"), MB_OK); + MessageBox(0, _T("gpg binary does not exists.\nplease choose another location"), _T("Warning"), MB_OK); break; } } } else { - MessageBox(0, TranslateT("please choose gpg binary location"), TranslateT("Warning"), MB_OK); + MessageBox(0, _T("please choose gpg binary location"), _T("Warning"), MB_OK); break; } { @@ -926,7 +802,7 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP params.out = &out; params.code = &code; params.result = &result; - gpg_valid = true; + gpg_configured = true; boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) { @@ -935,7 +811,7 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP gpg_thread.~thread(); debuglog<<time_str()<<": GPG execution timed out, aborted\n"; } - gpg_valid = false; + gpg_configured = false; DBDeleteContactSetting(NULL, szGPGModuleName, "szGpgBinPath"); string::size_type p1 = out.find("(GnuPG) "); if(p1 != string::npos) @@ -947,10 +823,10 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP 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, _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, 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, _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); @@ -958,7 +834,7 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP tmp[_tcslen(tmp)-1] = '\0'; if(!tmp[0]) { - MessageBox(0, TranslateT("please set keyring's home directory"), TranslateT("Warning"), MB_OK); + MessageBox(0, _T("please set keyring's home directory"), _T("Warning"), MB_OK); break; } DBWriteContactSettingTString(NULL, szGPGModuleName, "szHomePath", tmp); @@ -983,7 +859,7 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP wfstream f(path.c_str(), std::ios::out); if(!f.is_open()) { - MessageBox(0, TranslateT("Failed to open file"), TranslateT("Error"), MB_OK); + MessageBox(0, _T("Failed to open file"), _T("Error"), MB_OK); break; } f<<"Key-Type: RSA"; @@ -1018,7 +894,7 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP params.out = &out; params.code = &code; params.result = &result; - gpg_valid = true; + gpg_configured = true; boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); if(!gpg_thread.timed_join(boost::posix_time::minutes(10))) { @@ -1026,10 +902,10 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP TerminateProcess(params.hProcess, 1); params.hProcess = NULL; debuglog<<time_str()<<": GPG execution timed out, aborted"; - gpg_valid = false; + gpg_configured = false; break; } - gpg_valid = false; + gpg_configured = false; if(result == pxNotFound) break; DeleteFile(path.c_str()); @@ -1052,7 +928,7 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP params.out = &out; params.code = &code; params.result = &result; - gpg_valid = true; + gpg_configured = true; boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) { @@ -1060,10 +936,10 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP TerminateProcess(params.hProcess, 1); params.hProcess = NULL; debuglog<<time_str()<<"GPG execution timed out, aborted\n"; - gpg_valid = false; + gpg_configured = false; break; } - gpg_valid = false; + gpg_configured = false; if(result == pxNotFound) break; string::size_type s = 0; @@ -1078,7 +954,7 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP } } bAutoExchange = CheckStateStoreDB(hwndDlg, IDC_AUTO_EXCHANGE, "bAutoExchange"); - gpg_valid = true; + gpg_configured = true; DBWriteContactSettingByte(NULL, szGPGModuleName, "FirstRun", 0); DestroyWindow(hwndDlg); break; @@ -1113,24 +989,23 @@ static BOOL CALLBACK DlgProcNewKeyDialog(HWND hwndDlg, UINT msg, WPARAM wParam, { extern HANDLE new_key_hcnt; extern boost::mutex new_key_hcnt_mutex; - static HANDLE hContact = INVALID_HANDLE_VALUE; + HANDLE hContact = new_key_hcnt; + new_key_hcnt_mutex.unlock(); void ImportKey(); TCHAR *tmp = NULL; switch (msg) { case WM_INITDIALOG: { - hContact = new_key_hcnt; - 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("")); - SetDlgItemText(hwndDlg, IDC_MESSAGE, tmp[0]?TranslateT("There is existing key for contact, would you like to replace with new key ?"):TranslateT("New public key was received, do you want to import it?")); + SetDlgItemText(hwndDlg, IDC_MESSAGE, (_tcslen(tmp) > 0)?_T("There is existing key for contact, would you like to replace with new key ?"):_T("New public key was received, do you want to import it?")); EnableWindow(GetDlgItem(hwndDlg, IDC_IMPORT_AND_USE), DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0)?0:1); - SetDlgItemText(hwndDlg, ID_IMPORT, tmp[0]?TranslateT("Replace"):TranslateT("Accept")); + SetDlgItemText(hwndDlg, ID_IMPORT, (_tcslen(tmp) > 0)?_T("Replace"):_T("Accept")); mir_free(tmp); tmp = new TCHAR [256]; - _tcscpy(tmp, TranslateT("Received key from ")); + _tcscpy(tmp, _T("Received key from ")); _tcscat(tmp, (TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, (LPARAM)GCDNF_TCHAR)); SetDlgItemText(hwndDlg, IDC_KEY_FROM, tmp); delete [] tmp; @@ -1197,12 +1072,12 @@ static BOOL CALLBACK DlgProcKeyGenDialog(HWND hwndDlg, UINT msg, WPARAM wParam, { SetWindowPos(hwndDlg, 0, key_gen_rect.left, key_gen_rect.top, 0, 0, SWP_NOSIZE|SWP_SHOWWINDOW); TranslateDialogDefault(hwndDlg); - SetWindowText(hwndDlg, TranslateT("Key Generation dialog")); + SetWindowText(hwndDlg, TranslateW(_T("Key Generation dialog"))); ComboBoxAddStringUtf(GetDlgItem(hwndDlg, IDC_KEY_TYPE), _T("RSA"), 0); ComboBoxAddStringUtf(GetDlgItem(hwndDlg, IDC_KEY_TYPE), _T("DSA"), 1); SendDlgItemMessage(hwndDlg, IDC_KEY_TYPE, CB_SETCURSEL, (WPARAM)1, 0); SetDlgItemInt(hwndDlg, IDC_KEY_EXPIRE_DATE, 0, 0); - SetDlgItemInt(hwndDlg, IDC_KEY_LENGTH, 4096, 0); + SetDlgItemInt(hwndDlg, IDC_KEY_LENGTH, 2048, 0); return TRUE; } @@ -1223,7 +1098,7 @@ static BOOL CALLBACK DlgProcKeyGenDialog(HWND hwndDlg, UINT msg, WPARAM wParam, if(_tcslen(tmp) < 3) { mir_free(tmp); - MessageBox(0, TranslateT("You must set encryption algorythm first"), TranslateT("Error"), MB_OK); + MessageBox(0, TranslateW(_T("You must set encryption algorythm first")), TranslateW(_T("Error")), MB_OK); break; } mir_free(tmp); @@ -1233,14 +1108,14 @@ static BOOL CALLBACK DlgProcKeyGenDialog(HWND hwndDlg, UINT msg, WPARAM wParam, mir_free(tmp); if(length < 1024 || length > 4096) { - MessageBox(0, TranslateT("Key length must be of length from 1024 to 4096 bits"), TranslateT("Error"), MB_OK); + MessageBox(0, TranslateW(_T("Key length must be of length from 1024 to 4096 bits")), TranslateW(_T("Error")), MB_OK); break; } tmp = new TCHAR [12]; GetDlgItemText(hwndDlg, IDC_KEY_EXPIRE_DATE, tmp, 12); if(_tcslen(tmp) != 10 && tmp[0] != '0') { - MessageBox(0, TranslateT("Invalid date"), TranslateT("Error"), MB_OK); + MessageBox(0, TranslateW(_T("Invalid date")), TranslateW(_T("Error")), MB_OK); delete [] tmp; break; } @@ -1249,13 +1124,13 @@ static BOOL CALLBACK DlgProcKeyGenDialog(HWND hwndDlg, UINT msg, WPARAM wParam, GetDlgItemText(hwndDlg, IDC_KEY_REAL_NAME, tmp, 128); if(_tcslen(tmp) < 5) { - MessageBox(0, TranslateT("Name must contain at least 5 characters"), TranslateT("Error"), MB_OK); + MessageBox(0, TranslateW(_T("Name must contain at least 5 characters")), TranslateW(_T("Error")), MB_OK); delete [] tmp; break; } else if (_tcschr(tmp, _T('(')) || _tcschr(tmp, _T(')'))) { - MessageBox(0, TranslateT("Name cannot contain '(' or ')'"), TranslateT("Error"), MB_OK); + MessageBox(0, TranslateW(_T("Name cannot contain '(' or ')'")), TranslateW(_T("Error")), MB_OK); delete [] tmp; break; } @@ -1264,7 +1139,7 @@ static BOOL CALLBACK DlgProcKeyGenDialog(HWND hwndDlg, UINT msg, WPARAM wParam, GetDlgItemText(hwndDlg, IDC_KEY_EMAIL, tmp, 128); if((_tcslen(tmp)) < 5 || (!_tcschr(tmp, _T('@'))) || (!_tcschr(tmp, _T('.')))) { - MessageBox(0, TranslateT("Invalid Email"), TranslateT("Error"), MB_OK); + MessageBox(0, TranslateW(_T("Invalid Email")), TranslateW(_T("Error")), MB_OK); delete [] tmp; break; } @@ -1280,7 +1155,7 @@ static BOOL CALLBACK DlgProcKeyGenDialog(HWND hwndDlg, UINT msg, WPARAM wParam, wfstream f(path.c_str(), std::ios::out); if(!f.is_open()) { - MessageBox(0, TranslateT("Failed to open file"), TranslateT("Error"), MB_OK); + MessageBox(0, TranslateW(_T("Failed to open file")), TranslateW(_T("Error")), MB_OK); break; } f<<"Key-Type: "; @@ -1372,16 +1247,6 @@ static BOOL CALLBACK DlgProcKeyGenDialog(HWND hwndDlg, UINT msg, WPARAM wParam, params.out = &out; params.code = &code; params.result = &result; - SetWindowTextA(GetDlgItem(hwndDlg, IDC_GENERATING_TEXT), Translate("Generating new key, please wait...")); - EnableWindow(GetDlgItem(hwndDlg, IDCANCEL), 0); - EnableWindow(GetDlgItem(hwndDlg, IDOK), 0); - EnableWindow(GetDlgItem(hwndDlg, IDC_KEY_TYPE), 0); - EnableWindow(GetDlgItem(hwndDlg, IDC_KEY_LENGTH), 0); - EnableWindow(GetDlgItem(hwndDlg, IDC_KEY_PASSWD), 0); - EnableWindow(GetDlgItem(hwndDlg, IDC_KEY_REAL_NAME), 0); - EnableWindow(GetDlgItem(hwndDlg, IDC_KEY_EMAIL), 0); - EnableWindow(GetDlgItem(hwndDlg, IDC_KEY_COMMENT), 0); - EnableWindow(GetDlgItem(hwndDlg, IDC_KEY_EXPIRE_DATE), 0); boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); if(!gpg_thread.timed_join(boost::posix_time::minutes(10))) { @@ -1702,25 +1567,10 @@ static BOOL CALLBACK DlgProcLoadExistingKey(HWND hwndDlg,UINT msg,WPARAM wParam, { out.erase(s, 1); } - std::string::size_type p1 = 0, p2 = 0; - p1 = out.find("-----BEGIN PGP PUBLIC KEY BLOCK-----"); - if(p1 != std::string::npos) - { - p2 = out.find("-----END PGP PUBLIC KEY BLOCK-----", p1); - if(p2 != std::string::npos) - { - p2 += strlen("-----END PGP PUBLIC KEY BLOCK-----"); - out = out.substr(p1, p2-p1); - TCHAR *tmp = mir_a2t(out.c_str()); - SetWindowText(hPubKeyEdit, tmp); - mir_free(tmp); - } - else - MessageBox(NULL, TranslateT("Failed to export public key."), TranslateT("Error"), MB_OK); - } - else - MessageBox(NULL, TranslateT("Failed to export public key."), TranslateT("Error"), MB_OK); + TCHAR *tmp = mir_a2t(out.c_str()); // SetDlgItemText(hPubKeyEdit, IDC_PUBLIC_KEY_EDIT, tmp); + SetWindowText(hPubKeyEdit, tmp); + mir_free(tmp); } DestroyWindow(hwndDlg); break; @@ -1772,13 +1622,12 @@ static BOOL CALLBACK DlgProcImportKeyDialog(HWND hwndDlg, UINT msg, WPARAM wPara { extern HANDLE new_key_hcnt; extern boost::mutex new_key_hcnt_mutex; - HANDLE hContact = INVALID_HANDLE_VALUE; + HANDLE hContact = new_key_hcnt; + new_key_hcnt_mutex.unlock(); switch (msg) { case WM_INITDIALOG: { - hContact = new_key_hcnt; - new_key_hcnt_mutex.unlock(); SetWindowPos(hwndDlg, 0 , import_key_rect.left, import_key_rect.top, 0, 0, SWP_NOSIZE|SWP_SHOWWINDOW); TranslateDialogDefault(hwndDlg); ComboBoxAddStringUtf(GetDlgItem(hwndDlg, IDC_KEYSERVER), _T("subkeys.pgp.net"), 0); @@ -1920,49 +1769,9 @@ void FirstRun() void InitCheck() { {//parse gpg output - gpg_valid = isGPGValid(); - bool home_dir_access = false, temp_access = false; - TCHAR *home_dir = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); - std::wstring test_path = home_dir; - mir_free(home_dir); - test_path += _T("/"); - test_path += toUTF16(get_random(13)); - wfstream test_file; - test_file.open(test_path, std::ios::trunc | std::ios::out); - if(test_file.is_open() && test_file.good()) - { - test_file<<_T("access_test\n"); - if(test_file.good()) - home_dir_access = true; - test_file.close(); - DeleteFile(test_path.c_str()); - } - home_dir = _tgetenv(_T("TEMP")); - test_path = home_dir; - test_path += _T("/"); - test_path += toUTF16(get_random(13)); - test_file.open(test_path, std::ios::trunc | std::ios::out); - if(test_file.is_open() && test_file.good()) - { - test_file<<_T("access_test\n"); - if(test_file.good()) - temp_access = true; - test_file.close(); - DeleteFile(test_path.c_str()); - } - 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).")); - if(!gpg_valid) - strcat(buf, Translate("\nGPG will be disabled until you solve this problems")); - MessageBoxA(0, buf, Translate("GPG plugin problems"), MB_OK); - } - if(!gpg_valid) + gpg_configured = isGPGConfigured(); + if(!gpg_configured) return; - gpg_keyexist = isGPGKeyExist(); string out; DWORD code; pxResult result; @@ -1987,30 +1796,20 @@ void InitCheck() if(result == pxNotFound) return; } - home_dir = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); + TCHAR *home_dir = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); wstring tmp_dir = home_dir; mir_free(home_dir); tmp_dir += _T("\\tmp"); _wmkdir(tmp_dir.c_str()); - string question = Translate("Your secret key whith id: "); + string question = "Your secret key whith id: "; char *keyid = UniGetContactSettingUtf(NULL, szGPGModuleName, "KeyID", ""); - char *key = UniGetContactSettingUtf(NULL, szGPGModuleName, "GPGPubKey", ""); + question += keyid; + mir_free(keyid); + question += " deleted from gpg secret keyring\nDo you want to set another key ?"; void ShowFirstRunDialog(); - if(!DBGetContactSettingByte(NULL, szGPGModuleName, "FirstRun", 1) && (!keyid[0] || !key[0])) - { - question = Translate("You have not set public key for gpg, it's recommended to do it.\nDo you want to do it now ?"); - if(MessageBoxA(0, question.c_str(), Translate("Own public key warning"), MB_YESNO) == IDYES) - ShowFirstRunDialog(); - } if(out.find(keyid) == string::npos) - { - question += keyid; - 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) + if(MessageBoxA(0, question.c_str(), "Own secret key warning", MB_YESNO) == IDYES) ShowFirstRunDialog(); - } - mir_free(keyid); - mir_free(key); } { TCHAR *path = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); @@ -2043,7 +1842,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, _T("Do you want load key for all subcontacts ?"), _T("Metacontact detected"), MB_YESNO) == IDYES) for_all_sub = true; if(metaIsProtoMetaContacts(hContact)) { |