diff options
author | George Hazan <george.hazan@gmail.com> | 2014-01-26 15:22:35 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2014-01-26 15:22:35 +0000 |
commit | d0580040b51b6c4803e0f61863bd985c382370e9 (patch) | |
tree | fb9816ee0b889ec88694fbca29d7b2056320a3dc /plugins | |
parent | 1fb07e640abb626418980d241148b3fcba90998d (diff) |
fix for creating backup files in dbchecker
git-svn-id: http://svn.miranda-ng.org/main/trunk@7906 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/Db3x_mmap/src/dbcache.cpp | 12 | ||||
-rw-r--r-- | plugins/Db3x_mmap/src/dbintf.cpp | 14 | ||||
-rw-r--r-- | plugins/Db3x_mmap/src/dbintf.h | 2 | ||||
-rw-r--r-- | plugins/Db3x_mmap/src/init.cpp | 10 |
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();
}
|