summaryrefslogtreecommitdiff
path: root/db3x_autobackups/dbevents.c
diff options
context:
space:
mode:
Diffstat (limited to 'db3x_autobackups/dbevents.c')
-rw-r--r--db3x_autobackups/dbevents.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/db3x_autobackups/dbevents.c b/db3x_autobackups/dbevents.c
index b45cee4..8897575 100644
--- a/db3x_autobackups/dbevents.c
+++ b/db3x_autobackups/dbevents.c
@@ -22,8 +22,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "commonheaders.h"
-#include "database.h"
+extern BOOL safetyMode;
DWORD GetModuleNameOfs(const char *szName);
char *GetModuleNameByOfs(DWORD ofs);
@@ -41,9 +41,6 @@ static int FindLastEvent(WPARAM wParam,LPARAM lParam);
static int FindNextEvent(WPARAM wParam,LPARAM lParam);
static int FindPrevEvent(WPARAM wParam,LPARAM lParam);
-extern CRITICAL_SECTION csDbAccess;
-extern struct DBHeader dbHeader;
-
static HANDLE hEventDeletedEvent,hEventAddedEvent,hEventFilterAddedEvent;
int InitEvents(void)
@@ -90,6 +87,7 @@ static int AddEvent(WPARAM wParam,LPARAM lParam)
struct DBContact dbc;
struct DBEvent dbe,*dbeTest;
DWORD ofsNew,ofsModuleName,ofsContact,ofsThis;
+ BOOL neednotify;
if(dbei==NULL||dbei->cbSize!=sizeof(DBEVENTINFO)) return (int)NULL;
if(dbei->timestamp==0) return (int)NULL;
@@ -166,14 +164,22 @@ static int AddEvent(WPARAM wParam,LPARAM lParam)
dbc.timestampFirstUnread=dbe.timestamp;
dbc.ofsFirstUnreadEvent=ofsNew;
}
+ neednotify = TRUE;
}
+ else neednotify = safetyMode;
+
DBWrite(ofsContact,&dbc,sizeof(struct DBContact));
DBWrite(ofsNew,&dbe,offsetof(struct DBEvent,blob));
DBWrite(ofsNew+offsetof(struct DBEvent,blob),dbei->pBlob,dbei->cbBlob);
DBFlush(0);
+
LeaveCriticalSection(&csDbAccess);
log1("add event @ %08x",ofsNew);
- NotifyEventHooks(hEventAddedEvent,wParam,(LPARAM)ofsNew);
+
+ // Notify only in safe mode or on really new events
+ if (neednotify)
+ NotifyEventHooks(hEventAddedEvent,wParam,(LPARAM)ofsNew);
+
return (int)ofsNew;
}
@@ -278,7 +284,7 @@ static int GetEvent(WPARAM wParam,LPARAM lParam)
int bytesToCopy,i;
if(dbei==NULL||dbei->cbSize!=sizeof(DBEVENTINFO)) return 1;
- if(dbei->cbBlob > 0 && dbei->pBlob == NULL) {
+ if(dbei->cbBlob>0 && dbei->pBlob==NULL) {
dbei->cbBlob = 0;
return 1;
}
@@ -295,16 +301,15 @@ static int GetEvent(WPARAM wParam,LPARAM lParam)
if(dbei->cbBlob<dbe->cbBlob) bytesToCopy=dbei->cbBlob;
else bytesToCopy=dbe->cbBlob;
dbei->cbBlob=dbe->cbBlob;
- if(dbei->pBlob == 0 && bytesToCopy > 0) {
- LeaveCriticalSection(&csDbAccess);
- return 1;
- }
- for(i=0;;i+=MAXCACHEDREADSIZE) {
- if(bytesToCopy-i<=MAXCACHEDREADSIZE) {
- CopyMemory(dbei->pBlob+i,DBRead(wParam+offsetof(struct DBEvent,blob)+i,bytesToCopy-i,NULL),bytesToCopy-i);
- break;
+ if (bytesToCopy && dbei->pBlob)
+ {
+ for(i=0;;i+=MAXCACHEDREADSIZE) {
+ if(bytesToCopy-i<=MAXCACHEDREADSIZE) {
+ CopyMemory(dbei->pBlob+i,DBRead(wParam+offsetof(struct DBEvent,blob)+i,bytesToCopy-i,NULL),bytesToCopy-i);
+ break;
+ }
+ CopyMemory(dbei->pBlob+i,DBRead(wParam+offsetof(struct DBEvent,blob)+i,MAXCACHEDREADSIZE,NULL),MAXCACHEDREADSIZE);
}
- CopyMemory(dbei->pBlob+i,DBRead(wParam+offsetof(struct DBEvent,blob)+i,MAXCACHEDREADSIZE,NULL),MAXCACHEDREADSIZE);
}
LeaveCriticalSection(&csDbAccess);
return 0;