From bd8802ef0df758ca788bbed4851bb51478b28047 Mon Sep 17 00:00:00 2001 From: Alexander Gluzsky Date: Tue, 5 Feb 2013 01:51:10 +0000 Subject: 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 --- plugins/New_GPG/src/commonheaders.h | 1 + plugins/New_GPG/src/gpg_wrapper.cpp | 30 +++++------ plugins/New_GPG/src/init.cpp | 4 +- plugins/New_GPG/src/main.cpp | 41 ++++++--------- plugins/New_GPG/src/messages.cpp | 77 +++++++++++++-------------- plugins/New_GPG/src/options.cpp | 6 +-- plugins/New_GPG/src/utilities.cpp | 101 +++++++++++++++++++++--------------- 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 #include 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< &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<::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<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<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<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 -- cgit v1.2.3