summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/m_database.h13
-rw-r--r--src/core/miranda.h3
-rw-r--r--src/core/modules.cpp18
-rw-r--r--src/modules/database/database.cpp37
-rw-r--r--src/modules/database/dbutils.cpp18
-rw-r--r--src/modules/database/profilemanager.h2
-rw-r--r--src/modules/plugins/newplugins.cpp73
7 files changed, 109 insertions, 55 deletions
diff --git a/include/m_database.h b/include/m_database.h
index 9fcce5bd8d..f10cb76bfd 100644
--- a/include/m_database.h
+++ b/include/m_database.h
@@ -86,7 +86,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
/************************* SERVICES *******************************/
/******************************************************************/
-/* DB/Contact/GetProfileName service
+/* DB/GetProfileName service
Gets the name of the profile currently being used by the database module. This
is the same as the filename of the database
wParam = (WPARAM)(UINT)cbName
@@ -98,7 +98,7 @@ Returns 0 on success or nonzero otherwise
#define MS_DB_GETPROFILENAME "DB/GetProfileName"
#define MS_DB_GETPROFILENAMEW "DB/GetProfileNameW"
-/* DB/Contact/GetProfilePath service
+/* DB/GetProfilePath service
Get the path of the base folder where Miranda will store all individual profiles
The returned path does NOT include a trailing backslash.
Essentially this is what has been set in mirandaboot.ini as ProfileDir.
@@ -120,6 +120,15 @@ Returns 0 on success or nonzero otherwise
#define MS_DB_GETPROFILENAMET MS_DB_GETPROFILENAME
#endif
+/* DB/SetDefaultProfile service
+Sets the default profile name programmatically
+Analog of Database/DefaultProfile in mirandaboot.ini
+ wParam = (WPARAM)(TCHAR*)ptszProfileName
+ lParam = 0 (unused)
+*/
+
+#define MS_DB_SETDEFAULTPROFILE "DB/SetDefaultProfile"
+
/************************* Contact ********************************/
/* DB/Contact/GetSetting service
diff --git a/src/core/miranda.h b/src/core/miranda.h
index aeaa1fd593..169b8d5db4 100644
--- a/src/core/miranda.h
+++ b/src/core/miranda.h
@@ -114,6 +114,9 @@ extern MIDatabase* currDb;
extern DATABASELINK* currDblink;
extern LIST<DATABASELINK> arDbPlugins;
+int InitIni(void);
+void UninitIni(void);
+
/**** fontService.cpp ******************************************************************/
void KillModuleFonts(int hLangpack);
diff --git a/src/core/modules.cpp b/src/core/modules.cpp
index 6ada0cf650..a1fd29b5c3 100644
--- a/src/core/modules.cpp
+++ b/src/core/modules.cpp
@@ -42,8 +42,10 @@ int LoadProtocolsModule(void); // core: protocol manager
int LoadAccountsModule(void); // core: account manager
int LoadIgnoreModule(void); // protocol filter: ignore
int LoadDbintfModule(void);
+int LoadEventsModule(void);
int LoadContactListModule(void);// ui: clist
+int LoadDatabaseModule(void);
int LoadOptionsModule(void); // ui: options dialog
int LoadFindAddModule(void); // ui: search/add users
int LoadSkinIcons(void);
@@ -60,6 +62,7 @@ int LoadButtonModule(void); // window class: button class
int LoadFontserviceModule(void); // ui: font manager
int LoadIcoLibModule(void); // ui: icons manager
int LoadServiceModePlugin(void);
+int LoadDefaultServiceModePlugin(void);
int LoadErrorsModule();
void UnloadUtilsModule(void);
@@ -92,8 +95,23 @@ int LoadDefaultModules(void)
if ( LoadIcoTabsModule()) return 1;
if ( LoadHeaderbarModule()) return 1;
if ( LoadDbintfModule()) return 1;
+ if ( LoadEventsModule()) return 1;
+
+ // load database drivers & service plugins without executing their Load()
if ( LoadNewPluginsModuleInfos()) return 1;
+ switch ( LoadDefaultServiceModePlugin()) {
+ case SERVICE_CONTINUE: // continue loading Miranda normally
+ break;
+ case SERVICE_MONOPOLY: // unload database and go to the message cycle
+ return 0;
+ default: // smth went wrong, terminating
+ return 1;
+ }
+
+ // the database will select which db plugin to use, or fail if no profile is selected
+ if ( LoadDatabaseModule()) return 1;
+
// database is available here
if ( LoadButtonModule()) return 1;
if ( LoadIcoLibModule()) return 1;
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);
diff --git a/src/modules/plugins/newplugins.cpp b/src/modules/plugins/newplugins.cpp
index 32214a1c52..b52e917dd0 100644
--- a/src/modules/plugins/newplugins.cpp
+++ b/src/modules/plugins/newplugins.cpp
@@ -70,13 +70,8 @@ static int askAboutIgnoredPlugins;
static pluginEntry *pluginList_freeimg, *pluginList_crshdmp, *serviceModePlugin = NULL;
-int InitIni(void);
-void UninitIni(void);
-
#define PLUGINDISABLELIST "PluginDisable"
-int LoadDatabaseModule(void);
-
/////////////////////////////////////////////////////////////////////////////////////////
// basic functions
@@ -387,7 +382,7 @@ pluginEntry* OpenPlugin(TCHAR *tszFileName, TCHAR *dir, TCHAR *path)
// plugin declared that it's a database. load it asap!
if ( hasMuuid(pIds, miid_database)) {
BASIC_PLUGIN_INFO bpi;
- if (checkAPI(tszFullPath, &bpi, mirandaVersion, CHECKAPI_NONE)) {
+ if ( checkAPI(tszFullPath, &bpi, mirandaVersion, CHECKAPI_NONE)) {
// db plugin is valid
p->pclass |= (PCLASS_DB | PCLASS_BASICAPI);
// copy the dblink stuff
@@ -589,26 +584,52 @@ void SetServiceModePlugin(pluginEntry *p)
serviceModePlugin = p;
}
-int LoadServiceModePlugin(void)
+static int LaunchServicePlugin(pluginEntry* p)
{
- if (serviceModePlugin == NULL)
- return SERVICE_CONTINUE;
-
// plugin load failed - terminating Miranda
- if (serviceModePlugin->bpi.Load() != ERROR_SUCCESS) {
- Plugin_Uninit(serviceModePlugin);
- return SERVICE_FAILED;
+ if ( !( p->pclass & PCLASS_LOADED)) {
+ if (p->bpi.Load() != ERROR_SUCCESS) {
+ p->pclass |= PCLASS_FAILED;
+ Plugin_Uninit(p);
+ return SERVICE_FAILED;
+ }
+ p->pclass |= PCLASS_LOADED;
}
- serviceModePlugin->pclass |= PCLASS_LOADED;
INT_PTR res = CallService(MS_SERVICEMODE_LAUNCH, 0, 0);
if (res != CALLSERVICE_NOTFOUND)
return res;
- MessageBox(NULL, TranslateT("Unable to load plugin in Service Mode!"), serviceModePlugin->pluginname, 0);
+ MessageBox(NULL, TranslateT("Unable to load plugin in Service Mode!"), p->pluginname, 0);
+ Plugin_Uninit(p);
return SERVICE_FAILED;
}
+int LoadDefaultServiceModePlugin()
+{
+ LPCTSTR param = CmdLine_GetOption( _T("svc"));
+ if (param == NULL)
+ return SERVICE_CONTINUE;
+
+ size_t cbLen = _tcslen(param);
+ for (int i=0; i < servicePlugins.getCount(); i++) {
+ pluginEntry* p = servicePlugins[i];
+ if ( !_tcsnicmp(p->pluginname, param, cbLen)) {
+ int res = LaunchServicePlugin(p);
+ if (res == SERVICE_ONLYDB) // load it later
+ serviceModePlugin = p;
+ return res;
+ }
+ }
+
+ return SERVICE_CONTINUE;
+}
+
+int LoadServiceModePlugin()
+{
+ return (serviceModePlugin == NULL) ? SERVICE_CONTINUE : LaunchServicePlugin(serviceModePlugin);
+}
+
/////////////////////////////////////////////////////////////////////////////////////////
// Event hook to unload all non-core plugins
// hooked very late, after all the internal plugins, blah
@@ -731,25 +752,6 @@ int LoadNewPluginsModuleInfos(void)
PathToAbsoluteT(_T("mirandaboot.ini"), mirandabootini, NULL);
// look for all *.dll's
enumPlugins(scanPluginsDir, 0, 0);
- // the database will select which db plugin to use, or fail if no profile is selected
- if ( LoadDatabaseModule())
- return 1;
-
- if (serviceModePlugin == NULL) {
- LPCTSTR param = CmdLine_GetOption( _T("svc"));
- if (param != NULL) {
- size_t cbLen = _tcslen(param);
- for (int i=0; i < servicePlugins.getCount(); i++) {
- if ( !_tcsnicmp(servicePlugins[i]->pluginname, param, cbLen)) {
- serviceModePlugin = servicePlugins[i];
- break;
- }
- }
- }
- }
-
- InitIni();
- // could validate the plugin entries here but internal modules arent loaded so can't call Load(void) in one pass
return 0;
}
@@ -765,6 +767,8 @@ void UnloadDatabase(void)
currDb = NULL;
currDblink = NULL;
}
+
+ UninitIni();
}
void UnloadNewPluginsModule(void)
@@ -797,5 +801,4 @@ void UnloadNewPluginsModule(void)
pluginList.destroy();
servicePlugins.destroy();
clistPlugins.destroy();
- UninitIni();
}