mirror of
https://github.com/opensim/opensim.git
synced 2026-08-07 09:45:47 +08:00
Merge branch 'master' of git://opensimulator.org/git/opensim
This commit is contained in:
@@ -51,6 +51,12 @@ namespace OpenSim.Region.CoreModules.World.Archiver
|
||||
public class ArchiveReadRequest
|
||||
{
|
||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
/// <summary>
|
||||
/// The maximum major version of OAR that we can read. Minor versions shouldn't need a number since version
|
||||
/// bumps here should be compatible.
|
||||
/// </summary>
|
||||
public static int MAX_MAJOR_VERSION = 0;
|
||||
|
||||
protected Scene m_scene;
|
||||
protected Stream m_loadStream;
|
||||
@@ -497,6 +503,22 @@ namespace OpenSim.Region.CoreModules.World.Archiver
|
||||
{
|
||||
if (xtr.NodeType == XmlNodeType.Element)
|
||||
{
|
||||
if (xtr.Name.ToString() == "archive")
|
||||
{
|
||||
int majorVersion = int.Parse(xtr["major_version"]);
|
||||
int minorVersion = int.Parse(xtr["minor_version"]);
|
||||
string version = string.Format("{0}.{1}", majorVersion, minorVersion);
|
||||
|
||||
if (majorVersion > MAX_MAJOR_VERSION)
|
||||
{
|
||||
throw new Exception(
|
||||
string.Format(
|
||||
"The OAR you are trying to load has major version number of {0} but this version of OpenSim can only load OARs with major version number {1} and below",
|
||||
majorVersion, MAX_MAJOR_VERSION));
|
||||
}
|
||||
|
||||
m_log.InfoFormat("[ARCHIVER]: Loading OAR with version {0}", version);
|
||||
}
|
||||
if (xtr.Name.ToString() == "datetime")
|
||||
{
|
||||
int value;
|
||||
|
||||
@@ -60,6 +60,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver
|
||||
protected Scene m_scene;
|
||||
protected TarArchiveWriter m_archiveWriter;
|
||||
protected Guid m_requestId;
|
||||
protected Dictionary<string, object> m_options;
|
||||
|
||||
public ArchiveWriteRequestExecution(
|
||||
List<SceneObjectGroup> sceneObjects,
|
||||
@@ -67,7 +68,8 @@ namespace OpenSim.Region.CoreModules.World.Archiver
|
||||
IRegionSerialiserModule serialiser,
|
||||
Scene scene,
|
||||
TarArchiveWriter archiveWriter,
|
||||
Guid requestId)
|
||||
Guid requestId,
|
||||
Dictionary<string, object> options)
|
||||
{
|
||||
m_sceneObjects = sceneObjects;
|
||||
m_terrainModule = terrainModule;
|
||||
@@ -75,6 +77,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver
|
||||
m_scene = scene;
|
||||
m_archiveWriter = archiveWriter;
|
||||
m_requestId = requestId;
|
||||
m_options = options;
|
||||
}
|
||||
|
||||
protected internal void ReceivedAllAssets(
|
||||
@@ -105,12 +108,6 @@ namespace OpenSim.Region.CoreModules.World.Archiver
|
||||
// "[ARCHIVER]: Received {0} of {1} assets requested",
|
||||
// assetsFoundUuids.Count, assetsFoundUuids.Count + assetsNotFoundUuids.Count);
|
||||
|
||||
m_log.InfoFormat("[ARCHIVER]: Creating archive file. This may take some time.");
|
||||
|
||||
// Write out control file
|
||||
m_archiveWriter.WriteFile(ArchiveConstants.CONTROL_FILE_PATH, Create0p2ControlFile());
|
||||
m_log.InfoFormat("[ARCHIVER]: Added control file to archive.");
|
||||
|
||||
// Write out region settings
|
||||
string settingsPath
|
||||
= String.Format("{0}{1}.xml", ArchiveConstants.SETTINGS_PATH, m_scene.RegionInfo.RegionName);
|
||||
@@ -140,47 +137,22 @@ namespace OpenSim.Region.CoreModules.World.Archiver
|
||||
|
||||
m_log.InfoFormat("[ARCHIVER]: Added terrain information to archive.");
|
||||
|
||||
Dictionary<string, object> serializationOptions = new Dictionary<string, object>();
|
||||
// if (m_options.ContainsKey("version") && (string)m_options["version"] == "0")
|
||||
// serializationOptions["old-guids"] = true;
|
||||
|
||||
// Write out scene object metadata
|
||||
foreach (SceneObjectGroup sceneObject in m_sceneObjects)
|
||||
{
|
||||
//m_log.DebugFormat("[ARCHIVER]: Saving {0} {1}, {2}", entity.Name, entity.UUID, entity.GetType());
|
||||
|
||||
string serializedObject = m_serialiser.SerializeGroupToXml2(sceneObject);
|
||||
string serializedObject = m_serialiser.SerializeGroupToXml2(sceneObject, serializationOptions);
|
||||
m_archiveWriter.WriteFile(ArchiveHelpers.CreateObjectPath(sceneObject), serializedObject);
|
||||
}
|
||||
|
||||
m_log.InfoFormat("[ARCHIVER]: Added scene objects to archive.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create the control file for a 0.2 version archive
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static string Create0p2ControlFile()
|
||||
{
|
||||
StringWriter sw = new StringWriter();
|
||||
XmlTextWriter xtw = new XmlTextWriter(sw);
|
||||
xtw.Formatting = Formatting.Indented;
|
||||
xtw.WriteStartDocument();
|
||||
xtw.WriteStartElement("archive");
|
||||
xtw.WriteAttributeString("major_version", "0");
|
||||
xtw.WriteAttributeString("minor_version", "3");
|
||||
|
||||
xtw.WriteStartElement("creation_info");
|
||||
DateTime now = DateTime.UtcNow;
|
||||
TimeSpan t = now - new DateTime(1970, 1, 1);
|
||||
xtw.WriteElementString("datetime", ((int)t.TotalSeconds).ToString());
|
||||
xtw.WriteElementString("id", UUID.Random().ToString());
|
||||
xtw.WriteEndElement();
|
||||
xtw.WriteEndElement();
|
||||
|
||||
xtw.Flush();
|
||||
xtw.Close();
|
||||
|
||||
String s = sw.ToString();
|
||||
sw.Close();
|
||||
|
||||
return s;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ using System.IO.Compression;
|
||||
using System.Reflection;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Xml;
|
||||
using log4net;
|
||||
using OpenMetaverse;
|
||||
using OpenSim.Framework;
|
||||
@@ -98,7 +99,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver
|
||||
/// Archive the region requested.
|
||||
/// </summary>
|
||||
/// <exception cref="System.IO.IOException">if there was an io problem with creating the file</exception>
|
||||
public void ArchiveRegion()
|
||||
public void ArchiveRegion(Dictionary<string, object> options)
|
||||
{
|
||||
Dictionary<UUID, AssetType> assetUuids = new Dictionary<UUID, AssetType>();
|
||||
|
||||
@@ -165,11 +166,71 @@ namespace OpenSim.Region.CoreModules.World.Archiver
|
||||
m_scene.RequestModuleInterface<IRegionSerialiserModule>(),
|
||||
m_scene,
|
||||
archiveWriter,
|
||||
m_requestId);
|
||||
m_requestId,
|
||||
options);
|
||||
|
||||
m_log.InfoFormat("[ARCHIVER]: Creating archive file. This may take some time.");
|
||||
|
||||
// Write out control file
|
||||
archiveWriter.WriteFile(ArchiveConstants.CONTROL_FILE_PATH, Create0p2ControlFile(options));
|
||||
m_log.InfoFormat("[ARCHIVER]: Added control file to archive.");
|
||||
|
||||
new AssetsRequest(
|
||||
new AssetsArchiver(archiveWriter), assetUuids,
|
||||
m_scene.AssetService, awre.ReceivedAllAssets).Execute();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create the control file for the most up to date archive
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static string Create0p2ControlFile(Dictionary<string, object> options)
|
||||
{
|
||||
int majorVersion = 0, minorVersion = 4;
|
||||
|
||||
/*
|
||||
if (options.ContainsKey("version") && (string)options["version"] == "0")
|
||||
{
|
||||
majorVersion = 0;
|
||||
minorVersion = 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
majorVersion = 1;
|
||||
minorVersion = 0;
|
||||
}
|
||||
*/
|
||||
|
||||
m_log.InfoFormat("[ARCHIVER]: Creating version {0}.{1} OAR", majorVersion, minorVersion);
|
||||
// if (majorVersion == 1)
|
||||
// {
|
||||
// m_log.WarnFormat("[ARCHIVER]: Please be aware that version 1.0 OARs are not compatible with OpenSim 0.7.0.2 and earlier. Please use the --version=0 option if you want to produce a compatible OAR");
|
||||
// }
|
||||
|
||||
|
||||
StringWriter sw = new StringWriter();
|
||||
XmlTextWriter xtw = new XmlTextWriter(sw);
|
||||
xtw.Formatting = Formatting.Indented;
|
||||
xtw.WriteStartDocument();
|
||||
xtw.WriteStartElement("archive");
|
||||
xtw.WriteAttributeString("major_version", majorVersion.ToString());
|
||||
xtw.WriteAttributeString("minor_version", minorVersion.ToString());
|
||||
|
||||
xtw.WriteStartElement("creation_info");
|
||||
DateTime now = DateTime.UtcNow;
|
||||
TimeSpan t = now - new DateTime(1970, 1, 1);
|
||||
xtw.WriteElementString("datetime", ((int)t.TotalSeconds).ToString());
|
||||
xtw.WriteElementString("id", UUID.Random().ToString());
|
||||
xtw.WriteEndElement();
|
||||
xtw.WriteEndElement();
|
||||
|
||||
xtw.Flush();
|
||||
xtw.Close();
|
||||
|
||||
String s = sw.ToString();
|
||||
sw.Close();
|
||||
|
||||
return s;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,37 +122,44 @@ namespace OpenSim.Region.CoreModules.World.Archiver
|
||||
/// <param name="cmdparams"></param>
|
||||
public void HandleSaveOarConsoleCommand(string module, string[] cmdparams)
|
||||
{
|
||||
Dictionary<string, object> options = new Dictionary<string, object>();
|
||||
|
||||
OptionSet ops = new OptionSet();
|
||||
ops.Add("v|version=", delegate(string v) { options["version"] = v; });
|
||||
|
||||
List<string> mainParams = ops.Parse(cmdparams);
|
||||
|
||||
if (cmdparams.Length > 2)
|
||||
{
|
||||
ArchiveRegion(cmdparams[2]);
|
||||
ArchiveRegion(mainParams[2], options);
|
||||
}
|
||||
else
|
||||
{
|
||||
ArchiveRegion(DEFAULT_OAR_BACKUP_FILENAME);
|
||||
ArchiveRegion(DEFAULT_OAR_BACKUP_FILENAME, options);
|
||||
}
|
||||
}
|
||||
|
||||
public void ArchiveRegion(string savePath)
|
||||
public void ArchiveRegion(string savePath, Dictionary<string, object> options)
|
||||
{
|
||||
ArchiveRegion(savePath, Guid.Empty);
|
||||
ArchiveRegion(savePath, Guid.Empty, options);
|
||||
}
|
||||
|
||||
public void ArchiveRegion(string savePath, Guid requestId)
|
||||
|
||||
public void ArchiveRegion(string savePath, Guid requestId, Dictionary<string, object> options)
|
||||
{
|
||||
m_log.InfoFormat(
|
||||
"[ARCHIVER]: Writing archive for region {0} to {1}", m_scene.RegionInfo.RegionName, savePath);
|
||||
|
||||
new ArchiveWriteRequestPreparation(m_scene, savePath, requestId).ArchiveRegion();
|
||||
new ArchiveWriteRequestPreparation(m_scene, savePath, requestId).ArchiveRegion(options);
|
||||
}
|
||||
|
||||
|
||||
public void ArchiveRegion(Stream saveStream)
|
||||
{
|
||||
ArchiveRegion(saveStream, Guid.Empty);
|
||||
}
|
||||
|
||||
|
||||
public void ArchiveRegion(Stream saveStream, Guid requestId)
|
||||
{
|
||||
new ArchiveWriteRequestPreparation(m_scene, saveStream, requestId).ArchiveRegion();
|
||||
new ArchiveWriteRequestPreparation(m_scene, saveStream, requestId).ArchiveRegion(new Dictionary<string, object>());
|
||||
}
|
||||
|
||||
public void DearchiveRegion(string loadPath)
|
||||
|
||||
@@ -230,7 +230,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests
|
||||
// upset load
|
||||
tar.WriteDir(ArchiveConstants.TERRAINS_PATH);
|
||||
|
||||
tar.WriteFile(ArchiveConstants.CONTROL_FILE_PATH, ArchiveWriteRequestExecution.Create0p2ControlFile());
|
||||
tar.WriteFile(ArchiveConstants.CONTROL_FILE_PATH, ArchiveWriteRequestPreparation.Create0p2ControlFile(new Dictionary<string, Object>()));
|
||||
|
||||
SceneObjectPart part1 = CreateSceneObjectPart1();
|
||||
SceneObjectGroup object1 = new SceneObjectGroup(part1);
|
||||
@@ -329,7 +329,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests
|
||||
TarArchiveWriter tar = new TarArchiveWriter(archiveWriteStream);
|
||||
|
||||
tar.WriteDir(ArchiveConstants.TERRAINS_PATH);
|
||||
tar.WriteFile(ArchiveConstants.CONTROL_FILE_PATH, ArchiveWriteRequestExecution.Create0p2ControlFile());
|
||||
tar.WriteFile(ArchiveConstants.CONTROL_FILE_PATH, ArchiveWriteRequestPreparation.Create0p2ControlFile(new Dictionary<string, Object>()));
|
||||
|
||||
RegionSettings rs = new RegionSettings();
|
||||
rs.AgentLimit = 17;
|
||||
|
||||
@@ -160,9 +160,9 @@ namespace OpenSim.Region.CoreModules.World.Serialiser
|
||||
return SceneXmlLoader.DeserializeGroupFromXml2(xmlString);
|
||||
}
|
||||
|
||||
public string SerializeGroupToXml2(SceneObjectGroup grp)
|
||||
public string SerializeGroupToXml2(SceneObjectGroup grp, Dictionary<string, object> options)
|
||||
{
|
||||
return SceneXmlLoader.SaveGroupToXml2(grp);
|
||||
return SceneXmlLoader.SaveGroupToXml2(grp, options);
|
||||
}
|
||||
|
||||
public void SavePrimListToXml2(EntityBase[] entityList, string fileName)
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using log4net.Config;
|
||||
using NUnit.Framework;
|
||||
using NUnit.Framework.SyntaxHelpers;
|
||||
@@ -34,8 +37,6 @@ using OpenSim.Region.Framework.Scenes;
|
||||
using OpenSim.Region.Framework.Scenes.Serialization;
|
||||
using OpenSim.Tests.Common;
|
||||
using OpenSim.Tests.Common.Setup;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
|
||||
namespace OpenSim.Region.CoreModules.World.Serialiser.Tests
|
||||
{
|
||||
@@ -302,15 +303,19 @@ namespace OpenSim.Region.CoreModules.World.Serialiser.Tests
|
||||
{
|
||||
case "UUID":
|
||||
xtr.ReadStartElement("UUID");
|
||||
uuid = UUID.Parse(xtr.ReadElementString("Guid"));
|
||||
xtr.ReadEndElement();
|
||||
try
|
||||
{
|
||||
uuid = UUID.Parse(xtr.ReadElementString("UUID"));
|
||||
xtr.ReadEndElement();
|
||||
}
|
||||
catch { } // ignore everything but <UUID><UUID>...</UUID></UUID>
|
||||
break;
|
||||
case "Name":
|
||||
name = xtr.ReadElementContentAsString();
|
||||
break;
|
||||
case "CreatorID":
|
||||
xtr.ReadStartElement("CreatorID");
|
||||
creatorId = UUID.Parse(xtr.ReadElementString("Guid"));
|
||||
creatorId = UUID.Parse(xtr.ReadElementString("UUID"));
|
||||
xtr.ReadEndElement();
|
||||
break;
|
||||
}
|
||||
@@ -369,7 +374,9 @@ namespace OpenSim.Region.CoreModules.World.Serialiser.Tests
|
||||
// Need to add the object to the scene so that the request to get script state succeeds
|
||||
m_scene.AddSceneObject(so);
|
||||
|
||||
string xml2 = m_serialiserModule.SerializeGroupToXml2(so);
|
||||
Dictionary<string, object> options = new Dictionary<string, object>();
|
||||
options["old-guids"] = true;
|
||||
string xml2 = m_serialiserModule.SerializeGroupToXml2(so, options);
|
||||
|
||||
XmlTextReader xtr = new XmlTextReader(new StringReader(xml2));
|
||||
xtr.ReadStartElement("SceneObjectGroup");
|
||||
|
||||
Reference in New Issue
Block a user