AutoBackupModule: Implement per-region settings in Regions.ini.

bulletsim
Sean McNamara 2011-05-02 04:32:31 -04:00
parent fffd42f5cb
commit 0995fedcac
1 changed files with 186 additions and 105 deletions

View File

@ -110,6 +110,7 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup
new Dictionary<Timer, List<IScene>>(1); new Dictionary<Timer, List<IScene>>(1);
private readonly Dictionary<double, Timer> m_timers = new Dictionary<double, Timer>(1); private readonly Dictionary<double, Timer> m_timers = new Dictionary<double, Timer>(1);
private delegate T DefaultGetter<T>(string settingName, T defaultValue);
private bool m_enabled; private bool m_enabled;
/// <summary> /// <summary>
@ -299,16 +300,16 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup
} }
// Read the config settings and set variables. // Read the config settings and set variables.
IConfig regionConfig = (scene != null ? scene.Config.Configs[sRegionName] : null);
IConfig config = this.m_configSource.Configs["AutoBackupModule"]; IConfig config = this.m_configSource.Configs["AutoBackupModule"];
if (config == null) if (config == null)
{ {
// defaultState would be disabled too if the section doesn't exist. // defaultState would be disabled too if the section doesn't exist.
state = this.m_defaultState; state = this.m_defaultState;
m_log.Info("[AUTO BACKUP]: Region " + sRegionLabel + " is NOT AutoBackup enabled.");
return state; return state;
} }
bool tmpEnabled = config.GetBoolean(prepend + "AutoBackup", this.m_defaultState.Enabled); bool tmpEnabled = ResolveBoolean("AutoBackup", this.m_defaultState.Enabled, config, regionConfig);
if (state == null && tmpEnabled != this.m_defaultState.Enabled) if (state == null && tmpEnabled != this.m_defaultState.Enabled)
//Varies from default state //Varies from default state
{ {
@ -332,8 +333,8 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup
// Borrow an existing timer if one exists for the same interval; otherwise, make a new one. // Borrow an existing timer if one exists for the same interval; otherwise, make a new one.
double interval = double interval =
config.GetDouble(prepend + "AutoBackupInterval", this.m_defaultState.IntervalMinutes)* this.ResolveDouble("AutoBackupInterval", this.m_defaultState.IntervalMinutes,
60000.0; config, regionConfig) * 60000.0;
if (state == null && interval != this.m_defaultState.IntervalMinutes*60000.0) if (state == null && interval != this.m_defaultState.IntervalMinutes*60000.0)
{ {
state = new AutoBackupModuleState(); state = new AutoBackupModuleState();
@ -400,8 +401,8 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup
} }
} }
bool tmpBusyCheck = config.GetBoolean(prepend + "AutoBackupBusyCheck", bool tmpBusyCheck = ResolveBoolean("AutoBackupBusyCheck",
this.m_defaultState.BusyCheck); this.m_defaultState.BusyCheck, config, regionConfig);
if (state == null && tmpBusyCheck != this.m_defaultState.BusyCheck) if (state == null && tmpBusyCheck != this.m_defaultState.BusyCheck)
{ {
state = new AutoBackupModuleState(); state = new AutoBackupModuleState();
@ -413,8 +414,8 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup
} }
// Set file naming algorithm // Set file naming algorithm
string stmpNamingType = config.GetString(prepend + "AutoBackupNaming", string stmpNamingType = ResolveString("AutoBackupNaming",
this.m_defaultState.NamingType.ToString()); this.m_defaultState.NamingType.ToString(), config, regionConfig);
NamingType tmpNamingType; NamingType tmpNamingType;
if (stmpNamingType.Equals("Time", StringComparison.CurrentCultureIgnoreCase)) if (stmpNamingType.Equals("Time", StringComparison.CurrentCultureIgnoreCase))
{ {
@ -445,8 +446,8 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup
state.NamingType = tmpNamingType; state.NamingType = tmpNamingType;
} }
string tmpScript = config.GetString(prepend + "AutoBackupScript", string tmpScript = ResolveString("AutoBackupScript",
this.m_defaultState.Script); this.m_defaultState.Script, config, regionConfig);
if (state == null && tmpScript != this.m_defaultState.Script) if (state == null && tmpScript != this.m_defaultState.Script)
{ {
state = new AutoBackupModuleState(); state = new AutoBackupModuleState();
@ -457,7 +458,7 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup
state.Script = tmpScript; state.Script = tmpScript;
} }
string tmpBackupDir = config.GetString(prepend + "AutoBackupDir", "."); string tmpBackupDir = ResolveString("AutoBackupDir", ".", config, regionConfig);
if (state == null && tmpBackupDir != this.m_defaultState.BackupDir) if (state == null && tmpBackupDir != this.m_defaultState.BackupDir)
{ {
state = new AutoBackupModuleState(); state = new AutoBackupModuleState();
@ -491,6 +492,86 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup
return state; return state;
} }
/// <summary>
/// Helper function for ParseConfig.
/// </summary>
/// <param name="settingName"></param>
/// <param name="defaultValue"></param>
/// <param name="global"></param>
/// <param name="local"></param>
/// <returns></returns>
private bool ResolveBoolean(string settingName, bool defaultValue, IConfig global, IConfig local)
{
if(local != null)
{
return local.GetBoolean(settingName, global.GetBoolean(settingName, defaultValue));
}
else
{
return global.GetBoolean(settingName, defaultValue);
}
}
/// <summary>
/// Helper function for ParseConfig.
/// </summary>
/// <param name="settingName"></param>
/// <param name="defaultValue"></param>
/// <param name="global"></param>
/// <param name="local"></param>
/// <returns></returns>
private double ResolveDouble(string settingName, double defaultValue, IConfig global, IConfig local)
{
if (local != null)
{
return local.GetDouble(settingName, global.GetDouble(settingName, defaultValue));
}
else
{
return global.GetDouble(settingName, defaultValue);
}
}
/// <summary>
/// Helper function for ParseConfig.
/// </summary>
/// <param name="settingName"></param>
/// <param name="defaultValue"></param>
/// <param name="global"></param>
/// <param name="local"></param>
/// <returns></returns>
private int ResolveInt(string settingName, int defaultValue, IConfig global, IConfig local)
{
if (local != null)
{
return local.GetInt(settingName, global.GetInt(settingName, defaultValue));
}
else
{
return global.GetInt(settingName, defaultValue);
}
}
/// <summary>
/// Helper function for ParseConfig.
/// </summary>
/// <param name="settingName"></param>
/// <param name="defaultValue"></param>
/// <param name="global"></param>
/// <param name="local"></param>
/// <returns></returns>
private string ResolveString(string settingName, string defaultValue, IConfig global, IConfig local)
{
if (local != null)
{
return local.GetString(settingName, global.GetString(settingName, defaultValue));
}
else
{
return global.GetString(settingName, defaultValue);
}
}
/// <summary> /// <summary>
/// Called when any auto-backup timer expires. This starts the code path for actually performing a backup. /// Called when any auto-backup timer expires. This starts the code path for actually performing a backup.
/// </summary> /// </summary>