aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorJustin Clarke Casey2008-06-04 23:57:27 +0000
committerJustin Clarke Casey2008-06-04 23:57:27 +0000
commit168f9367cb39652bbee0dd825ac70ba66b4592fe (patch)
tree4d208792220177c545c8ff4982433f113da65b2a /OpenSim
parentUpdate svn properties. (diff)
downloadopensim-SC-168f9367cb39652bbee0dd825ac70ba66b4592fe.zip
opensim-SC-168f9367cb39652bbee0dd825ac70ba66b4592fe.tar.gz
opensim-SC-168f9367cb39652bbee0dd825ac70ba66b4592fe.tar.bz2
opensim-SC-168f9367cb39652bbee0dd825ac70ba66b4592fe.tar.xz
* Dearchive using assets metadata rather than assuming everything is a texture
* However, still not actually archiving anything except textures
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Region/Environment/Modules/World/Archiver/ArchiveConstants.cs5
-rw-r--r--OpenSim/Region/Environment/Modules/World/Archiver/ArchiveReadRequest.cs29
-rw-r--r--OpenSim/Region/Environment/Modules/World/Archiver/AssetsDearchiver.cs184
3 files changed, 199 insertions, 19 deletions
diff --git a/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveConstants.cs b/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveConstants.cs
index bfe635d..517a79e 100644
--- a/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveConstants.cs
+++ b/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveConstants.cs
@@ -43,6 +43,11 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver
43 public static readonly string TEXTURE_EXTENSION = ".jp2"; 43 public static readonly string TEXTURE_EXTENSION = ".jp2";
44 44
45 /// <summary> 45 /// <summary>
46 /// Path for the assets metadata file
47 /// </summary>
48 public static readonly string ASSETS_METADATA_PATH = "assets.xml";
49
50 /// <summary>
46 /// Path for the prims file 51 /// Path for the prims file
47 /// </summary> 52 /// </summary>
48 public static readonly string PRIMS_PATH = "prims.xml"; 53 public static readonly string PRIMS_PATH = "prims.xml";
diff --git a/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveReadRequest.cs b/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveReadRequest.cs
index 6a3b519..f92e955 100644
--- a/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveReadRequest.cs
+++ b/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveReadRequest.cs
@@ -45,8 +45,8 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver
45 45
46 protected static System.Text.ASCIIEncoding m_asciiEncoding = new System.Text.ASCIIEncoding(); 46 protected static System.Text.ASCIIEncoding m_asciiEncoding = new System.Text.ASCIIEncoding();
47 47
48 private Scene m_scene; 48 protected Scene m_scene;
49 private string m_loadPath; 49 protected string m_loadPath;
50 50
51 public ArchiveReadRequest(Scene scene, string loadPath) 51 public ArchiveReadRequest(Scene scene, string loadPath)
52 { 52 {
@@ -59,6 +59,7 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver
59 protected void DearchiveRegion() 59 protected void DearchiveRegion()
60 { 60 {
61 TarArchiveReader archive = new TarArchiveReader(m_loadPath); 61 TarArchiveReader archive = new TarArchiveReader(m_loadPath);
62 AssetsDearchiver dearchiver = new AssetsDearchiver(m_scene.AssetCache);
62 63
63 string serializedPrims = string.Empty; 64 string serializedPrims = string.Empty;
64 65
@@ -75,28 +76,18 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver
75 { 76 {
76 serializedPrims = m_asciiEncoding.GetString(data); 77 serializedPrims = m_asciiEncoding.GetString(data);
77 } 78 }
79 else if (filePath.Equals(ArchiveConstants.ASSETS_METADATA_PATH))
80 {
81 string xml = m_asciiEncoding.GetString(data);
82 dearchiver.AddAssetMetadata(xml);
83 }
78 else if (filePath.StartsWith(ArchiveConstants.TEXTURES_PATH)) 84 else if (filePath.StartsWith(ArchiveConstants.TEXTURES_PATH))
79 { 85 {
80 // Right now we're nastily obtaining the lluuid from the filename 86 dearchiver.AddAssetData(filePath, data);
81 string rawId = filePath.Remove(0, ArchiveConstants.TEXTURES_PATH.Length);
82 rawId = rawId.Remove(rawId.Length - ArchiveConstants.TEXTURE_EXTENSION.Length);
83
84 m_log.DebugFormat("[ARCHIVER]: Importing asset {0}", rawId);
85
86 // Not preserving asset name or description as of yet
87 AssetBase asset = new AssetBase(new LLUUID(rawId), "imported name");
88 asset.Description = "imported description";
89
90 asset.Type = (sbyte)AssetType.Texture;
91 asset.InvType = (sbyte)InventoryType.Texture;
92
93 asset.Data = data;
94
95 m_scene.AssetCache.AddAsset(asset);
96 } 87 }
97 } 88 }
98 89
99 m_log.DebugFormat("[ARCHIVER]: Reached end of archive"); 90 m_log.Debug("[ARCHIVER]: Reached end of archive");
100 91
101 archive.Close(); 92 archive.Close();
102 93
diff --git a/OpenSim/Region/Environment/Modules/World/Archiver/AssetsDearchiver.cs b/OpenSim/Region/Environment/Modules/World/Archiver/AssetsDearchiver.cs
new file mode 100644
index 0000000..1c5b535
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/World/Archiver/AssetsDearchiver.cs
@@ -0,0 +1,184 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.IO;
31using System.Reflection;
32using System.Xml;
33using libsecondlife;
34using log4net;
35using OpenSim.Framework;
36using OpenSim.Framework.Communications.Cache;
37
38namespace OpenSim.Region.Environment.Modules.World.Archiver
39{
40 /// <summary>
41 /// Dearchives assets
42 /// </summary>
43 public class AssetsDearchiver
44 {
45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
46
47 protected static System.Text.ASCIIEncoding m_asciiEncoding = new System.Text.ASCIIEncoding();
48
49 /// <summary>
50 /// Store for asset data we received before we get the metadata
51 /// </summary>
52 protected Dictionary<string, byte[]> m_assetDataAwaitingMetadata = new Dictionary<string, byte[]>();
53
54 /// <summary>
55 /// Asset metadata. Is null if asset metadata isn't yet available.
56 /// </summary>
57 protected Dictionary<string, AssetMetadata> m_metadata;
58
59 /// <summary>
60 /// Cache to which dearchived assets will be added
61 /// </summary>
62 protected AssetCache m_cache;
63
64 public AssetsDearchiver(AssetCache cache)
65 {
66 m_cache = cache;
67 }
68
69 /// <summary>
70 /// Add asset data to the dearchiver
71 /// </summary>
72 /// <param name="assetFilename"></param>
73 /// <param name="data"></param>
74 public void AddAssetData(string assetFilename, byte[] data)
75 {
76 if (null == m_metadata)
77 {
78 m_assetDataAwaitingMetadata[assetFilename] = data;
79 }
80 else
81 {
82 ResolveAssetData(assetFilename, data);
83 }
84 }
85
86 /// <summary>
87 /// Add asset metadata xml
88 /// </summary>
89 /// <param name="xml"></param>
90 public void AddAssetMetadata(string xml)
91 {
92 m_metadata = new Dictionary<string, AssetMetadata>();
93
94 StringReader sr = new StringReader(xml);
95 XmlTextReader reader = new XmlTextReader(sr);
96
97 reader.ReadStartElement("assets");
98 reader.Read();
99
100 m_log.DebugFormat("next node {0}", reader.Name);
101 while (reader.Name.Equals("asset"))
102 {
103 reader.Read();
104
105 AssetMetadata metadata = new AssetMetadata();
106
107 string filename = reader.ReadElementString("filename");
108 m_log.DebugFormat("[DEARCHIVER]: Reading node {0}", filename);
109
110 metadata.Name = reader.ReadElementString("name");
111 metadata.Description = reader.ReadElementString("description");
112 metadata.AssetType = Convert.ToSByte(reader.ReadElementString("asset-type"));
113 metadata.AssetType = Convert.ToSByte(reader.ReadElementString("inventory-type"));
114
115 m_metadata[filename] = metadata;
116
117 // Read asset end tag
118 reader.ReadEndElement();
119
120 reader.Read();
121 }
122
123 m_log.DebugFormat("[DEARCHIVER]: Resolved {0} items of asset metadata", m_metadata.Count);
124
125 ResolvePendingAssetData();
126 }
127
128 /// <summary>
129 /// Resolve asset data that we collected before receiving the metadata
130 /// </summary>
131 protected void ResolvePendingAssetData()
132 {
133 foreach (string filename in m_assetDataAwaitingMetadata.Keys)
134 {
135 ResolveAssetData(filename, m_assetDataAwaitingMetadata[filename]);
136 }
137 }
138
139 /// <summary>
140 /// Resolve a new piece of asset data against stored metadata
141 /// </summary>
142 /// <param name="assetFilename"></param>
143 /// <param name="data"></param>
144 protected void ResolveAssetData(string assetPath, byte[] data)
145 {
146 // Right now we're nastily obtaining the lluuid from the filename
147 string filename = assetPath.Remove(0, ArchiveConstants.TEXTURES_PATH.Length);
148
149 if (m_metadata.ContainsKey(filename))
150 {
151 AssetMetadata metadata = m_metadata[filename];
152
153 string rawId = filename.Remove(filename.Length - ArchiveConstants.TEXTURE_EXTENSION.Length);
154
155 m_log.DebugFormat("[ARCHIVER]: Importing asset {0}", rawId);
156
157 AssetBase asset = new AssetBase(new LLUUID(rawId), metadata.Name);
158 asset.Description = metadata.Description;
159 asset.Type = metadata.AssetType;
160 asset.InvType = metadata.InventoryType;
161 asset.Data = data;
162
163 m_cache.AddAsset(asset);
164 }
165 else
166 {
167 m_log.ErrorFormat(
168 "[DEARCHIVER]: Tried to dearchive data with filename {0} without any corresponding metadata",
169 assetPath);
170 }
171 }
172
173 /// <summary>
174 /// Metadata for an asset
175 /// </summary>
176 protected struct AssetMetadata
177 {
178 public string Name;
179 public string Description;
180 public sbyte AssetType;
181 public sbyte InventoryType;
182 }
183 }
184}