summaryrefslogtreecommitdiff
path: root/plugins/Db3x_mmap
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/Db3x_mmap')
-rw-r--r--plugins/Db3x_mmap/src/dbcache.cpp12
-rw-r--r--plugins/Db3x_mmap/src/dbintf.cpp14
-rw-r--r--plugins/Db3x_mmap/src/dbintf.h2
-rw-r--r--plugins/Db3x_mmap/src/init.cpp10
4 files changed, 26 insertions, 12 deletions
diff --git a/plugins/Db3x_mmap/src/dbcache.cpp b/plugins/Db3x_mmap/src/dbcache.cpp
index 76126f7885..f047af0a1b 100644
--- a/plugins/Db3x_mmap/src/dbcache.cpp
+++ b/plugins/Db3x_mmap/src/dbcache.cpp
@@ -25,9 +25,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
void CDb3Base::Map()
{
- m_hMap = CreateFileMapping(m_hDbFile, NULL, PAGE_READWRITE, 0, m_dwFileSize, NULL);
+ m_hMap = CreateFileMapping(m_hDbFile, NULL, (m_bReadOnly) ? PAGE_WRITECOPY : PAGE_READWRITE, 0, m_dwFileSize, NULL);
if (m_hMap) {
- m_pDbCache = (PBYTE)MapViewOfFile(m_hMap, FILE_MAP_ALL_ACCESS/*FILE_MAP_WRITE*/, 0, 0 ,0);
+ m_pDbCache = (PBYTE)MapViewOfFile(m_hMap, (m_bReadOnly) ? FILE_MAP_COPY : FILE_MAP_ALL_ACCESS, 0, 0, 0);
if (!m_pDbCache)
DatabaseCorruption( _T("%s (MapViewOfFile failed. Code: %d)"));
}
@@ -156,9 +156,11 @@ int CDb3Base::InitCache(void)
m_dwFileSize = GetFileSize(m_hDbFile, NULL);
// Align to chunk
- DWORD x = m_dwFileSize % m_ChunkSize;
- if (x)
- m_dwFileSize += m_ChunkSize - x;
+ if (!m_bReadOnly) {
+ DWORD x = m_dwFileSize % m_ChunkSize;
+ if (x)
+ m_dwFileSize += m_ChunkSize - x;
+ }
Map();
diff --git a/plugins/Db3x_mmap/src/dbintf.cpp b/plugins/Db3x_mmap/src/dbintf.cpp
index 549f32d357..a3fbb8a62e 100644
--- a/plugins/Db3x_mmap/src/dbintf.cpp
+++ b/plugins/Db3x_mmap/src/dbintf.cpp
@@ -190,6 +190,20 @@ static CheckWorker Workers[6] =
&CDb3Base::WorkFinalTasks
};
+int CDb3Mmap::PrepareCheck()
+{
+ int ret = CheckDbHeaders();
+ if (ret != ERROR_SUCCESS)
+ return ret;
+
+ InitCache();
+ InitModuleNames();
+ if ((ret = InitCrypt()) != ERROR_SUCCESS)
+ return ret;
+
+ return ERROR_SUCCESS;
+}
+
int CDb3Base::Start(DBCHeckCallback *callback)
{
cb = callback;
diff --git a/plugins/Db3x_mmap/src/dbintf.h b/plugins/Db3x_mmap/src/dbintf.h
index 4103d2c02c..32bda67466 100644
--- a/plugins/Db3x_mmap/src/dbintf.h
+++ b/plugins/Db3x_mmap/src/dbintf.h
@@ -333,6 +333,8 @@ struct CDb3Mmap : public CDb3Base
void SetPassword(const TCHAR *ptszPassword);
void UpdateMenuItem(void);
+ int PrepareCheck(void);
+
__forceinline LPSTR GetMenuTitle() const { return m_bUsesPassword ? LPGEN("Change/remove password") : LPGEN("Set password"); }
protected:
diff --git a/plugins/Db3x_mmap/src/init.cpp b/plugins/Db3x_mmap/src/init.cpp
index 4938ae9cba..e9810fabe4 100644
--- a/plugins/Db3x_mmap/src/init.cpp
+++ b/plugins/Db3x_mmap/src/init.cpp
@@ -72,7 +72,7 @@ static MIDatabase* LoadDatabase(const TCHAR *profile)
// set the memory, lists & UTF8 manager
mir_getLP( &pluginInfo );
- std::auto_ptr<CDb3Mmap> db( new CDb3Mmap(profile));
+ std::auto_ptr<CDb3Mmap> db(new CDb3Mmap(profile));
if (db->Load(false) != ERROR_SUCCESS)
return NULL;
@@ -90,18 +90,14 @@ static int UnloadDatabase(MIDatabase* db)
MIDatabaseChecker* CheckDb(const TCHAR* profile, int *error)
{
std::auto_ptr<CDb3Mmap> db(new CDb3Mmap(profile));
- if (db->Load(false) != ERROR_SUCCESS) {
+ if (db->Load(true) != ERROR_SUCCESS) {
*error = EGROKPRF_CANTREAD;
return NULL;
}
- int chk = db->CheckDbHeaders();
- if (chk != ERROR_SUCCESS) {
- *error = chk;
+ if (*error = db->PrepareCheck())
return NULL;
- }
- *error = 0;
return db.release();
}