opensim – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | eva | 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 | /// <summary> |
||
54 | /// Data of the Asset |
||
55 | /// </summary> |
||
56 | private byte[] m_data; |
||
57 | |||
58 | /// <summary> |
||
59 | /// Meta Data of the Asset |
||
60 | /// </summary> |
||
61 | private AssetMetadata m_metadata; |
||
62 | |||
63 | // This is needed for .NET serialization!!! |
||
64 | // Do NOT "Optimize" away! |
||
65 | public AssetBase() |
||
66 | { |
||
67 | m_metadata = new AssetMetadata(); |
||
68 | m_metadata.FullID = UUID.Zero; |
||
69 | m_metadata.ID = UUID.Zero.ToString(); |
||
70 | m_metadata.Type = (sbyte)AssetType.Unknown; |
||
71 | m_metadata.CreatorID = String.Empty; |
||
72 | } |
||
73 | |||
74 | public AssetBase(UUID assetID, string name, sbyte assetType, string creatorID) |
||
75 | { |
||
76 | if (assetType == (sbyte)AssetType.Unknown) |
||
77 | { |
||
78 | System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(true); |
||
79 | m_log.ErrorFormat("[ASSETBASE]: Creating asset '{0}' ({1}) with an unknown asset type\n{2}", |
||
80 | name, assetID, trace.ToString()); |
||
81 | } |
||
82 | |||
83 | m_metadata = new AssetMetadata(); |
||
84 | m_metadata.FullID = assetID; |
||
85 | m_metadata.Name = name; |
||
86 | m_metadata.Type = assetType; |
||
87 | m_metadata.CreatorID = creatorID; |
||
88 | } |
||
89 | |||
90 | public AssetBase(string assetID, string name, sbyte assetType, string creatorID) |
||
91 | { |
||
92 | if (assetType == (sbyte)AssetType.Unknown) |
||
93 | { |
||
94 | System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(true); |
||
95 | m_log.ErrorFormat("[ASSETBASE]: Creating asset '{0}' ({1}) with an unknown asset type\n{2}", |
||
96 | name, assetID, trace.ToString()); |
||
97 | } |
||
98 | |||
99 | m_metadata = new AssetMetadata(); |
||
100 | m_metadata.ID = assetID; |
||
101 | m_metadata.Name = name; |
||
102 | m_metadata.Type = assetType; |
||
103 | m_metadata.CreatorID = creatorID; |
||
104 | } |
||
105 | |||
106 | public bool ContainsReferences |
||
107 | { |
||
108 | get |
||
109 | { |
||
110 | return |
||
111 | IsTextualAsset && ( |
||
112 | Type != (sbyte)AssetType.Notecard |
||
113 | && Type != (sbyte)AssetType.CallingCard |
||
114 | && Type != (sbyte)AssetType.LSLText |
||
115 | && Type != (sbyte)AssetType.Landmark); |
||
116 | } |
||
117 | } |
||
118 | |||
119 | public bool IsTextualAsset |
||
120 | { |
||
121 | get |
||
122 | { |
||
123 | return !IsBinaryAsset; |
||
124 | } |
||
125 | |||
126 | } |
||
127 | |||
128 | /// <summary> |
||
129 | /// Checks if this asset is a binary or text asset |
||
130 | /// </summary> |
||
131 | public bool IsBinaryAsset |
||
132 | { |
||
133 | get |
||
134 | { |
||
135 | return |
||
136 | (Type == (sbyte) AssetType.Animation || |
||
137 | Type == (sbyte)AssetType.Gesture || |
||
138 | Type == (sbyte)AssetType.Simstate || |
||
139 | Type == (sbyte)AssetType.Unknown || |
||
140 | Type == (sbyte)AssetType.Object || |
||
141 | Type == (sbyte)AssetType.Sound || |
||
142 | Type == (sbyte)AssetType.SoundWAV || |
||
143 | Type == (sbyte)AssetType.Texture || |
||
144 | Type == (sbyte)AssetType.TextureTGA || |
||
145 | Type == (sbyte)AssetType.Folder || |
||
146 | Type == (sbyte)AssetType.RootFolder || |
||
147 | Type == (sbyte)AssetType.LostAndFoundFolder || |
||
148 | Type == (sbyte)AssetType.SnapshotFolder || |
||
149 | Type == (sbyte)AssetType.TrashFolder || |
||
150 | Type == (sbyte)AssetType.ImageJPEG || |
||
151 | Type == (sbyte) AssetType.ImageTGA || |
||
152 | Type == (sbyte) AssetType.LSLBytecode); |
||
153 | } |
||
154 | } |
||
155 | |||
156 | public virtual byte[] Data |
||
157 | { |
||
158 | get { return m_data; } |
||
159 | set { m_data = value; } |
||
160 | } |
||
161 | |||
162 | /// <summary> |
||
163 | /// Asset UUID |
||
164 | /// </summary> |
||
165 | public UUID FullID |
||
166 | { |
||
167 | get { return m_metadata.FullID; } |
||
168 | set { m_metadata.FullID = value; } |
||
169 | } |
||
170 | |||
171 | /// <summary> |
||
172 | /// Asset MetaData ID (transferring from UUID to string ID) |
||
173 | /// </summary> |
||
174 | public string ID |
||
175 | { |
||
176 | get { return m_metadata.ID; } |
||
177 | set { m_metadata.ID = value; } |
||
178 | } |
||
179 | |||
180 | public string Name |
||
181 | { |
||
182 | get { return m_metadata.Name; } |
||
183 | set { m_metadata.Name = value; } |
||
184 | } |
||
185 | |||
186 | public string Description |
||
187 | { |
||
188 | get { return m_metadata.Description; } |
||
189 | set { m_metadata.Description = value; } |
||
190 | } |
||
191 | |||
192 | /// <summary> |
||
193 | /// (sbyte) AssetType enum |
||
194 | /// </summary> |
||
195 | public sbyte Type |
||
196 | { |
||
197 | get { return m_metadata.Type; } |
||
198 | set { m_metadata.Type = value; } |
||
199 | } |
||
200 | |||
201 | /// <summary> |
||
202 | /// Is this a region only asset, or does this exist on the asset server also |
||
203 | /// </summary> |
||
204 | public bool Local |
||
205 | { |
||
206 | get { return m_metadata.Local; } |
||
207 | set { m_metadata.Local = value; } |
||
208 | } |
||
209 | |||
210 | /// <summary> |
||
211 | /// Is this asset going to be saved to the asset database? |
||
212 | /// </summary> |
||
213 | public bool Temporary |
||
214 | { |
||
215 | get { return m_metadata.Temporary; } |
||
216 | set { m_metadata.Temporary = value; } |
||
217 | } |
||
218 | |||
219 | public string CreatorID |
||
220 | { |
||
221 | get { return m_metadata.CreatorID; } |
||
222 | set { m_metadata.CreatorID = value; } |
||
223 | } |
||
224 | |||
225 | public AssetFlags Flags |
||
226 | { |
||
227 | get { return m_metadata.Flags; } |
||
228 | set { m_metadata.Flags = value; } |
||
229 | } |
||
230 | |||
231 | [XmlIgnore] |
||
232 | public AssetMetadata Metadata |
||
233 | { |
||
234 | get { return m_metadata; } |
||
235 | set { m_metadata = value; } |
||
236 | } |
||
237 | |||
238 | public override string ToString() |
||
239 | { |
||
240 | return FullID.ToString(); |
||
241 | } |
||
242 | } |
||
243 | |||
244 | [Serializable] |
||
245 | public class AssetMetadata |
||
246 | { |
||
247 | private UUID m_fullid; |
||
248 | private string m_id; |
||
249 | private string m_name = String.Empty; |
||
250 | private string m_description = String.Empty; |
||
251 | private DateTime m_creation_date; |
||
252 | private sbyte m_type = (sbyte)AssetType.Unknown; |
||
253 | private string m_content_type; |
||
254 | private byte[] m_sha1; |
||
255 | private bool m_local; |
||
256 | private bool m_temporary; |
||
257 | private string m_creatorid; |
||
258 | private AssetFlags m_flags; |
||
259 | |||
260 | public UUID FullID |
||
261 | { |
||
262 | get { return m_fullid; } |
||
263 | set { m_fullid = value; m_id = m_fullid.ToString(); } |
||
264 | } |
||
265 | |||
266 | public string ID |
||
267 | { |
||
268 | //get { return m_fullid.ToString(); } |
||
269 | //set { m_fullid = new UUID(value); } |
||
270 | get |
||
271 | { |
||
272 | if (String.IsNullOrEmpty(m_id)) |
||
273 | m_id = m_fullid.ToString(); |
||
274 | |||
275 | return m_id; |
||
276 | } |
||
277 | |||
278 | set |
||
279 | { |
||
280 | UUID uuid = UUID.Zero; |
||
281 | if (UUID.TryParse(value, out uuid)) |
||
282 | { |
||
283 | m_fullid = uuid; |
||
284 | m_id = m_fullid.ToString(); |
||
285 | } |
||
286 | else |
||
287 | m_id = value; |
||
288 | } |
||
289 | } |
||
290 | |||
291 | public string Name |
||
292 | { |
||
293 | get { return m_name; } |
||
294 | set { m_name = value; } |
||
295 | } |
||
296 | |||
297 | public string Description |
||
298 | { |
||
299 | get { return m_description; } |
||
300 | set { m_description = value; } |
||
301 | } |
||
302 | |||
303 | public DateTime CreationDate |
||
304 | { |
||
305 | get { return m_creation_date; } |
||
306 | set { m_creation_date = value; } |
||
307 | } |
||
308 | |||
309 | public sbyte Type |
||
310 | { |
||
311 | get { return m_type; } |
||
312 | set { m_type = value; } |
||
313 | } |
||
314 | |||
315 | public string ContentType |
||
316 | { |
||
317 | get |
||
318 | { |
||
319 | if (!String.IsNullOrEmpty(m_content_type)) |
||
320 | return m_content_type; |
||
321 | else |
||
322 | return SLUtil.SLAssetTypeToContentType(m_type); |
||
323 | } |
||
324 | set |
||
325 | { |
||
326 | m_content_type = value; |
||
327 | |||
328 | sbyte type = (sbyte)SLUtil.ContentTypeToSLAssetType(value); |
||
329 | if (type != -1) |
||
330 | m_type = type; |
||
331 | } |
||
332 | } |
||
333 | |||
334 | public byte[] SHA1 |
||
335 | { |
||
336 | get { return m_sha1; } |
||
337 | set { m_sha1 = value; } |
||
338 | } |
||
339 | |||
340 | public bool Local |
||
341 | { |
||
342 | get { return m_local; } |
||
343 | set { m_local = value; } |
||
344 | } |
||
345 | |||
346 | public bool Temporary |
||
347 | { |
||
348 | get { return m_temporary; } |
||
349 | set { m_temporary = value; } |
||
350 | } |
||
351 | |||
352 | public string CreatorID |
||
353 | { |
||
354 | get { return m_creatorid; } |
||
355 | set { m_creatorid = value; } |
||
356 | } |
||
357 | |||
358 | public AssetFlags Flags |
||
359 | { |
||
360 | get { return m_flags; } |
||
361 | set { m_flags = value; } |
||
362 | } |
||
363 | } |
||
364 | } |