UuidGatherer.cs 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279
  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.Collections.Generic;
  29. using System.IO;
  30. using System.Reflection;
  31. using System.Text;
  32. using log4net;
  33. using OpenMetaverse;
  34. using OpenMetaverse.Assets;
  35. using OpenMetaverse.StructuredData;
  36. using OpenSim.Framework;
  37. using OpenSim.Region.Framework.Scenes.Serialization;
  38. using OpenSim.Services.Interfaces;
  39. using OpenSimAssetType = OpenSim.Framework.SLUtil.OpenSimAssetType;
  40. namespace OpenSim.Region.Framework.Scenes
  41. {
  42. /// <summary>
  43. /// Gather uuids for a given entity.
  44. /// </summary>
  45. /// <remarks>
  46. /// This does a deep inspection of the entity to retrieve all the assets it uses (whether as textures, as scripts
  47. /// contained in inventory, as scripts contained in objects contained in another object's inventory, etc. Assets
  48. /// are only retrieved when they are necessary to carry out the inspection (i.e. a serialized object needs to be
  49. /// retrieved to work out which assets it references).
  50. /// </remarks>
  51. public class UuidGatherer
  52. {
  53. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  54. private static HashSet<UUID> ToSkip = new HashSet<UUID>()
  55. {
  56. new UUID("11111111-1111-0000-0000-000100bba000"),
  57. new UUID("5a9f4a74-30f2-821c-b88d-70499d3e7183"),
  58. new UUID("ae2de45c-d252-50b8-5c6e-19f39ce79317"),
  59. new UUID("24daea5f-0539-cfcf-047f-fbc40b2786ba"),
  60. new UUID("52cc6bb6-2ee5-e632-d3ad-50197b1dcb8a"),
  61. new UUID("43529ce8-7faa-ad92-165a-bc4078371687"),
  62. new UUID("09aac1fb-6bce-0bee-7d44-caac6dbb6c63"),
  63. new UUID("ff62763f-d60a-9855-890b-0c96f8f8cd98"),
  64. new UUID("8e915e25-31d1-cc95-ae08-d58a47488251"),
  65. new UUID("9742065b-19b5-297c-858a-29711d539043"),
  66. new UUID("03642e83-2bd1-4eb9-34b4-4c47ed586d2d"),
  67. new UUID("edd51b77-fc10-ce7a-4b3d-011dfc349e4f"),
  68. new UUID("44e87126-e794-4ded-05b3-7c42da3d5cdb"),
  69. new UUID("3d6181b0-6a4b-97ef-18d8-722652995cf1"),
  70. new UUID("b4ba225c-373f-446d-9f7e-6cb7b5cf9b3d"),
  71. new UUID("d2114404-dd59-4a4d-8e6c-49359e91bbf0"),
  72. new UUID("c228d1cf-4b5d-4ba8-84f4-899a0796aa97"),
  73. new UUID("e97cf410-8e61-7005-ec06-629eba4cd1fb"),
  74. new UUID("38b86f85-2575-52a9-a531-23108d8da837"),
  75. new UUID("8dcd4a48-2d37-4909-9f78-f7a9eb4ef903"),
  76. new UUID("3c59f7fe-9dc8-47f9-8aaf-a9dd1fbc3bef"),
  77. new UUID("0bc58228-74a0-7e83-89bc-5c23464bcec5"),
  78. new UUID("63338ede-0037-c4fd-855b-015d77112fc8"),
  79. new UUID("303cd381-8560-7579-23f1-f0a880799740"),
  80. new UUID("53a2f406-4895-1d13-d541-d2e3b86bc19c"),
  81. new UUID("822ded49-9a6c-f61c-cb89-6df54f42cdf4"),
  82. new UUID("6b61c8e8-4747-0d75-12d7-e49ff207a4ca"),
  83. new UUID("b5b4a67d-0aee-30d2-72cd-77b333e932ef"),
  84. new UUID("46bb4359-de38-4ed8-6a22-f1f52fe8f506"),
  85. new UUID("3147d815-6338-b932-f011-16b56d9ac18b"),
  86. new UUID("ea633413-8006-180a-c3ba-96dd1d756720"),
  87. new UUID("5747a48e-073e-c331-f6f3-7c2149613d3e"),
  88. new UUID("fd037134-85d4-f241-72c6-4f42164fedee"),
  89. new UUID("c4ca6188-9127-4f31-0158-23c4e2f93304"),
  90. new UUID("18b3a4b5-b463-bd48-e4b6-71eaac76c515"),
  91. new UUID("db84829b-462c-ee83-1e27-9bbee66bd624"),
  92. new UUID("b906c4ba-703b-1940-32a3-0c7f7d791510"),
  93. new UUID("82e99230-c906-1403-4d9c-3889dd98daba"),
  94. new UUID("349a3801-54f9-bf2c-3bd0-1ac89772af01"),
  95. new UUID("efcf670c-2d18-8128-973a-034ebc806b67"),
  96. new UUID("9b0c1c4e-8ac7-7969-1494-28c874c4f668"),
  97. new UUID("9ba1c942-08be-e43a-fb29-16ad440efc50"),
  98. new UUID("201f3fdf-cb1f-dbec-201f-7333e328ae7c"),
  99. new UUID("47f5f6fb-22e5-ae44-f871-73aaaf4a6022"),
  100. new UUID("92624d3e-1068-f1aa-a5ec-8244585193ed"),
  101. new UUID("038fcec9-5ebd-8a8e-0e2e-6e71a0a1ac53"),
  102. new UUID("6883a61a-b27b-5914-a61e-dda118a9ee2c"),
  103. new UUID("b68a3d7c-de9e-fc87-eec8-543d787e5b0d"),
  104. new UUID("928cae18-e31d-76fd-9cc9-2f55160ff818"),
  105. new UUID("30047778-10ea-1af7-6881-4db7a3a5a114"),
  106. new UUID("951469f4-c7b2-c818-9dee-ad7eea8c30b7"),
  107. new UUID("4bd69a1d-1114-a0b4-625f-84e0a5237155"),
  108. new UUID("cd28b69b-9c95-bb78-3f94-8d605ff1bb12"),
  109. new UUID("a54d8ee2-28bb-80a9-7f0c-7afbbe24a5d6"),
  110. new UUID("b0dc417c-1f11-af36-2e80-7e7489fa7cdc"),
  111. new UUID("57abaae6-1d17-7b1b-5f98-6d11a6411276"),
  112. new UUID("0f86e355-dd31-a61c-fdb0-3a96b9aad05f"),
  113. new UUID("514af488-9051-044a-b3fc-d4dbf76377c6"),
  114. new UUID("aa2df84d-cf8f-7218-527b-424a52de766e"),
  115. new UUID("1a03b575-9634-b62a-5767-3a679e81f4de"),
  116. new UUID("214aa6c1-ba6a-4578-f27c-ce7688f61d0d"),
  117. new UUID("d535471b-85bf-3b4d-a542-93bea4f59d33"),
  118. new UUID("d4416ff1-09d3-300f-4183-1b68a19b9fc1"),
  119. new UUID("0b8c8211-d78c-33e8-fa28-c51a9594e424"),
  120. new UUID("fee3df48-fa3d-1015-1e26-a205810e3001"),
  121. new UUID("1e8d90cc-a84e-e135-884c-7c82c8b03a14"),
  122. new UUID("62570842-0950-96f8-341c-809e65110823"),
  123. new UUID("d63bc1f9-fc81-9625-a0c6-007176d82eb7"),
  124. new UUID("f76cda94-41d4-a229-2872-e0296e58afe1"),
  125. new UUID("eb6ebfb2-a4b3-a19c-d388-4dd5c03823f7"),
  126. new UUID("a351b1bc-cc94-aac2-7bea-a7e6ebad15ef"),
  127. new UUID("b7c7c833-e3d3-c4e3-9fc0-131237446312"),
  128. new UUID("728646d9-cc79-08b2-32d6-937f0a835c24"),
  129. new UUID("835965c6-7f2f-bda2-5deb-2478737f91bf"),
  130. new UUID("b92ec1a5-e7ce-a76b-2b05-bcdb9311417e"),
  131. new UUID("da020525-4d94-59d6-23d7-81fdebf33148"),
  132. new UUID("9c05e5c7-6f07-6ca4-ed5a-b230390c3950"),
  133. new UUID("666307d9-a860-572d-6fd4-c3ab8865c094"),
  134. new UUID("85995026-eade-5d78-d364-94a64512cb66"),
  135. new UUID("f5fc7433-043d-e819-8298-f519a119b688"),
  136. new UUID("d60c41d2-7c24-7074-d3fa-6101cea22a51"),
  137. new UUID("c1bc7f36-3ba0-d844-f93c-93be945d644f"),
  138. new UUID("7db00ccd-f380-f3ee-439d-61968ec69c8a"),
  139. new UUID("aec4610c-757f-bc4e-c092-c6e9caf18daf"),
  140. new UUID("2b5a38b2-5e00-3a97-a495-4c826bc443e6"),
  141. new UUID("9b29cd61-c45b-5689-ded2-91756b8d76a9"),
  142. new UUID("ef62d355-c815-4816-2474-b1acc21094a6"),
  143. new UUID("8b102617-bcba-037b-86c1-b76219f90c88"),
  144. new UUID("efdc1727-8b8a-c800-4077-975fc27ee2f2"),
  145. new UUID("3d94bad0-c55b-7dcc-8763-033c59405d33"),
  146. new UUID("7570c7b5-1f22-56dd-56ef-a9168241bbb6"),
  147. new UUID("4ae8016b-31b9-03bb-c401-b1ea941db41d"),
  148. new UUID("20f063ea-8306-2562-0b07-5c853b37b31e"),
  149. new UUID("62c5de58-cb33-5743-3d07-9e4cd4352864"),
  150. new UUID("5ea3991f-c293-392e-6860-91dfa01278a3"),
  151. new UUID("2305bd75-1ca9-b03b-1faa-b176b8a8c49e"),
  152. new UUID("709ea28e-1573-c023-8bf8-520c8bc637fa"),
  153. new UUID("19999406-3a3a-d58c-a2ac-d72e555dcf51"),
  154. new UUID("7a17b059-12b2-41b1-570a-186368b6aa6f"),
  155. new UUID("ca5b3f14-3194-7a2b-c894-aa699b718d1f"),
  156. new UUID("f4f00d6e-b9fe-9292-f4cb-0ae06ea58d57"),
  157. new UUID("08464f78-3a8e-2944-cba5-0c94aff3af29"),
  158. new UUID("315c3a41-a5f3-0ba4-27da-f893f769e69b"),
  159. new UUID("5a977ed9-7f72-44e9-4c4c-6e913df8ae74"),
  160. new UUID("d83fa0e5-97ed-7eb2-e798-7bd006215cb4"),
  161. new UUID("f061723d-0a18-754f-66ee-29a44795a32f"),
  162. new UUID("eefc79be-daae-a239-8c04-890f5d23654a"),
  163. new UUID("b312b10e-65ab-a0a4-8b3c-1326ea8e3ed9"),
  164. new UUID("17c024cc-eef2-f6a0-3527-9869876d7752"),
  165. new UUID("ec952cca-61ef-aa3b-2789-4d1344f016de"),
  166. new UUID("7a4e87fe-de39-6fcb-6223-024b00893244"),
  167. new UUID("f3300ad9-3462-1d07-2044-0fef80062da0"),
  168. new UUID("c8e42d32-7310-6906-c903-cab5d4a34656"),
  169. new UUID("36f81a92-f076-5893-dc4b-7c3795e487cf"),
  170. new UUID("49aea43b-5ac3-8a44-b595-96100af0beda"),
  171. new UUID("35db4f7e-28c2-6679-cea9-3ee108f7fc7f"),
  172. new UUID("0836b67f-7f7b-f37b-c00a-460dc1521f5a"),
  173. new UUID("42dd95d5-0bc6-6392-f650-777304946c0f"),
  174. new UUID("16803a9f-5140-e042-4d7b-d28ba247c325"),
  175. new UUID("05ddbff8-aaa9-92a1-2b74-8fe77a29b445"),
  176. new UUID("1ab1b236-cd08-21e6-0cbc-0d923fc6eca2"),
  177. new UUID("0eb702e2-cc5a-9a88-56a5-661a55c0676a"),
  178. new UUID("cd7668a6-7011-d7e2-ead8-fc69eff1a104"),
  179. new UUID("e04d450d-fdb5-0432-fd68-818aaf5935f8"),
  180. new UUID("6bd01860-4ebd-127a-bb3d-d1427e8e0c42"),
  181. new UUID("70ea714f-3a97-d742-1b01-590a8fcd1db5"),
  182. new UUID("1a5fe8ac-a804-8a5d-7cbd-56bd83184568"),
  183. new UUID("b1709c8d-ecd3-54a1-4f28-d55ac0840782"),
  184. new UUID("245f3c54-f1c0-bf2e-811f-46d8eeb386e7"),
  185. new UUID("1c7600d6-661f-b87b-efe2-d7421eb93c86"),
  186. new UUID("1a2bd58e-87ff-0df8-0b4c-53e047b0bb6e"),
  187. new UUID("a8dee56f-2eae-9e7a-05a2-6fb92b97e21e"),
  188. new UUID("f2bed5f9-9d44-39af-b0cd-257b2a17fe40"),
  189. new UUID("d2f2ee58-8ad1-06c9-d8d3-3827ba31567a"),
  190. new UUID("6802d553-49da-0778-9f85-1599a2266526"),
  191. new UUID("0a9fb970-8b44-9114-d3a9-bf69cfe804d6"),
  192. new UUID("eae8905b-271a-99e2-4c0e-31106afd100c"),
  193. new UUID("2408fe9e-df1d-1d7d-f4ff-1384fa7b350f"),
  194. new UUID("3da1d753-028a-5446-24f3-9c9b856d9422"),
  195. new UUID("15468e00-3400-bb66-cecc-646d7c14458e"),
  196. new UUID("370f3a20-6ca6-9971-848c-9a01bc42ae3c"),
  197. new UUID("42b46214-4b44-79ae-deb8-0df61424ff4b"),
  198. new UUID("f22fed8b-a5ed-2c93-64d5-bdd8b93c889f"),
  199. new UUID("80700431-74ec-a008-14f8-77575e73693f"),
  200. new UUID("1cb562b0-ba21-2202-efb3-30f82cdf9595"),
  201. new UUID("41426836-7437-7e89-025d-0aa4d10f1d69"),
  202. new UUID("313b9881-4302-73c0-c7d0-0e7a36b6c224"),
  203. new UUID("85428680-6bf9-3e64-b489-6f81087c24bd"),
  204. new UUID("5c682a95-6da4-a463-0bf6-0f5b7be129d1"),
  205. new UUID("11000694-3f41-adc2-606b-eee1d66f3724"),
  206. new UUID("aa134404-7dac-7aca-2cba-435f9db875ca"),
  207. new UUID("83ff59fe-2346-f236-9009-4e3608af64c1"),
  208. new UUID("56e0ba0d-4a9f-7f27-6117-32f2ebbf6135"),
  209. new UUID("2d6daa51-3192-6794-8e2e-a15f8338ec30"),
  210. new UUID("c541c47f-e0c0-058b-ad1a-d6ae3a4584d9"),
  211. new UUID("6ed24bd8-91aa-4b12-ccc7-c97c857ab4e0"),
  212. new UUID("33339176-7ddc-9397-94a4-bf3403cbc8f5"),
  213. new UUID("7693f268-06c7-ea71-fa21-2b30d6533f8f"),
  214. new UUID("b1ed7982-c68e-a982-7561-52a88a5298c0"),
  215. new UUID("869ecdad-a44b-671e-3266-56aef2e3ac2e"),
  216. new UUID("c0c4030f-c02b-49de-24ba-2331f43fe41c"),
  217. new UUID("9f496bd2-589a-709f-16cc-69bf7df1d36c"),
  218. new UUID("15dd911d-be82-2856-26db-27659b142875"),
  219. new UUID("b8c8b2a3-9008-1771-3bfc-90924955ab2d"),
  220. new UUID("42ecd00b-9947-a97c-400a-bbc9174c7aeb")
  221. };
  222. /// <summary>
  223. /// Is gathering complete?
  224. /// </summary>
  225. public bool Complete { get { return m_assetUuidsToInspect.Count <= 0; } }
  226. /// <summary>
  227. /// The dictionary of UUIDs gathered so far. If Complete == true then this is all the reachable UUIDs.
  228. /// </summary>
  229. /// <value>The gathered uuids.</value>
  230. public IDictionary<UUID, sbyte> GatheredUuids { get; private set; }
  231. public HashSet<UUID> FailedUUIDs { get; private set; }
  232. public HashSet<UUID> UncertainAssetsUUIDs { get; private set; }
  233. public int possibleNotAssetCount { get; set; }
  234. public int ErrorCount { get; private set; }
  235. private bool verbose = true;
  236. /// <summary>
  237. /// Gets the next UUID to inspect.
  238. /// </summary>
  239. /// <value>If there is no next UUID then returns null</value>
  240. public UUID? NextUuidToInspect
  241. {
  242. get
  243. {
  244. if (Complete)
  245. return null;
  246. else
  247. return m_assetUuidsToInspect.Peek();
  248. }
  249. }
  250. protected IAssetService m_assetService;
  251. protected Queue<UUID> m_assetUuidsToInspect;
  252. /// <summary>
  253. /// Initializes a new instance of the <see cref="OpenSim.Region.Framework.Scenes.UuidGatherer"/> class.
  254. /// </summary>
  255. /// <remarks>In this case the collection of gathered assets will start out blank.</remarks>
  256. /// <param name="assetService">
  257. /// Asset service.
  258. /// </param>
  259. public UuidGatherer(IAssetService assetService) : this(assetService, new Dictionary<UUID, sbyte>(),
  260. new HashSet <UUID>(),new HashSet <UUID>()) {}
  261. public UuidGatherer(IAssetService assetService, IDictionary<UUID, sbyte> collector) : this(assetService, collector,
  262. new HashSet <UUID>(), new HashSet <UUID>()) {}
  263. /// <summary>
  264. /// Initializes a new instance of the <see cref="OpenSim.Region.Framework.Scenes.UuidGatherer"/> class.
  265. /// </summary>
  266. /// <param name="assetService">
  267. /// Asset service.
  268. /// </param>
  269. /// <param name="collector">
  270. /// Gathered UUIDs will be collected in this dictionary.
  271. /// It can be pre-populated if you want to stop the gatherer from analyzing assets that have already been fetched and inspected.
  272. /// </param>
  273. public UuidGatherer(IAssetService assetService, IDictionary<UUID, sbyte> collector, HashSet <UUID> failedIDs, HashSet <UUID> uncertainAssetsUUIDs)
  274. {
  275. m_assetService = assetService;
  276. GatheredUuids = collector;
  277. // FIXME: Not efficient for searching, can improve.
  278. m_assetUuidsToInspect = new Queue<UUID>();
  279. FailedUUIDs = failedIDs;
  280. UncertainAssetsUUIDs = uncertainAssetsUUIDs;
  281. ErrorCount = 0;
  282. possibleNotAssetCount = 0;
  283. }
  284. public bool AddGathered(UUID uuid, sbyte type)
  285. {
  286. if (uuid == UUID.Zero)
  287. return false;
  288. if (ToSkip.Contains(uuid))
  289. return false;
  290. if (FailedUUIDs.Contains(uuid))
  291. {
  292. if (UncertainAssetsUUIDs.Contains(uuid))
  293. possibleNotAssetCount++;
  294. else
  295. ErrorCount++;
  296. return false;
  297. }
  298. if (GatheredUuids.ContainsKey(uuid))
  299. return false;
  300. if (m_assetUuidsToInspect.Contains(uuid))
  301. return false;
  302. // m_log.DebugFormat("[UUID GATHERER]: Adding asset {0} for inspection", uuid);
  303. GatheredUuids[uuid] = type;
  304. return true;
  305. }
  306. /// <summary>
  307. /// Adds the asset uuid for inspection during the gathering process.
  308. /// </summary>
  309. /// <returns><c>true</c>, if for inspection was added, <c>false</c> otherwise.</returns>
  310. /// <param name="uuid">UUID.</param>
  311. public bool AddForInspection(UUID uuid)
  312. {
  313. if(uuid == UUID.Zero)
  314. return false;
  315. if(ToSkip.Contains(uuid))
  316. return false;
  317. if(FailedUUIDs.Contains(uuid))
  318. {
  319. if(UncertainAssetsUUIDs.Contains(uuid))
  320. possibleNotAssetCount++;
  321. else
  322. ErrorCount++;
  323. return false;
  324. }
  325. if(GatheredUuids.ContainsKey(uuid))
  326. return false;
  327. if (m_assetUuidsToInspect.Contains(uuid))
  328. return false;
  329. // m_log.DebugFormat("[UUID GATHERER]: Adding asset {0} for inspection", uuid);
  330. m_assetUuidsToInspect.Enqueue(uuid);
  331. return true;
  332. }
  333. /// <summary>
  334. /// Gather all the asset uuids associated with a given object.
  335. /// </summary>
  336. /// <remarks>
  337. /// This includes both those directly associated with
  338. /// it (e.g. face textures) and recursively, those of items within it's inventory (e.g. objects contained
  339. /// within this object).
  340. /// </remarks>
  341. /// <param name="sceneObject">The scene object for which to gather assets</param>
  342. public void AddForInspection(SceneObjectGroup sceneObject)
  343. {
  344. // m_log.DebugFormat(
  345. // "[UUID GATHERER]: Getting assets for object {0}, {1}", sceneObject.Name, sceneObject.UUID);
  346. if(sceneObject.IsDeleted)
  347. return;
  348. SceneObjectPart[] parts = sceneObject.Parts;
  349. for (int i = 0; i < parts.Length; ++i)
  350. {
  351. SceneObjectPart part = parts[i];
  352. // m_log.DebugFormat(
  353. // "[UUID GATHERER]: Getting part {0}, {1} for object {2}", part.Name, part.UUID, sceneObject.UUID);
  354. try
  355. {
  356. Primitive.TextureEntry textureEntry = part.Shape.Textures;
  357. if (textureEntry != null)
  358. {
  359. // Get the prim's default texture. This will be used for faces which don't have their own texture
  360. if (textureEntry.DefaultTexture != null)
  361. RecordTextureEntryAssetUuids(textureEntry.DefaultTexture);
  362. if (textureEntry.FaceTextures != null)
  363. {
  364. // Loop through the rest of the texture faces (a non-null face means the face is different from DefaultTexture)
  365. int nsides = part.GetNumberOfSides();
  366. foreach (Primitive.TextureEntryFace texture in textureEntry.FaceTextures)
  367. {
  368. if (texture != null)
  369. RecordTextureEntryAssetUuids(texture);
  370. if(--nsides <= 0)
  371. break;
  372. }
  373. }
  374. }
  375. // If the prim is a sculpt then preserve this information too
  376. if (part.Shape.SculptTexture != UUID.Zero)
  377. GatheredUuids[part.Shape.SculptTexture] = (sbyte)AssetType.Texture;
  378. if (part.Shape.ProjectionTextureUUID != UUID.Zero)
  379. GatheredUuids[part.Shape.ProjectionTextureUUID] = (sbyte)AssetType.Texture;
  380. UUID collisionSound = part.CollisionSound;
  381. if ( collisionSound != UUID.Zero &&
  382. collisionSound != part.invalidCollisionSoundUUID)
  383. GatheredUuids[collisionSound] = (sbyte)AssetType.Sound;
  384. if (part.ParticleSystem.Length > 0)
  385. {
  386. try
  387. {
  388. Primitive.ParticleSystem ps = new Primitive.ParticleSystem(part.ParticleSystem, 0);
  389. if (ps.Texture != UUID.Zero)
  390. GatheredUuids[ps.Texture] = (sbyte)AssetType.Texture;
  391. }
  392. catch (Exception)
  393. {
  394. m_log.WarnFormat(
  395. "[UUID GATHERER]: Could not check particle system for part {0} {1} in object {2} {3} since it is corrupt. Continuing.",
  396. part.Name, part.UUID, sceneObject.Name, sceneObject.UUID);
  397. }
  398. }
  399. List<TaskInventoryItem> items = part.TaskInventory.GetItems();
  400. // Now analyze this prim's inventory items to preserve all the uuids that they reference
  401. for(int j = 0; j < items.Count; ++j)
  402. {
  403. TaskInventoryItem tii = items[j];
  404. AddForInspection(tii.AssetID, (sbyte)tii.Type);
  405. }
  406. if(part.Animations != null && part.Animations.Count > 0)
  407. {
  408. foreach(UUID id in part.Animations.Keys)
  409. {
  410. if(id != UUID.Zero &&
  411. !ToSkip.Contains(id) &&
  412. !FailedUUIDs.Contains(id))
  413. {
  414. GatheredUuids[id] = (sbyte)AssetType.Animation;
  415. }
  416. }
  417. }
  418. RecordMaterialsUuids(part);
  419. }
  420. catch (Exception e)
  421. {
  422. m_log.ErrorFormat("[UUID GATHERER]: Failed to get part - {0}", e);
  423. }
  424. }
  425. if(sceneObject.TemporaryInstance)
  426. sceneObject.Dispose();
  427. }
  428. /// <summary>
  429. /// Gathers the next set of assets returned by the next uuid to get from the asset service.
  430. /// </summary>
  431. /// <returns>false if gathering is already complete, true otherwise</returns>
  432. public bool GatherNext()
  433. {
  434. if (Complete)
  435. return false;
  436. UUID nextToInspect = m_assetUuidsToInspect.Dequeue();
  437. // m_log.DebugFormat("[UUID GATHERER]: Inspecting asset {0}", nextToInspect);
  438. GetAssetUuids(nextToInspect);
  439. return m_assetUuidsToInspect.Count > 0;
  440. }
  441. /// <summary>
  442. /// Gathers all remaining asset UUIDS no matter how many calls are required to the asset service.
  443. /// </summary>
  444. /// <returns>false if gathering is already complete, true otherwise</returns>
  445. public bool GatherAll(bool report = false)
  446. {
  447. if (Complete)
  448. return false;
  449. if(report)
  450. verbose = false;
  451. while (GatherNext());
  452. if (report && FailedUUIDs.Count > 0)
  453. {
  454. StringBuilder sb = new StringBuilder(512);
  455. int i = FailedUUIDs.Count;
  456. sb.Append("[UUID GATHERER]: UUIDs that are not assets or really missing assets:\n\t");
  457. foreach (UUID id in FailedUUIDs)
  458. {
  459. sb.Append(id);
  460. if (--i > 0)
  461. sb.Append(',');
  462. }
  463. m_log.Debug(sb.ToString());
  464. }
  465. return true;
  466. }
  467. /// <summary>
  468. /// Gather all the asset uuids associated with the asset referenced by a given uuid
  469. /// </summary>
  470. /// <remarks>
  471. /// This includes both those directly associated with
  472. /// it (e.g. face textures) and recursively, those of items within it's inventory (e.g. objects contained
  473. /// within this object).
  474. /// This method assumes that the asset type associated with this asset in persistent storage is correct (which
  475. /// should always be the case). So with this method we always need to retrieve asset data even if the asset
  476. /// is of a type which is known not to reference any other assets
  477. /// </remarks>
  478. /// <param name="assetUuid">The uuid of the asset for which to gather referenced assets</param>
  479. private void GetAssetUuids(UUID assetUuid)
  480. {
  481. if(assetUuid == UUID.Zero)
  482. return;
  483. if(FailedUUIDs.Contains(assetUuid))
  484. {
  485. if(UncertainAssetsUUIDs.Contains(assetUuid))
  486. possibleNotAssetCount++;
  487. else
  488. ErrorCount++;
  489. return;
  490. }
  491. if (GatheredUuids.ContainsKey(assetUuid))
  492. return;
  493. AssetBase assetBase;
  494. try
  495. {
  496. assetBase = GetAsset(assetUuid);
  497. }
  498. catch (Exception e)
  499. {
  500. if(verbose)
  501. m_log.ErrorFormat("[UUID GATHERER]: Failed to get asset {0} : {1}", assetUuid, e.Message);
  502. ErrorCount++;
  503. FailedUUIDs.Add(assetUuid);
  504. return;
  505. }
  506. if(assetBase == null)
  507. {
  508. // m_log.ErrorFormat("[UUID GATHERER]: asset {0} not found", assetUuid);
  509. FailedUUIDs.Add(assetUuid);
  510. if(UncertainAssetsUUIDs.Contains(assetUuid))
  511. possibleNotAssetCount++;
  512. else
  513. ErrorCount++;
  514. return;
  515. }
  516. if(UncertainAssetsUUIDs.Contains(assetUuid))
  517. UncertainAssetsUUIDs.Remove(assetUuid);
  518. sbyte assetType = assetBase.Type;
  519. if(assetBase.Data == null || assetBase.Data.Length == 0)
  520. {
  521. // m_log.ErrorFormat("[UUID GATHERER]: asset {0}, type {1} has no data", assetUuid, assetType);
  522. ErrorCount++;
  523. FailedUUIDs.Add(assetUuid);
  524. return;
  525. }
  526. GatheredUuids[assetUuid] = assetType;
  527. try
  528. {
  529. if ((sbyte)AssetType.Bodypart == assetType || (sbyte)AssetType.Clothing == assetType)
  530. {
  531. RecordWearableAssetUuids(assetBase);
  532. }
  533. else if ((sbyte)AssetType.Gesture == assetType)
  534. {
  535. RecordGestureAssetUuids(assetBase);
  536. }
  537. else if ((sbyte)AssetType.Notecard == assetType)
  538. {
  539. RecordNoteCardEmbeddedAssetUuids(assetBase);
  540. }
  541. else if ((sbyte)AssetType.LSLText == assetType)
  542. {
  543. RecordEmbeddedAssetDataUuids(assetBase);
  544. }
  545. else if ((sbyte)OpenSimAssetType.Material == assetType)
  546. {
  547. RecordMaterialAssetUuids(assetBase);
  548. }
  549. else if ((sbyte)AssetType.Object == assetType)
  550. {
  551. RecordSceneObjectAssetUuids(assetBase);
  552. }
  553. else if ((sbyte)AssetType.Settings == assetType)
  554. {
  555. RecordEmbeddedAssetDataUuids(assetBase); // BAD to do
  556. }
  557. }
  558. catch (Exception e)
  559. {
  560. if(verbose)
  561. m_log.ErrorFormat("[UUID GATHERER]: Failed to gather uuids for asset with id {0} type {1}: {2}", assetUuid, assetType, e.Message);
  562. GatheredUuids.Remove(assetUuid);
  563. ErrorCount++;
  564. FailedUUIDs.Add(assetUuid);
  565. }
  566. }
  567. private void AddForInspection(UUID assetUuid, sbyte assetType)
  568. {
  569. if(assetUuid == UUID.Zero)
  570. return;
  571. // Here, we want to collect uuids which require further asset fetches but mark the others as gathered
  572. if(FailedUUIDs.Contains(assetUuid))
  573. {
  574. if(UncertainAssetsUUIDs.Contains(assetUuid))
  575. possibleNotAssetCount++;
  576. else
  577. ErrorCount++;
  578. return;
  579. }
  580. if(GatheredUuids.ContainsKey(assetUuid))
  581. return;
  582. try
  583. {
  584. if ((sbyte)AssetType.Bodypart == assetType
  585. || (sbyte)AssetType.Clothing == assetType
  586. || (sbyte)AssetType.Gesture == assetType
  587. || (sbyte)AssetType.Notecard == assetType
  588. || (sbyte)AssetType.LSLText == assetType
  589. || (sbyte)OpenSimAssetType.Material == assetType
  590. || (sbyte)AssetType.Object == assetType
  591. || (sbyte)AssetType.Settings == assetType)
  592. {
  593. AddForInspection(assetUuid);
  594. }
  595. else
  596. {
  597. GatheredUuids[assetUuid] = assetType;
  598. }
  599. }
  600. catch (Exception)
  601. {
  602. m_log.ErrorFormat(
  603. "[UUID GATHERER]: Failed to gather uuids for asset id {0}, type {1}",
  604. assetUuid, assetType);
  605. throw;
  606. }
  607. }
  608. /// <summary>
  609. /// Collect all the asset uuids found in one face of a Texture Entry.
  610. /// </summary>
  611. private void RecordTextureEntryAssetUuids(Primitive.TextureEntryFace texture)
  612. {
  613. UUID teid = texture.TextureID;
  614. if (teid != UUID.Zero &&
  615. !ToSkip.Contains(teid) &&
  616. !FailedUUIDs.Contains(teid))
  617. {
  618. GatheredUuids[teid] = (sbyte)AssetType.Texture;
  619. }
  620. if (texture.MaterialID != UUID.Zero)
  621. AddForInspection(texture.MaterialID);
  622. }
  623. /// <summary>
  624. /// Gather all of the texture asset UUIDs used to reference "Materials" such as normal and specular maps
  625. /// stored in legacy format in part.DynAttrs
  626. /// </summary>
  627. /// <param name="part"></param>
  628. private void RecordMaterialsUuids(SceneObjectPart part)
  629. {
  630. // scan thru the dynAttrs map of this part for any textures used as materials
  631. OSD osdMaterials = null;
  632. if(part.DynAttrs == null)
  633. return;
  634. lock (part.DynAttrs)
  635. {
  636. if (part.DynAttrs.ContainsStore("OpenSim", "Materials"))
  637. {
  638. OSDMap materialsStore = part.DynAttrs.GetStore("OpenSim", "Materials");
  639. if (materialsStore == null)
  640. return;
  641. materialsStore.TryGetValue("Materials", out osdMaterials);
  642. }
  643. if (osdMaterials != null)
  644. {
  645. //m_log.Info("[UUID Gatherer]: found Materials: " + OSDParser.SerializeJsonString(osd));
  646. if (osdMaterials is OSDArray)
  647. {
  648. OSDArray matsArr = osdMaterials as OSDArray;
  649. foreach (OSDMap matMap in matsArr)
  650. {
  651. try
  652. {
  653. if (matMap.ContainsKey("Material"))
  654. {
  655. OSDMap mat = matMap["Material"] as OSDMap;
  656. if (mat.ContainsKey("NormMap"))
  657. {
  658. UUID normalMapId = mat["NormMap"].AsUUID();
  659. if (normalMapId != UUID.Zero)
  660. {
  661. GatheredUuids[normalMapId] = (sbyte)AssetType.Texture;
  662. //m_log.Info("[UUID Gatherer]: found normal map ID: " + normalMapId.ToString());
  663. }
  664. }
  665. if (mat.ContainsKey("SpecMap"))
  666. {
  667. UUID specularMapId = mat["SpecMap"].AsUUID();
  668. if (specularMapId != UUID.Zero)
  669. {
  670. GatheredUuids[specularMapId] = (sbyte)AssetType.Texture;
  671. //m_log.Info("[UUID Gatherer]: found specular map ID: " + specularMapId.ToString());
  672. }
  673. }
  674. }
  675. }
  676. catch (Exception e)
  677. {
  678. m_log.Warn("[UUID Gatherer]: exception getting materials: " + e.Message);
  679. }
  680. }
  681. }
  682. }
  683. }
  684. }
  685. /// <summary>
  686. /// Get an asset synchronously, potentially using an asynchronous callback. If the
  687. /// asynchronous callback is used, we will wait for it to complete.
  688. /// </summary>
  689. /// <param name="uuid"></param>
  690. /// <returns></returns>
  691. protected virtual AssetBase GetAsset(UUID uuid)
  692. {
  693. return m_assetService.Get(uuid.ToString());
  694. }
  695. /// <summary>
  696. /// Record the asset uuids embedded within the given text (e.g. a script).
  697. /// </summary>
  698. /// <param name="textAsset"></param>
  699. private void RecordEmbeddedAssetDataUuids(AssetBase textAsset)
  700. {
  701. // m_log.DebugFormat("[ASSET GATHERER]: Getting assets for uuid references in asset {0}", embeddingAssetId);
  702. if(textAsset.Data.Length < 36)
  703. return;
  704. List<UUID> ids = Util.GetUUIDsOnData(textAsset.Data, 0, textAsset.Data.Length);
  705. if (ids == null || ids.Count == 0)
  706. return;
  707. for (int i = 0; i < ids.Count; ++i)
  708. {
  709. if (ids[i] == UUID.Zero)
  710. continue;
  711. if (!UncertainAssetsUUIDs.Contains(ids[i]))
  712. UncertainAssetsUUIDs.Add(ids[i]);
  713. AddForInspection(ids[i]);
  714. }
  715. }
  716. private void RecordNoteCardEmbeddedAssetUuids(AssetBase textAsset)
  717. {
  718. List<UUID> ids = SLUtil.GetEmbeddedAssetIDs(textAsset.Data);
  719. if(ids == null || ids.Count == 0)
  720. return;
  721. for(int i = 0; i < ids.Count; ++i)
  722. {
  723. if (ids[i] == UUID.Zero)
  724. continue;
  725. if (!UncertainAssetsUUIDs.Contains(ids[i]))
  726. UncertainAssetsUUIDs.Add(ids[i]);
  727. AddForInspection(ids[i]);
  728. }
  729. }
  730. private static byte[] wearableSeps = new byte[]{(byte)' ', (byte)'\t'};
  731. /// <summary>
  732. /// Record the uuids referenced by the given wearable asset
  733. /// </summary>
  734. /// <param name="asset"></param>
  735. private void RecordWearableAssetUuids(AssetBase asset)
  736. {
  737. if (asset.Data == null || asset.Data.Length < 64)
  738. return;
  739. try
  740. {
  741. osUTF8 ostmp = new osUTF8(asset.Data);
  742. if (!ostmp.SkipLine()) // version
  743. return;
  744. if (!ostmp.SkipLine()) // name
  745. return;
  746. if (!ostmp.SkipLine()) // description
  747. return;
  748. if (!ostmp.SkipLine())
  749. return;
  750. while (ostmp.ReadLine(out osUTF8 line))
  751. {
  752. line.SelfTrim(wearableSeps);
  753. osUTF8[] parts = line.Split(wearableSeps);
  754. if(parts[0].Length == 0)
  755. continue;
  756. parts[0].SelfTrim(wearableSeps);
  757. if (parts[0].ToString() == "parameters")
  758. {
  759. if (parts[1].Length == 0)
  760. return;
  761. parts[1].SelfTrim(wearableSeps);
  762. if (!osUTF8.TryParseInt(parts[1], out int count) || count == 0)
  763. return;
  764. for (int i = 0; i < count; ++i)
  765. {
  766. if (!ostmp.SkipLine())
  767. return;
  768. }
  769. }
  770. else if (parts[0].ToString() == "textures")
  771. {
  772. if(parts[1].Length == 0)
  773. return;
  774. parts[1].SelfTrim(wearableSeps);
  775. if (!osUTF8.TryParseInt(parts[1], out int count) || count == 0)
  776. return;
  777. for(int i = 0; i < count; ++i)
  778. {
  779. if(!ostmp.ReadLine(out osUTF8 texline))
  780. return;
  781. texline.SelfTrim(wearableSeps);
  782. osUTF8[] texparts = texline.Split(wearableSeps);
  783. if(texparts.Length <2 || texparts[1].Length < 36)
  784. continue;
  785. texparts[1].SelfTrim(wearableSeps);
  786. if (UUID.TryParse(texparts[1].ToString(), out UUID id) && id != UUID.Zero)
  787. GatheredUuids[id] = (sbyte)AssetType.Texture;
  788. }
  789. }
  790. }
  791. }
  792. catch
  793. {
  794. }
  795. }
  796. private int getxmlNode(ref osUTF8 data, out osUTF8 h)
  797. {
  798. h = data;
  799. int st = -1;
  800. while ((st = data.IndexOf('<')) >= 0)
  801. {
  802. if (st > 0 && data[st - 1] == (byte)'\\')
  803. data.osUTF8SubStringSelf(st + 1);
  804. break;
  805. }
  806. if (st < 0)
  807. return -1;
  808. ++st;
  809. int ed = -1;
  810. while ((ed = data.IndexOf('>')) >= 0)
  811. {
  812. if (data[st - 1] == (byte)'\\')
  813. data.osUTF8SubStringSelf(st + 1);
  814. break;
  815. }
  816. if (ed < 0)
  817. return -1;
  818. h = data.osUTF8SubString(st, ed - st);
  819. h.SelfTrim();
  820. ++ed;
  821. data.osUTF8SubStringSelf(ed);
  822. return ed;
  823. }
  824. private bool TryGetxmlUUIDValue(ref osUTF8 data, out UUID id)
  825. {
  826. id = UUID.Zero;
  827. if(getxmlNode(ref data, out osUTF8 h) < 0)
  828. return false;
  829. if (h.StartsWith(UUIDB))
  830. {
  831. if (h.EndsWith((byte)'/'))
  832. return true;
  833. int indx = data.IndexOf((byte)'<');
  834. if (indx < 0)
  835. return false;
  836. osUTF8 tmp = data.osUTF8SubString(0, indx);
  837. data.osUTF8SubStringSelf(indx + 1);
  838. return osUTF8.TryParseUUID(tmp, out id);
  839. }
  840. if (h.StartsWith(uuidB))
  841. {
  842. if (h.EndsWith((byte)'/'))
  843. return true;
  844. int indx = data.IndexOf((byte)'<');
  845. if (indx < 0)
  846. return false;
  847. osUTF8 tmp = data.osUTF8SubString(0, indx);
  848. data.osUTF8SubStringSelf(indx + 1);
  849. return osUTF8.TryParseUUID(tmp, out id);
  850. }
  851. return false;
  852. }
  853. private bool TryGetXMLBinary(ref osUTF8 data, out byte[] te)
  854. {
  855. te = null;
  856. int indx = data.IndexOf((byte)'<');
  857. if(indx <= 0)
  858. return false;
  859. osUTF8 tmp = data.osUTF8SubString(0, indx);
  860. data.osUTF8SubStringSelf(indx + 1);
  861. tmp.SelfTrim();
  862. if(tmp.Length == 0)
  863. return false;
  864. try
  865. {
  866. te = Convert.FromBase64String(tmp.ToString()); // need to replace
  867. return true;
  868. }
  869. catch { }
  870. return false;
  871. }
  872. // bad ugly and ulgy
  873. private static osUTF8 UUIDB = new osUTF8("UUID");
  874. private static osUTF8 uuidB = new osUTF8("uuid");
  875. private static osUTF8 SOPAnimsB = new osUTF8("SOPAnims");
  876. private static osUTF8 CollisionSoundB = new osUTF8("CollisionSound");
  877. private static osUTF8 SoundIDB = new osUTF8("SoundID");
  878. private static osUTF8 SculptTextureB = new osUTF8("SculptTexture");
  879. private static osUTF8 ExtraParamsB = new osUTF8("ExtraParams");
  880. private static osUTF8 ParticleSystemB = new osUTF8("ParticleSystem");
  881. private static osUTF8 TextureEntryB = new osUTF8("TextureEntry");
  882. private static osUTF8 TaskInventoryB = new osUTF8("TaskInventory");
  883. private static osUTF8 endTaskInventoryB = new osUTF8("/TaskInventory");
  884. private static osUTF8 AssetIDB = new osUTF8("AssetID");
  885. /// <summary>
  886. /// Get all the asset uuids associated with a given object. This includes both those directly associated with
  887. /// it (e.g. face textures) and recursively, those of items within it's inventory (e.g. objects contained
  888. /// within this object).
  889. /// </summary>
  890. /// <param name="sceneObjectAsset"></param>
  891. private void RecordSceneObjectAssetUuids(AssetBase sceneObjectAsset)
  892. {
  893. osUTF8 data = new osUTF8(sceneObjectAsset.Data);
  894. int next;
  895. osUTF8 nodeName;
  896. while ((next = getxmlNode(ref data, out nodeName)) > 0)
  897. {
  898. if (nodeName.StartsWith((byte)'/'))
  899. continue;
  900. if (nodeName.StartsWith(SOPAnimsB))
  901. {
  902. if (nodeName.EndsWith((byte)'/'))
  903. continue;
  904. if (TryGetXMLBinary(ref data, out byte[] abytes) && abytes != null && abytes.Length > 16)
  905. {
  906. try
  907. {
  908. int count = Utils.BytesToUInt16(abytes, 0);
  909. if (count >0)
  910. {
  911. int pos = 2;
  912. while (--count >= 0)
  913. {
  914. UUID id = new UUID(abytes, pos);
  915. if (id == UUID.Zero)
  916. break;
  917. if (!ToSkip.Contains(id) &&
  918. !FailedUUIDs.Contains(id))
  919. {
  920. GatheredUuids[id] = (sbyte)AssetType.Animation;
  921. }
  922. pos += 16;
  923. int strlen = data[pos++];
  924. pos += strlen;
  925. }
  926. }
  927. abytes = null;
  928. }
  929. catch { }
  930. }
  931. }
  932. else if (nodeName.StartsWith(CollisionSoundB))
  933. {
  934. if (!nodeName.EndsWith((byte)'d'))
  935. continue;
  936. if (TryGetxmlUUIDValue(ref data, out UUID id) && id != UUID.Zero)
  937. GatheredUuids[id] = (sbyte)AssetType.Sound;
  938. }
  939. else if (nodeName.StartsWith(SoundIDB))
  940. {
  941. if (nodeName.EndsWith((byte)'/'))
  942. continue;
  943. if (TryGetxmlUUIDValue(ref data, out UUID id) && id != UUID.Zero)
  944. GatheredUuids[id] = (sbyte)AssetType.Sound;
  945. }
  946. else if (nodeName.StartsWith(SculptTextureB))
  947. {
  948. if (nodeName.EndsWith((byte)'/'))
  949. continue;
  950. if (TryGetxmlUUIDValue(ref data, out UUID id) && id != UUID.Zero)
  951. GatheredUuids[id] = (sbyte)AssetType.Texture; // can be mesh but no prob
  952. }
  953. else if (nodeName.StartsWith(ExtraParamsB))
  954. {
  955. if (nodeName.EndsWith((byte)'/'))
  956. continue;
  957. if (TryGetXMLBinary(ref data, out byte[] exbytes) && exbytes != null && exbytes.Length > 16)
  958. {
  959. try
  960. {
  961. PrimitiveBaseShape ps = new PrimitiveBaseShape();
  962. ps.ReadInExtraParamsBytes(exbytes);
  963. UUID teid = ps.ProjectionTextureUUID;
  964. if (teid != UUID.Zero &&
  965. !ToSkip.Contains(teid) &&
  966. !FailedUUIDs.Contains(teid))
  967. {
  968. GatheredUuids[teid] = (sbyte)AssetType.Texture;
  969. }
  970. /* multiple store
  971. teid = ps.SculptTexture; //??
  972. if (teid != UUID.Zero &&
  973. !ToSkip.Contains(teid) &&
  974. !FailedUUIDs.Contains(teid))
  975. {
  976. GatheredUuids[teid] = (sbyte)AssetType.Texture;
  977. }
  978. */
  979. ps = null;
  980. exbytes = null;
  981. }
  982. catch { }
  983. }
  984. }
  985. else if (nodeName.StartsWith(ParticleSystemB))
  986. {
  987. if (nodeName.EndsWith((byte)'/'))
  988. continue;
  989. if (TryGetXMLBinary(ref data, out byte[] psbytes) && psbytes != null && psbytes.Length > 16)
  990. {
  991. try
  992. {
  993. Primitive.ParticleSystem ps = new Primitive.ParticleSystem(psbytes, 0);
  994. UUID teid = ps.Texture;
  995. if (teid != UUID.Zero &&
  996. !ToSkip.Contains(teid) &&
  997. !FailedUUIDs.Contains(teid))
  998. {
  999. GatheredUuids[teid] = (sbyte)AssetType.Texture;
  1000. }
  1001. psbytes = null;
  1002. }
  1003. catch { }
  1004. }
  1005. }
  1006. else if (nodeName.StartsWith(TextureEntryB))
  1007. {
  1008. if (nodeName.EndsWith((byte)'/'))
  1009. continue;
  1010. if (TryGetXMLBinary(ref data, out byte[] tebytes) && tebytes != null && tebytes.Length > 16)
  1011. {
  1012. try
  1013. {
  1014. Primitive.TextureEntry te = new Primitive.TextureEntry(tebytes, 0, tebytes.Length);
  1015. if (te != null)
  1016. {
  1017. // Get the prim's default texture. This will be used for faces which don't have their own texture
  1018. if (te.DefaultTexture != null)
  1019. RecordTextureEntryAssetUuids(te.DefaultTexture);
  1020. if (te.FaceTextures != null)
  1021. {
  1022. // Loop through the rest of the texture faces (a non-null face means the face is different from DefaultTexture)
  1023. foreach (Primitive.TextureEntryFace texture in te.FaceTextures)
  1024. {
  1025. if (texture != null)
  1026. RecordTextureEntryAssetUuids(texture);
  1027. }
  1028. }
  1029. }
  1030. te = null;
  1031. }
  1032. catch { }
  1033. }
  1034. }
  1035. else if (nodeName.StartsWith(TaskInventoryB))
  1036. {
  1037. if (nodeName.EndsWith((byte)'/'))
  1038. continue;
  1039. while ((next = getxmlNode(ref data, out nodeName)) > 0)
  1040. {
  1041. if (nodeName.StartsWith(AssetIDB))
  1042. {
  1043. if (TryGetxmlUUIDValue(ref data, out UUID id) && id != UUID.Zero)
  1044. AddForInspection(id);
  1045. }
  1046. else if (nodeName.StartsWith(endTaskInventoryB))
  1047. break;
  1048. }
  1049. }
  1050. }
  1051. }
  1052. /// <summary>
  1053. /// Get the asset uuid associated with a gesture
  1054. /// </summary>
  1055. /// <param name="gestureAsset"></param>
  1056. private void RecordGestureAssetUuids(AssetBase gestureAsset)
  1057. {
  1058. osUTF8 osdata = new osUTF8(gestureAsset.Data);
  1059. if (!osdata.SkipLine()) // version
  1060. return;
  1061. if (!osdata.SkipLine()) // key
  1062. return;
  1063. if (!osdata.SkipLine()) // mask
  1064. return;
  1065. if (!osdata.SkipLine()) // trigger
  1066. return;
  1067. if (!osdata.SkipLine()) // replace
  1068. return;
  1069. if (!osdata.ReadLine(out osUTF8 line))
  1070. return;
  1071. if(!osUTF8.TryParseInt(line, out int scount) || scount == 0)
  1072. return;
  1073. for(int i = 0; i < scount; ++i)
  1074. {
  1075. if (!osdata.ReadLine(out osUTF8 typeline)) // type
  1076. return;
  1077. typeline.SelfTrim();
  1078. if (!osUTF8.TryParseInt(typeline, out int type))
  1079. return;
  1080. osUTF8 id;
  1081. UUID uid;
  1082. switch(type)
  1083. {
  1084. case 0: // animation
  1085. case 1: // sound
  1086. if (!osdata.SkipLine()) // name
  1087. return;
  1088. if (!osdata.ReadLine(out id)) // uuid
  1089. return;
  1090. if (osUTF8.TryParseUUID(id, out uid) && uid != UUID.Zero)
  1091. GatheredUuids[uid] = type == 0 ? (sbyte)AssetType.Animation : (sbyte)AssetType.Sound;
  1092. if (!osdata.SkipLine()) // flags
  1093. return;
  1094. break;
  1095. case 2: // chat
  1096. case 3: // wait
  1097. if (!osdata.SkipLine()) // chat text or wait time
  1098. return;
  1099. if (!osdata.SkipLine()) // flags
  1100. return;
  1101. break;
  1102. default:
  1103. return; // no idea
  1104. }
  1105. }
  1106. }
  1107. /// <summary>
  1108. /// Get the asset uuid's referenced in a material.
  1109. /// </summary>
  1110. private void RecordMaterialAssetUuids(AssetBase materialAsset)
  1111. {
  1112. osUTF8 data = new osUTF8(materialAsset.Data);
  1113. int next;
  1114. while ((next = getxmlNode(ref data, out osUTF8 header)) > 0)
  1115. {
  1116. if (header.StartsWith((byte)'/'))
  1117. continue;
  1118. if (header.StartsWith(uuidB))
  1119. {
  1120. if(header.EndsWith((byte)'/'))
  1121. continue;
  1122. int indx = data.IndexOf((byte)'<');
  1123. if(indx < 0)
  1124. continue;
  1125. osUTF8 tmp = data.osUTF8SubString(0, indx);
  1126. if(osUTF8.TryParseUUID(tmp, out UUID id) && id != UUID.Zero)
  1127. GatheredUuids[id] = (sbyte)AssetType.Texture;
  1128. data.osUTF8SubStringSelf(indx + 1);
  1129. }
  1130. }
  1131. }
  1132. }
  1133. public class HGUuidGatherer : UuidGatherer
  1134. {
  1135. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  1136. protected string m_assetServerURL;
  1137. public HGUuidGatherer(IAssetService assetService, string assetServerURL)
  1138. : this(assetService, assetServerURL, new Dictionary<UUID, sbyte>()) {}
  1139. public HGUuidGatherer(IAssetService assetService, string assetServerURL, IDictionary<UUID, sbyte> collector)
  1140. : base(assetService, collector)
  1141. {
  1142. m_assetServerURL = assetServerURL;
  1143. if (!String.IsNullOrWhiteSpace(assetServerURL) && !m_assetServerURL.EndsWith("/") && !m_assetServerURL.EndsWith("="))
  1144. m_assetServerURL = m_assetServerURL + "/";
  1145. }
  1146. protected override AssetBase GetAsset(UUID uuid)
  1147. {
  1148. if (String.IsNullOrWhiteSpace(m_assetServerURL))
  1149. return base.GetAsset(uuid);
  1150. else
  1151. return FetchAsset(uuid);
  1152. }
  1153. public AssetBase FetchAsset(UUID assetID)
  1154. {
  1155. // Test if it's already here
  1156. AssetBase asset = m_assetService.Get(assetID.ToString());
  1157. if (asset == null)
  1158. {
  1159. // It's not, so fetch it from abroad
  1160. asset = m_assetService.Get(m_assetServerURL + assetID.ToString());
  1161. if (asset != null)
  1162. m_log.DebugFormat("[HGUUIDGatherer]: Copied asset {0} from {1} to local asset server", assetID, m_assetServerURL);
  1163. else
  1164. m_log.DebugFormat("[HGUUIDGatherer]: Failed to fetch asset {0} from {1}", assetID, m_assetServerURL);
  1165. }
  1166. //else
  1167. // m_log.DebugFormat("[HGUUIDGatherer]: Asset {0} from {1} was already here", assetID, m_assetServerURL);
  1168. return asset;
  1169. }
  1170. }
  1171. }