* Formatted ExportSerialiserModule and SvnBackupModule
* Added a form of GZip compression support to object.xml files produced by exportserialiser. Will look towards standard GZip support. File compression seems to be highly worthwhile reducing a 1.5mb sim state to 62kb.0.6.0-stable
parent
a7cb2b8c30
commit
f741a62d54
|
@ -37,10 +37,54 @@ namespace OpenSim.Region.Environment.Modules.ExportSerialiser
|
|||
{
|
||||
public class ExportSerialisationModule : IRegionModule, IRegionSerialiser
|
||||
{
|
||||
private List<Scene> m_regions = new List<Scene>();
|
||||
private List<IFileSerialiser> m_serialisers = new List<IFileSerialiser>();
|
||||
private Commander m_commander = new Commander("Export");
|
||||
private List<Scene> m_regions = new List<Scene>();
|
||||
private string m_savedir = "exports" + "/";
|
||||
private List<IFileSerialiser> m_serialisers = new List<IFileSerialiser>();
|
||||
|
||||
#region IRegionModule Members
|
||||
|
||||
public void Initialise(Scene scene, IConfigSource source)
|
||||
{
|
||||
scene.RegisterModuleCommander("Export", m_commander);
|
||||
scene.EventManager.OnPluginConsole += EventManager_OnPluginConsole;
|
||||
scene.RegisterModuleInterface<IRegionSerialiser>(this);
|
||||
|
||||
lock (m_regions)
|
||||
{
|
||||
m_regions.Add(scene);
|
||||
}
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
lock (m_serialisers)
|
||||
{
|
||||
m_serialisers.Add(new SerialiseTerrain());
|
||||
m_serialisers.Add(new SerialiseObjects());
|
||||
}
|
||||
|
||||
LoadCommanderCommands();
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
m_regions.Clear();
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "ExportSerialisationModule"; }
|
||||
}
|
||||
|
||||
public bool IsSharedModule
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IRegionSerialiser Members
|
||||
|
||||
public List<string> SerialiseRegion(Scene scene, string saveDir)
|
||||
{
|
||||
|
@ -76,22 +120,9 @@ namespace OpenSim.Region.Environment.Modules.ExportSerialiser
|
|||
return results;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IRegionModule Members
|
||||
|
||||
public void Initialise(Scene scene, IConfigSource source)
|
||||
{
|
||||
scene.RegisterModuleCommander("Export", m_commander);
|
||||
scene.EventManager.OnPluginConsole += EventManager_OnPluginConsole;
|
||||
scene.RegisterModuleInterface<IRegionSerialiser>(this);
|
||||
|
||||
lock (m_regions)
|
||||
{
|
||||
m_regions.Add(scene);
|
||||
}
|
||||
}
|
||||
|
||||
void EventManager_OnPluginConsole(string[] args)
|
||||
private void EventManager_OnPluginConsole(string[] args)
|
||||
{
|
||||
if (args[0] == "export")
|
||||
{
|
||||
|
@ -108,7 +139,7 @@ namespace OpenSim.Region.Environment.Modules.ExportSerialiser
|
|||
{
|
||||
foreach (Scene region in m_regions)
|
||||
{
|
||||
if (region.RegionInfo.RegionName == (string)args[0])
|
||||
if (region.RegionInfo.RegionName == (string) args[0])
|
||||
{
|
||||
List<string> results = SerialiseRegion(region, m_savedir + region.RegionInfo.RegionID.ToString() + "/");
|
||||
}
|
||||
|
@ -133,33 +164,5 @@ namespace OpenSim.Region.Environment.Modules.ExportSerialiser
|
|||
m_commander.RegisterCommand("save", serialiseSceneCommand);
|
||||
m_commander.RegisterCommand("save-all", serialiseAllScenesCommand);
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
lock (m_serialisers)
|
||||
{
|
||||
m_serialisers.Add(new SerialiseTerrain());
|
||||
m_serialisers.Add(new SerialiseObjects());
|
||||
}
|
||||
|
||||
LoadCommanderCommands();
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
m_regions.Clear();
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "ExportSerialisationModule"; }
|
||||
}
|
||||
|
||||
public bool IsSharedModule
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
|
@ -29,8 +29,8 @@ using OpenSim.Region.Environment.Scenes;
|
|||
|
||||
namespace OpenSim.Region.Environment.Modules.ExportSerialiser
|
||||
{
|
||||
interface IFileSerialiser
|
||||
internal interface IFileSerialiser
|
||||
{
|
||||
string WriteToFile(Scene scene, string dir);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -34,4 +34,4 @@ namespace OpenSim.Region.Environment.Modules.ExportSerialiser
|
|||
{
|
||||
List<string> SerialiseRegion(Scene scene, string saveDir);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -27,20 +27,30 @@
|
|||
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using OpenSim.Region.Environment.Scenes;
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules.ExportSerialiser
|
||||
{
|
||||
class SerialiseObjects : IFileSerialiser
|
||||
internal class SerialiseObjects : IFileSerialiser
|
||||
{
|
||||
#region IFileSerialiser Members
|
||||
|
||||
public string WriteToFile(Scene scene, string dir)
|
||||
{
|
||||
string targetFileName = dir + "objects.xml";
|
||||
|
||||
SaveSerialisedToFile(targetFileName, scene);
|
||||
|
||||
return "objects.xml";
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public void SaveSerialisedToFile(string fileName, Scene scene)
|
||||
{
|
||||
int primCount = 0;
|
||||
string xmlstream = "<scene>";
|
||||
|
||||
List<EntityBase> EntityList = scene.GetEntities();
|
||||
|
@ -50,8 +60,7 @@ namespace OpenSim.Region.Environment.Modules.ExportSerialiser
|
|||
{
|
||||
if (ent is SceneObjectGroup)
|
||||
{
|
||||
EntityXml.Add(((SceneObjectGroup)ent).ToXmlString2());
|
||||
primCount++;
|
||||
EntityXml.Add(((SceneObjectGroup) ent).ToXmlString2());
|
||||
}
|
||||
}
|
||||
EntityXml.Sort();
|
||||
|
@ -69,26 +78,24 @@ namespace OpenSim.Region.Environment.Modules.ExportSerialiser
|
|||
formatter.Formatting = Formatting.Indented;
|
||||
doc.WriteContentTo(formatter);
|
||||
formatter.Flush();
|
||||
StreamReader reader = new StreamReader(stream);
|
||||
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
FileStream objectsFile = new FileStream(fileName, FileMode.Create);
|
||||
|
||||
stream.WriteTo(objectsFile);
|
||||
objectsFile.Flush();
|
||||
objectsFile.Close();
|
||||
|
||||
#region GZip Compressed Version
|
||||
FileStream objectsFileCompressed = new FileStream(fileName + ".gzs", FileMode.Create);
|
||||
MemoryStream gzipMSStream = new MemoryStream();
|
||||
GZipStream gzipStream = new GZipStream(gzipMSStream, CompressionMode.Compress);
|
||||
stream.WriteTo(gzipStream);
|
||||
gzipMSStream.WriteTo(objectsFileCompressed);
|
||||
objectsFileCompressed.Flush();
|
||||
objectsFileCompressed.Close();
|
||||
#endregion
|
||||
}
|
||||
|
||||
public string WriteToFile(Scene scene, string dir)
|
||||
{
|
||||
string targetFileName = dir + "objects.xml";
|
||||
|
||||
SaveSerialisedToFile(targetFileName, scene);
|
||||
|
||||
return "objects.xml";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
|
@ -31,7 +31,7 @@ using OpenSim.Region.Environment.Scenes;
|
|||
|
||||
namespace OpenSim.Region.Environment.Modules.ExportSerialiser
|
||||
{
|
||||
class SerialiseTerrain : IFileSerialiser
|
||||
internal class SerialiseTerrain : IFileSerialiser
|
||||
{
|
||||
#region IFileSerialiser Members
|
||||
|
||||
|
@ -50,4 +50,4 @@ namespace OpenSim.Region.Environment.Modules.ExportSerialiser
|
|||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
|
@ -42,11 +42,11 @@ namespace OpenSim.Region.Environment.Modules.ModuleFramework
|
|||
public class Command : ICommand
|
||||
{
|
||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
private List<CommandArgument> m_args = new List<CommandArgument>();
|
||||
|
||||
private Action<object[]> m_command;
|
||||
private string m_name;
|
||||
private string m_help;
|
||||
private List<CommandArgument> m_args = new List<CommandArgument>();
|
||||
private string m_name;
|
||||
|
||||
public Command(string name, Action<Object[]> command, string help)
|
||||
{
|
||||
|
@ -55,6 +55,8 @@ namespace OpenSim.Region.Environment.Modules.ModuleFramework
|
|||
m_help = help;
|
||||
}
|
||||
|
||||
#region ICommand Members
|
||||
|
||||
public void AddArgument(string name, string helptext, string type)
|
||||
{
|
||||
m_args.Add(new CommandArgument(name, helptext, type));
|
||||
|
@ -143,8 +145,8 @@ namespace OpenSim.Region.Environment.Modules.ModuleFramework
|
|||
catch (FormatException)
|
||||
{
|
||||
m_log.Error("Argument number " + (i + 1) +
|
||||
" (" + m_args[i].Name + ") must be a valid " +
|
||||
m_args[i].ArgumentType.ToLower() + ".");
|
||||
" (" + m_args[i].Name + ") must be a valid " +
|
||||
m_args[i].ArgumentType.ToLower() + ".");
|
||||
}
|
||||
cleanArgs[i] = m_args[i].ArgumentValue;
|
||||
|
||||
|
@ -153,6 +155,8 @@ namespace OpenSim.Region.Environment.Modules.ModuleFramework
|
|||
|
||||
m_command.Invoke(cleanArgs);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -160,8 +164,8 @@ namespace OpenSim.Region.Environment.Modules.ModuleFramework
|
|||
/// </summary>
|
||||
public class CommandArgument
|
||||
{
|
||||
private string m_name;
|
||||
private string m_help;
|
||||
private string m_name;
|
||||
private string m_type;
|
||||
private Object m_val;
|
||||
|
||||
|
@ -208,29 +212,13 @@ namespace OpenSim.Region.Environment.Modules.ModuleFramework
|
|||
m_name = name;
|
||||
}
|
||||
|
||||
#region ICommander Members
|
||||
|
||||
public void RegisterCommand(string commandName, ICommand command)
|
||||
{
|
||||
m_commands[commandName] = command;
|
||||
}
|
||||
|
||||
void ShowConsoleHelp()
|
||||
{
|
||||
m_log.Info("===" + m_name + "===");
|
||||
foreach (ICommand com in m_commands.Values)
|
||||
{
|
||||
m_log.Info("* " + com.Name + " - " + com.Help);
|
||||
}
|
||||
}
|
||||
|
||||
string EscapeRuntimeAPICommand(string command)
|
||||
{
|
||||
command = command.Replace('-', '_');
|
||||
StringBuilder tmp = new StringBuilder(command);
|
||||
tmp[0] = tmp[0].ToString().ToUpper().ToCharArray()[0];
|
||||
|
||||
return tmp.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a runtime C# class which can be compiled and inserted via reflection to enable modules to register new script commands
|
||||
/// </summary>
|
||||
|
@ -253,7 +241,7 @@ namespace OpenSim.Region.Environment.Modules.ModuleFramework
|
|||
{
|
||||
classSrc += "\t\targs[" + i.ToString() + "] = " + Util.Md5Hash(arg.Key) + " " + ";\n";
|
||||
i++;
|
||||
}
|
||||
}
|
||||
classSrc += "\t\tGetCommander(\"" + m_name + "\").Run(\"" + com.Name + "\", args);\n";
|
||||
classSrc += "\t}\n";
|
||||
}
|
||||
|
@ -296,5 +284,25 @@ namespace OpenSim.Region.Environment.Modules.ModuleFramework
|
|||
ShowConsoleHelp();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void ShowConsoleHelp()
|
||||
{
|
||||
m_log.Info("===" + m_name + "===");
|
||||
foreach (ICommand com in m_commands.Values)
|
||||
{
|
||||
m_log.Info("* " + com.Name + " - " + com.Help);
|
||||
}
|
||||
}
|
||||
|
||||
private string EscapeRuntimeAPICommand(string command)
|
||||
{
|
||||
command = command.Replace('-', '_');
|
||||
StringBuilder tmp = new StringBuilder(command);
|
||||
tmp[0] = tmp[0].ToString().ToUpper().ToCharArray()[0];
|
||||
|
||||
return tmp.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,22 +18,21 @@ namespace OpenSim.Region.Modules.SvnSerialiser
|
|||
public class SvnBackupModule : IRegionModule
|
||||
{
|
||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
private SvnClient m_svnClient;
|
||||
|
||||
private bool m_enabled = false;
|
||||
private bool m_installBackupOnLoad = false;
|
||||
private string m_svnurl = "svn://insert.your.svn/here/";
|
||||
private string m_svnuser = "username";
|
||||
private string m_svnpass = "password";
|
||||
private List<Scene> m_scenes = new List<Scene>();
|
||||
private IRegionSerialiser m_serialiser;
|
||||
private bool m_svnAutoSave = false;
|
||||
private SvnClient m_svnClient;
|
||||
private string m_svndir = "SVNmodule\\repo";
|
||||
private string m_svnpass = "password";
|
||||
|
||||
private TimeSpan m_svnperiod = new TimeSpan(0, 0, 15, 0, 0);
|
||||
private bool m_svnAutoSave = false;
|
||||
private string m_svnurl = "svn://insert.your.svn/here/";
|
||||
private string m_svnuser = "username";
|
||||
private Timer m_timer = new Timer();
|
||||
|
||||
private IRegionSerialiser m_serialiser;
|
||||
private List<Scene> m_scenes = new List<Scene>();
|
||||
|
||||
#region SvnModule Core
|
||||
|
||||
/// <summary>
|
||||
|
@ -76,7 +75,9 @@ namespace OpenSim.Region.Modules.SvnSerialiser
|
|||
{
|
||||
m_svnClient.Add3(m_svndir + Slash.DirectorySeparatorChar + scene.RegionInfo.RegionID.ToString(), true, false, false);
|
||||
}
|
||||
catch (SvnException) { }
|
||||
catch (SvnException)
|
||||
{
|
||||
}
|
||||
|
||||
List<string> svnfilenames = new List<string>();
|
||||
foreach (string filename in filenames)
|
||||
|
@ -88,10 +89,10 @@ namespace OpenSim.Region.Modules.SvnSerialiser
|
|||
|
||||
public void LoadRegion(Scene scene)
|
||||
{
|
||||
scene.LoadPrimsFromXml2(m_svndir + Slash.DirectorySeparatorChar + scene.RegionInfo.RegionID.ToString() +
|
||||
Slash.DirectorySeparatorChar + "objects.xml");
|
||||
scene.LoadPrimsFromXml2(m_svndir + Slash.DirectorySeparatorChar + scene.RegionInfo.RegionID.ToString() +
|
||||
Slash.DirectorySeparatorChar + "objects.xml");
|
||||
scene.RequestModuleInterface<ITerrainModule>().LoadFromFile(m_svndir + Slash.DirectorySeparatorChar + scene.RegionInfo.RegionID.ToString() +
|
||||
Slash.DirectorySeparatorChar + "heightmap.r32");
|
||||
Slash.DirectorySeparatorChar + "heightmap.r32");
|
||||
m_log.Info("[SVNBACKUP]: Region load successful (" + scene.RegionInfo.RegionName + ").");
|
||||
}
|
||||
|
||||
|
@ -126,7 +127,7 @@ namespace OpenSim.Region.Modules.SvnSerialiser
|
|||
#region SvnDotNet Callbacks
|
||||
|
||||
private SvnError SimpleAuth(out SvnAuthCredSimple svnCredentials, IntPtr baton,
|
||||
AprString realm, AprString username, bool maySave, AprPool pool)
|
||||
AprString realm, AprString username, bool maySave, AprPool pool)
|
||||
{
|
||||
svnCredentials = SvnAuthCredSimple.Alloc(pool);
|
||||
svnCredentials.Username = new AprString(m_svnuser, pool);
|
||||
|
@ -140,7 +141,7 @@ namespace OpenSim.Region.Modules.SvnSerialiser
|
|||
if (!commitItems.IsNull)
|
||||
{
|
||||
foreach (SvnClientCommitItem2 item in commitItems)
|
||||
{
|
||||
{
|
||||
m_log.Debug("[SVNBACKUP]: ... " + Path.GetFileName(item.Path.ToString()) + " (" + item.Kind.ToString() + ") r" + item.Revision.ToString());
|
||||
}
|
||||
}
|
||||
|
@ -174,8 +175,11 @@ namespace OpenSim.Region.Modules.SvnSerialiser
|
|||
m_svnpass = source.Configs["SVN"].GetString("Password", m_svnpass);
|
||||
m_installBackupOnLoad = source.Configs["SVN"].GetBoolean("ImportOnStartup", m_installBackupOnLoad);
|
||||
m_svnAutoSave = source.Configs["SVN"].GetBoolean("Autosave", m_svnAutoSave);
|
||||
m_svnperiod = new TimeSpan(0, source.Configs["SVN"].GetInt("AutosavePeriod", (int)m_svnperiod.TotalMinutes), 0);
|
||||
} catch(Exception) { }
|
||||
m_svnperiod = new TimeSpan(0, source.Configs["SVN"].GetInt("AutosavePeriod", (int) m_svnperiod.TotalMinutes), 0);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
|
||||
lock (m_scenes)
|
||||
{
|
||||
|
@ -185,7 +189,54 @@ namespace OpenSim.Region.Modules.SvnSerialiser
|
|||
scene.EventManager.OnPluginConsole += EventManager_OnPluginConsole;
|
||||
}
|
||||
|
||||
void EventManager_OnPluginConsole(string[] args)
|
||||
public void PostInitialise()
|
||||
{
|
||||
if (m_enabled == false)
|
||||
return;
|
||||
|
||||
if (m_svnAutoSave == true)
|
||||
{
|
||||
m_timer.Interval = m_svnperiod.TotalMilliseconds;
|
||||
m_timer.Elapsed += new ElapsedEventHandler(m_timer_Elapsed);
|
||||
m_timer.AutoReset = true;
|
||||
m_timer.Start();
|
||||
}
|
||||
|
||||
m_log.Info("[SVNBACKUP]: Connecting to SVN server " + m_svnurl + " ...");
|
||||
SetupSvnProvider();
|
||||
|
||||
m_log.Info("[SVNBACKUP]: Creating repository in " + m_svndir + ".");
|
||||
CreateSvnDirectory();
|
||||
CheckoutSvn();
|
||||
SetupSerialiser();
|
||||
|
||||
if (m_installBackupOnLoad)
|
||||
{
|
||||
m_log.Info("[SVNBACKUP]: Importing latest SVN revision to scenes...");
|
||||
foreach (Scene scene in m_scenes)
|
||||
{
|
||||
LoadRegion(scene);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "SvnBackupModule"; }
|
||||
}
|
||||
|
||||
public bool IsSharedModule
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void EventManager_OnPluginConsole(string[] args)
|
||||
{
|
||||
if (args[0] == "svn" && args[1] == "save")
|
||||
{
|
||||
|
@ -272,38 +323,7 @@ namespace OpenSim.Region.Modules.SvnSerialiser
|
|||
}
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
if (m_enabled == false)
|
||||
return;
|
||||
|
||||
if (m_svnAutoSave == true)
|
||||
{
|
||||
m_timer.Interval = m_svnperiod.TotalMilliseconds;
|
||||
m_timer.Elapsed += new ElapsedEventHandler(m_timer_Elapsed);
|
||||
m_timer.AutoReset = true;
|
||||
m_timer.Start();
|
||||
}
|
||||
|
||||
m_log.Info("[SVNBACKUP]: Connecting to SVN server " + m_svnurl + " ...");
|
||||
SetupSvnProvider();
|
||||
|
||||
m_log.Info("[SVNBACKUP]: Creating repository in " + m_svndir + ".");
|
||||
CreateSvnDirectory();
|
||||
CheckoutSvn();
|
||||
SetupSerialiser();
|
||||
|
||||
if (m_installBackupOnLoad)
|
||||
{
|
||||
m_log.Info("[SVNBACKUP]: Importing latest SVN revision to scenes...");
|
||||
foreach (Scene scene in m_scenes)
|
||||
{
|
||||
LoadRegion(scene);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void m_timer_Elapsed(object sender, ElapsedEventArgs e)
|
||||
private void m_timer_Elapsed(object sender, ElapsedEventArgs e)
|
||||
{
|
||||
SaveAllRegions();
|
||||
}
|
||||
|
@ -320,7 +340,7 @@ namespace OpenSim.Region.Modules.SvnSerialiser
|
|||
m_svnClient.AddUsernameProvider();
|
||||
m_svnClient.AddPromptProvider(new SvnAuthProviderObject.SimplePrompt(SimpleAuth), IntPtr.Zero, 2);
|
||||
m_svnClient.OpenAuth();
|
||||
m_svnClient.Context.LogMsgFunc2 = new SvnDelegate(new SvnClient.GetCommitLog2(GetCommitLogCallback));
|
||||
m_svnClient.Context.LogMsgFunc2 = new SvnDelegate(new SvnClient.GetCommitLog2(GetCommitLogCallback));
|
||||
}
|
||||
|
||||
private void CreateSvnDirectory()
|
||||
|
@ -328,22 +348,5 @@ namespace OpenSim.Region.Modules.SvnSerialiser
|
|||
if (!Directory.Exists(m_svndir))
|
||||
Directory.CreateDirectory(m_svndir);
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "SvnBackupModule"; }
|
||||
}
|
||||
|
||||
public bool IsSharedModule
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue