summaryrefslogtreecommitdiff
path: root/plugins/Db3x_mmap/src/dbtool
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2012-07-27 15:33:58 +0000
committerGeorge Hazan <george.hazan@gmail.com>2012-07-27 15:33:58 +0000
commitdf77e258df8cec689a001ec92031538298661b1b (patch)
tree56ec236ca9675f049c4806e8d41986c40b537f07 /plugins/Db3x_mmap/src/dbtool
parent414ffc78d69f09d48fc43051e0806a30e8fb5c67 (diff)
merge of dbtool & database plugins
git-svn-id: http://svn.miranda-ng.org/main/trunk@1213 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Db3x_mmap/src/dbtool')
-rw-r--r--plugins/Db3x_mmap/src/dbtool/aggressive.cpp42
-rw-r--r--plugins/Db3x_mmap/src/dbtool/contactchain.cpp24
-rw-r--r--plugins/Db3x_mmap/src/dbtool/disk.cpp62
-rw-r--r--plugins/Db3x_mmap/src/dbtool/eventchain.cpp54
-rw-r--r--plugins/Db3x_mmap/src/dbtool/finaltasks.cpp64
-rw-r--r--plugins/Db3x_mmap/src/dbtool/initialchecks.cpp71
-rw-r--r--plugins/Db3x_mmap/src/dbtool/modulechain.cpp27
-rw-r--r--plugins/Db3x_mmap/src/dbtool/settingschain.cpp10
-rw-r--r--plugins/Db3x_mmap/src/dbtool/user.cpp59
9 files changed, 177 insertions, 236 deletions
diff --git a/plugins/Db3x_mmap/src/dbtool/aggressive.cpp b/plugins/Db3x_mmap/src/dbtool/aggressive.cpp
index 7cafb63043..0a47754920 100644
--- a/plugins/Db3x_mmap/src/dbtool/aggressive.cpp
+++ b/plugins/Db3x_mmap/src/dbtool/aggressive.cpp
@@ -20,44 +20,36 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define BLOCKSIZE 65536
-extern DWORD sourceFileSize;
-extern DWORD spaceProcessed;
-extern DWORD sp;
-static DWORD ofsCurrent;
-
-int WorkAggressive(int firstTime)
+int CDb3Base::WorkAggressive(int firstTime)
{
- int blockBytes,i;
- BYTE *buf;
-
if (firstTime) {
- if (!opts.bAggressive)
+ if (!cb->bAggressive)
return ERROR_NO_MORE_ITEMS;
- AddToStatus(STATUS_MESSAGE,TranslateT("Performing aggressive pass"));
- ofsCurrent = 0;
- spaceProcessed = 0;
- sp = 0;
+ cb->pfnAddLogMessage(STATUS_MESSAGE,TranslateT("Performing aggressive pass"));
+ ofsAggrCur = 0;
+ cb->spaceProcessed = 0;
}
- blockBytes = min(BLOCKSIZE+3,(int)(sourceFileSize-ofsCurrent));
+
+ int blockBytes = min(BLOCKSIZE+3,(int)(sourceFileSize-ofsAggrCur));
if (blockBytes <= 0)
return ERROR_NO_MORE_ITEMS;
- buf = opts.pFile+ofsCurrent;
+ BYTE *buf = m_pDbCache + ofsAggrCur;
blockBytes -= 3;
- for(i = 0;i<blockBytes;i++) {
+ for (int i=0; i < blockBytes; i++) {
if (buf[i]) {
- if ((*(PDWORD)&buf[i]&0x00FFFFFF) != 0xDECADE)
- AddToStatus(STATUS_WARNING,TranslateT("Aggressive: random junk at %08X: skipping"),ofsCurrent+i);
- else {
+ if ((*(PDWORD)&buf[i] & 0x00FFFFFF) != 0xDECADE)
+ cb->pfnAddLogMessage(STATUS_WARNING,TranslateT("Aggressive: random junk at %08X: skipping"),ofsAggrCur+i);
+ else
//TODO: give user the option of placing manually
- AddToStatus(STATUS_ERROR,TranslateT("Aggressive: unlinked data at %08X: can't automatically place"),ofsCurrent+i);
- }
- for(; i < blockBytes; i++)
+ cb->pfnAddLogMessage(STATUS_ERROR,TranslateT("Aggressive: unlinked data at %08X: can't automatically place"),ofsAggrCur+i);
+
+ for (; i < blockBytes; i++)
if (buf[i] == 0) {i--; break;}
}
}
- ofsCurrent += BLOCKSIZE;
- spaceProcessed = ofsCurrent;
+ ofsAggrCur += BLOCKSIZE;
+ cb->spaceProcessed = ofsAggrCur;
return ERROR_SUCCESS;
}
diff --git a/plugins/Db3x_mmap/src/dbtool/contactchain.cpp b/plugins/Db3x_mmap/src/dbtool/contactchain.cpp
index 0993371848..80c4b62168 100644
--- a/plugins/Db3x_mmap/src/dbtool/contactchain.cpp
+++ b/plugins/Db3x_mmap/src/dbtool/contactchain.cpp
@@ -16,10 +16,8 @@ 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"
-int WorkSettingsChain(DWORD ofsContact,DBContact *dbc,int firstTime);
-int WorkEventChain(DWORD ofsContact,DBContact *dbc,int firstTime);
+#include "..\commonheaders.h"
static DWORD ofsThisContact,ofsDestPrevContact;
static DWORD contactCount;
@@ -27,17 +25,17 @@ static DWORD ofsDestThis,ofsNextContact;
static int phase;
static DBContact dbc;
-int WorkContactChain(int firstTime)
+int CDb3Base::WorkContactChain(int firstTime)
{
int first = 0;
int ret;
if (firstTime) {
- AddToStatus(STATUS_MESSAGE,TranslateT("Processing contact chain"));
+ cb->pfnAddLogMessage(STATUS_MESSAGE,TranslateT("Processing contact chain"));
ofsDestPrevContact = 0;
- ofsThisContact = dbhdr.ofsFirstContact;
+ ofsThisContact = m_dbHeader.ofsFirstContact;
contactCount = 0;
- dbhdr.ofsFirstContact = 0;
+ m_dbHeader.ofsFirstContact = 0;
phase = 0;
}
@@ -45,13 +43,13 @@ int WorkContactChain(int firstTime)
case 0:
if (ofsThisContact == 0) {
LBL_FinishUp:
- if (contactCount != dbhdr.contactCount)
- AddToStatus(STATUS_WARNING,TranslateT("Contact count marked wrongly: correcting"));
- dbhdr.contactCount = contactCount;
+ if (contactCount != m_dbHeader.contactCount)
+ cb->pfnAddLogMessage(STATUS_WARNING,TranslateT("Contact count marked wrongly: correcting"));
+ m_dbHeader.contactCount = contactCount;
return ERROR_NO_MORE_ITEMS;
}
if (!SignatureValid(ofsThisContact,DBCONTACT_SIGNATURE)) {
- AddToStatus(STATUS_ERROR,TranslateT("Contact chain corrupted, further entries ignored"));
+ cb->pfnAddLogMessage(STATUS_ERROR,TranslateT("Contact chain corrupted, further entries ignored"));
goto LBL_FinishUp;
}
if (ReadSegment(ofsThisContact,&dbc,sizeof(dbc)) != ERROR_SUCCESS)
@@ -59,13 +57,13 @@ LBL_FinishUp:
ofsNextContact = dbc.ofsNext;
dbc.ofsNext = 0;
- if (!opts.bCheckOnly) {
+ if (!cb->bCheckOnly) {
if ((ofsDestThis = WriteSegment(WSOFS_END,&dbc,sizeof(dbc))) == WS_ERROR)
return ERROR_HANDLE_DISK_FULL;
if (ofsDestPrevContact)
WriteSegment(ofsDestPrevContact+offsetof(DBContact,ofsNext),&ofsDestThis,sizeof(DWORD));
else
- dbhdr.ofsFirstContact = ofsDestThis;
+ m_dbHeader.ofsFirstContact = ofsDestThis;
} else
ofsDestThis = ofsThisContact; // needed in event chain worker
contactCount++;
diff --git a/plugins/Db3x_mmap/src/dbtool/disk.cpp b/plugins/Db3x_mmap/src/dbtool/disk.cpp
index 2cf9136a71..a5178c8ea2 100644
--- a/plugins/Db3x_mmap/src/dbtool/disk.cpp
+++ b/plugins/Db3x_mmap/src/dbtool/disk.cpp
@@ -16,95 +16,91 @@ 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 "dbtool.h"
-extern DWORD spaceProcessed, sourceFileSize;
+#include "..\commonheaders.h"
-int SignatureValid(DWORD ofs, DWORD signature)
+int CDb3Base::SignatureValid(DWORD ofs, DWORD signature)
{
DWORD sig;
if (ofs+sizeof(sig) >= sourceFileSize) {
- AddToStatus(STATUS_ERROR, TranslateT("Invalid offset found (database truncated?)"));
+ cb->pfnAddLogMessage(STATUS_ERROR, TranslateT("Invalid offset found (database truncated?)"));
return 0;
}
- sig = *(DWORD*)(opts.pFile+ofs);
+ sig = *(DWORD*)(m_pDbCache+ofs);
return sig == signature;
}
-int PeekSegment(DWORD ofs, PVOID buf, int cbBytes)
+int CDb3Base::PeekSegment(DWORD ofs, PVOID buf, int cbBytes)
{
DWORD bytesRead;
if (ofs >= sourceFileSize) {
- AddToStatus(STATUS_ERROR, TranslateT("Invalid offset found"));
+ cb->pfnAddLogMessage(STATUS_ERROR, TranslateT("Invalid offset found"));
return ERROR_SEEK;
}
- if (ofs+cbBytes>sourceFileSize)
+ if (ofs+cbBytes > sourceFileSize)
bytesRead = sourceFileSize - ofs;
else
bytesRead = cbBytes;
if (bytesRead == 0) {
- AddToStatus(STATUS_ERROR, TranslateT("Error reading, database truncated? (%u)"), GetLastError());
+ cb->pfnAddLogMessage(STATUS_ERROR, TranslateT("Error reading, database truncated? (%u)"), GetLastError());
return ERROR_READ_FAULT;
}
- CopyMemory(buf, opts.pFile+ofs, bytesRead);
+ CopyMemory(buf, m_pDbCache+ofs, bytesRead);
if ((int)bytesRead<cbBytes) return ERROR_HANDLE_EOF;
return ERROR_SUCCESS;
}
-int ReadSegment(DWORD ofs, PVOID buf, int cbBytes)
+int CDb3Base::ReadSegment(DWORD ofs, PVOID buf, int cbBytes)
{
- int ret;
-
- ret = PeekSegment(ofs, buf, cbBytes);
+ int ret = PeekSegment(ofs, buf, cbBytes);
if (ret != ERROR_SUCCESS && ret != ERROR_HANDLE_EOF) return ret;
- if (opts.bAggressive) {
- if (ofs+cbBytes>sourceFileSize) {
- AddToStatus(STATUS_WARNING, TranslateT("Can't write to working file, aggressive mode may be too aggressive now"));
- ZeroMemory(opts.pFile+ofs, sourceFileSize-ofs);
+ if (cb->bAggressive) {
+ if (ofs+cbBytes > sourceFileSize) {
+ cb->pfnAddLogMessage(STATUS_WARNING, TranslateT("Can't write to working file, aggressive mode may be too aggressive now"));
+ ZeroMemory(m_pDbCache+ofs, sourceFileSize-ofs);
}
else
- ZeroMemory(opts.pFile+ofs, cbBytes);
+ ZeroMemory(m_pDbCache+ofs, cbBytes);
}
- spaceProcessed += cbBytes;
+ cb->spaceProcessed += cbBytes;
return ERROR_SUCCESS;
}
-DWORD WriteSegment(DWORD ofs, PVOID buf, int cbBytes)
+DWORD CDb3Base::WriteSegment(DWORD ofs, PVOID buf, int cbBytes)
{
DWORD bytesWritten;
- if (opts.bCheckOnly) return 0xbfbfbfbf;
+ if (cb->bCheckOnly) return 0xbfbfbfbf;
if (ofs == WSOFS_END) {
- ofs = dbhdr.ofsFileEnd;
- dbhdr.ofsFileEnd += cbBytes;
+ ofs = m_dbHeader.ofsFileEnd;
+ m_dbHeader.ofsFileEnd += cbBytes;
}
- SetFilePointer(opts.hOutFile, ofs, NULL, FILE_BEGIN);
- WriteFile(opts.hOutFile, buf, cbBytes, &bytesWritten, NULL);
+ SetFilePointer(cb->hOutFile, ofs, NULL, FILE_BEGIN);
+ WriteFile(cb->hOutFile, buf, cbBytes, &bytesWritten, NULL);
if ((int)bytesWritten<cbBytes) {
- AddToStatus(STATUS_FATAL, TranslateT("Can't write to output file - disk full? (%u)"), GetLastError());
+ cb->pfnAddLogMessage(STATUS_FATAL, TranslateT("Can't write to output file - disk full? (%u)"), GetLastError());
return WS_ERROR;
}
return ofs;
}
-
-int ReadWrittenSegment(DWORD ofs, PVOID buf, int cbBytes)
+int CDb3Base::ReadWrittenSegment(DWORD ofs, PVOID buf, int cbBytes)
{
DWORD bytesRead;
- if (opts.bCheckOnly) return 0xbfbfbfbf;
- if (ofs + cbBytes > dbhdr.ofsFileEnd)
+ if (cb->bCheckOnly) return 0xbfbfbfbf;
+ if (ofs + cbBytes > m_dbHeader.ofsFileEnd)
return ERROR_SEEK;
- SetFilePointer(opts.hOutFile, ofs, NULL, FILE_BEGIN);
- ReadFile(opts.hOutFile, buf, cbBytes, &bytesRead, NULL);
+ SetFilePointer(cb->hOutFile, ofs, NULL, FILE_BEGIN);
+ ReadFile(cb->hOutFile, buf, cbBytes, &bytesRead, NULL);
if ((int)bytesRead<cbBytes)
return ERROR_READ_FAULT;
diff --git a/plugins/Db3x_mmap/src/dbtool/eventchain.cpp b/plugins/Db3x_mmap/src/dbtool/eventchain.cpp
index 1e0076371d..9c9a41f999 100644
--- a/plugins/Db3x_mmap/src/dbtool/eventchain.cpp
+++ b/plugins/Db3x_mmap/src/dbtool/eventchain.cpp
@@ -32,7 +32,7 @@ static DWORD memsize = 0;
static DBEvent* memblock = NULL;
static DBEvent* dbePrevEvent = NULL;
-static void ConvertOldEvent(DBEvent*& dbei)
+void CDb3Base::ConvertOldEvent(DBEvent*& dbei)
{
int msglen = (int)strlen((char*)dbei->blob) + 1, msglenW = 0;
if (msglen != (int) dbei->cbBlob) {
@@ -44,7 +44,7 @@ static void ConvertOldEvent(DBEvent*& dbei)
break;
} } }
else {
- if (!is_utf8_string((char*)dbei->blob))
+ if (!Utf8CheckString((char*)dbei->blob))
dbei->flags &= ~DBEF_UTF;
}
@@ -61,7 +61,7 @@ static void ConvertOldEvent(DBEvent*& dbei)
free(utf8str);
} }
-static void WriteOfsNextToPrevious(DWORD ofsPrev,DBContact *dbc,DWORD ofsNext)
+void CDb3Base::WriteOfsNextToPrevious(DWORD ofsPrev,DBContact *dbc,DWORD ofsNext)
{
if (ofsPrev)
WriteSegment(ofsPrev+offsetof(DBEvent,ofsNext),&ofsNext,sizeof(DWORD));
@@ -69,14 +69,14 @@ static void WriteOfsNextToPrevious(DWORD ofsPrev,DBContact *dbc,DWORD ofsNext)
dbc->ofsFirstEvent = ofsNext;
}
-static void FinishUp(DWORD ofsLast,DBContact *dbc)
+void CDb3Base::FinishUp(DWORD ofsLast,DBContact *dbc)
{
WriteOfsNextToPrevious(ofsLast,dbc,0);
if (eventCount != dbc->eventCount)
- AddToStatus(STATUS_WARNING,TranslateT("Event count marked wrongly: correcting"));
+ cb->pfnAddLogMessage(STATUS_WARNING,TranslateT("Event count marked wrongly: correcting"));
dbc->eventCount = eventCount;
dbc->ofsLastEvent = ofsLast;
- if (opts.bMarkRead) {
+ if (cb->bMarkRead) {
dbc->ofsFirstUnreadEvent = 0;
dbc->timestampFirstUnread = 0;
}
@@ -91,7 +91,7 @@ static void FinishUp(DWORD ofsLast,DBContact *dbc)
}
}
-static DWORD WriteEvent(DBEvent *dbe)
+DWORD CDb3Base::WriteEvent(DBEvent *dbe)
{
DWORD ofs = WriteSegment(WSOFS_END, dbe, offsetof(DBEvent,blob)+dbe->cbBlob);
if (ofs == WS_ERROR) {
@@ -103,7 +103,7 @@ static DWORD WriteEvent(DBEvent *dbe)
return ofs;
}
-int WorkEventChain(DWORD ofsContact,DBContact *dbc,int firstTime)
+int CDb3Base::WorkEventChain(DWORD ofsContact,DBContact *dbc,int firstTime)
{
DBEvent *dbeNew,dbeOld;
DBEvent *dbePrev = NULL;
@@ -119,7 +119,7 @@ int WorkEventChain(DWORD ofsContact,DBContact *dbc,int firstTime)
backLookup = 0;
lastTimestamp = 0;
ofsFirstUnread = timestampFirstUnread = 0;
- if (opts.bEraseHistory) {
+ if (cb->bEraseHistory) {
dbc->eventCount = 0;
dbc->ofsFirstEvent = 0;
dbc->ofsLastEvent = 0;
@@ -148,10 +148,10 @@ int WorkEventChain(DWORD ofsContact,DBContact *dbc,int firstTime)
}
}
if (ofsNew) {
- AddToStatus(STATUS_WARNING,TranslateT("Event chain corrupted, trying to recover..."));
+ cb->pfnAddLogMessage(STATUS_WARNING,TranslateT("Event chain corrupted, trying to recover..."));
ofsThisEvent = ofsNew;
} else {
- AddToStatus(STATUS_ERROR,TranslateT("Event chain corrupted, further entries ignored"));
+ cb->pfnAddLogMessage(STATUS_ERROR,TranslateT("Event chain corrupted, further entries ignored"));
FinishUp(ofsDestPrevEvent,dbc);
return ERROR_NO_MORE_ITEMS;
}
@@ -164,32 +164,32 @@ int WorkEventChain(DWORD ofsContact,DBContact *dbc,int firstTime)
if (firstTime) {
if (!(dbeOld.flags&DBEF_FIRST)) {
- AddToStatus(STATUS_WARNING,TranslateT("First event not marked as such: correcting"));
+ cb->pfnAddLogMessage(STATUS_WARNING,TranslateT("First event not marked as such: correcting"));
dbeOld.flags|=DBEF_FIRST;
}
dbeOld.ofsPrev = ofsContact;
lastTimestamp = dbeOld.timestamp;
}
else if (dbeOld.flags&DBEF_FIRST) {
- AddToStatus(STATUS_WARNING,TranslateT("Event marked as first which is not: correcting"));
+ cb->pfnAddLogMessage(STATUS_WARNING,TranslateT("Event marked as first which is not: correcting"));
dbeOld.flags&=~DBEF_FIRST;
}
if (dbeOld.flags&~(DBEF_FIRST|DBEF_READ|DBEF_SENT|DBEF_RTL|DBEF_UTF)) {
- AddToStatus(STATUS_WARNING,TranslateT("Extra flags found in event: removing"));
+ cb->pfnAddLogMessage(STATUS_WARNING,TranslateT("Extra flags found in event: removing"));
dbeOld.flags&=(DBEF_FIRST|DBEF_READ|DBEF_SENT|DBEF_RTL|DBEF_UTF);
}
if (!(dbeOld.flags&(DBEF_READ|DBEF_SENT))) {
- if (opts.bMarkRead) dbeOld.flags|=DBEF_READ;
+ if (cb->bMarkRead) dbeOld.flags|=DBEF_READ;
else if (ofsFirstUnread == 0) {
if (dbc->ofsFirstUnreadEvent != ofsThisEvent || dbc->timestampFirstUnread != dbeOld.timestamp)
- AddToStatus(STATUS_WARNING,TranslateT("First unread event marked wrong: fixing"));
+ cb->pfnAddLogMessage(STATUS_WARNING,TranslateT("First unread event marked wrong: fixing"));
isUnread = 1;
} }
if (dbeOld.cbBlob>1024*1024 || dbeOld.cbBlob == 0) {
- AddToStatus(STATUS_ERROR,TranslateT("Infeasibly large event blob: skipping"));
+ cb->pfnAddLogMessage(STATUS_ERROR,TranslateT("Infeasibly large event blob: skipping"));
ofsThisEvent = dbeOld.ofsNext;
return ERROR_SUCCESS;
}
@@ -217,13 +217,13 @@ int WorkEventChain(DWORD ofsContact,DBContact *dbc,int firstTime)
}
if (!firstTime && dbeOld.ofsPrev != ofsPrevEvent)
- AddToStatus(STATUS_WARNING,TranslateT("Event not backlinked correctly: fixing"));
+ cb->pfnAddLogMessage(STATUS_WARNING,TranslateT("Event not backlinked correctly: fixing"));
dbeNew->flags = dbeOld.flags;
dbeNew->ofsPrev = ofsDestPrevEvent;
dbeNew->ofsNext = 0;
- if (dbeOld.eventType == EVENTTYPE_MESSAGE && opts.bConvertUtf)
+ if (dbeOld.eventType == EVENTTYPE_MESSAGE && cb->bConvertUtf)
ConvertOldEvent(dbeNew);
if (dbePrev)
@@ -234,7 +234,7 @@ int WorkEventChain(DWORD ofsContact,DBContact *dbc,int firstTime)
(dbePrev->flags & DBEF_SENT) == (dbeNew->flags & DBEF_SENT) &&
!memcmp(dbePrev->blob, dbeNew->blob, dbeNew->cbBlob)
) {
- AddToStatus(STATUS_WARNING,TranslateT("Duplicate event was found: skipping"));
+ cb->pfnAddLogMessage(STATUS_WARNING,TranslateT("Duplicate event was found: skipping"));
if (dbc->eventCount)
dbc->eventCount--;
free(dbePrev);
@@ -251,9 +251,9 @@ int WorkEventChain(DWORD ofsContact,DBContact *dbc,int firstTime)
DBEvent dbeTmp;
DWORD ofsTmp;
- if (opts.bCheckOnly)
+ if (cb->bCheckOnly)
{
- if (!opts.bAggressive)
+ if (!cb->bAggressive)
{
ofsTmp = dbeOld.ofsPrev;
while(PeekSegment(ofsTmp,&dbeTmp,sizeof(dbeTmp)) == ERROR_SUCCESS)
@@ -269,7 +269,7 @@ int WorkEventChain(DWORD ofsContact,DBContact *dbc,int firstTime)
ofsTmp = dbeTmp.ofsPrev;
}
}
- AddToStatus(STATUS_WARNING,TranslateT("Event position in chain is not correct"));
+ cb->pfnAddLogMessage(STATUS_WARNING,TranslateT("Event position in chain is not correct"));
}
else
{
@@ -287,13 +287,13 @@ int WorkEventChain(DWORD ofsContact,DBContact *dbc,int firstTime)
ofsTmp = dbeTmp.ofsPrev;
}
if (found)
- AddToStatus(STATUS_WARNING,TranslateT("Event position in chain is not correct: fixing"));
+ cb->pfnAddLogMessage(STATUS_WARNING,TranslateT("Event position in chain is not correct: fixing"));
else
- AddToStatus(STATUS_WARNING,TranslateT("Event position in chain is not correct: unable to fix"));
+ cb->pfnAddLogMessage(STATUS_WARNING,TranslateT("Event position in chain is not correct: unable to fix"));
}
// insert before FIRST
- if (found == 1 && !opts.bCheckOnly) {
+ if (found == 1 && !cb->bCheckOnly) {
dbeNew->flags|=DBEF_FIRST;
dbeNew->ofsPrev = ofsContact;
dbeNew->ofsNext = dbc->ofsFirstEvent;
@@ -313,7 +313,7 @@ int WorkEventChain(DWORD ofsContact,DBContact *dbc,int firstTime)
dbeTmp.flags &=~DBEF_FIRST;
WriteSegment(dbeNew->ofsNext+offsetof(DBEvent,flags),&dbeTmp.flags,sizeof(DWORD));
}
- else if (found == 2 && !opts.bCheckOnly) {
+ else if (found == 2 && !cb->bCheckOnly) {
dbeNew->ofsPrev = ofsTmp;
dbeNew->ofsNext = dbeTmp.ofsNext;
diff --git a/plugins/Db3x_mmap/src/dbtool/finaltasks.cpp b/plugins/Db3x_mmap/src/dbtool/finaltasks.cpp
index 939fd680d1..a307c0b9fb 100644
--- a/plugins/Db3x_mmap/src/dbtool/finaltasks.cpp
+++ b/plugins/Db3x_mmap/src/dbtool/finaltasks.cpp
@@ -18,61 +18,25 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "..\commonheaders.h"
-extern int errorCount;
-
-int WorkFinalTasks(int firstTime)
+int CDb3Base::WorkFinalTasks(int firstTime)
{
FreeModuleChain();
- AddToStatus(STATUS_MESSAGE,TranslateT("Processing final tasks"));
- dbhdr.slackSpace = 0;
- if (WriteSegment(0,&dbhdr,sizeof(dbhdr)) == WS_ERROR)
+ cb->pfnAddLogMessage(STATUS_MESSAGE,TranslateT("Processing final tasks"));
+ m_dbHeader.slackSpace = 0;
+ if (WriteSegment(0,&m_dbHeader,sizeof(m_dbHeader)) == WS_ERROR)
return ERROR_WRITE_FAULT;
- if (opts.hFile) {
- CloseHandle(opts.hFile);
- opts.hFile = NULL;
- }
- if (opts.hOutFile) {
- CloseHandle(opts.hOutFile);
- opts.hOutFile = NULL;
- }
- if (opts.pFile) {
- UnmapViewOfFile(opts.pFile);
- opts.pFile = NULL;
- }
- if (opts.hMap) {
- CloseHandle(opts.hMap);
- opts.hMap = NULL;
+
+ if (m_hDbFile) {
+ CloseHandle(m_hDbFile);
+ m_hDbFile = NULL;
}
- if (errorCount && !opts.bBackup && !opts.bCheckOnly) {
- extern time_t ts;
- time_t dlg_ts = time(NULL);
- if (IDYES == MessageBox(NULL,
- TranslateT("Errors were encountered, however you selected not to backup the original database. It is strongly recommended that you do so in case important data was omitted. Do you wish to keep a backup of the original database?"),
- TranslateT("Miranda Database Tool"), MB_YESNO))
- opts.bBackup = 1;
- ts += time(NULL) - dlg_ts;
+ if (m_pDbCache) {
+ UnmapViewOfFile(m_pDbCache);
+ m_pDbCache = NULL;
}
- if (opts.bBackup) {
- int i;
- TCHAR dbPath[MAX_PATH],dbFile[MAX_PATH];
- _tcscpy(dbPath, opts.filename);
- TCHAR* str2 = _tcsrchr(dbPath, '\\');
- if (str2 != NULL) {
- _tcscpy(dbFile, str2+1);
- *str2 = 0;
- }
- else {
- _tcscpy(dbFile, dbPath);
- dbPath[0] = 0;
- }
- for(i = 1;;i++) {
- if (i == 1) wsprintf(opts.backupFilename,TranslateT("%s\\Backup of %s"),dbPath,dbFile);
- else wsprintf(opts.backupFilename,TranslateT("%s\\Backup (%d) of %s"),dbPath,i,dbFile);
- if (_taccess(opts.backupFilename,0) == -1) break;
- }
- MoveFile(opts.filename,opts.backupFilename) || AddToStatus(STATUS_WARNING,TranslateT("Unable to rename original file"));
+ if (m_hMap) {
+ CloseHandle(m_hMap);
+ m_hMap = NULL;
}
- else if (!opts.bCheckOnly) DeleteFile(opts.filename) || AddToStatus(STATUS_WARNING,TranslateT("Unable to delete original file"));
- if (!opts.bCheckOnly) MoveFile(opts.outputFilename,opts.filename) || AddToStatus(STATUS_WARNING,TranslateT("Unable to rename output file"));
return ERROR_NO_MORE_ITEMS;
}
diff --git a/plugins/Db3x_mmap/src/dbtool/initialchecks.cpp b/plugins/Db3x_mmap/src/dbtool/initialchecks.cpp
index 21ccff5976..5769eff84d 100644
--- a/plugins/Db3x_mmap/src/dbtool/initialchecks.cpp
+++ b/plugins/Db3x_mmap/src/dbtool/initialchecks.cpp
@@ -18,64 +18,49 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "..\commonheaders.h"
-extern DWORD sourceFileSize,spaceUsed;
+extern DBSignature dbSignature;
-int WorkInitialChecks(int firstTime)
+int CDb3Base::WorkInitialCheckHeaders()
{
- DWORD bytesRead;
-
- sourceFileSize = GetFileSize(opts.hFile,NULL);
- if (sourceFileSize == 0) {
- AddToStatus(STATUS_WARNING,TranslateT("Database is newly created and has no data to process"));
- AddToStatus(STATUS_SUCCESS,TranslateT("Processing completed successfully"));
- return ERROR_INVALID_DATA;
- }
- ReadFile(opts.hFile,&dbhdr,sizeof(dbhdr),&bytesRead,NULL);
- if (bytesRead<sizeof(dbhdr)) {
- AddToStatus(STATUS_FATAL,TranslateT("Database is corrupted and too small to contain any recoverable data"));
- return ERROR_BAD_FORMAT;
- }
- if (memcmp(dbhdr.signature,&dbSignature,sizeof(dbhdr.signature))) {
- AddToStatus(STATUS_FATAL,TranslateT("Database signature is corrupted, automatic repair is impossible"));
+ if (memcmp(m_dbHeader.signature, &dbSignature, sizeof(m_dbHeader.signature))) {
+ cb->pfnAddLogMessage(STATUS_FATAL,TranslateT("Database signature is corrupted, automatic repair is impossible"));
return ERROR_BAD_FORMAT;
}
- if (dbhdr.version != 0x00000700) {
- AddToStatus(STATUS_FATAL,TranslateT("Database is marked as belonging to an unknown version of Miranda"));
+ if (m_dbHeader.version != 0x00000700) {
+ cb->pfnAddLogMessage(STATUS_FATAL,TranslateT("Database is marked as belonging to an unknown version of Miranda"));
return ERROR_BAD_FORMAT;
}
- _tcscpy(opts.workingFilename,opts.filename);
+ return ERROR_SUCCESS;
+}
- if (opts.bCheckOnly) {
- _tcscpy(opts.outputFilename, TranslateT("<check only>"));
- opts.hOutFile = INVALID_HANDLE_VALUE;
- }
- else {
- _tcscpy(opts.outputFilename,opts.filename);
- *_tcsrchr(opts.outputFilename,'.') = 0;
- _tcscat(opts.outputFilename,TranslateT(" (Output).dat"));
- opts.hOutFile = CreateFile(opts.outputFilename,GENERIC_WRITE,FILE_SHARE_READ,NULL,CREATE_ALWAYS,FILE_FLAG_SEQUENTIAL_SCAN,NULL);
- if (opts.hOutFile == INVALID_HANDLE_VALUE) {
- AddToStatus(STATUS_FATAL,TranslateT("Can't create output file (%u)"),GetLastError());
- return ERROR_ACCESS_DENIED;
- }
+int CDb3Base::WorkInitialChecks(int firstTime)
+{
+ sourceFileSize = GetFileSize(m_hDbFile,NULL);
+ if (sourceFileSize == 0) {
+ cb->pfnAddLogMessage(STATUS_WARNING,TranslateT("Database is newly created and has no data to process"));
+ cb->pfnAddLogMessage(STATUS_SUCCESS,TranslateT("Processing completed successfully"));
+ return ERROR_INVALID_DATA;
}
- opts.hMap = CreateFileMapping(opts.hFile, NULL, opts.bAggressive?PAGE_WRITECOPY:PAGE_READONLY, 0, 0, NULL);
+ int res = WorkInitialCheckHeaders();
+ if (res)
+ return res;
- if (opts.hMap)
- opts.pFile = (BYTE*)MapViewOfFile(opts.hMap, opts.bAggressive?FILE_MAP_COPY:FILE_MAP_READ, 0, 0 ,0);
+ m_hMap = CreateFileMapping(m_hDbFile, NULL, cb->bAggressive?PAGE_WRITECOPY:PAGE_READONLY, 0, 0, NULL);
+ if (m_hMap)
+ m_pDbCache = (BYTE*)MapViewOfFile(m_hMap, cb->bAggressive?FILE_MAP_COPY:FILE_MAP_READ, 0, 0 ,0);
else {
- AddToStatus(STATUS_FATAL,TranslateT("Can't create file mapping (%u)"),GetLastError());
+ cb->pfnAddLogMessage(STATUS_FATAL,TranslateT("Can't create file mapping (%u)"),GetLastError());
return ERROR_ACCESS_DENIED;
}
- if (!opts.pFile) {
- AddToStatus(STATUS_FATAL,TranslateT("Can't create map view of file (%u)"),GetLastError());
+ if (!m_pDbCache) {
+ cb->pfnAddLogMessage(STATUS_FATAL,TranslateT("Can't create map view of file (%u)"),GetLastError());
return ERROR_ACCESS_DENIED;
}
- if (ReadSegment(0,&dbhdr,sizeof(dbhdr)) != ERROR_SUCCESS) return ERROR_READ_FAULT;
- if (WriteSegment(0,&dbhdr,sizeof(dbhdr)) == WS_ERROR) return ERROR_HANDLE_DISK_FULL;
- spaceUsed = dbhdr.ofsFileEnd-dbhdr.slackSpace;
- dbhdr.ofsFileEnd = sizeof(dbhdr);
+ if (ReadSegment(0,&m_dbHeader,sizeof(m_dbHeader)) != ERROR_SUCCESS) return ERROR_READ_FAULT;
+ if (WriteSegment(0,&m_dbHeader,sizeof(m_dbHeader)) == WS_ERROR) return ERROR_HANDLE_DISK_FULL;
+ cb->spaceUsed = m_dbHeader.ofsFileEnd-m_dbHeader.slackSpace;
+ m_dbHeader.ofsFileEnd = sizeof(m_dbHeader);
return ERROR_NO_MORE_ITEMS;
}
diff --git a/plugins/Db3x_mmap/src/dbtool/modulechain.cpp b/plugins/Db3x_mmap/src/dbtool/modulechain.cpp
index f53f63c469..56d784bcfb 100644
--- a/plugins/Db3x_mmap/src/dbtool/modulechain.cpp
+++ b/plugins/Db3x_mmap/src/dbtool/modulechain.cpp
@@ -16,6 +16,7 @@ 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"
struct ModChainEntry {
@@ -29,18 +30,18 @@ static int phase,iCurrentModName;
static DWORD ofsLast;
static int last_mod = 0;
-int WorkModuleChain(int firstTime)
+int CDb3Base::WorkModuleChain(int firstTime)
{
DBModuleName moduleName,*newModName;
if (firstTime) {
- AddToStatus(STATUS_MESSAGE,TranslateT("Processing module name chain"));
+ cb->pfnAddLogMessage(STATUS_MESSAGE,TranslateT("Processing module name chain"));
modChainCount = 0;
last_mod = 0;
if (modChain != NULL) free(modChain);
modChain = (ModChainEntry*)malloc(sizeof(ModChainEntry));
phase = 0;
- ofsCurrent = dbhdr.ofsFirstModuleName;
+ ofsCurrent = m_dbHeader.ofsFirstModuleName;
}
switch(phase) {
case 0:
@@ -49,7 +50,7 @@ int WorkModuleChain(int firstTime)
return ERROR_SUCCESS;
}
if (!SignatureValid(ofsCurrent,DBMODULENAME_SIGNATURE)) {
- AddToStatus(STATUS_ERROR,TranslateT("Module chain corrupted, further entries ignored"));
+ cb->pfnAddLogMessage(STATUS_ERROR,TranslateT("Module chain corrupted, further entries ignored"));
phase++;
return ERROR_SUCCESS;
}
@@ -58,7 +59,7 @@ int WorkModuleChain(int firstTime)
return ERROR_SUCCESS;
}
if (moduleName.cbName>256)
- AddToStatus(STATUS_WARNING,TranslateT("Unreasonably long module name, skipping"));
+ cb->pfnAddLogMessage(STATUS_WARNING,TranslateT("Unreasonably long module name, skipping"));
else {
modChain = (ModChainEntry*)realloc(modChain,sizeof(ModChainEntry)*++modChainCount);
@@ -75,7 +76,7 @@ int WorkModuleChain(int firstTime)
case 1:
ofsLast = 0;
iCurrentModName = 0;
- dbhdr.ofsFirstModuleName = 0;
+ m_dbHeader.ofsFirstModuleName = 0;
phase++;
case 2:
if (iCurrentModName >= modChainCount) {
@@ -91,7 +92,7 @@ int WorkModuleChain(int firstTime)
return ERROR_HANDLE_DISK_FULL;
{ // check duplicated modulenames
int i, n = 0;
- for(i = iCurrentModName+1;i<modChainCount;i++)
+ for (i = iCurrentModName+1;i<modChainCount;i++)
if (!strcmp(modChain[i].name, modChain[iCurrentModName].name)) {
modChain[i].ofsNew = modChain[iCurrentModName].ofsNew;
n++;
@@ -103,11 +104,11 @@ int WorkModuleChain(int firstTime)
MultiByteToWideChar(CP_ACP, 0, modChain[iCurrentModName].name, -1, szModuleName, sizeof(szModuleName) / sizeof(TCHAR));
pszModuleName = szModuleName;
- AddToStatus(STATUS_WARNING,TranslateT("Module name '%s' is not unique: %d duplicates found)"), pszModuleName, n);
+ cb->pfnAddLogMessage(STATUS_WARNING,TranslateT("Module name '%s' is not unique: %d duplicates found)"), pszModuleName, n);
}
}
if (iCurrentModName == 0)
- dbhdr.ofsFirstModuleName = modChain[iCurrentModName].ofsNew;
+ m_dbHeader.ofsFirstModuleName = modChain[iCurrentModName].ofsNew;
else
if (WriteSegment(ofsLast+offsetof(DBModuleName,ofsNext),&modChain[iCurrentModName].ofsNew,sizeof(DWORD)) == WS_ERROR)
return ERROR_HANDLE_DISK_FULL;
@@ -119,24 +120,24 @@ int WorkModuleChain(int firstTime)
return ERROR_SUCCESS;
}
-DWORD ConvertModuleNameOfs(DWORD ofsOld)
+DWORD CDb3Base::ConvertModuleNameOfs(DWORD ofsOld)
{
int i;
if (modChain[last_mod].ofsOld == ofsOld)
return modChain[last_mod].ofsNew;
- for(i = 0;i<modChainCount;i++)
+ for (i = 0;i<modChainCount;i++)
if (modChain[i].ofsOld == ofsOld) {
last_mod = i;
return modChain[last_mod].ofsNew;
}
- AddToStatus(STATUS_ERROR,TranslateT("Invalid module name offset, skipping data"));
+ cb->pfnAddLogMessage(STATUS_ERROR,TranslateT("Invalid module name offset, skipping data"));
return 0;
}
-void FreeModuleChain()
+void CDb3Base::FreeModuleChain()
{
if (modChain != NULL) {
free(modChain);
diff --git a/plugins/Db3x_mmap/src/dbtool/settingschain.cpp b/plugins/Db3x_mmap/src/dbtool/settingschain.cpp
index a2bfc48482..aaa52d9e22 100644
--- a/plugins/Db3x_mmap/src/dbtool/settingschain.cpp
+++ b/plugins/Db3x_mmap/src/dbtool/settingschain.cpp
@@ -16,11 +16,12 @@ 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"
static DWORD ofsThisSettings,ofsDestPrevSettings;
-int WorkSettingsChain(DWORD ofsContact,DBContact *dbc,int firstTime)
+int CDb3Base::WorkSettingsChain(DWORD ofsContact,DBContact *dbc,int firstTime)
{
DBContactSettings *dbcsNew,dbcsOld;
DWORD ofsDestThis;
@@ -33,14 +34,15 @@ int WorkSettingsChain(DWORD ofsContact,DBContact *dbc,int firstTime)
}
if (ofsThisSettings == 0)
return ERROR_NO_MORE_ITEMS;
+
if (!SignatureValid(ofsThisSettings,DBCONTACTSETTINGS_SIGNATURE)) {
- AddToStatus(STATUS_ERROR,TranslateT("Settings chain corrupted, further entries ignored"));
+ cb->pfnAddLogMessage(STATUS_ERROR,TranslateT("Settings chain corrupted, further entries ignored"));
return ERROR_NO_MORE_ITEMS;
}
if (PeekSegment(ofsThisSettings,&dbcsOld,sizeof(dbcsOld)) != ERROR_SUCCESS)
return ERROR_NO_MORE_ITEMS;
if (dbcsOld.cbBlob>256*1024 || dbcsOld.cbBlob == 0) {
- AddToStatus(STATUS_ERROR,TranslateT("Infeasibly large settings blob: skipping"));
+ cb->pfnAddLogMessage(STATUS_ERROR,TranslateT("Infeasibly large settings blob: skipping"));
ofsThisSettings = dbcsOld.ofsNext;
return ERROR_SUCCESS;
}
@@ -55,7 +57,7 @@ int WorkSettingsChain(DWORD ofsContact,DBContact *dbc,int firstTime)
return ERROR_SUCCESS;
}
if (dbcsNew->blob[0] == 0) {
- AddToStatus(STATUS_MESSAGE,TranslateT("Empty settings group at %08X: skipping"),ofsThisSettings);
+ cb->pfnAddLogMessage(STATUS_MESSAGE,TranslateT("Empty settings group at %08X: skipping"),ofsThisSettings);
ofsThisSettings = dbcsOld.ofsNext;
return ERROR_SUCCESS;
}
diff --git a/plugins/Db3x_mmap/src/dbtool/user.cpp b/plugins/Db3x_mmap/src/dbtool/user.cpp
index d61add09d4..ac200d2409 100644
--- a/plugins/Db3x_mmap/src/dbtool/user.cpp
+++ b/plugins/Db3x_mmap/src/dbtool/user.cpp
@@ -16,56 +16,59 @@ 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"
static DBContact user;
static int phase;
static DWORD ofsUser;
-int WorkSettingsChain(DWORD ofsContact,DBContact *dbc,int firstTime);
-int WorkEventChain(DWORD ofsContact,DBContact *dbc,int firstTime);
-
-int WorkUser(int firstTime)
+int CDb3Base::WorkUser(int firstTime)
{
int first = 0;
if (firstTime) {
- AddToStatus(STATUS_MESSAGE,TranslateT("Processing user data"));
- if (!SignatureValid(dbhdr.ofsUser,DBCONTACT_SIGNATURE)) {
- AddToStatus(STATUS_ERROR,TranslateT("User corrupted, this could cause major problems"));
+ cb->pfnAddLogMessage(STATUS_MESSAGE,TranslateT("Processing user data"));
+ if ( !SignatureValid(m_dbHeader.ofsUser, DBCONTACT_SIGNATURE)) {
+ cb->pfnAddLogMessage(STATUS_ERROR,TranslateT("User corrupted, this could cause major problems"));
return ERROR_NO_MORE_ITEMS;
}
- if (ReadSegment(dbhdr.ofsUser,&user,sizeof(DBContact)) != ERROR_SUCCESS)
+
+ if ( ReadSegment(m_dbHeader.ofsUser,&user,sizeof(DBContact)) != ERROR_SUCCESS)
return ERROR_NO_MORE_ITEMS;
+
if (user.ofsNext) {
- AddToStatus(STATUS_WARNING,TranslateT("More than one user contact: keeping only first"));
+ cb->pfnAddLogMessage(STATUS_WARNING,TranslateT("More than one user contact: keeping only first"));
user.ofsNext = 0;
}
+
if ((ofsUser = WriteSegment(WSOFS_END,&user,sizeof(DBContact))) == WS_ERROR)
return ERROR_HANDLE_DISK_FULL;
- dbhdr.ofsUser = ofsUser;
+
+ m_dbHeader.ofsUser = ofsUser;
phase = 0;
first = 1;
}
+
+ int ret;
switch(phase) {
- int ret;
+ case 0:
+ ret = WorkSettingsChain(ofsUser,&user,first);
+ if (ret == ERROR_NO_MORE_ITEMS) {
+ phase++; first = 1;
+ }
+ else if (ret) return ret;
+ else break;
- case 0:
- ret = WorkSettingsChain(ofsUser,&user,first);
- if (ret == ERROR_NO_MORE_ITEMS) {
- phase++; first = 1;
- }
- else if (ret) return ret;
- else break;
- case 1:
- ret = WorkEventChain(ofsUser,&user,first);
- if (ret == ERROR_NO_MORE_ITEMS) {
- if (WriteSegment(ofsUser,&user,sizeof(DBContact)) == WS_ERROR)
- return ERROR_HANDLE_DISK_FULL;
- return ERROR_NO_MORE_ITEMS;
- }
- else if (ret) return ret;
- break;
+ case 1:
+ ret = WorkEventChain(ofsUser,&user,first);
+ if (ret == ERROR_NO_MORE_ITEMS) {
+ if (WriteSegment(ofsUser,&user,sizeof(DBContact)) == WS_ERROR)
+ return ERROR_HANDLE_DISK_FULL;
+ return ERROR_NO_MORE_ITEMS;
+ }
+ else if (ret) return ret;
+ break;
}
return ERROR_SUCCESS;
-} \ No newline at end of file
+}