OpenSim/Framework/Util.cs
/// <summary>
/// Reads a configuration file, configFile, merging it with the main configuration, config.
/// If the file doesn't exist, it copies a given exampleConfigFile onto configFile, and then
/// merges it.
/// </summary>
/// <param name="config">The main configuration data</param>
/// <param name="configFileName">The name of a configuration file in ConfigDirectory variable, no path</param>
/// <param name="exampleConfigFile">Full path to an example configuration file</param>
/// <param name="configFilePath">Full path ConfigDirectory/configFileName</param>
/// <param name="created">True if the file was created in ConfigDirectory, false if it existed</param>
/// <returns>True if success</returns>
Reads a configuration file, configFile, merging it with the main configuration, config.
If the file doesn't exist, it copies a given exampleConfigFile onto configFile, and then
merges it.
Reads a configuration file configFile merging it with the main configuration config . If the file doesn ' t exist it copies a given exampleConfigFile onto configFile and then merges it .
public static bool MergeConfigurationFile(IConfigSource config, string configFileName, string exampleConfigFile, out string configFilePath, out bool created)
        {
            created = false;
            configFilePath = string.Empty;
            IConfig cnf = config.Configs["Startup"];
            if (cnf == null)
            {
                m_log.WarnFormat("[UTILS]: Startup section doesn't exist");
                return false;
            }
            string configDirectory = cnf.GetString("ConfigDirectory", ".");
            string configFile = Path.Combine(configDirectory, configFileName);
            if (!File.Exists(configFile) && !string.IsNullOrEmpty(exampleConfigFile))
            {
                if (!Directory.Exists(configDirectory))
                    Directory.CreateDirectory(configDirectory);
                try
                {
                    File.Copy(exampleConfigFile, configFile);
                    created = true;
                }
                catch (Exception e)
                {
                    m_log.WarnFormat("[UTILS]: Exception copying configuration file {0} to {1}: {2}", configFile, exampleConfigFile, e.Message);
                    return false;
                }
            }
            if (File.Exists(configFile))
            {
                config.Merge(new IniConfigSource(configFile));
                config.ExpandKeyValues();
                configFilePath = configFile;
                return true;
            }
            else
                return false;
        }
public static bool MergeConfigurationFile ( IConfigSource config , string configFileName , string exampleConfigFile , out string configFilePath , out bool created ) { created = false ; configFilePath = string . Empty ; IConfig cnf = config . Configs [ " " ] ; if ( cnf == null ) { m_log . WarnFormat ( " " ) ; return false ; } string configDirectory = cnf . GetString ( " " , " " ) ; string configFile = Path . Combine ( configDirectory , configFileName ) ; if ( ! File . Exists ( configFile ) && ! string . IsNullOrEmpty ( exampleConfigFile ) ) { if ( ! Directory . Exists ( configDirectory ) ) Directory . CreateDirectory ( configDirectory ) ; try { File . Copy ( exampleConfigFile , configFile ) ; created = true ; } catch ( Exception e ) { m_log . WarnFormat ( " " , configFile , exampleConfigFile , e . Message ) ; return false ; } } if ( File . Exists ( configFile ) ) { config . Merge ( new IniConfigSource ( configFile ) ) ; config . ExpandKeyValues ( ) ; configFilePath = configFile ; return true ; } else return false ; }
Reads a configuration file, configFile, merging it with the main configuration, config.
Reads a configuration file configFile merging it with the main configuration config .
// We need to copy the example onto it // Merge 
True if success
True if success
config
IConfigSource
The main configuration data
The main configuration data
configFileName
string
The name of a configuration file in ConfigDirectory variable, no path
The name of a configuration file in ConfigDirectory variable no path
exampleConfigFile
string
Full path to an example configuration file
Full path to an example configuration file
string
out
bool
out
configFilePath
Full path ConfigDirectory/configFileName
Full path ConfigDirectory / configFileName
created
True if the file was created in ConfigDirectory, false if it existed
True if the file was created in ConfigDirectory false if it existed