summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.cpp107
1 files changed, 91 insertions, 16 deletions
diff --git a/main.cpp b/main.cpp
index c087b6b..c5ed2cf 100644
--- a/main.cpp
+++ b/main.cpp
@@ -418,21 +418,19 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP
{
char *mir_path = new char [MAX_PATH];
CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)"\\", (LPARAM)mir_path);
- TCHAR *path = mir_a2t(mir_path);
+ tmp = mir_a2t(mir_path);
mir_free(mir_path);
mir_realloc(path, (_tcslen(path)+128)*sizeof(TCHAR));
- TCHAR *gpg_path = NULL, *gpg_lang_path = NULL;
- gpg_path = mir_wstrdup(path);
- mir_realloc(gpg_path, (_tcslen(gpg_path)+_tcslen(_T("\\GnuPG\\gnupg.exe")) + 1)*sizeof(TCHAR));
- _tcscat(gpg_path, _T("\\GnuPG\\gnupg.exe"));
- gpg_lang_path = mir_wstrdup(path);
- mir_realloc(gpg_lang_path, (_tcslen(gpg_path)+_tcslen(_T("\\GnuPG\\gnupg.nls\\en@quot.mo")) + 1)*sizeof(TCHAR));
+ TCHAR *gpg_path = new TCHAR [MAX_PATH], *gpg_lang_path = new TCHAR [MAX_PATH];
+ _tcscpy(gpg_path, tmp);
+ _tcscat(gpg_path, _T("\\GnuPG\\gpg.exe"));
+ _tcscpy(gpg_lang_path, tmp);
_tcscat(gpg_lang_path, _T("\\GnuPG\\gnupg.nls\\en@quot.mo"));
- mir_free(path);
+ mir_free(tmp);
if(_waccess(gpg_path, 0) != -1)
{
gpg_exists = true;
- _tcscpy(path, _T("GnuPG\\gnupg.exe"));
+ _tcscpy(path, _T("GnuPG\\gpg.exe"));
}
if(_waccess(gpg_lang_path, 0) != -1)
lang_exists = true;
@@ -443,21 +441,60 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP
}
DWORD len = MAX_PATH;
if(!gpg_exists)
- tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szGpgBinPath", (SHGetValue(HKEY_CURRENT_USER, _T("Software\\GNU\\GnuPG"), _T("gpgProgram"), 0, path, &len) == ERROR_SUCCESS)?path:_T(""));
- else
- tmp = mir_wstrdup(path);
- if(tmp[0])
{
- if(_waccess(tmp, 0) == -1)
+ tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szGpgBinPath", (SHGetValue(HKEY_CURRENT_USER, _T("Software\\GNU\\GnuPG"), _T("gpgProgram"), 0, path, &len) == ERROR_SUCCESS)?path:_T(""));
+ if(tmp[0])
{
- if(errno == ENOENT)
+ if(_waccess(tmp, 0) == -1)
{
- MessageBox(0, _T("gpg binary location found in system, but it does not exists.\nplease choose another location"), _T("Warning"), MB_OK);
+ if(errno == ENOENT)
+ {
+ MessageBox(0, _T("wrong gpg binary location found in system.\nplease choose another location"), _T("Warning"), MB_OK);
+ }
}
}
}
+ else
+ tmp = mir_wstrdup(path);
delete [] path;
SetDlgItemText(hwndDlg, IDC_BIN_PATH, tmp);
+ bool bad_version = false;
+ if(gpg_exists && lang_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;
+ HANDLE gpg_thread = mir_forkthread(pxEexcute_thread, (void*)&params);
+ if(WaitForSingleObject(gpg_thread, 10000) == WAIT_TIMEOUT)
+ {
+ TerminateThread(gpg_thread, 0);
+ MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK);
+ }
+ if(result == pxNotFound)
+ {
+ MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK);
+ }
+ 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 = true;
+ 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);
+ }
mir_free(tmp);
if(!gpg_exists)
{
@@ -467,6 +504,8 @@ 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, _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);
return TRUE;
}
@@ -531,6 +570,42 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP
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;
+ HANDLE gpg_thread = mir_forkthread(pxEexcute_thread, (void*)&params);
+ if(WaitForSingleObject(gpg_thread, 10000) == WAIT_TIMEOUT)
+ {
+ TerminateThread(gpg_thread, 0);
+ MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK);
+ }
+ if(result == pxNotFound)
+ {
+ MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK);
+ }
+ 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 = true;
+ 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] == '\\')