diff options
author | George Hazan <george.hazan@gmail.com> | 2012-07-28 12:35:00 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2012-07-28 12:35:00 +0000 |
commit | a7001dfd139fbb9d5cf5434fc40370f8da0cf04c (patch) | |
tree | 844416b2bc429054557bda440e75f466f1e30bf7 /plugins/Dbx_mmap_SA/src | |
parent | d5defc979cd71a5f2bb5176382fa2f5f50f23d1b (diff) |
perversive error reporting schema in DATABASELINK removed
git-svn-id: http://svn.miranda-ng.org/main/trunk@1223 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Dbx_mmap_SA/src')
-rw-r--r-- | plugins/Dbx_mmap_SA/src/commonheaders.h | 1 | ||||
-rw-r--r-- | plugins/Dbx_mmap_SA/src/init.cpp | 77 |
2 files changed, 22 insertions, 56 deletions
diff --git a/plugins/Dbx_mmap_SA/src/commonheaders.h b/plugins/Dbx_mmap_SA/src/commonheaders.h index 27c7036adf..da38757088 100644 --- a/plugins/Dbx_mmap_SA/src/commonheaders.h +++ b/plugins/Dbx_mmap_SA/src/commonheaders.h @@ -43,6 +43,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include <string.h>
#include <direct.h>
#include <crtdbg.h>
+#include <memory>
//miranda headers
#include <newpluginapi.h>
diff --git a/plugins/Dbx_mmap_SA/src/init.cpp b/plugins/Dbx_mmap_SA/src/init.cpp index a59ae1bc09..f7d96822a8 100644 --- a/plugins/Dbx_mmap_SA/src/init.cpp +++ b/plugins/Dbx_mmap_SA/src/init.cpp @@ -49,56 +49,25 @@ LIST<CDdxMmapSA> g_Dbs(1, (LIST<CDdxMmapSA>::FTSortFunc)HandleKeySort); /////////////////////////////////////////////////////////////////////////////////////////
// returns 0 if the profile is created, EMKPRF*
-static int makeDatabase(const TCHAR *profile, int *error)
+static int makeDatabase(const TCHAR *profile)
{
- CDdxMmapSA *tmp = new CDdxMmapSA(profile);
- if (tmp->Create() == ERROR_SUCCESS) {
- tmp->CreateDbHeaders();
- delete tmp;
+ std::auto_ptr<CDdxMmapSA> db( new CDdxMmapSA(profile));
+ if (db->Create() == ERROR_SUCCESS) {
+ db->CreateDbHeaders();
return 0;
}
- delete tmp;
- if (error != NULL) *error = EMKPRF_CREATEFAILED;
- return 1;
+
+ return EMKPRF_CREATEFAILED;
}
// returns 0 if the given profile has a valid header
-static int grokHeader(const TCHAR *profile, int *error)
+static int grokHeader(const TCHAR *profile)
{
- CDdxMmapSA *tmp = new CDdxMmapSA(profile);
- if (tmp->Load(true) != ERROR_SUCCESS) {
- delete tmp;
- if (error != NULL) *error = EGROKPRF_CANTREAD;
- return 1;
- }
+ std::auto_ptr<CDdxMmapSA> db( new CDdxMmapSA(profile));
+ if (db->Load(true) != ERROR_SUCCESS)
+ return EGROKPRF_CANTREAD;
- int chk = tmp->CheckDbHeaders();
- delete tmp;
- if ( chk == 0 ) {
- // all the internal tests passed, hurrah
- if (error != NULL) *error = 0;
- return 0;
- }
-
- // didn't pass at all, or some did.
- switch ( chk ) {
- case 1:
- // "Miranda ICQ DB" wasn't present
- if (error != NULL) *error = EGROKPRF_UNKHEADER;
- break;
-
- case 2:
- // header was present, but version information newer
- if (error != NULL) *error = EGROKPRF_VERNEWER;
- break;
-
- case 3:
- // header/version OK, internal data missing
- if (error != NULL) *error = EGROKPRF_DAMAGED;
- break;
- }
-
- return 1;
+ return db->CheckDbHeaders();
}
// returns 0 if all the APIs are injected otherwise, 1
@@ -107,14 +76,12 @@ static MIDatabase* LoadDatabase(const TCHAR *profile) // set the memory, lists & UTF8 manager
mir_getLP( &pluginInfo );
- CDdxMmapSA* db = new CDdxMmapSA(profile);
- if (db->Load(false) != ERROR_SUCCESS) {
- delete db;
+ std::auto_ptr<CDdxMmapSA> db( new CDdxMmapSA(profile));
+ if (db->Load(false) != ERROR_SUCCESS)
return NULL;
- }
- g_Dbs.insert(db);
- return db;
+ g_Dbs.insert(db.get());
+ return db.release();
}
static int UnloadDatabase(MIDatabase* db)
@@ -124,24 +91,22 @@ static int UnloadDatabase(MIDatabase* db) return 0;
}
-MIDatabaseChecker* CheckDb(const TCHAR* ptszFileName, int *error)
+MIDatabaseChecker* CheckDb(const TCHAR* profile, int *error)
{
- CDdxMmapSA *tmp = new CDdxMmapSA(ptszFileName);
- if (tmp->Load(true) != ERROR_SUCCESS) {
- delete tmp;
- if (error != NULL) *error = EGROKPRF_CANTREAD;
+ std::auto_ptr<CDdxMmapSA> db( new CDdxMmapSA(profile));
+ if (db->Load(true) != ERROR_SUCCESS) {
+ *error = EGROKPRF_CANTREAD;
return NULL;
}
- int chk = tmp->CheckDbHeaders();
+ int chk = db->CheckDbHeaders();
if (chk != ERROR_SUCCESS) {
- delete tmp;
*error = chk;
return NULL;
}
*error = 0;
- return tmp;
+ return db.release();
}
static DATABASELINK dblink =
|