[sword-svn] r1803 - trunk/src/mgr

jansorg at crosswire.org jansorg at crosswire.org
Fri May 6 04:30:57 MST 2005


Author: jansorg
Date: 2005-05-06 04:30:57 -0700 (Fri, 06 May 2005)
New Revision: 1803

Modified:
   trunk/src/mgr/swmgr.cpp
Log:
Fixed multimod problem: With the old solution the new module name_1 had the same config data as the old one, now we rename the config sections before merging configs

Modified: trunk/src/mgr/swmgr.cpp
===================================================================
--- trunk/src/mgr/swmgr.cpp	2005-05-06 09:06:35 UTC (rev 1802)
+++ trunk/src/mgr/swmgr.cpp	2005-05-06 11:30:57 UTC (rev 1803)
@@ -74,6 +74,8 @@
 
 #include <swlog.h>
 
+#include <iterator>
+
 #ifndef EXCLUDEZLIB
 #include "zipcomprs.h"
 #endif
@@ -552,13 +554,36 @@
 		config = myconfig = 0;
 		loadConfigDir(configPath);
 
+		if (multiMod) {
+			// fix config's Section names to rename modules which are available more than once
+			// find out which sections are in both config objects
+			// inserting all configs first is not good because that overwrites old keys and new modules would share the same config
+			for (SectionMap::iterator it = config->Sections.begin(); it != config->Sections.end(); ++it) {
+				if (saveConfig->Sections.find( (*it).first ) != saveConfig->Sections.end()) { //if the new section is already present rename it
+					ConfigEntMap entMap( (*it).second );
+					
+					SWBuf name;
+					int i = 1;
+					do { //module name already used?
+						name.setFormatted("%s_%d", (*it).first.c_str(), i);
+						i++;
+					} while (config->Sections.find(name) != config->Sections.end());
+					
+					config->Sections.insert( make_pair(name, entMap) );
+					config->Sections.erase( it );
+				}
+			}
+		}
+		
 		CreateMods(multiMod);
 
 		stdstr(&prefixPath, savePrefixPath);
 		delete []savePrefixPath;
 		stdstr(&configPath, saveConfigPath);
 		delete []saveConfigPath;
+
 		(*saveConfig) += *config;
+		
 		homeConfig = myconfig;
 		config = myconfig = saveConfig;
 	}
@@ -949,23 +974,10 @@
 				AddEncodingFilters(newmod, section);
 				
 				SWModule *oldmod = Modules[newmod->Name()];
-
 				if (oldmod) {
-					if (!multiMod)
-						delete oldmod;
-					else {
-						SWBuf name;
-						int i = 1; 
-						SWModule *mod;
-						do {
-							name = newmod->Name();
-							name.appendFormatted("_%d", i);
-							mod = Modules[name];
-							i++;
-						} while (mod);
-						newmod->Name(name);
-					}
+					delete oldmod;
 				}
+				
 				Modules[newmod->Name()] = newmod;
 			}
 		}



More information about the sword-cvs mailing list