summaryrefslogtreecommitdiff
path: root/plugins/Db3x/src/init.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2012-07-18 14:11:28 +0000
committerGeorge Hazan <george.hazan@gmail.com>2012-07-18 14:11:28 +0000
commit4bc88d46fa9859615521f436511d4f102f20eb67 (patch)
tree3a6ee91b74be2a4f5e60520885aa601c74bc3fa7 /plugins/Db3x/src/init.cpp
parent4f8f5427687792492ee49e06cafb9bd50cfc53d4 (diff)
databases are still static, but are controlled via classes
git-svn-id: http://svn.miranda-ng.org/main/trunk@1014 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Db3x/src/init.cpp')
-rw-r--r--plugins/Db3x/src/init.cpp49
1 files changed, 28 insertions, 21 deletions
diff --git a/plugins/Db3x/src/init.cpp b/plugins/Db3x/src/init.cpp
index f9b1269bda..b2b3f1fa72 100644
--- a/plugins/Db3x/src/init.cpp
+++ b/plugins/Db3x/src/init.cpp
@@ -25,7 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
int hLangpack;
-HINSTANCE g_hInst=NULL;
+HINSTANCE g_hInst = NULL;
static PLUGININFOEX pluginInfo = {
sizeof(PLUGININFOEX),
@@ -40,6 +40,8 @@ static PLUGININFOEX pluginInfo = {
{0x1394a3ab, 0x2585, 0x4196, { 0x8f, 0x72, 0xe, 0xae, 0xc2, 0x45, 0xe, 0x11 }} //{1394A3AB-2585-4196-8F72-0EAEC2450E11}
};
+CDdxMmap* g_Db = NULL;
+
/////////////////////////////////////////////////////////////////////////////////////////
static int getCapability( int flag )
@@ -48,43 +50,43 @@ static int getCapability( int flag )
}
// returns 0 if the profile is created, EMKPRF*
-static int makeDatabase(char * profile, int * error)
+static int makeDatabase(TCHAR *profile, int * error)
{
- HANDLE hFile=CreateFileA(profile, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
+ HANDLE hFile = CreateFile(profile, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
if ( hFile != INVALID_HANDLE_VALUE ) {
CreateDbHeaders(hFile);
CloseHandle(hFile);
return 0;
}
- if ( error != NULL ) *error=EMKPRF_CREATEFAILED;
+ if ( error != NULL ) *error = EMKPRF_CREATEFAILED;
return 1;
}
// returns 0 if the given profile has a valid header
-static int grokHeader( char * profile, int * error )
+static int grokHeader(TCHAR *profile, int * error )
{
- int rc=1;
- int chk=0;
+ int rc = 1;
+ int chk = 0;
struct DBHeader hdr;
HANDLE hFile = INVALID_HANDLE_VALUE;
- DWORD dummy=0;
+ DWORD dummy = 0;
- hFile = CreateFileA(profile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
+ hFile = CreateFile(profile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
if ( hFile == INVALID_HANDLE_VALUE ) {
- if ( error != NULL ) *error=EGROKPRF_CANTREAD;
+ if ( error != NULL ) *error = EGROKPRF_CANTREAD;
return 1;
}
// read the header, which can fail (for various reasons)
if ( !ReadFile(hFile, &hdr, sizeof(struct DBHeader), &dummy, NULL)) {
- if ( error != NULL) *error=EGROKPRF_CANTREAD;
+ if ( error != NULL) *error = EGROKPRF_CANTREAD;
CloseHandle(hFile);
return 1;
}
- chk=CheckDbHeaders(&hdr);
+ chk = CheckDbHeaders(&hdr);
if ( chk == 0 ) {
// all the internal tests passed, hurrah
- rc=0;
- if ( error != NULL ) *error=0;
+ rc = 0;
+ if ( error != NULL ) *error = 0;
} else {
// didn't pass at all, or some did.
switch ( chk ) {
@@ -97,13 +99,13 @@ static int grokHeader( char * profile, int * error )
case 2:
{
// header was present, but version information newer
- if ( error != NULL ) *error= EGROKPRF_VERNEWER;
+ if ( error != NULL ) *error = EGROKPRF_VERNEWER;
break;
}
case 3:
{
// header/version OK, internal data missing
- if ( error != NULL ) *error=EGROKPRF_DAMAGED;
+ if ( error != NULL ) *error = EGROKPRF_DAMAGED;
break;
}
} // switch
@@ -113,15 +115,20 @@ static int grokHeader( char * profile, int * error )
}
// returns 0 if all the APIs are injected otherwise, 1
-static int LoadDatabase( char* profile )
+static MIDatabase* LoadDatabase(TCHAR *profile)
{
+ if (g_Db) delete g_Db;
+ g_Db = new CDdxMmap(profile);
+
// don't need thread notifications
- strncpy(szDbPath, profile, sizeof(szDbPath));
+ _tcsncpy(szDbPath, profile, SIZEOF(szDbPath));
mir_getLP(&pluginInfo);
// inject all APIs and hooks into the core
- return LoadDatabaseModule();
+ LoadDatabaseModule();
+
+ return g_Db;
}
static int UnloadDatabase(int wasLoaded)
@@ -131,9 +138,9 @@ static int UnloadDatabase(int wasLoaded)
return 0;
}
-static int getFriendlyName( char * buf, size_t cch, int shortName )
+static int getFriendlyName( TCHAR *buf, size_t cch, int shortName )
{
- strncpy(buf,shortName ? "db3x driver" : "db3x database support",cch);
+ _tcsncpy(buf, shortName ? _T("db3x driver") : _T("db3x database support"), cch);
return 0;
}