clockwerk-opensim – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 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  
28 using System;
29 using System.Xml.Serialization;
30 using System.Reflection;
31 using log4net;
32 using OpenMetaverse;
33  
34 namespace 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.RootFolder ||
150 Type == (sbyte)AssetType.LostAndFoundFolder ||
151 Type == (sbyte)AssetType.SnapshotFolder ||
152 Type == (sbyte)AssetType.TrashFolder ||
153 Type == (sbyte)AssetType.ImageJPEG ||
154 Type == (sbyte) AssetType.ImageTGA ||
155 Type == (sbyte) AssetType.LSLBytecode);
156 }
157 }
158  
159 public virtual byte[] Data
160 {
161 get { return m_data; }
162 set { m_data = value; }
163 }
164  
165 /// <summary>
166 /// Asset UUID
167 /// </summary>
168 public UUID FullID
169 {
170 get { return m_metadata.FullID; }
171 set { m_metadata.FullID = value; }
172 }
173  
174 /// <summary>
175 /// Asset MetaData ID (transferring from UUID to string ID)
176 /// </summary>
177 public string ID
178 {
179 get { return m_metadata.ID; }
180 set { m_metadata.ID = value; }
181 }
182  
183 public string Name
184 {
185 get { return m_metadata.Name; }
186 set { m_metadata.Name = value; }
187 }
188  
189 public string Description
190 {
191 get { return m_metadata.Description; }
192 set { m_metadata.Description = value; }
193 }
194  
195 /// <summary>
196 /// (sbyte) AssetType enum
197 /// </summary>
198 public sbyte Type
199 {
200 get { return m_metadata.Type; }
201 set { m_metadata.Type = value; }
202 }
203  
204 /// <summary>
205 /// Is this a region only asset, or does this exist on the asset server also
206 /// </summary>
207 public bool Local
208 {
209 get { return m_metadata.Local; }
210 set { m_metadata.Local = value; }
211 }
212  
213 /// <summary>
214 /// Is this asset going to be saved to the asset database?
215 /// </summary>
216 public bool Temporary
217 {
218 get { return m_metadata.Temporary; }
219 set { m_metadata.Temporary = value; }
220 }
221  
222 public string CreatorID
223 {
224 get { return m_metadata.CreatorID; }
225 set { m_metadata.CreatorID = value; }
226 }
227  
228 public AssetFlags Flags
229 {
230 get { return m_metadata.Flags; }
231 set { m_metadata.Flags = value; }
232 }
233  
234 [XmlIgnore]
235 public AssetMetadata Metadata
236 {
237 get { return m_metadata; }
238 set { m_metadata = value; }
239 }
240  
241 public override string ToString()
242 {
243 return FullID.ToString();
244 }
245 }
246  
247 [Serializable]
248 public class AssetMetadata
249 {
250 private UUID m_fullid;
251 private string m_id;
252 private string m_name = String.Empty;
253 private string m_description = String.Empty;
254 private DateTime m_creation_date;
255 private sbyte m_type = (sbyte)AssetType.Unknown;
256 private string m_content_type;
257 private byte[] m_sha1;
258 private bool m_local;
259 private bool m_temporary;
260 private string m_creatorid;
261 private AssetFlags m_flags;
262  
263 public UUID FullID
264 {
265 get { return m_fullid; }
266 set { m_fullid = value; m_id = m_fullid.ToString(); }
267 }
268  
269 public string ID
270 {
271 //get { return m_fullid.ToString(); }
272 //set { m_fullid = new UUID(value); }
273 get
274 {
275 if (String.IsNullOrEmpty(m_id))
276 m_id = m_fullid.ToString();
277  
278 return m_id;
279 }
280  
281 set
282 {
283 UUID uuid = UUID.Zero;
284 if (UUID.TryParse(value, out uuid))
285 {
286 m_fullid = uuid;
287 m_id = m_fullid.ToString();
288 }
289 else
290 m_id = value;
291 }
292 }
293  
294 public string Name
295 {
296 get { return m_name; }
297 set { m_name = value; }
298 }
299  
300 public string Description
301 {
302 get { return m_description; }
303 set { m_description = value; }
304 }
305  
306 public DateTime CreationDate
307 {
308 get { return m_creation_date; }
309 set { m_creation_date = value; }
310 }
311  
312 public sbyte Type
313 {
314 get { return m_type; }
315 set { m_type = value; }
316 }
317  
318 public string ContentType
319 {
320 get
321 {
322 if (!String.IsNullOrEmpty(m_content_type))
323 return m_content_type;
324 else
325 return SLUtil.SLAssetTypeToContentType(m_type);
326 }
327 set
328 {
329 m_content_type = value;
330  
331 sbyte type = (sbyte)SLUtil.ContentTypeToSLAssetType(value);
332 if (type != -1)
333 m_type = type;
334 }
335 }
336  
337 public byte[] SHA1
338 {
339 get { return m_sha1; }
340 set { m_sha1 = value; }
341 }
342  
343 public bool Local
344 {
345 get { return m_local; }
346 set { m_local = value; }
347 }
348  
349 public bool Temporary
350 {
351 get { return m_temporary; }
352 set { m_temporary = value; }
353 }
354  
355 public string CreatorID
356 {
357 get { return m_creatorid; }
358 set { m_creatorid = value; }
359 }
360  
361 public AssetFlags Flags
362 {
363 get { return m_flags; }
364 set { m_flags = value; }
365 }
366 }
367 }