aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules
diff options
context:
space:
mode:
authorJustin Clarke Casey2008-06-04 18:50:58 +0000
committerJustin Clarke Casey2008-06-04 18:50:58 +0000
commit1d745cca1753ee62a75633029adeb3abfb9b224a (patch)
treee18ed3ba3a4d02ae75b2b3a55205ebadd447b3f6 /OpenSim/Region/Environment/Modules
parent* adding XmppPresenceStanza and deserialization/reification support (diff)
downloadopensim-SC_OLD-1d745cca1753ee62a75633029adeb3abfb9b224a.zip
opensim-SC_OLD-1d745cca1753ee62a75633029adeb3abfb9b224a.tar.gz
opensim-SC_OLD-1d745cca1753ee62a75633029adeb3abfb9b224a.tar.bz2
opensim-SC_OLD-1d745cca1753ee62a75633029adeb3abfb9b224a.tar.xz
* Start writing out assets metadata file for archiver
* Ignoring it on reload as of yet
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Environment/Modules/World/Archiver/ArchiveWriteRequest.cs20
-rw-r--r--OpenSim/Region/Environment/Modules/World/Archiver/AssetsArchiver.cs129
2 files changed, 132 insertions, 17 deletions
diff --git a/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveWriteRequest.cs b/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveWriteRequest.cs
index 6c341c6..41f230c 100644
--- a/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveWriteRequest.cs
+++ b/OpenSim/Region/Environment/Modules/World/Archiver/ArchiveWriteRequest.cs
@@ -123,23 +123,9 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver
123 TarArchiveWriter archive = new TarArchiveWriter(); 123 TarArchiveWriter archive = new TarArchiveWriter();
124 124
125 archive.AddFile(ArchiveConstants.PRIMS_PATH, m_serializedEntities); 125 archive.AddFile(ArchiveConstants.PRIMS_PATH, m_serializedEntities);
126 126
127 // It appears that gtar, at least, doesn't need the intermediate directory entries in the tar 127 AssetsArchiver assetsArchiver = new AssetsArchiver(assets);
128 //archive.AddDir("assets"); 128 assetsArchiver.Archive(archive);
129
130 foreach (LLUUID uuid in assets.Keys)
131 {
132 if (assets[uuid] != null)
133 {
134 archive.AddFile(
135 ArchiveConstants.TEXTURES_PATH + uuid.ToString() + ArchiveConstants.TEXTURE_EXTENSION,
136 assets[uuid].Data);
137 }
138 else
139 {
140 m_log.DebugFormat("[ARCHIVER]: Could not find asset {0} to archive", uuid);
141 }
142 }
143 129
144 archive.WriteTar(m_savePath); 130 archive.WriteTar(m_savePath);
145 131
diff --git a/OpenSim/Region/Environment/Modules/World/Archiver/AssetsArchiver.cs b/OpenSim/Region/Environment/Modules/World/Archiver/AssetsArchiver.cs
new file mode 100644
index 0000000..44757cc
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/World/Archiver/AssetsArchiver.cs
@@ -0,0 +1,129 @@
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.Collections.Generic;
29using System.IO;
30using System.Reflection;
31using System.Xml;
32using libsecondlife;
33using log4net;
34using OpenSim.Framework;
35
36namespace OpenSim.Region.Environment.Modules.World.Archiver
37{
38 /// <summary>
39 /// Archives assets
40 /// </summary>
41 public class AssetsArchiver
42 {
43 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
44
45 /// <summary>
46 /// Archive assets
47 /// </summary>
48 protected IDictionary<LLUUID, AssetBase> m_assets;
49
50 public AssetsArchiver(IDictionary<LLUUID, AssetBase> assets)
51 {
52 m_assets = assets;
53 }
54
55 /// <summary>
56 /// Archive the assets given to this archiver to the given archive.
57 /// </summary>
58 /// <param name="archive"></param>
59 public void Archive(TarArchiveWriter archive)
60 {
61 // It appears that gtar, at least, doesn't need the intermediate directory entries in the tar
62 //archive.AddDir("assets");
63
64 WriteMetadata(archive);
65 WriteData(archive);
66 }
67
68 /// <summary>
69 /// Write an assets metadata file to the given archive
70 /// </summary>
71 /// <param name="archive"></param>
72 protected void WriteMetadata(TarArchiveWriter archive)
73 {
74 StringWriter sw = new StringWriter();
75 XmlTextWriter xtw = new XmlTextWriter(sw);
76
77 xtw.Formatting = Formatting.Indented;
78 xtw.WriteStartDocument();
79
80 xtw.WriteStartElement("assets");
81
82 foreach (LLUUID uuid in m_assets.Keys)
83 {
84 if (m_assets[uuid] != null)
85 {
86 xtw.WriteStartElement("asset");
87
88 AssetBase asset = m_assets[uuid];
89
90 xtw.WriteElementString("filename", uuid.ToString() + ArchiveConstants.TEXTURE_EXTENSION);
91 xtw.WriteElementString("name", asset.Name);
92 xtw.WriteElementString("description", asset.Description);
93 xtw.WriteElementString("asset-type", asset.Type.ToString());
94 xtw.WriteElementString("inventory-type", asset.InvType.ToString());
95
96 xtw.WriteEndElement();
97 }
98
99 }
100
101 xtw.WriteEndElement();
102
103 xtw.WriteEndDocument();
104
105 archive.AddFile("assets.xml", sw.ToString());
106 }
107
108 /// <summary>
109 /// Write asset data files to the given archive
110 /// </summary>
111 /// <param name="archive"></param>
112 protected void WriteData(TarArchiveWriter archive)
113 {
114 foreach (LLUUID uuid in m_assets.Keys)
115 {
116 if (m_assets[uuid] != null)
117 {
118 archive.AddFile(
119 ArchiveConstants.TEXTURES_PATH + uuid.ToString() + ArchiveConstants.TEXTURE_EXTENSION,
120 m_assets[uuid].Data);
121 }
122 else
123 {
124 m_log.DebugFormat("[ARCHIVER]: Could not find asset {0} to archive", uuid);
125 }
126 }
127 }
128 }
129}