Update of /cvsroot/mahogany/M/src/classes
In directory usw-pr-cvs1:/tmp/cvs-serv22456/src/classes
Modified Files:
MessageTemplate.cpp Profile.cpp
Log Message:
1. implemented --config=filename command line option support for Windows
2. changes the profile section name handling to account for this: now we
may use either Unix or Windows-style section names under Windows
Index: MessageTemplate.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/classes/MessageTemplate.cpp,v
retrieving revision 1.27
retrieving revision 1.28
diff -b -u -2 -r1.27 -r1.28
--- MessageTemplate.cpp 4 Mar 2002 20:53:27 -0000 1.27
+++ MessageTemplate.cpp 14 Apr 2002 12:16:54 -0000 1.28
@@ -571,5 +571,5 @@
{
String path;
- path << M_TEMPLATES_CONFIG_SECTION << '/' << GetTemplateKindPath(kind);
+ path << Profile::GetTemplatesPath() << '/' << GetTemplateKindPath(kind);
return path;
Index: Profile.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/classes/Profile.cpp,v
retrieving revision 1.127
retrieving revision 1.128
diff -b -u -2 -r1.127 -r1.128
--- Profile.cpp 12 Apr 2002 12:41:16 -0000 1.127
+++ Profile.cpp 14 Apr 2002 12:16:54 -0000 1.128
@@ -422,15 +422,18 @@
virtual String GetIdentity(void) const;
- MOBJECT_DEBUG(ProfileImpl)
-
virtual bool IsAncestor(Profile *profile) const;
- virtual String GetFolderName() const;
-
- virtual const char * GetRootPath(void) const
+ String GetRootPath(void) const
{
- return M_PROFILE_CONFIG_SECTION;
+ return GetSectionPath(GetProfileSection());
}
+ virtual String GetFolderName() const;
+
+#ifdef OS_WIN
+ /// true if we use reg config under Windows, false otherwise
+ static bool ms_usingRegConfig;
+#endif // OS_WIN
+
protected:
ProfileImpl()
@@ -443,4 +446,9 @@
~ProfileImpl();
+ virtual const char * GetProfileSection(void) const
+ {
+ return M_PROFILE_CONFIG_SECTION;
+ }
+
/// Name of this profile == path in wxConfig
String m_ProfileName;
@@ -472,4 +480,6 @@
static size_t ms_suspendCount;
+ MOBJECT_DEBUG(ProfileImpl)
+
GCC_DTOR_WARN_OFF
};
@@ -477,4 +487,6 @@
size_t ProfileImpl::ms_suspendCount = 0;
+bool ProfileImpl::ms_usingRegConfig = true;
+
//@}
@@ -493,5 +505,5 @@
{ return new Identity(name); }
- virtual const char * GetRootPath(void) const
+ virtual const char * GetProfileSection(void) const
{
return M_IDENTITY_CONFIG_SECTION;
@@ -525,5 +537,5 @@
{ return new FilterProfile(name); }
- virtual const char * GetRootPath(void) const
+ virtual const char * GetProfileSection(void) const
{
return M_FILTERS_CONFIG_SECTION;
@@ -672,10 +684,10 @@
wxArrayString Profile::GetAllFilters()
{
- return GetAllGroupsUnder(M_FILTERS_CONFIG_SECTION);
+ return GetAllGroupsUnder(GetFiltersPath());
}
wxArrayString Profile::GetAllIdentities()
{
- return GetAllGroupsUnder(M_IDENTITY_CONFIG_SECTION);
+ return GetAllGroupsUnder(GetIdentityPath());
}
@@ -921,21 +933,31 @@
//else: not an error, file may be simply not there yet
}
-#else // Windows
- // no such concerns here, just use the registry
- if ( strConfFile.empty() )
- {
- strConfFile = M_APPLICATIONNAME;
- }
-#endif // Win/Unix
+#endif // Unix
#ifdef OS_WIN
+ // no such concerns here, we just use the registry if the filename is not
+ // specified
+ if ( strConfFile.empty() )
+ {
// don't give explicit name, but rather use the default logic (it's
// perfectly ok, for the registry case our keys are under
// vendor\appname)
-
ms_GlobalConfig = new wxConfig(M_APPLICATIONNAME, M_VENDORNAME,
"", "",
wxCONFIG_USE_LOCAL_FILE |
wxCONFIG_USE_GLOBAL_FILE);
+ }
+ else // we do have the config file name
+ {
+ // use the config file: this allows to use the same file for Windows and
+ // Unix Mahogany installations
+ ms_GlobalConfig = new wxFileConfig(M_APPLICATIONNAME, M_VENDORNAME,
+ strConfFile, "",
+ wxCONFIG_USE_LOCAL_FILE|
+ wxCONFIG_USE_GLOBAL_FILE);
+
+ // we need to modify the path handling under Windows in this case
+ ProfileImpl::ms_usingRegConfig = false;
+ }
#else // Unix
// look for the global config file in the following places in order:
@@ -1096,8 +1118,14 @@
PCHECK();
+ CHECK( !path.empty(), false, "must have a valid group name to delete it" );
+
+ if ( path[0u] != '/' )
+ {
String root = GetName();
if ( !m_ProfilePath.empty() )
root << '/' << m_ProfilePath;
ms_GlobalConfig->SetPath(root);
+ }
+
return ms_GlobalConfig->DeleteGroup(path);
}
@@ -1560,10 +1588,8 @@
String ProfileImpl::GetFolderName() const
{
- String folderName,
- profileName = GetName();
- size_t lenPrefix = strlen(M_PROFILE_CONFIG_SECTION);
- if ( strncmp(profileName, M_PROFILE_CONFIG_SECTION, lenPrefix) == 0 )
+ String folderName;
+ if ( GetName().StartsWith(GetProfilePath(), &folderName) )
{
- const char *p = profileName.c_str() + lenPrefix;
+ const char *p = folderName.c_str();
if ( *p )
@@ -1571,6 +1597,6 @@
ASSERT_MSG( *p == '/', "profile path must start with slash" );
- // +1 to skip following '/'
- folderName = p + 1;
+ // erase the slash
+ folderName.erase(0, 1);
}
//else: leave empty
@@ -1578,4 +1604,30 @@
return folderName;
+}
+
+/* static */
+String Profile::GetSectionPath(const String& section)
+{
+ String path = section;
+
+ // we don't use "/M" prefix when working with wxRegConfig as it would be
+ // superfluous: our config key is already Mahogany-Team/M
+ //
+ // but for the file based config formats (both local and remote) we do use
+ // it for mostly historical reasons - even though if it probably would be
+ // better to never use it, it's simply too much trouble to write the upgrade
+ // code to deal with the existing config files
+#ifdef OS_WIN
+ if ( ProfileImpl::ms_usingRegConfig )
+ {
+ // remove "/M" prefix
+ ASSERT_MSG( path[0u] == '/' && path[1u] == 'M',
+ "all profile sections must start with \"/M\"" );
+
+ path.erase(0, 2);
+ }
+#endif // Windows
+
+ return path;
}
_______________________________________________
Mahogany-cvsupdates mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates