diff options
author | George Hazan <george.hazan@gmail.com> | 2013-11-25 19:54:47 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2013-11-25 19:54:47 +0000 |
commit | e4c1b5ae00efaa470a4b41953656ff059d0fd87d (patch) | |
tree | 1dd416290ae1b9d58ac1da84b8462fcf8e3506da /plugins/Db3x_mmap | |
parent | 1b44de1b140c2155dde5c42172e4d9df2d43e843 (diff) |
unique signature for the new mmap profile format
git-svn-id: http://svn.miranda-ng.org/main/trunk@6983 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Db3x_mmap')
-rw-r--r-- | plugins/Db3x_mmap/src/commonheaders.h | 2 | ||||
-rw-r--r-- | plugins/Db3x_mmap/src/dbheaders.cpp | 3 | ||||
-rw-r--r-- | plugins/Db3x_mmap/src/dbintf.cpp | 17 | ||||
-rw-r--r-- | plugins/Db3x_mmap/src/dbsettings.cpp | 22 | ||||
-rw-r--r-- | plugins/Db3x_mmap/src/dbtool/initialchecks.cpp | 16 |
5 files changed, 33 insertions, 27 deletions
diff --git a/plugins/Db3x_mmap/src/commonheaders.h b/plugins/Db3x_mmap/src/commonheaders.h index 811535f4d2..bb31a01615 100644 --- a/plugins/Db3x_mmap/src/commonheaders.h +++ b/plugins/Db3x_mmap/src/commonheaders.h @@ -42,7 +42,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "version.h"
extern LIST<CDb3Mmap> g_Dbs;
-extern DBSignature dbSignature, dbSignatureSA;
+extern DBSignature dbSignature, dbSignatureIM, dbSignatureSA;
#ifdef __GNUC__
#define mir_i64(x) (x##LL)
diff --git a/plugins/Db3x_mmap/src/dbheaders.cpp b/plugins/Db3x_mmap/src/dbheaders.cpp index 2a703a97d3..5fe77eb0ba 100644 --- a/plugins/Db3x_mmap/src/dbheaders.cpp +++ b/plugins/Db3x_mmap/src/dbheaders.cpp @@ -54,7 +54,8 @@ int CDb3Base::CreateDbHeaders(const DBSignature& _sign) int CDb3Base::CheckDbHeaders()
{
- if (memcmp(m_dbHeader.signature, &dbSignature, sizeof(m_dbHeader.signature)) &&
+ if (memcmp(m_dbHeader.signature, &dbSignature, sizeof(m_dbHeader.signature)) &&
+ memcmp(m_dbHeader.signature, &dbSignatureIM, sizeof(m_dbHeader.signature)) &&
memcmp(m_dbHeader.signature, &dbSignatureSA, sizeof(m_dbHeader.signature)))
return EGROKPRF_UNKHEADER;
diff --git a/plugins/Db3x_mmap/src/dbintf.cpp b/plugins/Db3x_mmap/src/dbintf.cpp index 77df014472..3263c5e8ea 100644 --- a/plugins/Db3x_mmap/src/dbintf.cpp +++ b/plugins/Db3x_mmap/src/dbintf.cpp @@ -23,17 +23,18 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "commonheaders.h"
-DBSignature dbSignature = { "Miranda ICQ DB", 0x1A };
+DBSignature dbSignature = { "Miranda NG DBu", 0x1A };
+DBSignature dbSignatureIM = { "Miranda ICQ DB", 0x1A };
DBSignature dbSignatureSA = { "Miranda ICQ SA", 0x1A };
-static int ModCompare(const ModuleName *mn1, const ModuleName *mn2 )
+static int ModCompare(const ModuleName *mn1, const ModuleName *mn2)
{
- return strcmp( mn1->name, mn2->name );
+ return strcmp(mn1->name, mn2->name);
}
-static int OfsCompare(const ModuleName *mn1, const ModuleName *mn2 )
+static int OfsCompare(const ModuleName *mn1, const ModuleName *mn2)
{
- return ( mn1->ofs - mn2->ofs );
+ return (mn1->ofs - mn2->ofs);
}
static int stringCompare2(const char *p1, const char *p2)
@@ -118,12 +119,12 @@ int CDb3Base::Load(bool bSkipInit) if ( m_hDbFile == INVALID_HANDLE_VALUE )
return EGROKPRF_CANTREAD;
- if ( !ReadFile(m_hDbFile,&m_dbHeader,sizeof(m_dbHeader),&dummy,NULL)) {
+ if (!ReadFile(m_hDbFile, &m_dbHeader, sizeof(m_dbHeader), &dummy, NULL)) {
CloseHandle(m_hDbFile);
return EGROKPRF_CANTREAD;
}
- if ( !bSkipInit) {
+ if (!bSkipInit) {
if (InitCache()) return 1;
if (InitModuleNames()) return 1;
if (InitCrypt()) return 1;
@@ -144,7 +145,7 @@ int CDb3Base::Load(bool bSkipInit) int CDb3Base::Create()
{
m_hDbFile = CreateFile(m_tszProfileName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, 0, NULL);
- return ( m_hDbFile == INVALID_HANDLE_VALUE );
+ return (m_hDbFile == INVALID_HANDLE_VALUE);
}
STDMETHODIMP_(void) CDb3Base::SetCacheSafetyMode(BOOL bIsSet)
diff --git a/plugins/Db3x_mmap/src/dbsettings.cpp b/plugins/Db3x_mmap/src/dbsettings.cpp index 45e9c5fa82..eafc619f0c 100644 --- a/plugins/Db3x_mmap/src/dbsettings.cpp +++ b/plugins/Db3x_mmap/src/dbsettings.cpp @@ -475,7 +475,7 @@ STDMETHODIMP_(BOOL) CDb3Base::WriteContactSetting(HANDLE hContact, DBCONTACTWRIT }
else bytesRequired = tmp.value.type;
bytesRequired += 2 + settingNameLen;
- bytesRequired += (DB_SETTINGS_RESIZE_GRANULARITY - (bytesRequired%DB_SETTINGS_RESIZE_GRANULARITY)) % DB_SETTINGS_RESIZE_GRANULARITY;
+ bytesRequired += (DB_SETTINGS_RESIZE_GRANULARITY - (bytesRequired % DB_SETTINGS_RESIZE_GRANULARITY)) % DB_SETTINGS_RESIZE_GRANULARITY;
ofsSettingsGroup = CreateNewSpace(bytesRequired + offsetof(DBContactSettings, blob));
dbcs.signature = DBCONTACTSETTINGS_SIGNATURE;
dbcs.ofsNext = dbc.ofsFirstSettings;
@@ -612,22 +612,20 @@ STDMETHODIMP_(BOOL) CDb3Base::WriteContactSetting(HANDLE hContact, DBCONTACTWRIT case DBVT_BYTE: DBWrite(ofsBlobPtr, &tmp.value.bVal, 1); MoveAlong(1); break;
case DBVT_WORD: DBWrite(ofsBlobPtr, &tmp.value.wVal, 2); MoveAlong(2); break;
case DBVT_DWORD: DBWrite(ofsBlobPtr, &tmp.value.dVal, 4); MoveAlong(4); break;
- case DBVT_UTF8:
- case DBVT_ASCIIZ:
- {
- int len = (int)strlen(tmp.value.pszVal);
- if (bIsEncrypted)
- EncodeString(tmp.value.pszVal);
- DBWrite(ofsBlobPtr, &len, 2);
- DBWrite(ofsBlobPtr + 2, tmp.value.pszVal, len); // encode
- MoveAlong(2 + len);
- }
- break;
case DBVT_BLOB:
DBWrite(ofsBlobPtr, &tmp.value.cpbVal, 2);
DBWrite(ofsBlobPtr + 2, tmp.value.pbVal, tmp.value.cpbVal); // encode
MoveAlong(2 + tmp.value.cpbVal);
break;
+ case DBVT_UTF8:
+ case DBVT_ASCIIZ:
+ int len = (int)strlen(tmp.value.pszVal);
+ if (bIsEncrypted)
+ EncodeString(tmp.value.pszVal);
+ DBWrite(ofsBlobPtr, &len, 2);
+ DBWrite(ofsBlobPtr + 2, tmp.value.pszVal, len); // encode
+ MoveAlong(2 + len);
+ break;
}
BYTE zero = 0;
diff --git a/plugins/Db3x_mmap/src/dbtool/initialchecks.cpp b/plugins/Db3x_mmap/src/dbtool/initialchecks.cpp index ee3c1fe729..2b199312cf 100644 --- a/plugins/Db3x_mmap/src/dbtool/initialchecks.cpp +++ b/plugins/Db3x_mmap/src/dbtool/initialchecks.cpp @@ -20,7 +20,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. int CDb3Base::WorkInitialCheckHeaders()
{
- if (memcmp(m_dbHeader.signature, &dbSignature, sizeof(m_dbHeader.signature))) {
+ if (memcmp(m_dbHeader.signature, &dbSignature, sizeof(m_dbHeader.signature)) &&
+ memcmp(m_dbHeader.signature, &dbSignatureIM, sizeof(m_dbHeader.signature)))
+ {
cb->pfnAddLogMessage(STATUS_FATAL,TranslateT("Database signature is corrupted, automatic repair is impossible"));
return ERROR_BAD_FORMAT;
}
@@ -44,9 +46,9 @@ int CDb3Base::WorkInitialChecks(int firstTime) if (res)
return res;
- m_hMap = CreateFileMapping(m_hDbFile, NULL, cb->bAggressive?PAGE_WRITECOPY:PAGE_READONLY, 0, 0, NULL);
+ 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);
+ m_pDbCache = (BYTE*)MapViewOfFile(m_hMap, cb->bAggressive ? FILE_MAP_COPY : FILE_MAP_READ, 0, 0, 0);
else {
cb->pfnAddLogMessage(STATUS_FATAL,TranslateT("Can't create file mapping (%u)"),GetLastError());
return ERROR_ACCESS_DENIED;
@@ -56,8 +58,12 @@ int CDb3Base::WorkInitialChecks(int firstTime) cb->pfnAddLogMessage(STATUS_FATAL,TranslateT("Can't create map view of file (%u)"),GetLastError());
return ERROR_ACCESS_DENIED;
}
- 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;
+ 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;
|