diff options
author | Gluzskiy Alexandr <sss123next@list.ru> | 2010-08-30 23:06:15 +0300 |
---|---|---|
committer | Gluzskiy Alexandr <sss123next@list.ru> | 2010-08-30 23:06:15 +0300 |
commit | bef8e360e5e40ee4e8648a5c56b2fae3fefb1c0a (patch) | |
tree | 4db038ab8bc14390b24caeea75cfd48845bfc782 | |
parent | c0b213bd890aef062faadf1701df1959c9f73816 (diff) |
better logging
-rw-r--r-- | commonheaders.h | 1 | ||||
-rw-r--r-- | gpg_wrapper.cpp | 15 | ||||
-rw-r--r-- | init.cpp | 13 | ||||
-rw-r--r-- | log.cpp | 80 | ||||
-rw-r--r-- | log.h | 33 | ||||
-rw-r--r-- | main.h | 2 | ||||
-rw-r--r-- | new_gpg.vcproj | 9 | ||||
-rw-r--r-- | options.cpp | 22 |
8 files changed, 145 insertions, 30 deletions
diff --git a/commonheaders.h b/commonheaders.h index 67948c6..24fcb69 100644 --- a/commonheaders.h +++ b/commonheaders.h @@ -65,4 +65,5 @@ using std::fstream; #include "gpg_wrapper.h" #include "jabber_account.h" #include "metacontacts.h" +#include "log.h" #endif diff --git a/gpg_wrapper.cpp b/gpg_wrapper.cpp index 1a29440..fa8c8f7 100644 --- a/gpg_wrapper.cpp +++ b/gpg_wrapper.cpp @@ -21,8 +21,7 @@ pxResult pxExecute(wstring *acommandline, char *ainput, string *aoutput, LPDWORD aexitcode, pxResult *result) { - extern bool bDebugLog; - extern fstream debuglog; + extern logtofile debuglog; BOOL success; STARTUPINFO sinfo = {0}; SECURITY_ATTRIBUTES sattrs = {0}; @@ -87,12 +86,7 @@ pxResult pxExecute(wstring *acommandline, char *ainput, string *aoutput, LPDWORD mir_free(home_dir); } - if(bDebugLog) - { - char* tmp = mir_utf8encodeW(commandline.c_str()); - debuglog<<"in: "<<tmp<<"\n"; - mir_free(tmp); - } + debuglog<<"in: "<<commandline<<"\n"; TCHAR chNewEnv[128]; LPTSTR lpszCurrentVariable; @@ -132,10 +126,7 @@ pxResult pxExecute(wstring *acommandline, char *ainput, string *aoutput, LPDWORD storeOutput(readstdout,aoutput); - if(bDebugLog) - { - debuglog<<"out: "<<aoutput->c_str()<<"\n"; - } + debuglog<<"out: "<<aoutput->c_str()<<"\n"; WaitForSingleObject(pri.hProcess,INFINITE); @@ -31,7 +31,7 @@ extern char *date(); MM_INTERFACE mmi = {0}; UTF8_INTERFACE utfi = {0}; XML_API xi = {0}; -fstream debuglog; +logtofile debuglog; #define MIID_GPG { 0x4227c050, 0x8d97, 0x48d2, { 0x91, 0xec, 0x6a, 0x95, 0x2b, 0x3d, 0xab, 0x94 } } @@ -87,13 +87,8 @@ void init_vars() outopentag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szOutOpenTag", _T("<GPGenc>")); outclosetag = UniGetContactSettingUtf(NULL, szGPGModuleName, "szOutCloseTag", _T("</GPGenc>")); bDebugLog = DBGetContactSettingByte(NULL, szGPGModuleName, "bDebugLog", 0); - bJabberAPI = DBGetContactSettingByte(NULL, szGPGModuleName, "bJabberAPI", 1); - if(bDebugLog) - { - TCHAR *tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szLogFilePath", _T("C:\\gpglog.txt")); - debuglog.open(tmp, std::ios::app |std::ios::ate |std::ios::binary); -// mir_free(tmp); - } + debuglog.init(); + bJabberAPI = DBGetContactSettingByte(NULL, szGPGModuleName, "bJabberAPI", bIsMiranda09?1:0); } extern "C" int __declspec(dllexport) Load(PLUGINLINK *link) @@ -236,7 +231,5 @@ extern "C" int __declspec(dllexport) Unload(void) mir_free(outclosetag); if(password) delete [] password; - if(debuglog.is_open()) - debuglog.close(); return 0; } @@ -0,0 +1,80 @@ +// Copyright © 2010 sss +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#include "commonheaders.h" + +logtofile& logtofile::operator<<(TCHAR *buf) +{ + extern bool bDebugLog; + if(bDebugLog) + { + char *tmp = mir_utf8encodeW(buf); + log.open(path, std::ios::app |std::ios::ate |std::ios::binary); + log<<tmp; + log.close(); + mir_free(tmp); + } + return *this; +} +logtofile& logtofile::operator<<(char *buf) +{ + extern bool bDebugLog; + if(bDebugLog) + { + char *tmp = mir_utf8encode(buf); + log.open(path, std::ios::app |std::ios::ate |std::ios::binary); + log<<tmp; + log.close(); + mir_free(tmp); + } + return *this; +} +logtofile& logtofile::operator<<(string buf) +{ + extern bool bDebugLog; + if(bDebugLog) + { + char *tmp = mir_utf8encode(buf.c_str()); + log.open(path, std::ios::app |std::ios::ate |std::ios::binary); + log<<tmp; + log.close(); + mir_free(tmp); + } + return *this; +} +logtofile& logtofile::operator<<(wstring buf) +{ + extern bool bDebugLog; + if(bDebugLog) + { + char *tmp = mir_utf8encodeW(buf.c_str()); + log.open(path, std::ios::app |std::ios::ate |std::ios::binary); + log<<tmp; + log.close(); + mir_free(tmp); + } + return *this; +} +void logtofile::init() +{ + extern bool bDebugLog; + if(bDebugLog) + path = UniGetContactSettingUtf(NULL, szGPGModuleName, "szLogFilePath", _T("C:\\GPGdebug.log")); +} +logtofile::~logtofile() +{ + mir_free(path); +} @@ -0,0 +1,33 @@ +// Copyright © 2010 sss +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +#ifndef LOG_H +#define LOG_H + +class logtofile +{ +public: + logtofile& operator<<(TCHAR *buf); + logtofile& operator<<(char *buf); + logtofile& operator<<(string buf); + logtofile& operator<<(wstring buf); + void init(); + ~logtofile(); +private: + fstream log; + TCHAR *path; +}; + +#endif
\ No newline at end of file @@ -1,4 +1,4 @@ -// Copyright © 2010 sss, chaos.persei +// Copyright © 2010 sss // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License diff --git a/new_gpg.vcproj b/new_gpg.vcproj index d64753c..9cccfd6 100644 --- a/new_gpg.vcproj +++ b/new_gpg.vcproj @@ -184,6 +184,7 @@ SuppressStartupBanner="true"
AdditionalLibraryDirectories=""
GenerateDebugInformation="true"
+ ProgramDatabaseFile="./$(TargetName).pdb"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
ImportLibrary=".\Debug/testplug.lib"
@@ -730,6 +731,10 @@ </FileConfiguration>
</File>
<File
+ RelativePath=".\log.cpp"
+ >
+ </File>
+ <File
RelativePath=".\main.cpp"
>
<FileConfiguration
@@ -887,6 +892,10 @@ >
</File>
<File
+ RelativePath=".\log.h"
+ >
+ </File>
+ <File
RelativePath=".\main.h"
>
</File>
diff --git a/options.cpp b/options.cpp index fd762b5..766035e 100644 --- a/options.cpp +++ b/options.cpp @@ -101,31 +101,31 @@ static BOOL CALLBACK DlgProcGpgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA col.pszText = _T("Contact"); col.mask = LVCF_TEXT | LVCF_WIDTH; col.fmt = LVCFMT_LEFT; - col.cx = 100; + col.cx = 60; ListView_InsertColumn(hwndList, 0, &col); ZeroMemory(&col,sizeof(col)); col.pszText = _T("Key ID"); col.mask = LVCF_TEXT | LVCF_WIDTH; col.fmt = LVCFMT_LEFT; - col.cx = 30; + col.cx = 50; ListView_InsertColumn(hwndList, 1, &col); ZeroMemory(&col,sizeof(col)); col.pszText = _T("Name"); col.mask = LVCF_TEXT | LVCF_WIDTH; col.fmt = LVCFMT_LEFT; - col.cx = 30; + col.cx = 50; ListView_InsertColumn(hwndList, 2, &col); ZeroMemory(&col,sizeof(col)); col.pszText = _T("Email"); col.mask = LVCF_TEXT | LVCF_WIDTH; col.fmt = LVCFMT_LEFT; - col.cx = 30; + col.cx = 50; ListView_InsertColumn(hwndList, 3, &col); ZeroMemory(&col,sizeof(col)); col.pszText = _T("Protocol"); col.mask = LVCF_TEXT | LVCF_WIDTH; col.fmt = LVCFMT_LEFT; - col.cx = 30; + col.cx = 60; ListView_InsertColumn(hwndList, 4, &col); ListView_SetExtendedListViewStyleEx(hwndList, 0, LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT); int i = 1, iRow = 0; @@ -187,6 +187,8 @@ static BOOL CALLBACK DlgProcGpgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA switch (LOWORD(wParam)) { case IDC_DELETE_KEY_BUTTON: + void setClistIcon(HANDLE hContact); + void setSrmmIcon(HANDLE hContact); { //gpg execute block TCHAR tmp2[MAX_PATH] = {0}; TCHAR *ptmp; @@ -261,10 +263,10 @@ static BOOL CALLBACK DlgProcGpgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA if(MessageBox(0, _T("Do you want to remove key from entire metacontact (all subcontacts) ?"), _T("Metacontact detected"), MB_YESNO) == IDYES) { HANDLE hcnt = NULL; - int count = metaGetContactsNum(hContact); + int count = metaGetContactsNum(meta); for(int i = 0; i < count; i++) { - hcnt = metaGetSubcontact(hContact, i); + hcnt = metaGetSubcontact(meta, i); if(hcnt) { DBDeleteContactSetting(hcnt, szGPGModuleName, "KeyID"); @@ -273,6 +275,8 @@ static BOOL CALLBACK DlgProcGpgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA DBDeleteContactSetting(hcnt, szGPGModuleName, "KeyType"); DBDeleteContactSetting(hcnt, szGPGModuleName, "KeyMainEmail"); DBDeleteContactSetting(hcnt, szGPGModuleName, "KeyComment"); + setClistIcon(hcnt); + setSrmmIcon(hcnt); } } } @@ -284,6 +288,8 @@ static BOOL CALLBACK DlgProcGpgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA DBDeleteContactSetting(hContact, szGPGModuleName, "KeyType"); DBDeleteContactSetting(hContact, szGPGModuleName, "KeyMainEmail"); DBDeleteContactSetting(hContact, szGPGModuleName, "KeyComment"); + setClistIcon(hContact); + setSrmmIcon(hContact); } } else @@ -294,6 +300,8 @@ static BOOL CALLBACK DlgProcGpgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA DBDeleteContactSetting(user_data[item_num+1], szGPGModuleName, "KeyType"); DBDeleteContactSetting(user_data[item_num+1], szGPGModuleName, "KeyMainEmail"); DBDeleteContactSetting(user_data[item_num+1], szGPGModuleName, "KeyComment"); + setClistIcon(user_data[item_num+1]); + setSrmmIcon(user_data[item_num+1]); } } ListView_SetItemText(hwndList, item_num, 3, _T("not set")); |