aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/AssetBase.cs
diff options
context:
space:
mode:
authorUbitUmarov2015-09-01 11:43:07 +0100
committerUbitUmarov2015-09-01 11:43:07 +0100
commitfb78b182520fc9bb0f971afd0322029c70278ea6 (patch)
treeb4e30d383938fdeef8c92d1d1c2f44bb61d329bd /OpenSim/Framework/AssetBase.cs
parentlixo (diff)
parentMantis #7713: fixed bug introduced by 1st MOSES patch. (diff)
downloadopensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.zip
opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.gz
opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.bz2
opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.xz
Merge remote-tracking branch 'os/master'
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/AssetBase.cs363
1 files changed, 363 insertions, 0 deletions
diff --git a/OpenSim/Framework/AssetBase.cs b/OpenSim/Framework/AssetBase.cs
new file mode 100644
index 0000000..2f04d2e
--- /dev/null
+++ b/OpenSim/Framework/AssetBase.cs
@@ -0,0 +1,363 @@
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 OpenSimulator 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.Xml.Serialization;
30using System.Reflection;
31using log4net;
32using OpenMetaverse;
33
34namespace OpenSim.Framework
35{
36 [Flags]
37 public enum AssetFlags : int
38 {
39 Normal = 0, // Immutable asset
40 Maptile = 1, // What it says
41 Rewritable = 2, // Content can be rewritten
42 Collectable = 4 // Can be GC'ed after some time
43 }
44
45 /// <summary>
46 /// Asset class. All Assets are reference by this class or a class derived from this class
47 /// </summary>
48 [Serializable]
49 public class AssetBase
50 {
51 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
52
53 public static readonly int MAX_ASSET_NAME = 64;
54 public static readonly int MAX_ASSET_DESC = 64;
55
56 /// <summary>
57 /// Data of the Asset
58 /// </summary>
59 private byte[] m_data;
60
61 /// <summary>
62 /// Meta Data of the Asset
63 /// </summary>
64 private AssetMetadata m_metadata;
65
66 // This is needed for .NET serialization!!!
67 // Do NOT "Optimize" away!
68 public AssetBase()
69 {
70 m_metadata = new AssetMetadata();
71 m_metadata.FullID = UUID.Zero;
72 m_metadata.ID = UUID.Zero.ToString();
73 m_metadata.Type = (sbyte)AssetType.Unknown;
74 m_metadata.CreatorID = String.Empty;
75 }
76
77 public AssetBase(UUID assetID, string name, sbyte assetType, string creatorID)
78 {
79 if (assetType == (sbyte)AssetType.Unknown)
80 {
81 System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(true);
82 m_log.ErrorFormat("[ASSETBASE]: Creating asset '{0}' ({1}) with an unknown asset type\n{2}",
83 name, assetID, trace.ToString());
84 }
85
86 m_metadata = new AssetMetadata();
87 m_metadata.FullID = assetID;
88 m_metadata.Name = name;
89 m_metadata.Type = assetType;
90 m_metadata.CreatorID = creatorID;
91 }
92
93 public AssetBase(string assetID, string name, sbyte assetType, string creatorID)
94 {
95 if (assetType == (sbyte)AssetType.Unknown)
96 {
97 System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(true);
98 m_log.ErrorFormat("[ASSETBASE]: Creating asset '{0}' ({1}) with an unknown asset type\n{2}",
99 name, assetID, trace.ToString());
100 }
101
102 m_metadata = new AssetMetadata();
103 m_metadata.ID = assetID;
104 m_metadata.Name = name;
105 m_metadata.Type = assetType;
106 m_metadata.CreatorID = creatorID;
107 }
108
109 public bool ContainsReferences
110 {
111 get
112 {
113 return
114 IsTextualAsset && (
115 Type != (sbyte)AssetType.Notecard
116 && Type != (sbyte)AssetType.CallingCard
117 && Type != (sbyte)AssetType.LSLText
118 && Type != (sbyte)AssetType.Landmark);
119 }
120 }
121
122 public bool IsTextualAsset
123 {
124 get
125 {
126 return !IsBinaryAsset;
127 }
128
129 }
130
131 /// <summary>
132 /// Checks if this asset is a binary or text asset
133 /// </summary>
134 public bool IsBinaryAsset
135 {
136 get
137 {
138 return
139 (Type == (sbyte)AssetType.Animation ||
140 Type == (sbyte)AssetType.Gesture ||
141 Type == (sbyte)AssetType.Simstate ||
142 Type == (sbyte)AssetType.Unknown ||
143 Type == (sbyte)AssetType.Object ||
144 Type == (sbyte)AssetType.Sound ||
145 Type == (sbyte)AssetType.SoundWAV ||
146 Type == (sbyte)AssetType.Texture ||
147 Type == (sbyte)AssetType.TextureTGA ||
148 Type == (sbyte)AssetType.Folder ||
149 Type == (sbyte)AssetType.ImageJPEG ||
150 Type == (sbyte)AssetType.ImageTGA ||
151 Type == (sbyte)AssetType.LSLBytecode);
152 }
153 }
154
155 public virtual byte[] Data
156 {
157 get { return m_data; }
158 set { m_data = value; }
159 }
160
161 /// <summary>
162 /// Asset UUID
163 /// </summary>
164 public UUID FullID
165 {
166 get { return m_metadata.FullID; }
167 set { m_metadata.FullID = value; }
168 }
169
170 /// <summary>
171 /// Asset MetaData ID (transferring from UUID to string ID)
172 /// </summary>
173 public string ID
174 {
175 get { return m_metadata.ID; }
176 set { m_metadata.ID = value; }
177 }
178
179 public string Name
180 {
181 get { return m_metadata.Name; }
182 set { m_metadata.Name = value; }
183 }
184
185 public string Description
186 {
187 get { return m_metadata.Description; }
188 set { m_metadata.Description = value; }
189 }
190
191 /// <summary>
192 /// (sbyte) AssetType enum
193 /// </summary>
194 public sbyte Type
195 {
196 get { return m_metadata.Type; }
197 set { m_metadata.Type = value; }
198 }
199
200 /// <summary>
201 /// Is this a region only asset, or does this exist on the asset server also
202 /// </summary>
203 public bool Local
204 {
205 get { return m_metadata.Local; }
206 set { m_metadata.Local = value; }
207 }
208
209 /// <summary>
210 /// Is this asset going to be saved to the asset database?
211 /// </summary>
212 public bool Temporary
213 {
214 get { return m_metadata.Temporary; }
215 set { m_metadata.Temporary = value; }
216 }
217
218 public string CreatorID
219 {
220 get { return m_metadata.CreatorID; }
221 set { m_metadata.CreatorID = value; }
222 }
223
224 public AssetFlags Flags
225 {
226 get { return m_metadata.Flags; }
227 set { m_metadata.Flags = value; }
228 }
229
230 [XmlIgnore]
231 public AssetMetadata Metadata
232 {
233 get { return m_metadata; }
234 set { m_metadata = value; }
235 }
236
237 public override string ToString()
238 {
239 return FullID.ToString();
240 }
241 }
242
243 [Serializable]
244 public class AssetMetadata
245 {
246 private UUID m_fullid;
247 private string m_id;
248 private string m_name = String.Empty;
249 private string m_description = String.Empty;
250 private DateTime m_creation_date;
251 private sbyte m_type = (sbyte)AssetType.Unknown;
252 private string m_content_type;
253 private byte[] m_sha1;
254 private bool m_local;
255 private bool m_temporary;
256 private string m_creatorid;
257 private AssetFlags m_flags;
258
259 public UUID FullID
260 {
261 get { return m_fullid; }
262 set { m_fullid = value; m_id = m_fullid.ToString(); }
263 }
264
265 public string ID
266 {
267 //get { return m_fullid.ToString(); }
268 //set { m_fullid = new UUID(value); }
269 get
270 {
271 if (String.IsNullOrEmpty(m_id))
272 m_id = m_fullid.ToString();
273
274 return m_id;
275 }
276
277 set
278 {
279 UUID uuid = UUID.Zero;
280 if (UUID.TryParse(value, out uuid))
281 {
282 m_fullid = uuid;
283 m_id = m_fullid.ToString();
284 }
285 else
286 m_id = value;
287 }
288 }
289
290 public string Name
291 {
292 get { return m_name; }
293 set { m_name = value; }
294 }
295
296 public string Description
297 {
298 get { return m_description; }
299 set { m_description = value; }
300 }
301
302 public DateTime CreationDate
303 {
304 get { return m_creation_date; }
305 set { m_creation_date = value; }
306 }
307
308 public sbyte Type
309 {
310 get { return m_type; }
311 set { m_type = value; }
312 }
313
314 public string ContentType
315 {
316 get
317 {
318 if (!String.IsNullOrEmpty(m_content_type))
319 return m_content_type;
320 else
321 return SLUtil.SLAssetTypeToContentType(m_type);
322 }
323 set
324 {
325 m_content_type = value;
326
327 sbyte type = (sbyte)SLUtil.ContentTypeToSLAssetType(value);
328 if (type != -1)
329 m_type = type;
330 }
331 }
332
333 public byte[] SHA1
334 {
335 get { return m_sha1; }
336 set { m_sha1 = value; }
337 }
338
339 public bool Local
340 {
341 get { return m_local; }
342 set { m_local = value; }
343 }
344
345 public bool Temporary
346 {
347 get { return m_temporary; }
348 set { m_temporary = value; }
349 }
350
351 public string CreatorID
352 {
353 get { return m_creatorid; }
354 set { m_creatorid = value; }
355 }
356
357 public AssetFlags Flags
358 {
359 get { return m_flags; }
360 set { m_flags = value; }
361 }
362 }
363}