diff options
Diffstat (limited to 'db3x_autobackups/database.c')
-rw-r--r-- | db3x_autobackups/database.c | 78 |
1 files changed, 52 insertions, 26 deletions
diff --git a/db3x_autobackups/database.c b/db3x_autobackups/database.c index d4c2215..f26289a 100644 --- a/db3x_autobackups/database.c +++ b/db3x_autobackups/database.c @@ -2,8 +2,8 @@ Miranda IM: the free IM client for Microsoft* Windows*
-Copyright 2000-2003 Miranda ICQ/IM project,
-all portions of this codebase are copyrighted to the people
+Copyright 2000-2003 Miranda ICQ/IM project,
+all portions of this codebase are copyrighted to the people
listed in contributors.txt.
This program is free software; you can redistribute it and/or
@@ -21,7 +21,7 @@ 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"
-#include "database.h"
+
int ProfileManager(char *szDbDest,int cbDbDest);
int ShouldAutoCreate(void);
@@ -57,13 +57,17 @@ BOOL bUnloading=FALSE; static void UnloadDatabase(void)
{
+ // update profile last modified time
+ DWORD bytesWritten;
+ SetFilePointer(hDbFile,0,NULL,FILE_BEGIN);
+ WriteFile(hDbFile,&dbSignature,1,&bytesWritten,NULL);
+
CloseHandle(hDbFile);
}
DWORD CreateNewSpace(int bytes)
{
DWORD ofsNew;
-
ofsNew=dbHeader.ofsFileEnd;
dbHeader.ofsFileEnd+=bytes;
DBWrite(0,&dbHeader,sizeof(dbHeader));
@@ -73,27 +77,34 @@ DWORD CreateNewSpace(int bytes) void DeleteSpace(DWORD ofs,int bytes)
{
- PBYTE buf;
- log2("deletespace %d@%08x",bytes,ofs);
+ if (ofs+bytes == dbHeader.ofsFileEnd) {
+ log2("freespace %d@%08x",bytes,ofs);
+ dbHeader.ofsFileEnd=ofs;
+ } else {
+ log2("deletespace %d@%08x",bytes,ofs);
+ dbHeader.slackSpace+=bytes;
+ }
+ DBWrite(0,&dbHeader,sizeof(dbHeader));
+ DBFill(ofs,bytes);
+}
- // reclaim a little space - will result in e.g. multiple db events with the same handle!
-#ifdef DB_RECLAIM
- if(ofs + bytes == dbHeader.ofsFileEnd) {
- dbHeader.ofsFileEnd-=bytes;
+DWORD ReallocSpace(DWORD ofs,int oldSize,int newSize)
+{
+ DWORD ofsNew;
+
+ if (oldSize >= newSize) return ofs;
+
+ if (ofs+oldSize == dbHeader.ofsFileEnd) {
+ ofsNew = ofs;
+ dbHeader.ofsFileEnd+=newSize-oldSize;
DBWrite(0,&dbHeader,sizeof(dbHeader));
- // shrink file
- SetFilePointer(hDbFile, dbHeader.ofsFileEnd, 0, FILE_BEGIN);
- SetEndOfFile(hDbFile);
- return;
+ log3("adding newspace %d@%08x+%d",newSize,ofsNew,oldSize);
+ } else {
+ ofsNew=CreateNewSpace(newSize);
+ DBMoveChunk(ofsNew,ofs,oldSize);
+ DeleteSpace(ofs,oldSize);
}
-#endif
-
- dbHeader.slackSpace+=bytes;
- DBWrite(0,&dbHeader,sizeof(dbHeader));
- buf=(PBYTE)mir_alloc(bytes);
- memset(buf,0,bytes);
- DBWrite(ofs,buf,bytes);
- mir_free(buf);
+ return ofsNew;
}
void UnloadDatabaseModule(void)
@@ -165,21 +176,34 @@ int LoadDatabaseModule(void) CreateServiceFunction(MS_DB_GETPROFILEPATH,GetProfilePath);
if(InitOptions()) return 1;
-
return 0;
}
static DWORD DatabaseCorrupted=0;
+static char *msg = NULL;
+static DWORD dwErr = 0;
void __cdecl dbpanic(void *arg)
{
-
- MessageBox(0,Translate("Miranda has detected corruption in your database. This corruption maybe fixed by DBTool. Please download it from http://www.miranda-im.org. Miranda will now shutdown."),Translate("Database Panic"),MB_SETFOREGROUND|MB_TOPMOST|MB_APPLMODAL|MB_ICONWARNING|MB_OK);
+ if (msg)
+ {
+ char err[256];
+
+ if (dwErr==ERROR_DISK_FULL)
+ msg = Translate("Disk is full. Miranda will now shutdown.");
+
+ mir_snprintf(err, sizeof(err), msg, Translate("Database failure. Miranda will now shutdown."), dwErr);
+
+ MessageBox(0,err,Translate("Database Error"),MB_SETFOREGROUND|MB_TOPMOST|MB_APPLMODAL|MB_ICONWARNING|MB_OK);
+ }
+ else
+ MessageBox(0,Translate("Miranda has detected corruption in your database. This corruption maybe fixed by DBTool. Please download it from http://www.miranda-im.org. Miranda will now shutdown."),
+ Translate("Database Panic"),MB_SETFOREGROUND|MB_TOPMOST|MB_APPLMODAL|MB_ICONWARNING|MB_OK);
TerminateProcess(GetCurrentProcess(),255);
return;
}
-void DatabaseCorruption(void)
+void DatabaseCorruption(char *text)
{
int kill=0;
@@ -187,6 +211,8 @@ void DatabaseCorruption(void) if (DatabaseCorrupted==0) {
DatabaseCorrupted++;
kill++;
+ msg = text;
+ dwErr = GetLastError();
} else {
/* db is already corrupted, someone else is dealing with it, wait here
so that we don't do any more damage */
|