From f3311cd7eb5e87b3718f763a3c08cd3764c84f51 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 28 Jul 2012 16:23:55 +0000 Subject: - added MS_DB_SETDEFAULTPROFILE service for the service plugins - added ability to call the service plugin before loading database - changed the core module modules' loading order git-svn-id: http://svn.miranda-ng.org/main/trunk@1225 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- src/modules/database/database.cpp | 37 ++++++++++++++++++++++++----------- src/modules/database/dbutils.cpp | 18 ++++++++++++----- src/modules/database/profilemanager.h | 2 -- 3 files changed, 39 insertions(+), 18 deletions(-) (limited to 'src/modules/database') diff --git a/src/modules/database/database.cpp b/src/modules/database/database.cpp index 24b220cd44..8aaa5b9ccc 100644 --- a/src/modules/database/database.cpp +++ b/src/modules/database/database.cpp @@ -27,6 +27,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern TCHAR mirandabootini[MAX_PATH]; bool dbCreated; TCHAR g_profileDir[MAX_PATH], g_profileName[MAX_PATH]; +TCHAR* g_defaultProfile; bool fileExist(TCHAR* fname) { @@ -129,14 +130,10 @@ static void getDefaultProfile(TCHAR *szProfile, size_t cch, TCHAR *profiledir) } // returns 1 if something that looks like a profile is there -void getProfileCmdLine(TCHAR *szProfile, size_t cch, TCHAR *profiledir) -{ - LPCTSTR ptszProfileName = CmdLine_GetOption( _T("profile")); - if (ptszProfileName == NULL) - return; - +static void loadProfileByShortName(const TCHAR* src, TCHAR *szProfile, size_t cch, TCHAR *profiledir) +{ TCHAR buf[MAX_PATH]; - _tcsncpy(buf, ptszProfileName, SIZEOF(buf)); + _tcsncpy(buf, src, SIZEOF(buf)); TCHAR *p = _tcsrchr(buf, '\\'); if (p) ++p; else p = buf; if ( !isValidProfileName(buf) && *p) @@ -165,6 +162,21 @@ void getProfileCmdLine(TCHAR *szProfile, size_t cch, TCHAR *profiledir) } } +void getProfileCmdLine(TCHAR *szProfile, size_t cch, TCHAR *profiledir) +{ + LPCTSTR ptszProfileName = CmdLine_GetOption( _T("profile")); + if (ptszProfileName != NULL) + loadProfileByShortName(ptszProfileName, szProfile, cch, profiledir); +} + +void getProfileDefault(TCHAR *szProfile, size_t cch, TCHAR *profiledir) +{ + if (g_defaultProfile != NULL) { + loadProfileByShortName(g_defaultProfile, szProfile, cch, profiledir); + mir_free(g_defaultProfile); + } +} + // move profile from profile subdir static void moveProfileDirProfiles(TCHAR *profiledir, BOOL isRootDir = TRUE) { @@ -288,6 +300,7 @@ static int getProfile(TCHAR *szProfile, size_t cch) getDefaultProfile(szProfile, cch, g_profileDir); getProfileCmdLine(szProfile, cch, g_profileDir); + getProfileDefault(szProfile, cch, g_profileDir); if (IsInsideRootDir(g_profileDir, true)) { MessageBox(NULL, _T("Profile cannot be placed into Miranda root folder.\n") @@ -464,9 +477,6 @@ int LoadDatabaseModule(void) _tchdir(szProfile); szProfile[0] = 0; - // load the older basic services of the db - InitUtils(); - // find out which profile to load if ( !getProfile(szProfile, SIZEOF(szProfile))) return 1; @@ -508,5 +518,10 @@ int LoadDatabaseModule(void) } while (retry); - return (rc != 0); + if (rc == ERROR_SUCCESS) { + InitIni(); + return 0; + } + + return rc; } diff --git a/src/modules/database/dbutils.cpp b/src/modules/database/dbutils.cpp index 1e62b160b4..cca96a763c 100644 --- a/src/modules/database/dbutils.cpp +++ b/src/modules/database/dbutils.cpp @@ -304,9 +304,16 @@ static INT_PTR GetProfileNameW(WPARAM wParam, LPARAM lParam) return 0; } +static INT_PTR SetDefaultProfile(WPARAM wParam, LPARAM lParam) +{ + extern TCHAR* g_defaultProfile; + replaceStrT(g_defaultProfile, (TCHAR*)wParam); + return 0; +} + ///////////////////////////////////////////////////////////////////////////////////////// -int InitUtils() +int LoadEventsModule() { bModuleInitialized = TRUE; @@ -322,16 +329,17 @@ int InitUtils() CreateServiceFunction(MS_DB_GETPROFILENAME, GetProfileName); CreateServiceFunction(MS_DB_GETPROFILEPATHW, GetProfilePathW); CreateServiceFunction(MS_DB_GETPROFILENAMEW, GetProfileNameW); + + CreateServiceFunction(MS_DB_SETDEFAULTPROFILE, SetDefaultProfile); return 0; } void UnloadEventsModule() { - int i; - - if ( !bModuleInitialized) return; + if ( !bModuleInitialized) + return; - for (i=0; i < eventTypes.getCount(); i++) { + for (int i=0; i < eventTypes.getCount(); i++) { DBEVENTTYPEDESCR* p = eventTypes[i]; mir_free(p->module); mir_free(p->descr); diff --git a/src/modules/database/profilemanager.h b/src/modules/database/profilemanager.h index e3ed554e56..848d2797d9 100644 --- a/src/modules/database/profilemanager.h +++ b/src/modules/database/profilemanager.h @@ -30,8 +30,6 @@ struct PROFILEMANAGERDATA DATABASELINK *dblink; // out }; -int InitUtils(void); - char* makeFileName(const TCHAR* tszOriginalName); int makeDatabase(TCHAR *profile, DATABASELINK * link, HWND hwndDlg); int getProfileManager(PROFILEMANAGERDATA * pd); -- cgit v1.2.3