summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2015-03-17 21:33:21 +0000
committerGeorge Hazan <george.hazan@gmail.com>2015-03-17 21:33:21 +0000
commit1218b9d9946a89818c17c065295601b36743cc5d (patch)
tree6243ed2be5fdac3f35f9bbcaef0df982f94d2db9 /plugins
parentc37d75940462df40da126c7696bacc604923a043 (diff)
fix for file logs in SeenPlugin
git-svn-id: http://svn.miranda-ng.org/main/trunk@12426 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins')
-rw-r--r--plugins/SeenPlugin/src/file.cpp85
-rw-r--r--plugins/SeenPlugin/src/main.cpp7
-rw-r--r--plugins/SeenPlugin/src/options.cpp36
-rw-r--r--plugins/SeenPlugin/src/seen.h11
-rw-r--r--plugins/SeenPlugin/src/utils.cpp8
-rw-r--r--plugins/SeenPlugin/src/version.h2
6 files changed, 56 insertions, 93 deletions
diff --git a/plugins/SeenPlugin/src/file.cpp b/plugins/SeenPlugin/src/file.cpp
index f8afc15c8d..91572bcb96 100644
--- a/plugins/SeenPlugin/src/file.cpp
+++ b/plugins/SeenPlugin/src/file.cpp
@@ -20,39 +20,34 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "seen.h"
+BOOL g_bFileActive;
+TCHAR *g_ptszFileStamp, *g_ptszFileName;
+
/////////////////////////////////////////////////////////////////////////////////////////
// Prepares the log file:
// - calculates the absolute path (and store it in the db)
// - creates the directory
-int InitFileOutput(void)
+void InitFileOutput(void)
{
- TCHAR szfpath[MAX_PATH], szmpath[MAX_PATH];
- GetModuleFileName(NULL, szmpath, MAX_PATH);
-
- DBVARIANT dbv;
- if (!db_get_ts(NULL, S_MOD, "FileName", &dbv)) {
- _tcsncpy(szfpath, dbv.ptszVal, MAX_PATH);
- db_free(&dbv);
- }
- else _tcsncpy(szfpath, DEFAULT_FILENAME, MAX_PATH);
-
- if (szfpath[0] == '\\')
- _tcsncpy(szfpath, szfpath + 1, MAX_PATH);
-
- TCHAR *str = _tcsrchr(szmpath, '\\');
- if (str != NULL)
- *++str = 0;
-
- _tcsncat(szmpath, szfpath, MAX_PATH);
- _tcsncpy(szfpath, szmpath, MAX_PATH);
-
- str = _tcsrchr(szmpath, '\\');
- if (str != NULL)
- *++str = 0;
+ ptrT tszFileName(db_get_tsa(NULL, S_MOD, "FileName"));
+ if (tszFileName == NULL)
+ tszFileName = mir_tstrdup(DEFAULT_FILENAME);
+ replaceStrT(g_ptszFileName, VARST(tszFileName));
+
+ TCHAR *tszPath = NEWTSTR_ALLOCA(g_ptszFileName);
+ TCHAR *p = _tcsrchr(tszPath, '\\');
+ if (p) *p = 0;
+ CreateDirectoryTreeT(tszPath);
+
+ ptrT tszFileStamp(db_get_tsa(NULL, S_MOD, "FileStamp"));
+ replaceStrT(g_ptszFileStamp, (tszFileStamp == NULL) ? DEFAULT_FILESTAMP : tszFileStamp);
+}
- db_set_ts(NULL, S_MOD, "PathToFile", szfpath);
- return 0;
+void UninitFileOutput()
+{
+ mir_free(g_ptszFileName);
+ mir_free(g_ptszFileStamp);
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -60,38 +55,10 @@ int InitFileOutput(void)
void FileWrite(MCONTACT hcontact)
{
- TCHAR szout[1024];
-
- DBVARIANT dbv;
- if (!db_get_ts(NULL, S_MOD, "PathToFile", &dbv)) {
- _tcsncpy(szout, ParseString(dbv.ptszVal, hcontact, 1), SIZEOF(szout));
- db_free(&dbv);
- }
- else _tcsncpy(szout, DEFAULT_FILENAME, SIZEOF(szout));
-
- HANDLE fhout = CreateFile(szout, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, 0, NULL);
- if (fhout == INVALID_HANDLE_VALUE) {
- TCHAR fullpath[1024];
- _tcsncpy(fullpath, szout, SIZEOF(fullpath));
- TCHAR *dirpath = _tcsrchr(fullpath, '\\');
- if (dirpath != NULL)
- *dirpath = '\0';
- CreateDirectoryTreeT(fullpath);
- fhout = CreateFile(szout, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, 0, NULL);
- if (fhout == INVALID_HANDLE_VALUE)
- return;
+ FILE *log = _tfopen(ParseString(g_ptszFileName, hcontact, 1), _T("a"));
+ if (log != NULL) {
+ _fputts(ParseString(g_ptszFileStamp, hcontact, 1), log);
+ fputs("\r\n", log);
+ fclose(log);
}
- SetFilePointer(fhout, 0, 0, FILE_END);
-
- if (!db_get_ts(NULL, S_MOD, "FileStamp", &dbv)) {
- _tcsncpy(szout, ParseString(dbv.ptszVal, hcontact, 1), SIZEOF(szout));
- db_free(&dbv);
- }
- else _tcsncpy(szout, ParseString(DEFAULT_FILESTAMP, hcontact, 1), SIZEOF(szout));
-
- DWORD byteswritten;
- WriteFile(fhout, _T2A(szout), (DWORD)_tcslen(szout), &byteswritten, NULL);
- WriteFile(fhout, "\r\n", 2, &byteswritten, NULL);
-
- CloseHandle(fhout);
}
diff --git a/plugins/SeenPlugin/src/main.cpp b/plugins/SeenPlugin/src/main.cpp
index ad6f81bfad..b5a50a98c1 100644
--- a/plugins/SeenPlugin/src/main.cpp
+++ b/plugins/SeenPlugin/src/main.cpp
@@ -59,6 +59,9 @@ void UninitHistoryDialog(void);
int MainInit(WPARAM, LPARAM)
{
+ if (g_bFileActive = db_get_b(NULL, S_MOD, "FileOutput", 0))
+ InitFileOutput();
+
if (db_get_b(NULL, S_MOD, "MenuItem", 1))
InitMenuitem();
@@ -93,9 +96,6 @@ extern "C" __declspec(dllexport) int Load(void)
includeIdle = (BOOL)db_get_b(NULL, S_MOD, "IdleSupport", 1);
- if (db_get_b(NULL, S_MOD, "FileOutput", 0))
- InitFileOutput();
-
if (db_get_b(NULL, S_MOD, "MissedOnes", 0))
ehmissed_proto = HookEvent(ME_PROTO_ACK, ModeChange_mo);
@@ -115,6 +115,7 @@ extern "C" __declspec(dllexport) PLUGININFOEX * MirandaPluginInfoEx(DWORD)
extern "C" __declspec(dllexport) int Unload(void)
{
+ UninitFileOutput();
UnloadWatchedProtos();
WindowList_Destroy(g_pUserInfo);
diff --git a/plugins/SeenPlugin/src/options.cpp b/plugins/SeenPlugin/src/options.cpp
index 1d84184131..c8fdc3be3b 100644
--- a/plugins/SeenPlugin/src/options.cpp
+++ b/plugins/SeenPlugin/src/options.cpp
@@ -20,15 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "seen.h"
-void BuildInfo(char *,char *,char *);
-int BuildContactMenu(WPARAM,LPARAM);
-int UserinfoInit(WPARAM,LPARAM);
-int InitFileOutput(void);
-void ShutdownFileOutput(void);
-void InitMenuitem(void);
-int ModeChange_mo(WPARAM,LPARAM);
-int CheckIfOnline(void);
-int ResetMissed(void);
+#define VARIABLE_LIST "%s \n%%Y: \t %s \n%%y: \t %s \n%%m: \t %s \n%%E: \t %s \n%%e: \t %s \n%%d: \t %s \n%%W: \t %s \n%%w: \t %s \n\n%s \n%%H: \t %s \n%%h: \t %s \n%%p: \t %s \n%%M: \t %s \n%%S: \t %s \n\n%s \n%%n: \t %s \n%%N: \t %s \n%%u: \t %s \n%%G: \t %s \n%%s: \t %s \n%%T: \t %s \n%%o: \t %s \n%%i: \t %s \n%%r: \t %s \n%%C: \t %s \n%%P: \t %s \n%%A:\t %s\n\n%s \n%%t: \t %s \n%%b: \t %s\n\n%s\t%s \"#\" %s\n\t%s %s", Translate("-- Date --"), Translate("year (4 digits)"), Translate("year (2 digits)"), Translate("month"), Translate("name of month"), Translate("short name of month"), Translate("day"), Translate("weekday (full)"), Translate("weekday (abbreviated)"), Translate("-- Time --"), Translate("hours (24)"), Translate("hours (12)"), Translate("AM/PM"), Translate("minutes"), Translate("seconds"), Translate("-- User --"), Translate("username"), Translate("nick"), Translate("UIN/handle"), Translate("Group"), Translate("Status"), Translate("Status message"), Translate("Old status"), Translate("external IP"), Translate("internal IP"),Translate("Client info"),Translate("Protocol"), Translate("Account"),Translate("-- Format --"), Translate("tabulator"), Translate("line break"), Translate("Note:"),Translate("Use"),Translate("for empty string"),Translate("instead of"),Translate("<unknown>")
INT_PTR CALLBACK OptsPopupsDlgProc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam)
{
@@ -175,7 +167,6 @@ INT_PTR CALLBACK OptsSettingsDlgProc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM
{
DBVARIANT dbv;
TCHAR szstamp[256];
- BYTE bchecked;
switch (msg) {
case WM_INITDIALOG:
@@ -183,7 +174,7 @@ INT_PTR CALLBACK OptsSettingsDlgProc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM
CheckDlgButton(hdlg, IDC_MENUITEM, db_get_b(NULL, S_MOD, "MenuItem", 1) ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hdlg, IDC_USERINFO, db_get_b(NULL, S_MOD, "UserinfoTab", 1) ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hdlg, IDC_FILE, db_get_b(NULL, S_MOD, "FileOutput", 0) ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(hdlg, IDC_FILE, g_bFileActive ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hdlg, IDC_HISTORY, db_get_b(NULL, S_MOD, "KeepHistory", 0) ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hdlg, IDC_IGNOREOFFLINE, db_get_b(NULL, S_MOD, "IgnoreOffline", 1) ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hdlg, IDC_MISSEDONES, db_get_b(NULL, S_MOD, "MissedOnes", 0) ? BST_CHECKED : BST_UNCHECKED);
@@ -314,14 +305,14 @@ INT_PTR CALLBACK OptsSettingsDlgProc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM
db_set_w(NULL, S_MOD, "HistoryMax", (WORD)(GetDlgItemInt(hdlg, IDC_HISTORYSIZE, NULL, FALSE) + 1));
- bchecked = (BYTE)IsDlgButtonChecked(hdlg, IDC_MENUITEM);
+ BOOL bchecked = IsDlgButtonChecked(hdlg, IDC_MENUITEM);
if (db_get_b(NULL, S_MOD, "MenuItem", 1) != bchecked) {
db_set_b(NULL, S_MOD, "MenuItem", bchecked);
if (hmenuitem == NULL && bchecked)
InitMenuitem();
}
- bchecked = (BYTE)IsDlgButtonChecked(hdlg, IDC_USERINFO);
+ bchecked = IsDlgButtonChecked(hdlg, IDC_USERINFO);
if (db_get_b(NULL, S_MOD, "UserinfoTab", 1) != bchecked) {
db_set_b(NULL, S_MOD, "UserinfoTab", bchecked);
if (bchecked)
@@ -330,22 +321,25 @@ INT_PTR CALLBACK OptsSettingsDlgProc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM
UnhookEvent(ehuserinfo);
}
- bchecked = (BYTE)IsDlgButtonChecked(hdlg, IDC_FILE);
- if (db_get_b(NULL, S_MOD, "FileOutput", 0) != bchecked) {
+ bchecked = IsDlgButtonChecked(hdlg, IDC_FILE);
+ if (g_bFileActive != bchecked) {
+ g_bFileActive = bchecked;
db_set_b(NULL, S_MOD, "FileOutput", bchecked);
if (bchecked)
InitFileOutput();
+ else
+ UninitFileOutput();
}
- bchecked = (BYTE)IsDlgButtonChecked(hdlg, IDC_HISTORY);
+ bchecked = IsDlgButtonChecked(hdlg, IDC_HISTORY);
if (db_get_b(NULL, S_MOD, "KeepHistory", 0) != bchecked)
db_set_b(NULL, S_MOD, "KeepHistory", bchecked);
- bchecked = (BYTE)IsDlgButtonChecked(hdlg, IDC_IGNOREOFFLINE);
+ bchecked = IsDlgButtonChecked(hdlg, IDC_IGNOREOFFLINE);
if (db_get_b(NULL, S_MOD, "IgnoreOffline", 1) != bchecked)
db_set_b(NULL, S_MOD, "IgnoreOffline", bchecked);
- bchecked = (BYTE)IsDlgButtonChecked(hdlg, IDC_MISSEDONES);
+ bchecked = IsDlgButtonChecked(hdlg, IDC_MISSEDONES);
if (db_get_b(NULL, S_MOD, "MissedOnes", 0) != bchecked) {
db_set_b(NULL, S_MOD, "MissedOnes", bchecked);
if (bchecked)
@@ -354,15 +348,15 @@ INT_PTR CALLBACK OptsSettingsDlgProc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM
UnhookEvent(ehmissed_proto);
}
- bchecked = (BYTE)IsDlgButtonChecked(hdlg, IDC_SHOWICON);
+ bchecked = IsDlgButtonChecked(hdlg, IDC_SHOWICON);
if (db_get_b(NULL, S_MOD, "ShowIcon", 1) != bchecked)
db_set_b(NULL, S_MOD, "ShowIcon", bchecked);
- bchecked = (BYTE)IsDlgButtonChecked(hdlg, IDC_COUNT);
+ bchecked = IsDlgButtonChecked(hdlg, IDC_COUNT);
if (db_get_b(NULL, S_MOD, "MissedOnes_Count", 0) != bchecked)
db_set_b(NULL, S_MOD, "MissedOnes_Count", bchecked);
- includeIdle = (BYTE)IsDlgButtonChecked(hdlg, IDC_IDLESUPPORT);
+ includeIdle = IsDlgButtonChecked(hdlg, IDC_IDLESUPPORT);
if (db_get_b(NULL, S_MOD, "IdleSupport", 1) != includeIdle)
db_set_b(NULL, S_MOD, "IdleSupport", (BYTE)includeIdle);
diff --git a/plugins/SeenPlugin/src/seen.h b/plugins/SeenPlugin/src/seen.h
index 543ea214d0..59090eae93 100644
--- a/plugins/SeenPlugin/src/seen.h
+++ b/plugins/SeenPlugin/src/seen.h
@@ -84,12 +84,10 @@ WCHAR *any_to_Idle(MCONTACT hContact, const char *module_name, const char *setti
#define DEFAULT_POPUPSTAMPTEXT TranslateT("%i(%r)%bWas %o")
#define DEFAULT_USERSTAMP TranslateT("Name:%t%N%bStatus:%t%s%bDay:%t%d.%m.%Y%bTime:%t%H:%M:%S%bPrevious Status:%t%o%b%b%P ID:%t%u%bExternal IP:%t%i%bInternal IP:%t%r%bClient ID: %t%C%b%bStatus Message:%t%T")
#define DEFAULT_FILESTAMP _T("%d.%m.%Y %H:%M:%S%t%n%t%s%t%u%t%r | %i%t%N")
-#define DEFAULT_FILENAME _T("logs\\%P.txt")
+#define DEFAULT_FILENAME _T("%miranda_logpath%\\LastSeen\\%P.txt")
#define DEFAULT_HISTORYSTAMP _T("%d.%m.%Y - %H:%M [%s]")
#define DEFAULT_WATCHEDPROTOCOLS ""
-#define VARIABLE_LIST "%s \n%%Y: \t %s \n%%y: \t %s \n%%m: \t %s \n%%E: \t %s \n%%e: \t %s \n%%d: \t %s \n%%W: \t %s \n%%w: \t %s \n\n%s \n%%H: \t %s \n%%h: \t %s \n%%p: \t %s \n%%M: \t %s \n%%S: \t %s \n\n%s \n%%n: \t %s \n%%N: \t %s \n%%u: \t %s \n%%G: \t %s \n%%s: \t %s \n%%T: \t %s \n%%o: \t %s \n%%i: \t %s \n%%r: \t %s \n%%C: \t %s \n%%P: \t %s \n%%A:\t %s\n\n%s \n%%t: \t %s \n%%b: \t %s\n\n%s\t%s \"#\" %s\n\t%s %s", Translate("-- Date --"), Translate("year (4 digits)"), Translate("year (2 digits)"), Translate("month"), Translate("name of month"), Translate("short name of month"), Translate("day"), Translate("weekday (full)"), Translate("weekday (abbreviated)"), Translate("-- Time --"), Translate("hours (24)"), Translate("hours (12)"), Translate("AM/PM"), Translate("minutes"), Translate("seconds"), Translate("-- User --"), Translate("username"), Translate("nick"), Translate("UIN/handle"), Translate("Group"), Translate("Status"), Translate("Status message"), Translate("Old status"), Translate("external IP"), Translate("internal IP"),Translate("Client info"),Translate("Protocol"), Translate("Account"),Translate("-- Format --"), Translate("tabulator"), Translate("line break"), Translate("Note:"),Translate("Use"),Translate("for empty string"),Translate("instead of"),Translate("<unknown>")
-
typedef struct{
int count;
WPARAM wpcontact[1024];
@@ -102,7 +100,6 @@ void GetColorsFromDWord(LPCOLORREF First, LPCOLORREF Second, DWORD colDword);
DWORD GetDWordFromColors(COLORREF First, COLORREF Second);
int OptionsInit(WPARAM,LPARAM);
int UserinfoInit(WPARAM,LPARAM);
-int InitFileOutput(void);
void InitMenuitem(void);
int UpdateValues(WPARAM, LPARAM);
int ModeChange(WPARAM,LPARAM);
@@ -111,6 +108,9 @@ int ModeChange_mo(WPARAM,LPARAM);
int CheckIfOnline(void);
void ShowHistory(MCONTACT hContact, BYTE isAlert);
+void InitFileOutput(void);
+void UninitFileOutput(void);
+
struct logthread_info
{
MCONTACT hContact;
@@ -126,6 +126,9 @@ extern HANDLE g_pUserInfo;
extern HGENMENU hmenuitem;
extern DWORD dwmirver;
+extern BOOL g_bFileActive;
+extern TCHAR *g_ptszFileStamp, *g_ptszFileName;
+
void LoadWatchedProtos();
void UnloadWatchedProtos();
extern LIST<char> arWatchedProtos;
diff --git a/plugins/SeenPlugin/src/utils.cpp b/plugins/SeenPlugin/src/utils.cpp
index ea830618b1..230f23486b 100644
--- a/plugins/SeenPlugin/src/utils.cpp
+++ b/plugins/SeenPlugin/src/utils.cpp
@@ -598,7 +598,7 @@ int UpdateValues(WPARAM hContact, LPARAM lparam)
}
if (!db_get_b(NULL, S_MOD, "IgnoreOffline", 1)) {
- if (db_get_b(NULL, S_MOD, "FileOutput", 0))
+ if (g_bFileActive)
FileWrite(hContact);
char *sProto = GetContactProto(hContact);
@@ -622,9 +622,7 @@ int UpdateValues(WPARAM hContact, LPARAM lparam)
DBWriteTimeTS(time(NULL), hContact);
- //db_set_w(hContact,S_MOD,"StatusTriger",(WORD)cws->value.wVal);
-
- if (db_get_b(NULL, S_MOD, "FileOutput", 0)) FileWrite(hContact);
+ if (g_bFileActive) FileWrite(hContact);
if (prevStatus != cws->value.wVal) myPlaySound(hContact, cws->value.wVal, prevStatus);
if (db_get_b(NULL, S_MOD, "UsePopups", 0))
if (prevStatus != cws->value.wVal)
@@ -722,7 +720,7 @@ int ModeChange(WPARAM wparam, LPARAM lparam)
db_set_w(NULL, S_MOD, courProtoName, isetting);
- if (db_get_b(NULL, S_MOD, "FileOutput", 0))
+ if (g_bFileActive)
FileWrite(NULL);
courProtoName = NULL;
diff --git a/plugins/SeenPlugin/src/version.h b/plugins/SeenPlugin/src/version.h
index 03e0885d88..fe02adfd17 100644
--- a/plugins/SeenPlugin/src/version.h
+++ b/plugins/SeenPlugin/src/version.h
@@ -22,7 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define __MAJOR_VERSION 5
#define __MINOR_VERSION 0
#define __RELEASE_NUM 5
-#define __BUILD_NUM 1
+#define __BUILD_NUM 2
#include <stdver.h>