AssetBase.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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. using System;
  28. using System.Xml.Serialization;
  29. using OpenMetaverse;
  30. namespace OpenSim.Framework
  31. {
  32. /// <summary>
  33. /// Asset class. All Assets are reference by this class or a class derived from this class
  34. /// </summary>
  35. [Serializable]
  36. public class AssetBase
  37. {
  38. /// <summary>
  39. /// Data of the Asset
  40. /// </summary>
  41. private byte[] m_data;
  42. /// <summary>
  43. /// Meta Data of the Asset
  44. /// </summary>
  45. private AssetMetadata m_metadata;
  46. public AssetBase()
  47. {
  48. m_metadata = new AssetMetadata();
  49. }
  50. public AssetBase(UUID assetId, string name)
  51. {
  52. m_metadata = new AssetMetadata();
  53. m_metadata.FullID = assetId;
  54. m_metadata.Name = name;
  55. }
  56. public bool ContainsReferences
  57. {
  58. get
  59. {
  60. return
  61. IsTextualAsset && (
  62. Type != (sbyte)AssetType.Notecard
  63. && Type != (sbyte)AssetType.CallingCard
  64. && Type != (sbyte)AssetType.LSLText
  65. && Type != (sbyte)AssetType.Landmark);
  66. }
  67. }
  68. public bool IsTextualAsset
  69. {
  70. get
  71. {
  72. return !IsBinaryAsset;
  73. }
  74. }
  75. /// <summary>
  76. /// Checks if this asset is a binary or text asset
  77. /// </summary>
  78. public bool IsBinaryAsset
  79. {
  80. get
  81. {
  82. return
  83. (Type == (sbyte) AssetType.Animation ||
  84. Type == (sbyte)AssetType.Gesture ||
  85. Type == (sbyte)AssetType.Simstate ||
  86. Type == (sbyte)AssetType.Unknown ||
  87. Type == (sbyte)AssetType.Object ||
  88. Type == (sbyte)AssetType.Sound ||
  89. Type == (sbyte)AssetType.SoundWAV ||
  90. Type == (sbyte)AssetType.Texture ||
  91. Type == (sbyte)AssetType.TextureTGA ||
  92. Type == (sbyte)AssetType.Folder ||
  93. Type == (sbyte)AssetType.RootFolder ||
  94. Type == (sbyte)AssetType.LostAndFoundFolder ||
  95. Type == (sbyte)AssetType.SnapshotFolder ||
  96. Type == (sbyte)AssetType.TrashFolder ||
  97. Type == (sbyte)AssetType.ImageJPEG ||
  98. Type == (sbyte) AssetType.ImageTGA ||
  99. Type == (sbyte) AssetType.LSLBytecode);
  100. }
  101. }
  102. public virtual byte[] Data
  103. {
  104. get { return m_data; }
  105. set { m_data = value; }
  106. }
  107. /// <summary>
  108. /// Asset UUID
  109. /// </summary>
  110. public UUID FullID
  111. {
  112. get { return m_metadata.FullID; }
  113. set { m_metadata.FullID = value; }
  114. }
  115. /// <summary>
  116. /// Asset MetaData ID (transferring from UUID to string ID)
  117. /// </summary>
  118. public string ID
  119. {
  120. get { return m_metadata.ID; }
  121. set { m_metadata.ID = value; }
  122. }
  123. public string Name
  124. {
  125. get { return m_metadata.Name; }
  126. set { m_metadata.Name = value; }
  127. }
  128. public string Description
  129. {
  130. get { return m_metadata.Description; }
  131. set { m_metadata.Description = value; }
  132. }
  133. /// <summary>
  134. /// (sbyte) AssetType enum
  135. /// </summary>
  136. public sbyte Type
  137. {
  138. get { return m_metadata.Type; }
  139. set { m_metadata.Type = value; }
  140. }
  141. /// <summary>
  142. /// Is this a region only asset, or does this exist on the asset server also
  143. /// </summary>
  144. public bool Local
  145. {
  146. get { return m_metadata.Local; }
  147. set { m_metadata.Local = value; }
  148. }
  149. /// <summary>
  150. /// Is this asset going to be saved to the asset database?
  151. /// </summary>
  152. public bool Temporary
  153. {
  154. get { return m_metadata.Temporary; }
  155. set { m_metadata.Temporary = value; }
  156. }
  157. [XmlIgnore]
  158. public AssetMetadata Metadata
  159. {
  160. get { return m_metadata; }
  161. set { m_metadata = value; }
  162. }
  163. public override string ToString()
  164. {
  165. return FullID.ToString();
  166. }
  167. }
  168. [Serializable]
  169. public class AssetMetadata
  170. {
  171. private UUID m_fullid;
  172. // m_id added as a dirty hack to transition from FullID to ID
  173. private string m_id;
  174. private string m_name = String.Empty;
  175. private string m_description = String.Empty;
  176. private DateTime m_creation_date;
  177. private sbyte m_type;
  178. private string m_content_type;
  179. private byte[] m_sha1;
  180. private bool m_local = false;
  181. private bool m_temporary = false;
  182. //private Dictionary<string, Uri> m_methods = new Dictionary<string, Uri>();
  183. //private OSDMap m_extra_data;
  184. public UUID FullID
  185. {
  186. get { return m_fullid; }
  187. set { m_fullid = value; m_id = m_fullid.ToString(); }
  188. }
  189. public string ID
  190. {
  191. //get { return m_fullid.ToString(); }
  192. //set { m_fullid = new UUID(value); }
  193. get { return m_id; }
  194. set
  195. {
  196. UUID uuid = UUID.Zero;
  197. if (UUID.TryParse(value, out uuid))
  198. {
  199. m_fullid = uuid;
  200. m_id = m_fullid.ToString();
  201. }
  202. else
  203. m_id = value;
  204. }
  205. }
  206. public string Name
  207. {
  208. get { return m_name; }
  209. set { m_name = value; }
  210. }
  211. public string Description
  212. {
  213. get { return m_description; }
  214. set { m_description = value; }
  215. }
  216. public DateTime CreationDate
  217. {
  218. get { return m_creation_date; }
  219. set { m_creation_date = value; }
  220. }
  221. public sbyte Type
  222. {
  223. get { return m_type; }
  224. set { m_type = value; }
  225. }
  226. public string ContentType
  227. {
  228. get { return m_content_type; }
  229. set { m_content_type = value; }
  230. }
  231. public byte[] SHA1
  232. {
  233. get { return m_sha1; }
  234. set { m_sha1 = value; }
  235. }
  236. public bool Local
  237. {
  238. get { return m_local; }
  239. set { m_local = value; }
  240. }
  241. public bool Temporary
  242. {
  243. get { return m_temporary; }
  244. set { m_temporary = value; }
  245. }
  246. //public Dictionary<string, Uri> Methods
  247. //{
  248. // get { return m_methods; }
  249. // set { m_methods = value; }
  250. //}
  251. //public OSDMap ExtraData
  252. //{
  253. // get { return m_extra_data; }
  254. // set { m_extra_data = value; }
  255. //}
  256. }
  257. }