summaryrefslogtreecommitdiff
path: root/plugins/Dbx_mmap_SA/database.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/Dbx_mmap_SA/database.cpp')
-rw-r--r--plugins/Dbx_mmap_SA/database.cpp64
1 files changed, 30 insertions, 34 deletions
diff --git a/plugins/Dbx_mmap_SA/database.cpp b/plugins/Dbx_mmap_SA/database.cpp
index c1e1483fb0..288c7b898a 100644
--- a/plugins/Dbx_mmap_SA/database.cpp
+++ b/plugins/Dbx_mmap_SA/database.cpp
@@ -29,9 +29,7 @@ int InitialiseDbHeaders(void);
int InitSettings(void);
void UninitSettings(void);
int InitContacts(void);
-void UninitContacts(void);
int InitEvents(void);
-void UninitEvents(void);
int InitCrypt(void);
int InitModuleNames(void);
void UninitModuleNames(void);
@@ -45,10 +43,10 @@ int InitDialogs(void);
void InitSecurity(void);
void UnloadSecurity(void);
-HANDLE hDbFile=INVALID_HANDLE_VALUE;
+HANDLE hDbFile = INVALID_HANDLE_VALUE;
CRITICAL_SECTION csDbAccess;
struct DBHeader dbHeader;
-char szDbPath[MAX_PATH];
+TCHAR szDbPath[MAX_PATH];
static void UnloadDatabase(void)
{
@@ -63,8 +61,8 @@ static void UnloadDatabase(void)
DWORD CreateNewSpace(int bytes)
{
DWORD ofsNew;
- ofsNew=dbHeader.ofsFileEnd;
- dbHeader.ofsFileEnd+=bytes;
+ ofsNew = dbHeader.ofsFileEnd;
+ dbHeader.ofsFileEnd += bytes;
DBWrite(0,&dbHeader,sizeof(dbHeader));
log2("newspace %d@%08x",bytes,ofsNew);
return ofsNew;
@@ -74,10 +72,10 @@ void DeleteSpace(DWORD ofs,int bytes)
{
if (ofs+bytes == dbHeader.ofsFileEnd) {
log2("freespace %d@%08x",bytes,ofs);
- dbHeader.ofsFileEnd=ofs;
+ dbHeader.ofsFileEnd = ofs;
} else {
log2("deletespace %d@%08x",bytes,ofs);
- dbHeader.slackSpace+=bytes;
+ dbHeader.slackSpace += bytes;
}
DBWrite(0,&dbHeader,sizeof(dbHeader));
DBFill(ofs,bytes);
@@ -91,11 +89,11 @@ DWORD ReallocSpace(DWORD ofs,int oldSize,int newSize)
if (ofs+oldSize == dbHeader.ofsFileEnd) {
ofsNew = ofs;
- dbHeader.ofsFileEnd+=newSize-oldSize;
+ dbHeader.ofsFileEnd += newSize-oldSize;
DBWrite(0,&dbHeader,sizeof(dbHeader));
log3("adding newspace %d@%08x+%d",newSize,ofsNew,oldSize);
} else {
- ofsNew=CreateNewSpace(newSize);
+ ofsNew = CreateNewSpace(newSize);
DBMoveChunk(ofsNew,ofs,oldSize);
DeleteSpace(ofs,oldSize);
}
@@ -106,9 +104,7 @@ void UnloadDatabaseModule(void)
{
//UninitIni();
UninitPreset();
- UninitEvents();
UninitSettings();
- UninitContacts();
UninitModuleNames();
UninitCache();
UnloadDatabase();
@@ -118,22 +114,20 @@ void UnloadDatabaseModule(void)
INT_PTR GetProfileName(WPARAM wParam, LPARAM lParam)
{
- char * p = 0;
- p = strrchr(szDbPath, '\\');
+ TCHAR *p = _tcsrchr(szDbPath, '\\');
if ( p == 0 ) return 1;
p++;
- strncpy((char*)lParam, p, (size_t) wParam);
+ _tcsncpy((TCHAR*)lParam, p, (size_t) wParam);
return 0;
}
int LoadDatabaseModule(void)
{
- char szDBName[255];
InitializeCriticalSection(&csDbAccess);
log0("DB logging running");
{
- DWORD dummy=0;
- hDbFile=CreateFileA(szDbPath,GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, NULL);
+ DWORD dummy = 0;
+ hDbFile = CreateFile(szDbPath,GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, NULL);
if ( hDbFile == INVALID_HANDLE_VALUE ) {
return 1;
}
@@ -144,22 +138,24 @@ int LoadDatabaseModule(void)
}
InitSecurity();
CheckDbHeaders(&dbHeader);
+
+ TCHAR szDBName[MAX_PATH];
GetProfileName((WPARAM)50, (LPARAM)szDBName);
- if(bEncoding && !CheckPassword(dbHeader.checkWord, szDBName)) return 1;
- //if(ParseCommandLine()) return 1;
- if(InitCache()) return 1;
- if(InitModuleNames()) return 1;
- if(InitContacts()) return 1;
- if(InitSettings()) return 1;
- if(InitEvents()) return 1;
- if(InitCrypt()) return 1;
- if(InitPreset()) return 1;
- if(InitDialogs()) return 1;
- //EncryptDB();
+ if (bEncoding && !g_Db->CheckPassword(dbHeader.checkWord, szDBName))
+ return 1;
+
+ if (InitCache()) return 1;
+ if (InitModuleNames()) return 1;
+ if (InitContacts()) return 1;
+ if (InitSettings()) return 1;
+ if (InitEvents()) return 1;
+ if (InitCrypt()) return 1;
+ if (InitPreset()) return 1;
+ if (InitDialogs()) return 1;
return 0;
}
-static DWORD DatabaseCorrupted=0;
+static DWORD DatabaseCorrupted = 0;
static TCHAR *msg = NULL;
static DWORD dwErr = 0;
@@ -169,7 +165,7 @@ void __cdecl dbpanic(void *arg)
{
TCHAR err[256];
- if (dwErr==ERROR_DISK_FULL)
+ if (dwErr == ERROR_DISK_FULL)
msg = TranslateT("Disk is full. Miranda will now shutdown.");
mir_sntprintf(err, SIZEOF(err), msg, TranslateT("Database failure. Miranda will now shutdown."), dwErr);
@@ -185,10 +181,10 @@ void __cdecl dbpanic(void *arg)
void DatabaseCorruption(TCHAR *text)
{
- int kill=0;
+ int kill = 0;
EnterCriticalSection(&csDbAccess);
- if (DatabaseCorrupted==0) {
+ if (DatabaseCorrupted == 0) {
DatabaseCorrupted++;
kill++;
msg = text;
@@ -217,7 +213,7 @@ void DBLog(const char *file,int line,const char *fmt,...)
va_start(vararg,fmt);
mir_vsnprintf(str,sizeof(str),fmt,vararg);
va_end(vararg);
- fp=fopen("c:\\mirandadatabase.log.txt","at");
+ fp = fopen("c:\\mirandadatabase.log.txt","at");
fprintf(fp,"%u: %s %d: %s\n",GetTickCount(),file,line,str);
fclose(fp);
}