diff options
-rw-r--r-- | plugins/Db3x_mmap/src/dbintf.cpp | 24 | ||||
-rw-r--r-- | plugins/Db3x_mmap/src/dbintf.h | 7 | ||||
-rw-r--r-- | plugins/Db3x_mmap/src/init.cpp | 10 | ||||
-rw-r--r-- | plugins/Db3x_mmap/src/version.h | 2 | ||||
-rw-r--r-- | plugins/DbChecker/src/selectdb.cpp | 25 | ||||
-rw-r--r-- | plugins/DbChecker/src/version.h | 16 |
6 files changed, 55 insertions, 29 deletions
diff --git a/plugins/Db3x_mmap/src/dbintf.cpp b/plugins/Db3x_mmap/src/dbintf.cpp index 888d47e1d3..0e2187e993 100644 --- a/plugins/Db3x_mmap/src/dbintf.cpp +++ b/plugins/Db3x_mmap/src/dbintf.cpp @@ -43,10 +43,11 @@ static int stringCompare2(const char *p1, const char *p2) return strcmp(p1, p2);
}
-CDb3Mmap::CDb3Mmap(const TCHAR *tszFileName, bool bReadOnly) :
+CDb3Mmap::CDb3Mmap(const TCHAR *tszFileName, int iMode) :
m_hDbFile(INVALID_HANDLE_VALUE),
m_safetyMode(true),
- m_bReadOnly(bReadOnly),
+ m_bReadOnly((iMode & DBMODE_READONLY) != 0),
+ m_bShared((iMode & DBMODE_SHARED) != 0),
m_dwMaxContactId(1),
m_lMods(50, ModCompare),
m_lOfs(50, OfsCompare),
@@ -79,7 +80,7 @@ CDb3Mmap::~CDb3Mmap() }
DestroyServiceFunction(hService);
- UnhookEvent(hHook); + UnhookEvent(hHook);
if (m_crypto)
m_crypto->destroy();
@@ -93,7 +94,9 @@ CDb3Mmap::~CDb3Mmap() SetFilePointer(m_hDbFile, 0, NULL, FILE_BEGIN);
WriteFile(m_hDbFile, &dbSignatureIM, 1, &bytesWritten, NULL);
}
- CloseHandle(m_hDbFile);
+
+ if (m_hDbFile != INVALID_HANDLE_VALUE)
+ CloseHandle(m_hDbFile);
DestroyHookableEvent(hContactDeletedEvent);
DestroyHookableEvent(hContactAddedEvent);
@@ -118,13 +121,16 @@ static TCHAR szMsgConvert[] = int CDb3Mmap::Load(bool bSkipInit)
{
log0("DB logging running");
-
- DWORD dummy = 0;
+
+ DWORD dummy = 0, dwMode = FILE_SHARE_READ;
+ if (m_bShared)
+ dwMode |= FILE_SHARE_WRITE;
if (m_bReadOnly)
- m_hDbFile = CreateFile(m_tszProfileName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
+ m_hDbFile = CreateFile(m_tszProfileName, GENERIC_READ, dwMode, NULL, OPEN_EXISTING, 0, NULL);
else
- m_hDbFile = CreateFile(m_tszProfileName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, NULL);
- if ( m_hDbFile == INVALID_HANDLE_VALUE )
+ m_hDbFile = CreateFile(m_tszProfileName, GENERIC_READ | GENERIC_WRITE, dwMode, NULL, OPEN_ALWAYS, 0, NULL);
+
+ if (m_hDbFile == INVALID_HANDLE_VALUE)
return EGROKPRF_CANTREAD;
if (!ReadFile(m_hDbFile, &m_dbHeader, sizeof(m_dbHeader), &dummy, NULL)) {
diff --git a/plugins/Db3x_mmap/src/dbintf.h b/plugins/Db3x_mmap/src/dbintf.h index bc9bd220da..9582c928bb 100644 --- a/plugins/Db3x_mmap/src/dbintf.h +++ b/plugins/Db3x_mmap/src/dbintf.h @@ -44,6 +44,9 @@ DBHeader \--> ...
*/
+#define DBMODE_SHARED 0x0001
+#define DBMODE_READONLY 0x0002
+
#define DB_OLD_VERSION 0x00000700u
#define DB_094_VERSION 0x00000701u
#define DB_095_VERSION 0x00000800u
@@ -174,7 +177,7 @@ struct ConvertedContact struct CDb3Mmap : public MIDatabase, public MIDatabaseChecker, public MZeroedObject
{
- CDb3Mmap(const TCHAR *tszFileName, bool bReadOnly);
+ CDb3Mmap(const TCHAR *tszFileName, int mode);
~CDb3Mmap();
int Load(bool bSkipInit);
@@ -275,7 +278,7 @@ protected: HANDLE m_hDbFile;
DBHeader m_dbHeader;
DWORD m_ChunkSize;
- bool m_safetyMode, m_bReadOnly, m_bEncrypted, m_bUsesPassword;
+ bool m_safetyMode, m_bReadOnly, m_bShared, m_bEncrypted, m_bUsesPassword;
////////////////////////////////////////////////////////////////////////////
// database stuff
diff --git a/plugins/Db3x_mmap/src/init.cpp b/plugins/Db3x_mmap/src/init.cpp index d283f944cb..928ec0739f 100644 --- a/plugins/Db3x_mmap/src/init.cpp +++ b/plugins/Db3x_mmap/src/init.cpp @@ -49,7 +49,7 @@ LIST<CDb3Mmap> g_Dbs(1, HandleKeySortT); // returns 0 if the profile is created, EMKPRF*
static int makeDatabase(const TCHAR *profile)
{
- std::auto_ptr<CDb3Mmap> db(new CDb3Mmap(profile, false));
+ std::auto_ptr<CDb3Mmap> db(new CDb3Mmap(profile, 0));
if (db->Create() != ERROR_SUCCESS)
return EMKPRF_CREATEFAILED;
@@ -59,7 +59,7 @@ static int makeDatabase(const TCHAR *profile) // returns 0 if the given profile has a valid header
static int grokHeader(const TCHAR *profile)
{
- std::auto_ptr<CDb3Mmap> db(new CDb3Mmap(profile, true));
+ std::auto_ptr<CDb3Mmap> db(new CDb3Mmap(profile, DBMODE_SHARED | DBMODE_READONLY));
if (db->Load(true) != ERROR_SUCCESS)
return EGROKPRF_CANTREAD;
@@ -72,7 +72,7 @@ static MIDatabase* LoadDatabase(const TCHAR *profile, BOOL bReadOnly) // set the memory, lists & UTF8 manager
mir_getLP(&pluginInfo);
- std::auto_ptr<CDb3Mmap> db(new CDb3Mmap(profile, bReadOnly != 0));
+ std::auto_ptr<CDb3Mmap> db(new CDb3Mmap(profile, (bReadOnly) ? DBMODE_READONLY : 0));
if (db->Load(false) != ERROR_SUCCESS)
return NULL;
@@ -89,9 +89,9 @@ static int UnloadDatabase(MIDatabase *db) MIDatabaseChecker* CheckDb(const TCHAR *profile, int *error)
{
- std::auto_ptr<CDb3Mmap> db(new CDb3Mmap(profile, true));
+ std::auto_ptr<CDb3Mmap> db(new CDb3Mmap(profile, DBMODE_READONLY));
if (db->Load(true) != ERROR_SUCCESS) {
- *error = EGROKPRF_CANTREAD;
+ *error = ERROR_ACCESS_DENIED;
return NULL;
}
diff --git a/plugins/Db3x_mmap/src/version.h b/plugins/Db3x_mmap/src/version.h index 7e85a65adc..2f1eb214a5 100644 --- a/plugins/Db3x_mmap/src/version.h +++ b/plugins/Db3x_mmap/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0
#define __MINOR_VERSION 95
#define __RELEASE_NUM 0
-#define __BUILD_NUM 3
+#define __BUILD_NUM 4
#include <stdver.h>
diff --git a/plugins/DbChecker/src/selectdb.cpp b/plugins/DbChecker/src/selectdb.cpp index a92d72febc..32f2370077 100644 --- a/plugins/DbChecker/src/selectdb.cpp +++ b/plugins/DbChecker/src/selectdb.cpp @@ -18,6 +18,21 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "dbchecker.h"
+static bool CheckBroken(const TCHAR *ptszFullPath)
+{
+ DATABASELINK *dblink = FindDatabasePlugin(ptszFullPath);
+ if (dblink == NULL || dblink->CheckDB == NULL)
+ return true;
+
+ int error = 0;
+ MIDatabaseChecker *dbChecker = dblink->CheckDB(ptszFullPath, &error);
+ if (dbChecker == NULL)
+ return true;
+
+ dbChecker->Destroy();
+ return false;
+}
+
void OpenDatabase(HWND hdlg, INT iNextPage)
{
TCHAR tszMsg[1024];
@@ -43,7 +58,8 @@ LBL_Error: int error = 0;
opts.dbChecker = dblink->CheckDB(opts.filename, &error);
if (opts.dbChecker == NULL) {
- opts.error = error;
+ if ((opts.error = GetLastError()) == 0)
+ opts.error = error;
PostMessage(GetParent(hdlg), WZM_GOTOPAGE, IDD_OPENERROR, (LPARAM)OpenErrorDlgProc);
return;
}
@@ -86,10 +102,11 @@ static int AddDatabaseToList(HWND hwndList, const TCHAR* filename, TCHAR* dir) if ( _tstat(filename, &st) == -1)
return -1;
- int broken = 0;
DWORD totalSize = st.st_size;
DWORD wasted = 0;
+ bool isBroken = CheckBroken(filename);
+
const TCHAR *pName = _tcsrchr(filename, '\\');
if (pName == NULL)
pName = (LPTSTR)filename;
@@ -108,7 +125,7 @@ static int AddDatabaseToList(HWND hwndList, const TCHAR* filename, TCHAR* dir) lvi.iSubItem = 0;
lvi.lParam = (LPARAM)_tcsdup(filename);
lvi.pszText = szName;
- if (broken)
+ if (isBroken)
lvi.iImage = 3;
else if (wasted < 1024*128)
lvi.iImage = 0;
@@ -121,7 +138,7 @@ static int AddDatabaseToList(HWND hwndList, const TCHAR* filename, TCHAR* dir) TCHAR szSize[20];
mir_sntprintf(szSize, SIZEOF(szSize), _T("%.2lf MB"), totalSize / 1048576.0);
ListView_SetItemText(hwndList, iNewItem, 1, szSize);
- if (!broken) {
+ if (!isBroken) {
mir_sntprintf(szSize, SIZEOF(szSize), _T("%.2lf MB"), wasted / 1048576.0);
ListView_SetItemText(hwndList, iNewItem, 2, szSize);
}
diff --git a/plugins/DbChecker/src/version.h b/plugins/DbChecker/src/version.h index 5282ad490a..911e6fc2fa 100644 --- a/plugins/DbChecker/src/version.h +++ b/plugins/DbChecker/src/version.h @@ -1,14 +1,14 @@ -#define __MAJOR_VERSION 0
-#define __MINOR_VERSION 11
-#define __RELEASE_NUM 0
-#define __BUILD_NUM 1
+#define __MAJOR_VERSION 0
+#define __MINOR_VERSION 95
+#define __RELEASE_NUM 0
+#define __BUILD_NUM 2
#include <stdver.h>
#define __PLUGIN_NAME "Database checker"
#define __FILENAME "DbChecker.dll"
-#define __DESCRIPTION "Miranda NG Database Checker."
-#define __AUTHOR "George Hazan"
+#define __DESCRIPTION "Miranda NG Database Checker."
+#define __AUTHOR "George Hazan"
#define __AUTHOREMAIL "ghazan@miranda-ng.org"
-#define __AUTHORWEB "http://miranda-ng.org/p/DbChecker/"
-#define __COPYRIGHT "© 2012 George Hazan"
+#define __AUTHORWEB "http://miranda-ng.org/p/DbChecker/"
+#define __COPYRIGHT "© 2012-14 George Hazan"
|