summaryrefslogtreecommitdiff
path: root/utilities.cpp
diff options
context:
space:
mode:
authorGluzskiy Alexandr <sss@sss.chaoslab.ru>2012-05-18 22:28:05 +0300
committerGluzskiy Alexandr <sss@sss.chaoslab.ru>2012-05-18 22:28:05 +0300
commit365d949d8ec2712fbdec479e73e78cbbe80b3399 (patch)
tree8b3fdf275d6ec5cc92d0ecedbe57cf9cc9617be7 /utilities.cpp
parent570935ac486f2e1f5d36ecd07216e1474603c8ce (diff)
fixed (#33 Settings)
Diffstat (limited to 'utilities.cpp')
-rwxr-xr-xutilities.cpp70
1 files changed, 69 insertions, 1 deletions
diff --git a/utilities.cpp b/utilities.cpp
index f6a0290..0648c37 100755
--- a/utilities.cpp
+++ b/utilities.cpp
@@ -1033,7 +1033,7 @@ bool isContactHaveKey(HANDLE hContact)
return false;
}
-bool isGPGConfigured()
+bool isGPGKeyExist()
{
TCHAR *id = UniGetContactSettingUtf(NULL, szGPGModuleName, "KeyID", _T(""));
char *key = UniGetContactSettingUtf(NULL, szGPGModuleName, "GPGPubKey", "");
@@ -1047,6 +1047,74 @@ bool isGPGConfigured()
mir_free(key);
return false;
}
+bool isGPGValid()
+{
+ TCHAR *tmp;
+ bool gpg_exists = false, is_valid = true;
+ tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szGpgBinPath", _T(""));
+ if(_waccess(tmp, 0) != -1)
+ gpg_exists = true;
+ else
+ {
+ mir_free(tmp);
+ TCHAR *path = new TCHAR [MAX_PATH];
+ char *mir_path = new char [MAX_PATH];
+ CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)"\\", (LPARAM)mir_path);
+ SetCurrentDirectoryA(mir_path);
+ tmp = mir_a2t(mir_path);
+ mir_free(mir_path);
+ mir_realloc(path, (_tcslen(path)+128)*sizeof(TCHAR));
+ TCHAR *gpg_path = new TCHAR [MAX_PATH];
+ _tcscpy(gpg_path, tmp);
+ _tcscat(gpg_path, _T("\\GnuPG\\gpg.exe"));
+ mir_free(tmp);
+ if(_waccess(gpg_path, 0) != -1)
+ {
+ gpg_exists = true;
+ _tcscpy(path, _T("GnuPG\\gpg.exe"));
+ }
+ mir_free(gpg_path);
+ tmp = mir_wstrdup(path);
+ delete [] path;
+ }
+ DWORD len = MAX_PATH;
+ if(gpg_exists)
+ {
+ 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_valid = true;
+ 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;
+ debuglog<<time_str()<<": GPG execution timed out, aborted\n";
+ }
+ gpg_valid = false;
+ string::size_type p1 = out.find("(GnuPG) ");
+ if(p1 == string::npos)
+ is_valid = false;
+ }
+ mir_free(tmp);
+ if(!gpg_exists)
+ {
+ wstring path_ = _wgetenv(_T("APPDATA"));
+ path_ += _T("\\GnuPG");
+ tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", (TCHAR*)path_.c_str());
+ }
+ mir_free(tmp);
+ return is_valid;
+}
#define NEWTSTR_MALLOC(A) (A==NULL)?NULL:strcpy((char*)mir_alloc(sizeof(char)*(strlen(A)+1)),A)