diff options
author | Alexander Gluzsky <sss123next@list.ru> | 2013-02-05 01:51:10 +0000 |
---|---|---|
committer | Alexander Gluzsky <sss123next@list.ru> | 2013-02-05 01:51:10 +0000 |
commit | bd8802ef0df758ca788bbed4851bb51478b28047 (patch) | |
tree | 3c354c62ffa937427c9e719e209c2714ac175421 /plugins/New_GPG/src | |
parent | 8770cf2fdfd72c89260edfa924452e8ca7237d93 (diff) |
fixed temporary files cleanup during runtime
added temporary files cleanup on start and exit
"boosted" code instead of winapi in some places
//TODO: "boosted" process management (it will provide more convenient way to control process and work with pipes, it also should be faster because currently loops with sleep interval used)
git-svn-id: http://svn.miranda-ng.org/main/trunk@3428 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/New_GPG/src')
-rwxr-xr-x | plugins/New_GPG/src/commonheaders.h | 1 | ||||
-rwxr-xr-x | plugins/New_GPG/src/gpg_wrapper.cpp | 30 | ||||
-rwxr-xr-x | plugins/New_GPG/src/init.cpp | 4 | ||||
-rwxr-xr-x | plugins/New_GPG/src/main.cpp | 41 | ||||
-rwxr-xr-x | plugins/New_GPG/src/messages.cpp | 77 | ||||
-rwxr-xr-x | plugins/New_GPG/src/options.cpp | 6 | ||||
-rwxr-xr-x | plugins/New_GPG/src/utilities.cpp | 101 | ||||
-rwxr-xr-x | plugins/New_GPG/src/utilities.h | 1 |
8 files changed, 132 insertions, 129 deletions
diff --git a/plugins/New_GPG/src/commonheaders.h b/plugins/New_GPG/src/commonheaders.h index e788db4375..6476f127cf 100755 --- a/plugins/New_GPG/src/commonheaders.h +++ b/plugins/New_GPG/src/commonheaders.h @@ -45,6 +45,7 @@ using std::wstring; using std::wfstream; using std::fstream; + //boost #include <boost/thread/thread.hpp> #include <boost/thread/mutex.hpp> diff --git a/plugins/New_GPG/src/gpg_wrapper.cpp b/plugins/New_GPG/src/gpg_wrapper.cpp index adce958b50..e110f74c73 100755 --- a/plugins/New_GPG/src/gpg_wrapper.cpp +++ b/plugins/New_GPG/src/gpg_wrapper.cpp @@ -75,16 +75,13 @@ pxResult pxExecute(wstring *acommandline, char *ainput, string *aoutput, LPDWORD TCHAR *bin_path = UniGetContactSettingUtf(NULL, szGPGModuleName, "szGpgBinPath", _T("")); { - if(_waccess(bin_path, 0) == -1) + if(!boost::filesystem::exists(bin_path)) { - if(errno == ENOENT) - { - mir_free(bin_path); - if(bDebugLog) - debuglog<<std::string(time_str()+": GPG executable not found"); - *result = pxNotFound; - return pxNotFound; - } + mir_free(bin_path); + if(bDebugLog) + debuglog<<std::string(time_str()+": GPG executable not found"); + *result = pxNotFound; + return pxNotFound; } } TCHAR *home_dir = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); @@ -185,16 +182,13 @@ pxResult pxExecute_passwd_change(std::vector<std::wstring> &aargv, char *ainput, TCHAR *bin_path = UniGetContactSettingUtf(NULL, szGPGModuleName, "szGpgBinPath", _T("")); { - if(_waccess(bin_path, 0) == -1) + if(!boost::filesystem::exists(bin_path)) { - if(errno == ENOENT) - { - mir_free(bin_path); - if(bDebugLog) - debuglog<<std::string(time_str()+": GPG executable not found"); - *result = pxNotFound; - return pxNotFound; - } + mir_free(bin_path); + if(bDebugLog) + debuglog<<std::string(time_str()+": GPG executable not found"); + *result = pxNotFound; + return pxNotFound; } } diff --git a/plugins/New_GPG/src/init.cpp b/plugins/New_GPG/src/init.cpp index 3b6c662032..de1f3144f9 100755 --- a/plugins/New_GPG/src/init.cpp +++ b/plugins/New_GPG/src/init.cpp @@ -178,6 +178,7 @@ static int OnModulesLoaded(WPARAM wParam,LPARAM lParam) CreateProtoServiceFunction(szGPGModuleName, PSS_FILE, (MIRANDASERVICE)onSendFile);
CreateProtoServiceFunction(szGPGModuleName, PSS_FILE"W", (MIRANDASERVICE)onSendFile);
+ clean_temp_dir();
return 0;
}
@@ -250,7 +251,7 @@ extern "C" int __declspec(dllexport) Unload(void) {
for(list<wstring>::iterator p = transfers.begin(); p != transfers.end(); p++)
if(!(*p).empty())
- DeleteFile((*p).c_str());
+ boost::filesystem::remove((*p));
}
mir_free(inopentag);
mir_free(inclosetag);
@@ -258,5 +259,6 @@ extern "C" int __declspec(dllexport) Unload(void) mir_free(outclosetag);
if(password)
mir_free(password);
+ clean_temp_dir();
return 0;
}
diff --git a/plugins/New_GPG/src/main.cpp b/plugins/New_GPG/src/main.cpp index 5b6acd5a3e..17822d3668 100755 --- a/plugins/New_GPG/src/main.cpp +++ b/plugins/New_GPG/src/main.cpp @@ -626,7 +626,7 @@ static INT_PTR CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR if(result == pxNotFound)
break;
- DeleteFile(path.c_str());
+ boost::filesystem::remove(path);
string::size_type p1 = 0;
if((p1 = out.find("key ")) != string::npos)
path = toUTF16(out.substr(p1+4, 8));
@@ -922,12 +922,12 @@ static INT_PTR CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, _tcscpy(gpg_lang_path, tmp);
_tcscat(gpg_lang_path, _T("\\GnuPG\\gnupg.nls\\en@quot.mo"));
mir_free(tmp);
- if(_waccess(gpg_path, 0) != -1)
+ if(boost::filesystem::exists(gpg_path))
{
gpg_exists = true;
_tcscpy(path, _T("GnuPG\\gpg.exe"));
}
- if(_waccess(gpg_lang_path, 0) != -1)
+ if(boost::filesystem::exists(gpg_lang_path))
lang_exists = true;
if(gpg_exists && !lang_exists)
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);
@@ -940,10 +940,9 @@ static INT_PTR CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, 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(_waccess(tmp, 0) == -1)
+ if(!boost::filesystem::exists(tmp))
{
- if(errno == ENOENT)
- MessageBox(0, TranslateT("wrong gpg binary location found in system.\nplease choose another location"), TranslateT("Warning"), MB_OK);
+ MessageBox(0, TranslateT("wrong gpg binary location found in system.\nplease choose another location"), TranslateT("Warning"), MB_OK);
}
/* char *mir_path = (char*)mir_alloc(MAX_PATH);
CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)"\\", (LPARAM)mir_path);
@@ -1079,13 +1078,10 @@ static INT_PTR CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)"\\", (LPARAM)mir_path);
SetCurrentDirectoryA(mir_path);
delete [] mir_path;
- if(_waccess(tmp, 0) == -1)
+ if(!boost::filesystem::exists(tmp))
{
- if(errno == ENOENT)
- {
- MessageBox(0, TranslateT("gpg binary does not exists.\nplease choose another location"), TranslateT("Warning"), MB_OK);
- break;
- }
+ MessageBox(0, TranslateT("gpg binary does not exists.\nplease choose another location"), TranslateT("Warning"), MB_OK);
+ break;
}
}
else
@@ -1169,13 +1165,10 @@ static INT_PTR CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)"\\", (LPARAM)mir_path);
SetCurrentDirectoryA(mir_path);
delete [] mir_path;
- if(_waccess(tmp, 0) == -1)
+ if(!boost::filesystem::exists(tmp))
{
- if(errno == ENOENT)
- {
- MessageBox(0, TranslateT("gpg binary does not exists.\nplease choose another location"), TranslateT("Warning"), MB_OK);
- break;
- }
+ MessageBox(0, TranslateT("gpg binary does not exists.\nplease choose another location"), TranslateT("Warning"), MB_OK);
+ break;
}
}
else
@@ -1304,7 +1297,7 @@ static INT_PTR CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, gpg_valid = false;
if(result == pxNotFound)
break;
- DeleteFile(path.c_str());
+ boost::filesystem::remove(path);
string::size_type p1 = 0;
if((p1 = out.find("key ")) != string::npos)
path = toUTF16(out.substr(p1+4, 8));
@@ -1673,7 +1666,7 @@ static INT_PTR CALLBACK DlgProcKeyGenDialog(HWND hwndDlg, UINT msg, WPARAM wPara if(result == pxNotFound)
break;
}
- DeleteFile(path.c_str());
+ boost::filesystem::remove(path);
DestroyWindow(hwndDlg);
{//parse gpg output
LVITEM item = {0};
@@ -2218,7 +2211,7 @@ void InitCheck() if(test_file.good())
home_dir_access = true;
test_file.close();
- DeleteFile(test_path.c_str());
+ boost::filesystem::remove(test_path);
}
home_dir = _tgetenv(_T("TEMP"));
test_path = home_dir;
@@ -2231,7 +2224,7 @@ void InitCheck() if(test_file.good())
temp_access = true;
test_file.close();
- DeleteFile(test_path.c_str());
+ boost::filesystem::remove(test_path);
}
if(!home_dir_access || !temp_access || !gpg_valid)
{
@@ -2513,7 +2506,7 @@ void ImportKey() mir_free(ptmp);
_tcscat(tmp2, _T("\\"));
_tcscat(tmp2, _T("temporary_exported.asc"));
- DeleteFile(tmp2);
+ boost::filesystem::remove(tmp2);
wfstream f(tmp2, std::ios::out);
if(metaIsProtoMetaContacts(hContact))
ptmp = UniGetContactSettingUtf(metaGetMostOnline(hContact), szGPGModuleName, "GPGPubKey", _T(""));
@@ -2772,6 +2765,6 @@ void ImportKey() ptmp = mir_wstrdup(toUTF16(output).c_str());
MessageBox(0, ptmp, _T(""), MB_OK);
mir_free(ptmp);
- DeleteFile(tmp2);
+ boost::filesystem::remove(tmp2);
}
}
\ No newline at end of file diff --git a/plugins/New_GPG/src/messages.cpp b/plugins/New_GPG/src/messages.cpp index d3525d2a3f..c4afd1fc48 100755 --- a/plugins/New_GPG/src/messages.cpp +++ b/plugins/New_GPG/src/messages.cpp @@ -86,7 +86,7 @@ void RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, wstring decfile = toUTF16(get_random(10)); path.append(_T("\\tmp\\")); path.append(encfile); - DeleteFile(path.c_str()); + boost::filesystem::remove(path); fstream f(path.c_str(), std::ios::out); while(!f.is_open()) f.open(path.c_str(), std::ios::out); @@ -140,7 +140,7 @@ void RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, wstring path = tmp2; path += _T("\\tmp\\"); path += decfile; - DeleteFile(path.c_str()); + boost::filesystem::remove(path); } cmd += _T("--output \""); cmd += tmp2; @@ -165,7 +165,7 @@ void RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, params.hProcess = NULL; if(bDebugLog) debuglog<<std::string(time_str()+": GPG execution timed out, aborted"); - DeleteFile(path.c_str()); + boost::filesystem::remove(path); HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags)); BYTE enc = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0); DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0); @@ -176,13 +176,13 @@ void RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, } if(result == pxNotFound) { - DeleteFile(path.c_str()); + boost::filesystem::remove(path); HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags)); return; } if(result == pxSuccessExitCodeInvalid) { - DeleteFile(path.c_str()); + boost::filesystem::remove(path); HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags)); HistoryLog(hContact, db_event(Translate("failed to decrypt message, GPG returned error, turn on debug log for more details"), timestamp, 0, 0)); return; @@ -240,7 +240,7 @@ void RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, params.hProcess = NULL; if(bDebugLog) debuglog<<std::string(time_str()+": GPG execution timed out, aborted"); - DeleteFile(path.c_str()); + boost::filesystem::remove(path); HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags)); BYTE enc = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0); DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0); @@ -251,7 +251,7 @@ void RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, } if(result == pxNotFound) { - DeleteFile(path.c_str()); + boost::filesystem::remove(path); HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags)); return; } @@ -265,7 +265,7 @@ void RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, params.hProcess = NULL; if(bDebugLog) debuglog<<std::string(time_str()+": GPG execution timed out, aborted"); - DeleteFile(path.c_str()); + boost::filesystem::remove(path); HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags)); BYTE enc = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0); DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0); @@ -276,38 +276,35 @@ void RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, } if(result == pxNotFound) { - DeleteFile(path.c_str()); + boost::filesystem::remove(path); HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags)); } { wstring tmp = tmp2; tmp += _T("\\tmp\\"); tmp += encfile; - DeleteFile(tmp.c_str()); + boost::filesystem::remove(tmp); } { wstring tmp = tmp2; tmp += _T("\\tmp\\"); tmp += decfile; - if(_waccess(tmp.c_str(), 0) == -1) + if(!boost::filesystem::exists(tmp)) { - if(errno == ENOENT) - { - string str = msg; - str.insert(0, "Received unencrypted message:\n"); - if(bDebugLog) - debuglog<<std::string(time_str()+": info: Failed to decrypt GPG encrypted message."); - char *tmp = new char [str.length()+1]; - strcpy(tmp, str.c_str()); - HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags)); - BYTE enc = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0); - DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0); - CallContactService(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)"Unable to decrypt PGP encrypted message"); - HistoryLog(hContact, db_event("Error message sent", 0, 0, DBEF_SENT)); - DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", enc); - mir_free(tmp); - return; - } + string str = msg; + str.insert(0, "Received unencrypted message:\n"); + if(bDebugLog) + debuglog<<std::string(time_str()+": info: Failed to decrypt GPG encrypted message."); + char *tmp = new char [str.length()+1]; + strcpy(tmp, str.c_str()); + HistoryLog(hContact, db_event(msg, timestamp, 0, dbflags)); + BYTE enc = DBGetContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0); + DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 0); + CallContactService(hContact, PSS_MESSAGE, (WPARAM)PREF_UTF, (LPARAM)"Unable to decrypt PGP encrypted message"); + HistoryLog(hContact, db_event("Error message sent", 0, 0, DBEF_SENT)); + DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", enc); + mir_free(tmp); + return; } } str.clear(); @@ -328,7 +325,7 @@ void RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, str.append(toUTF16(tmp)); delete [] tmp; f.close(); - DeleteFile(path.c_str()); + boost::filesystem::remove(path); } if(str.empty()) { @@ -439,7 +436,7 @@ int RecvMsgSvc(WPARAM w, LPARAM l) _tcscat(tmp2, _T(".asc")); mir_free(tmp3); //_tcscat(tmp2, _T("temporary_exported.asc")); - DeleteFile(tmp2); + boost::filesystem::remove(tmp2); wfstream f(tmp2, std::ios::out); while(!f.is_open()) f.open(tmp2, std::ios::out); @@ -470,7 +467,7 @@ int RecvMsgSvc(WPARAM w, LPARAM l) debuglog<<std::string(time_str()+": GPG execution timed out, aborted"); return 1; } - DeleteFile(tmp2); + boost::filesystem::remove(tmp2); if(result == pxNotFound) return 1; if(result == pxSuccessExitCodeInvalid) @@ -652,12 +649,11 @@ int RecvMsgSvc(WPARAM w, LPARAM l) void SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) { - wstring str; bool isansi = false; DWORD dbflags = 0; if((flags & PREF_UTF) == PREF_UTF) dbflags |= DBEF_UTF; - str = toUTF16(msg); + wstring str = toUTF16(msg); if(bStripTags && bAppendTags) { if(bDebugLog) @@ -668,9 +664,7 @@ void SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) str.replace(i, 2, _T("\n")); */ string out; DWORD code; - wstring cmd; - wstring file = toUTF16(get_random(10)); - wstring path; + wstring file = toUTF16(get_random(10)), path, cmd; extern bool bJabberAPI, bIsMiranda09; char *tmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyID", ""); if(!tmp[0]) @@ -693,12 +687,12 @@ void SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) mir_free(tmp2); cmd += _T(" \""); tmp2 = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); - path.append(tmp2); + path = tmp2; cmd += tmp2; mir_free(tmp2); cmd += _T("\\tmp\\"); cmd += file; - path.append(_T("\\tmp\\")); + path += L"\\tmp\\"; path += file; cmd += _T("\""); { @@ -781,7 +775,7 @@ void SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) { mir_free(msg); HistoryLog(hContact, db_event(Translate("failed o encrypt message, GPG returned error, turn on debug log for more details"), 0,0, DBEF_SENT)); - DeleteFile(path.c_str()); + boost::filesystem::remove(path); return; } if(out.find("usage: ") != string::npos) @@ -789,9 +783,10 @@ void SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) MessageBox(0, TranslateT("Something wrong, gpg does not understand us, aborting encryption."), TranslateT("Warning"), MB_OK); mir_free(msg); CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg); - DeleteFile(path.c_str()); + boost::filesystem::remove(path); return; } + boost::filesystem::remove(path); path.append(_T(".asc")); wfstream f(path.c_str(), std::ios::in | std::ios::ate | std::ios::binary); while(!f.is_open()) @@ -810,7 +805,7 @@ void SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) str.append(tmp); delete [] tmp; f.close(); - DeleteFile(path.c_str()); + boost::filesystem::remove(path); } if(str.empty()) { diff --git a/plugins/New_GPG/src/options.cpp b/plugins/New_GPG/src/options.cpp index 230749623c..ddc6323479 100755 --- a/plugins/New_GPG/src/options.cpp +++ b/plugins/New_GPG/src/options.cpp @@ -985,7 +985,7 @@ static INT_PTR CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam mir_free(ptmp); _tcscat(tmp2, _T("\\")); _tcscat(tmp2, _T("temporary_exported.asc")); - DeleteFile(tmp2); + boost::filesystem::remove(tmp2); wfstream f(tmp2, std::ios::out); ptmp = UniGetContactSettingUtf(hcnt, szGPGModuleName, "GPGPubKey", _T("")); wstring str = ptmp; @@ -1049,7 +1049,7 @@ static INT_PTR CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam if(output.find("already in secret keyring") != string::npos) { MessageBox(0, TranslateT("Key already in scret key ring."), TranslateT("Info"), MB_OK); - DeleteFile(tmp2); + boost::filesystem::remove(tmp2); break; } char *tmp2; @@ -1280,7 +1280,7 @@ static INT_PTR CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam tmp = mir_wstrdup(toUTF16(output).c_str()); MessageBox(0, tmp, _T(""), MB_OK); mir_free(tmp); - DeleteFile(tmp2); + boost::filesystem::remove(tmp2); } key_buf.clear(); if(IsDlgButtonChecked(hwndDlg, IDC_ENABLE_ENCRYPTION)) diff --git a/plugins/New_GPG/src/utilities.cpp b/plugins/New_GPG/src/utilities.cpp index 0a43cc4cc7..49df88a301 100755 --- a/plugins/New_GPG/src/utilities.cpp +++ b/plugins/New_GPG/src/utilities.cpp @@ -325,11 +325,8 @@ int onProtoAck(WPARAM w, LPARAM l) if(file_msg_state < 1)
return 0;
HistoryLog(ack->hContact, db_event("Recieved encrypted file, trying to decrypt", 0,0, 0));
- if(_waccess(f->tszCurrentFile, 0) == -1)
- {
- if(errno == ENOENT)
- return 0;
- }
+ if(!boost::filesystem::exists(f->tszCurrentFile))
+ return 0;
string out;
DWORD code;
pxResult result;
@@ -337,12 +334,12 @@ int onProtoAck(WPARAM w, LPARAM l) wstring file = filename;
wstring::size_type p1 = file.rfind(_T(".gpg"));
file.erase(p1, _tcslen(_T(".gpg")));
- if(_waccess(file.c_str(), 0) != -1)
+ if(boost::filesystem::exists(file))
{
if(MessageBox(0, TranslateT("Target file exists, do you want to replace it ?"), TranslateT("Warning"), MB_YESNO) == IDNO)
return 0;
}
- DeleteFile(file.c_str());
+ boost::filesystem::remove(file);
file.insert(0, _T("\""));
file.insert(file.length(), _T("\" "));
cmd += file;
@@ -452,17 +449,17 @@ int onProtoAck(WPARAM w, LPARAM l) params.hProcess = NULL;
if(bDebugLog)
debuglog<<std::string(time_str()+": GPG execution timed out, aborted");
- //DeleteFile(filename);
+ //boost::filesystem::remove(filename);
return 0;
}
if(result == pxNotFound)
{
- //DeleteFile(filename);
+ //boost::filesystem::remove(filename);
return 0;
}
}
if(result == pxSuccess)
- DeleteFile(filename);
+ boost::filesystem::remove(filename);
mir_free(filename);
}
}
@@ -524,7 +521,7 @@ std::wstring encrypt_file(HANDLE hContact, TCHAR *filename) wstring path_out = temp;
path_out += _T("\\");
path_out += file_out;
- DeleteFile(path_out.c_str());
+ boost::filesystem::remove(path_out);
cmd += _T("\" ");
cmd += _T(" -e \"");
cmd += filename;
@@ -642,9 +639,8 @@ int onSendFile(WPARAM w, LPARAM l) TCHAR **file=(TCHAR **)ccs->lParam;
for(i = 0; file[i]; i++)
{
- if(_waccess(file[i], 0) == -1)
- if(errno == ENOENT)
- return 0; //we do not want to send file unencrypted (sometimes ack have wrong info)
+ if(!boost::filesystem::exists(file[i]))
+ return 0; //we do not want to send file unencrypted (sometimes ack have wrong info)
if (_tcsstr(file[i],_T(".gpg")))
continue;
std::wstring path_out = encrypt_file(ccs->hContact, file[i]);
@@ -658,9 +654,8 @@ int onSendFile(WPARAM w, LPARAM l) char **file = (char**) ccs->lParam;
for(i = 0; file[i]; i++)
{
- if(_access(file[i], 0) == -1)
- if(errno == ENOENT)
- return 0; //we do not want to send file unencrypted (sometimes ack have wrong info)
+ if(!boost::filesystem::exists(file[i]))
+ return 0; //we do not want to send file unencrypted (sometimes ack have wrong info)
if (strstr(file[i],".gpg"))
continue;
TCHAR *tmp = mir_utf8decodeT(file[i]);
@@ -823,18 +818,15 @@ static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, HXML node, void *pU mir_free(path_c);
path_out += _T("\\tmp\\");
path_out += file;
- DeleteFile(path_out.c_str());
+ boost::filesystem::remove(path_out);
wfstream f(path_out.c_str(), std::ios::out);
f<<toUTF8(str).c_str();
f.close();
- if(_waccess(path_out.c_str(), 0) == -1)
+ if(!boost::filesystem::exists(path_out))
{
- if(errno == ENOENT)
- {
- if(bDebugLog)
- debuglog<<std::string(time_str()+": info: Failed to write prescense in file");
- return FALSE;
- }
+ if(bDebugLog)
+ debuglog<<std::string(time_str()+": info: Failed to write prescense in file");
+ return FALSE;
}
{
extern TCHAR *password;
@@ -915,7 +907,7 @@ static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, HXML node, void *pU if(bDebugLog)
debuglog<<std::string(time_str()+"GPG execution timed out, aborted");
}
- DeleteFile(path_out.c_str());
+ boost::filesystem::remove(path_out);
path_out += _T(".asc");
f.open(path_out.c_str(), std::ios::in | std::ios::ate | std::ios::binary);
wstring data;
@@ -929,7 +921,7 @@ static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, HXML node, void *pU data.append(tmp);
delete [] tmp;
f.close();
- DeleteFile(path_out.c_str());
+ boost::filesystem::remove(path_out);
}
if(data.empty())
{
@@ -1032,8 +1024,8 @@ static JABBER_HANDLER_FUNC PrescenseHandler(IJabberInterface *ji, HXML node, voi status_file_out += status_file;
status_file_out += L".status";
// sign_file_mutex.lock();
- DeleteFile(path_out.c_str());
- DeleteFile(status_file_out.c_str());
+ boost::filesystem::remove(path_out);
+ boost::filesystem::remove(status_file_out);
wfstream f(path_out.c_str(), std::ios::out);
while(!f.is_open())
f.open(path_out.c_str(), std::ios::out);
@@ -1044,15 +1036,12 @@ static JABBER_HANDLER_FUNC PrescenseHandler(IJabberInterface *ji, HXML node, voi f.open(status_file_out.c_str(), std::ios::out);
f<<toUTF8(status_str).c_str();
f.close();
- if(_waccess(path_out.c_str(), 0) == -1)
+ if(!boost::filesystem::exists(path_out))
{
- if(errno == ENOENT)
- {
// sign_file_mutex.unlock();
- if(bDebugLog)
- debuglog<<std::string(time_str()+": info: Failed to write sign in file");
- return FALSE;
- }
+ if(bDebugLog)
+ debuglog<<std::string(time_str()+": info: Failed to write sign in file");
+ return FALSE;
}
{ //gpg
string out;
@@ -1084,8 +1073,8 @@ static JABBER_HANDLER_FUNC PrescenseHandler(IJabberInterface *ji, HXML node, voi {
return FALSE;
}
- DeleteFile(path_out.c_str());
- DeleteFile(status_file_out.c_str());
+ boost::filesystem::remove(path_out);
+ boost::filesystem::remove(status_file_out);
if(out.find("key ID ") != string::npos)
{
//need to get hcontact here, i can get jid from hxml, and get handle from jid, maybe exists better way ?
@@ -1880,7 +1869,7 @@ INT_PTR ImportGpGKeys(WPARAM w, LPARAM l) mir_free(ptmp);
_tcscat(tmp2, _T("\\"));
_tcscat(tmp2, _T("temporary_exported.asc"));
- DeleteFile(tmp2);
+ boost::filesystem::remove(tmp2);
wfstream f(tmp2, std::ios::out);
f<<toUTF16(key).c_str();
f.close();
@@ -1914,7 +1903,7 @@ INT_PTR ImportGpGKeys(WPARAM w, LPARAM l) if(output.find("already in secret keyring") != string::npos)
{
MessageBox(0, TranslateT("Key already in scret key ring."), TranslateT("Info"), MB_OK);
- DeleteFile(tmp2);
+ boost::filesystem::remove(tmp2);
break;
}
char *tmp2;
@@ -1982,7 +1971,7 @@ INT_PTR ImportGpGKeys(WPARAM w, LPARAM l) DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 1);
DBWriteContactSettingTString(hContact, szGPGModuleName, "GPGPubKey", toUTF16(key).c_str());
}
- DeleteFile(tmp2);
+ boost::filesystem::remove(tmp2);
break;
}
}
@@ -2002,7 +1991,7 @@ INT_PTR ImportGpGKeys(WPARAM w, LPARAM l) mir_free(ptmp);
_tcscat(tmp2, _T("\\"));
_tcscat(tmp2, _T("temporary_exported.asc"));
- DeleteFile(tmp2);
+ boost::filesystem::remove(tmp2);
wfstream f(tmp2, std::ios::out);
f<<toUTF16(key).c_str();
f.close();
@@ -2325,3 +2314,31 @@ void ShowChangePasswdDlg() hwndPaaswdDlg = CreateDialog(hInst, MAKEINTRESOURCE(IDD_CHANGE_PASSWD), NULL, DlgProcChangePasswd);
SetForegroundWindow(hwndPaaswdDlg);
}
+
+
+void clean_temp_dir()
+{
+ using namespace boost::filesystem; + char *mir_path = new char [MAX_PATH]; + CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)"\\", (LPARAM)mir_path); + wstring path = toUTF16(mir_path); + SetCurrentDirectoryA(mir_path); + delete [] mir_path; + TCHAR *tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T(""));
+ path += tmp;
+ mir_free(tmp);
+ path += L"\\tmp";
+ if(exists(path) && is_directory(path))
+ {
+ boost::filesystem::path p(path);
+ for(directory_iterator i = directory_iterator(p), end = directory_iterator(); i != end; ++i)
+ {
+ if(boost::filesystem::is_regular_file(i->path()))
+ {
+ if((i->path().filename().generic_string().length() == 10 && (i->path().filename().generic_string().find(".") == std::string::npos)) ||
+ i->path().extension() == ".sig" || i->path().extension() == ".asc" || i->path().extension() == ".status")
+ boost::filesystem::remove(i->path());
+ }
+ }
+ }
+}
\ No newline at end of file diff --git a/plugins/New_GPG/src/utilities.h b/plugins/New_GPG/src/utilities.h index 508a241110..eaa7ef71b5 100755 --- a/plugins/New_GPG/src/utilities.h +++ b/plugins/New_GPG/src/utilities.h @@ -105,5 +105,6 @@ void fix_line_term(std::wstring &s); void strip_line_term(std::wstring &s);
void strip_line_term(std::string &s);
void strip_tags(std::wstring &s);
+void clean_temp_dir();
#endif
|