UuidGatherer.cs 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274
  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. public int AssetGetCount;
  236. private bool verbose = true;
  237. /// <summary>
  238. /// Gets the next UUID to inspect.
  239. /// </summary>
  240. /// <value>If there is no next UUID then returns null</value>
  241. public UUID? NextUuidToInspect
  242. {
  243. get
  244. {
  245. if (Complete)
  246. return null;
  247. else
  248. return m_assetUuidsToInspect.Peek();
  249. }
  250. }
  251. protected IAssetService m_assetService;
  252. protected Queue<UUID> m_assetUuidsToInspect;
  253. /// <summary>
  254. /// Initializes a new instance of the <see cref="OpenSim.Region.Framework.Scenes.UuidGatherer"/> class.
  255. /// </summary>
  256. /// <remarks>In this case the collection of gathered assets will start out blank.</remarks>
  257. /// <param name="assetService">
  258. /// Asset service.
  259. /// </param>
  260. public UuidGatherer(IAssetService assetService) : this(assetService, new Dictionary<UUID, sbyte>(),
  261. new HashSet <UUID>(),new HashSet <UUID>()) {}
  262. public UuidGatherer(IAssetService assetService, IDictionary<UUID, sbyte> collector) : this(assetService, collector,
  263. new HashSet <UUID>(), new HashSet <UUID>()) {}
  264. /// <summary>
  265. /// Initializes a new instance of the <see cref="OpenSim.Region.Framework.Scenes.UuidGatherer"/> class.
  266. /// </summary>
  267. /// <param name="assetService">
  268. /// Asset service.
  269. /// </param>
  270. /// <param name="collector">
  271. /// Gathered UUIDs will be collected in this dictionary.
  272. /// It can be pre-populated if you want to stop the gatherer from analyzing assets that have already been fetched and inspected.
  273. /// </param>
  274. public UuidGatherer(IAssetService assetService, IDictionary<UUID, sbyte> collector, HashSet <UUID> failedIDs, HashSet <UUID> uncertainAssetsUUIDs)
  275. {
  276. m_assetService = assetService;
  277. GatheredUuids = collector;
  278. // FIXME: Not efficient for searching, can improve.
  279. m_assetUuidsToInspect = new Queue<UUID>();
  280. FailedUUIDs = failedIDs;
  281. UncertainAssetsUUIDs = uncertainAssetsUUIDs;
  282. ErrorCount = 0;
  283. possibleNotAssetCount = 0;
  284. AssetGetCount = 0;
  285. }
  286. public bool AddGathered(UUID uuid, sbyte type)
  287. {
  288. if (uuid == UUID.Zero)
  289. return false;
  290. if (ToSkip.Contains(uuid))
  291. return false;
  292. if (FailedUUIDs.Contains(uuid))
  293. {
  294. if (UncertainAssetsUUIDs.Contains(uuid))
  295. possibleNotAssetCount++;
  296. else
  297. ErrorCount++;
  298. return false;
  299. }
  300. if (GatheredUuids.ContainsKey(uuid))
  301. return false;
  302. if (m_assetUuidsToInspect.Contains(uuid))
  303. return false;
  304. // m_log.DebugFormat("[UUID GATHERER]: Adding asset {0} for inspection", uuid);
  305. GatheredUuids[uuid] = type;
  306. return true;
  307. }
  308. /// <summary>
  309. /// Adds the asset uuid for inspection during the gathering process.
  310. /// </summary>
  311. /// <returns><c>true</c>, if for inspection was added, <c>false</c> otherwise.</returns>
  312. /// <param name="uuid">UUID.</param>
  313. public bool AddForInspection(UUID uuid)
  314. {
  315. if(uuid == UUID.Zero)
  316. return false;
  317. if(ToSkip.Contains(uuid))
  318. return false;
  319. if(FailedUUIDs.Contains(uuid))
  320. {
  321. if(UncertainAssetsUUIDs.Contains(uuid))
  322. possibleNotAssetCount++;
  323. else
  324. ErrorCount++;
  325. return false;
  326. }
  327. if(GatheredUuids.ContainsKey(uuid))
  328. return false;
  329. if (m_assetUuidsToInspect.Contains(uuid))
  330. return false;
  331. // m_log.DebugFormat("[UUID GATHERER]: Adding asset {0} for inspection", uuid);
  332. m_assetUuidsToInspect.Enqueue(uuid);
  333. return true;
  334. }
  335. /// <summary>
  336. /// Gather all the asset uuids associated with a given object.
  337. /// </summary>
  338. /// <remarks>
  339. /// This includes both those directly associated with
  340. /// it (e.g. face textures) and recursively, those of items within it's inventory (e.g. objects contained
  341. /// within this object).
  342. /// </remarks>
  343. /// <param name="sceneObject">The scene object for which to gather assets</param>
  344. public void AddForInspection(SceneObjectGroup sceneObject)
  345. {
  346. // m_log.DebugFormat(
  347. // "[UUID GATHERER]: Getting assets for object {0}, {1}", sceneObject.Name, sceneObject.UUID);
  348. if(sceneObject.IsDeleted)
  349. return;
  350. SceneObjectPart[] parts = sceneObject.Parts;
  351. for (int i = 0; i < parts.Length; ++i)
  352. {
  353. SceneObjectPart part = parts[i];
  354. // m_log.DebugFormat(
  355. // "[UUID GATHERER]: Getting part {0}, {1} for object {2}", part.Name, part.UUID, sceneObject.UUID);
  356. try
  357. {
  358. Primitive.TextureEntry textureEntry = part.Shape.Textures;
  359. if (textureEntry != null)
  360. {
  361. // Get the prim's default texture. This will be used for faces which don't have their own texture
  362. if (textureEntry.DefaultTexture != null)
  363. RecordTextureEntryAssetUuids(textureEntry.DefaultTexture);
  364. if (textureEntry.FaceTextures != null)
  365. {
  366. // Loop through the rest of the texture faces (a non-null face means the face is different from DefaultTexture)
  367. int nsides = part.GetNumberOfSides();
  368. foreach (Primitive.TextureEntryFace texture in textureEntry.FaceTextures)
  369. {
  370. if (texture != null)
  371. RecordTextureEntryAssetUuids(texture);
  372. if(--nsides <= 0)
  373. break;
  374. }
  375. }
  376. }
  377. if (part.Shape.SculptTexture != UUID.Zero)
  378. GatheredUuids[part.Shape.SculptTexture] = (sbyte)AssetType.Texture;
  379. if (part.Shape.ProjectionTextureUUID != UUID.Zero)
  380. GatheredUuids[part.Shape.ProjectionTextureUUID] = (sbyte)AssetType.Texture;
  381. UUID collisionSound = part.CollisionSound;
  382. if ( collisionSound != UUID.Zero &&
  383. collisionSound != part.invalidCollisionSoundUUID)
  384. GatheredUuids[collisionSound] = (sbyte)AssetType.Sound;
  385. if (part.ParticleSystem.Length > 0)
  386. {
  387. try
  388. {
  389. Primitive.ParticleSystem ps = new Primitive.ParticleSystem(part.ParticleSystem, 0);
  390. if (ps.Texture != UUID.Zero)
  391. GatheredUuids[ps.Texture] = (sbyte)AssetType.Texture;
  392. }
  393. catch (Exception)
  394. {
  395. m_log.WarnFormat(
  396. "[UUID GATHERER]: Could not check particle system for part {0} {1} in object {2} {3} since it is corrupt. Continuing.",
  397. part.Name, part.UUID, sceneObject.Name, sceneObject.UUID);
  398. }
  399. }
  400. List<TaskInventoryItem> items = part.TaskInventory.GetItems();
  401. // Now analyze this prim's inventory items to preserve all the uuids that they reference
  402. for(int j = 0; j < items.Count; ++j)
  403. {
  404. TaskInventoryItem tii = items[j];
  405. AddForInspection(tii.AssetID, (sbyte)tii.Type);
  406. }
  407. if(part.Animations != null && part.Animations.Count > 0)
  408. {
  409. foreach(UUID id in part.Animations.Keys)
  410. {
  411. if(id != UUID.Zero &&
  412. !ToSkip.Contains(id) &&
  413. !FailedUUIDs.Contains(id))
  414. {
  415. GatheredUuids[id] = (sbyte)AssetType.Animation;
  416. }
  417. }
  418. }
  419. RecordMaterialsUuids(part);
  420. }
  421. catch (Exception e)
  422. {
  423. m_log.ErrorFormat("[UUID GATHERER]: Failed to get part - {0}", e);
  424. }
  425. }
  426. if(sceneObject.TemporaryInstance)
  427. sceneObject.Dispose();
  428. }
  429. /// <summary>
  430. /// Gathers the next set of assets returned by the next uuid to get from the asset service.
  431. /// </summary>
  432. /// <returns>false if gathering is already complete, true otherwise</returns>
  433. public bool GatherNext()
  434. {
  435. if (Complete)
  436. return false;
  437. UUID nextToInspect = m_assetUuidsToInspect.Dequeue();
  438. // m_log.DebugFormat("[UUID GATHERER]: Inspecting asset {0}", nextToInspect);
  439. GetAssetUuids(nextToInspect);
  440. return m_assetUuidsToInspect.Count > 0;
  441. }
  442. /// <summary>
  443. /// Gathers all remaining asset UUIDS no matter how many calls are required to the asset service.
  444. /// </summary>
  445. /// <returns>false if gathering is already complete, true otherwise</returns>
  446. public bool GatherAll(bool report = false)
  447. {
  448. if (Complete)
  449. return false;
  450. if(report)
  451. verbose = false;
  452. while (GatherNext());
  453. if (report && FailedUUIDs.Count > 0)
  454. {
  455. StringBuilder sb = new StringBuilder(512);
  456. int i = FailedUUIDs.Count;
  457. sb.Append("[UUID GATHERER]: UUIDs that are not assets or really missing assets:\n\t");
  458. foreach (UUID id in FailedUUIDs)
  459. {
  460. sb.Append(id);
  461. if (--i > 0)
  462. sb.Append(',');
  463. }
  464. m_log.Debug(sb.ToString());
  465. }
  466. return true;
  467. }
  468. /// <summary>
  469. /// Gather all the asset uuids associated with the asset referenced by a given uuid
  470. /// </summary>
  471. /// <remarks>
  472. /// This includes both those directly associated with
  473. /// it (e.g. face textures) and recursively, those of items within it's inventory (e.g. objects contained
  474. /// within this object).
  475. /// This method assumes that the asset type associated with this asset in persistent storage is correct (which
  476. /// should always be the case). So with this method we always need to retrieve asset data even if the asset
  477. /// is of a type which is known not to reference any other assets
  478. /// </remarks>
  479. /// <param name="assetUuid">The uuid of the asset for which to gather referenced assets</param>
  480. private void GetAssetUuids(UUID assetUuid)
  481. {
  482. if(assetUuid == UUID.Zero)
  483. return;
  484. if(FailedUUIDs.Contains(assetUuid))
  485. {
  486. if(UncertainAssetsUUIDs.Contains(assetUuid))
  487. possibleNotAssetCount++;
  488. else
  489. ErrorCount++;
  490. return;
  491. }
  492. if (GatheredUuids.ContainsKey(assetUuid))
  493. return;
  494. AssetBase assetBase;
  495. try
  496. {
  497. assetBase = GetAsset(assetUuid);
  498. }
  499. catch (Exception e)
  500. {
  501. if(verbose)
  502. m_log.ErrorFormat("[UUID GATHERER]: Failed to get asset {0} : {1}", assetUuid, e.Message);
  503. ErrorCount++;
  504. FailedUUIDs.Add(assetUuid);
  505. return;
  506. }
  507. if(assetBase == null)
  508. {
  509. // m_log.ErrorFormat("[UUID GATHERER]: asset {0} not found", assetUuid);
  510. FailedUUIDs.Add(assetUuid);
  511. if(UncertainAssetsUUIDs.Contains(assetUuid))
  512. possibleNotAssetCount++;
  513. else
  514. ErrorCount++;
  515. return;
  516. }
  517. ++AssetGetCount;
  518. if(UncertainAssetsUUIDs.Contains(assetUuid))
  519. UncertainAssetsUUIDs.Remove(assetUuid);
  520. sbyte assetType = assetBase.Type;
  521. if(assetBase.Data == null || assetBase.Data.Length == 0)
  522. {
  523. // m_log.ErrorFormat("[UUID GATHERER]: asset {0}, type {1} has no data", assetUuid, assetType);
  524. ErrorCount++;
  525. FailedUUIDs.Add(assetUuid);
  526. return;
  527. }
  528. GatheredUuids[assetUuid] = assetType;
  529. try
  530. {
  531. if ((sbyte)AssetType.Bodypart == assetType || (sbyte)AssetType.Clothing == assetType)
  532. {
  533. RecordWearableAssetUuids(assetBase);
  534. }
  535. else if ((sbyte)AssetType.Gesture == assetType)
  536. {
  537. RecordGestureAssetUuids(assetBase);
  538. }
  539. else if ((sbyte)AssetType.Notecard == assetType)
  540. {
  541. RecordNoteCardEmbeddedAssetUuids(assetBase);
  542. }
  543. else if ((sbyte)AssetType.LSLText == assetType)
  544. {
  545. RecordEmbeddedAssetDataUuids(assetBase);
  546. }
  547. else if ((sbyte)OpenSimAssetType.Material == assetType)
  548. {
  549. RecordMaterialAssetUuids(assetBase);
  550. }
  551. else if ((sbyte)AssetType.Object == assetType)
  552. {
  553. RecordSceneObjectAssetUuids(assetBase);
  554. }
  555. else if ((sbyte)AssetType.Settings == assetType)
  556. {
  557. RecordEmbeddedAssetDataUuids(assetBase); // BAD to do
  558. }
  559. }
  560. catch (Exception e)
  561. {
  562. if(verbose)
  563. m_log.ErrorFormat("[UUID GATHERER]: Failed to gather uuids for asset with id {0} type {1}: {2}", assetUuid, assetType, e.Message);
  564. GatheredUuids.Remove(assetUuid);
  565. ErrorCount++;
  566. FailedUUIDs.Add(assetUuid);
  567. }
  568. }
  569. private void AddForInspection(UUID assetUuid, sbyte assetType)
  570. {
  571. if(assetUuid == UUID.Zero)
  572. return;
  573. // Here, we want to collect uuids which require further asset fetches but mark the others as gathered
  574. if(FailedUUIDs.Contains(assetUuid))
  575. {
  576. if(UncertainAssetsUUIDs.Contains(assetUuid))
  577. possibleNotAssetCount++;
  578. else
  579. ErrorCount++;
  580. return;
  581. }
  582. if(GatheredUuids.ContainsKey(assetUuid))
  583. return;
  584. try
  585. {
  586. if ((sbyte)AssetType.Bodypart == assetType
  587. || (sbyte)AssetType.Clothing == assetType
  588. || (sbyte)AssetType.Gesture == assetType
  589. || (sbyte)AssetType.Notecard == assetType
  590. || (sbyte)AssetType.LSLText == assetType
  591. || (sbyte)OpenSimAssetType.Material == assetType
  592. || (sbyte)AssetType.Object == assetType
  593. || (sbyte)AssetType.Settings == assetType)
  594. {
  595. AddForInspection(assetUuid);
  596. }
  597. else
  598. {
  599. GatheredUuids[assetUuid] = assetType;
  600. }
  601. }
  602. catch (Exception)
  603. {
  604. m_log.ErrorFormat(
  605. "[UUID GATHERER]: Failed to gather uuids for asset id {0}, type {1}",
  606. assetUuid, assetType);
  607. throw;
  608. }
  609. }
  610. /// <summary>
  611. /// Collect all the asset uuids found in one face of a Texture Entry.
  612. /// </summary>
  613. private void RecordTextureEntryAssetUuids(Primitive.TextureEntryFace texture)
  614. {
  615. UUID teid = texture.TextureID;
  616. if (teid != UUID.Zero &&
  617. !ToSkip.Contains(teid) &&
  618. !FailedUUIDs.Contains(teid))
  619. {
  620. GatheredUuids[teid] = (sbyte)AssetType.Texture;
  621. }
  622. if (texture.MaterialID != UUID.Zero)
  623. AddForInspection(texture.MaterialID);
  624. }
  625. /// <summary>
  626. /// Gather all of the texture asset UUIDs used to reference "Materials" such as normal and specular maps
  627. /// stored in legacy format in part.DynAttrs
  628. /// </summary>
  629. /// <param name="part"></param>
  630. private void RecordMaterialsUuids(SceneObjectPart part)
  631. {
  632. // scan thru the dynAttrs map of this part for any textures used as materials
  633. OSD osdMaterials = null;
  634. if(part.DynAttrs == null)
  635. return;
  636. lock (part.DynAttrs)
  637. {
  638. if (part.DynAttrs.ContainsStore("OpenSim", "Materials"))
  639. {
  640. OSDMap materialsStore = part.DynAttrs.GetStore("OpenSim", "Materials");
  641. if (materialsStore == null)
  642. return;
  643. materialsStore.TryGetValue("Materials", out osdMaterials);
  644. }
  645. if (osdMaterials != null)
  646. {
  647. //m_log.Info("[UUID Gatherer]: found Materials: " + OSDParser.SerializeJsonString(osd));
  648. if (osdMaterials is OSDArray)
  649. {
  650. OSDArray matsArr = osdMaterials as OSDArray;
  651. foreach (OSDMap matMap in matsArr)
  652. {
  653. try
  654. {
  655. if (matMap.ContainsKey("Material"))
  656. {
  657. OSDMap mat = matMap["Material"] as OSDMap;
  658. if (mat.ContainsKey("NormMap"))
  659. {
  660. UUID normalMapId = mat["NormMap"].AsUUID();
  661. if (normalMapId != UUID.Zero)
  662. {
  663. GatheredUuids[normalMapId] = (sbyte)AssetType.Texture;
  664. //m_log.Info("[UUID Gatherer]: found normal map ID: " + normalMapId.ToString());
  665. }
  666. }
  667. if (mat.ContainsKey("SpecMap"))
  668. {
  669. UUID specularMapId = mat["SpecMap"].AsUUID();
  670. if (specularMapId != UUID.Zero)
  671. {
  672. GatheredUuids[specularMapId] = (sbyte)AssetType.Texture;
  673. //m_log.Info("[UUID Gatherer]: found specular map ID: " + specularMapId.ToString());
  674. }
  675. }
  676. }
  677. }
  678. catch (Exception e)
  679. {
  680. m_log.Warn("[UUID Gatherer]: exception getting materials: " + e.Message);
  681. }
  682. }
  683. }
  684. }
  685. }
  686. }
  687. /// <summary>
  688. /// Get an asset synchronously, potentially using an asynchronous callback. If the
  689. /// asynchronous callback is used, we will wait for it to complete.
  690. /// </summary>
  691. /// <param name="uuid"></param>
  692. /// <returns></returns>
  693. protected virtual AssetBase GetAsset(UUID uuid)
  694. {
  695. return m_assetService.Get(uuid.ToString());
  696. }
  697. /// <summary>
  698. /// Record the asset uuids embedded within the given text (e.g. a script).
  699. /// </summary>
  700. /// <param name="textAsset"></param>
  701. private void RecordEmbeddedAssetDataUuids(AssetBase textAsset)
  702. {
  703. // m_log.DebugFormat("[ASSET GATHERER]: Getting assets for uuid references in asset {0}", embeddingAssetId);
  704. if(textAsset.Data.Length < 36)
  705. return;
  706. List<UUID> ids = Util.GetUUIDsOnData(textAsset.Data, 0, textAsset.Data.Length);
  707. if (ids == null || ids.Count == 0)
  708. return;
  709. for (int i = 0; i < ids.Count; ++i)
  710. {
  711. if (ids[i] == UUID.Zero)
  712. continue;
  713. if (!UncertainAssetsUUIDs.Contains(ids[i]))
  714. UncertainAssetsUUIDs.Add(ids[i]);
  715. AddForInspection(ids[i]);
  716. }
  717. }
  718. private void RecordNoteCardEmbeddedAssetUuids(AssetBase textAsset)
  719. {
  720. List<UUID> ids = SLUtil.GetEmbeddedAssetIDs(textAsset.Data);
  721. if(ids == null || ids.Count == 0)
  722. return;
  723. for(int i = 0; i < ids.Count; ++i)
  724. {
  725. if (ids[i] == UUID.Zero)
  726. continue;
  727. if (!UncertainAssetsUUIDs.Contains(ids[i]))
  728. UncertainAssetsUUIDs.Add(ids[i]);
  729. AddForInspection(ids[i]);
  730. }
  731. }
  732. private static byte[] wearableSeps = new byte[]{(byte)' ', (byte)'\t'};
  733. /// <summary>
  734. /// Record the uuids referenced by the given wearable asset
  735. /// </summary>
  736. /// <param name="asset"></param>
  737. private void RecordWearableAssetUuids(AssetBase asset)
  738. {
  739. if (asset.Data == null || asset.Data.Length < 64)
  740. return;
  741. try
  742. {
  743. osUTF8Slice ostmp = new osUTF8Slice(asset.Data);
  744. if (!ostmp.SkipLine()) // version
  745. return;
  746. if (!ostmp.SkipLine()) // name
  747. return;
  748. if (!ostmp.SkipLine()) // description
  749. return;
  750. if (!ostmp.SkipLine())
  751. return;
  752. while (ostmp.ReadLine(out osUTF8Slice line))
  753. {
  754. line.SelfTrim(wearableSeps);
  755. osUTF8Slice[] parts = line.Split(wearableSeps);
  756. if(parts[0].Length == 0)
  757. continue;
  758. parts[0].SelfTrim(wearableSeps);
  759. if (parts[0].Equals(parametersB))
  760. {
  761. if (parts[1].Length == 0)
  762. return;
  763. parts[1].SelfTrim(wearableSeps);
  764. if (!osUTF8Slice.TryParseInt(parts[1], out int count) || count == 0)
  765. return;
  766. for (int i = 0; i < count; ++i)
  767. {
  768. if (!ostmp.SkipLine())
  769. return;
  770. }
  771. }
  772. else if (parts[0].Equals(texturesB))
  773. {
  774. if(parts[1].Length == 0)
  775. return;
  776. parts[1].SelfTrim(wearableSeps);
  777. if (!osUTF8Slice.TryParseInt(parts[1], out int count) || count == 0)
  778. return;
  779. for(int i = 0; i < count; ++i)
  780. {
  781. if(!ostmp.ReadLine(out osUTF8Slice texline))
  782. return;
  783. texline.SelfTrim(wearableSeps);
  784. osUTF8Slice[] texparts = texline.Split(wearableSeps);
  785. if(texparts.Length <2 || texparts[1].Length < 36)
  786. continue;
  787. texparts[1].SelfTrim(wearableSeps);
  788. if (UUID.TryParse(texparts[1].ToString(), out UUID id) && id != UUID.Zero)
  789. GatheredUuids[id] = (sbyte)AssetType.Texture;
  790. }
  791. }
  792. }
  793. }
  794. catch
  795. {
  796. }
  797. }
  798. private int getxmlNode(osUTF8Slice data, out osUTF8Slice h)
  799. {
  800. h = data;
  801. int st = -1;
  802. while ((st = data.IndexOf('<')) >= 0)
  803. {
  804. if (st > 0 && data[st - 1] == (byte)'\\')
  805. data.SubUTF8Self(st + 1);
  806. break;
  807. }
  808. if (st < 0)
  809. return -1;
  810. ++st;
  811. int ed = -1;
  812. while ((ed = data.IndexOf('>')) >= 0)
  813. {
  814. if (data[st - 1] == (byte)'\\')
  815. data.SubUTF8Self(st + 1);
  816. break;
  817. }
  818. if (ed < 0)
  819. return -1;
  820. h = data.SubUTF8(st, ed - st);
  821. h.SelfTrim();
  822. ++ed;
  823. data.SubUTF8Self(ed);
  824. return ed;
  825. }
  826. private bool TryGetxmlUUIDValue(osUTF8Slice data, out UUID id)
  827. {
  828. id = UUID.Zero;
  829. if(getxmlNode(data, out osUTF8Slice h) < 0)
  830. return false;
  831. if (h.StartsWith(UUIDB))
  832. {
  833. if (h.EndsWith((byte)'/'))
  834. return true;
  835. int indx = data.IndexOf((byte)'<');
  836. if (indx < 0)
  837. return false;
  838. osUTF8Slice tmp = data.SubUTF8(0, indx);
  839. data.SubUTF8Self(indx + 1);
  840. return osUTF8Slice.TryParseUUID(tmp, out id);
  841. }
  842. if (h.StartsWith(uuidB))
  843. {
  844. if (h.EndsWith((byte)'/'))
  845. return true;
  846. int indx = data.IndexOf((byte)'<');
  847. if (indx < 0)
  848. return false;
  849. osUTF8Slice tmp = data.SubUTF8(0, indx);
  850. data.SubUTF8Self(indx + 1);
  851. return osUTF8Slice.TryParseUUID(tmp, out id);
  852. }
  853. return false;
  854. }
  855. private bool TryGetXMLBinary(osUTF8Slice data, out byte[] te)
  856. {
  857. te = null;
  858. int indx = data.IndexOf((byte)'<');
  859. if(indx <= 0)
  860. return false;
  861. osUTF8Slice tmp = data.SubUTF8(0, indx);
  862. data.SubUTF8Self(indx + 1);
  863. tmp.SelfTrim();
  864. if(tmp.Length == 0)
  865. return false;
  866. try
  867. {
  868. te = Convert.FromBase64String(tmp.ToString()); // need to replace
  869. return true;
  870. }
  871. catch { }
  872. return false;
  873. }
  874. // bad ugly
  875. private static byte[] UUIDB = osUTF8.GetASCIIBytes("UUID");
  876. private static byte[] uuidB = osUTF8.GetASCIIBytes("uuid");
  877. private static byte[] SOPAnimsB = osUTF8.GetASCIIBytes("SOPAnims");
  878. private static byte[] CollisionSoundB = osUTF8.GetASCIIBytes("CollisionSound");
  879. private static byte[] SoundIDB = osUTF8.GetASCIIBytes("SoundID");
  880. private static byte[] SculptTextureB = osUTF8.GetASCIIBytes("SculptTexture");
  881. private static byte[] ExtraParamsB = osUTF8.GetASCIIBytes("ExtraParams");
  882. private static byte[] ParticleSystemB = osUTF8.GetASCIIBytes("ParticleSystem");
  883. private static byte[] TextureEntryB = osUTF8.GetASCIIBytes("TextureEntry");
  884. private static byte[] TaskInventoryB = osUTF8.GetASCIIBytes("TaskInventory");
  885. private static byte[] endTaskInventoryB = osUTF8.GetASCIIBytes("/TaskInventory");
  886. private static byte[] AssetIDB = osUTF8.GetASCIIBytes("AssetID");
  887. private static byte[] texturesB = osUTF8.GetASCIIBytes("textures");
  888. private static byte[] parametersB = osUTF8.GetASCIIBytes("parameters");
  889. /// <summary>
  890. /// Get all the asset uuids associated with a given object. This includes both those directly associated with
  891. /// it (e.g. face textures) and recursively, those of items within it's inventory (e.g. objects contained
  892. /// within this object).
  893. /// </summary>
  894. /// <param name="sceneObjectAsset"></param>
  895. private void RecordSceneObjectAssetUuids(AssetBase sceneObjectAsset)
  896. {
  897. osUTF8Slice data = new osUTF8Slice(sceneObjectAsset.Data);
  898. int next;
  899. osUTF8Slice nodeName;
  900. while ((next = getxmlNode(data, out nodeName)) > 0)
  901. {
  902. if (nodeName.StartsWith((byte)'/'))
  903. continue;
  904. if (nodeName.StartsWith(SOPAnimsB))
  905. {
  906. if (nodeName.EndsWith((byte)'/'))
  907. continue;
  908. if (TryGetXMLBinary(data, out byte[] abytes) && abytes != null && abytes.Length > 16)
  909. {
  910. try
  911. {
  912. int count = Utils.BytesToUInt16(abytes, 0);
  913. if (count >0)
  914. {
  915. int pos = 2;
  916. while (--count >= 0)
  917. {
  918. UUID id = new UUID(abytes, pos);
  919. if (id == UUID.Zero)
  920. break;
  921. if (!ToSkip.Contains(id) &&
  922. !FailedUUIDs.Contains(id))
  923. {
  924. GatheredUuids[id] = (sbyte)AssetType.Animation;
  925. }
  926. pos += 16;
  927. int strlen = data[pos++];
  928. pos += strlen;
  929. }
  930. }
  931. abytes = null;
  932. }
  933. catch { }
  934. }
  935. }
  936. else if (nodeName.StartsWith(CollisionSoundB))
  937. {
  938. if (!nodeName.EndsWith((byte)'d'))
  939. continue;
  940. if (TryGetxmlUUIDValue(data, out UUID id) && id != UUID.Zero)
  941. GatheredUuids[id] = (sbyte)AssetType.Sound;
  942. }
  943. else if (nodeName.StartsWith(SoundIDB))
  944. {
  945. if (nodeName.EndsWith((byte)'/'))
  946. continue;
  947. if (TryGetxmlUUIDValue(data, out UUID id) && id != UUID.Zero)
  948. GatheredUuids[id] = (sbyte)AssetType.Sound;
  949. }
  950. else if (nodeName.StartsWith(SculptTextureB))
  951. {
  952. if (nodeName.EndsWith((byte)'/'))
  953. continue;
  954. if (TryGetxmlUUIDValue(data, out UUID id) && id != UUID.Zero)
  955. GatheredUuids[id] = (sbyte)AssetType.Texture; // can be mesh but no prob
  956. }
  957. else if (nodeName.StartsWith(ExtraParamsB))
  958. {
  959. if (nodeName.EndsWith((byte)'/'))
  960. continue;
  961. if (TryGetXMLBinary(data, out byte[] exbytes) && exbytes != null && exbytes.Length > 16)
  962. {
  963. try
  964. {
  965. PrimitiveBaseShape ps = new PrimitiveBaseShape();
  966. ps.ReadInExtraParamsBytes(exbytes);
  967. UUID teid = ps.ProjectionTextureUUID;
  968. if (teid != UUID.Zero &&
  969. !ToSkip.Contains(teid) &&
  970. !FailedUUIDs.Contains(teid))
  971. {
  972. GatheredUuids[teid] = (sbyte)AssetType.Texture;
  973. }
  974. /* multiple store
  975. teid = ps.SculptTexture; //??
  976. if (teid != UUID.Zero &&
  977. !ToSkip.Contains(teid) &&
  978. !FailedUUIDs.Contains(teid))
  979. {
  980. GatheredUuids[teid] = (sbyte)AssetType.Texture;
  981. }
  982. */
  983. ps = null;
  984. exbytes = null;
  985. }
  986. catch { }
  987. }
  988. }
  989. else if (nodeName.StartsWith(ParticleSystemB))
  990. {
  991. if (nodeName.EndsWith((byte)'/'))
  992. continue;
  993. if (TryGetXMLBinary(data, out byte[] psbytes) && psbytes != null && psbytes.Length > 16)
  994. {
  995. try
  996. {
  997. Primitive.ParticleSystem ps = new Primitive.ParticleSystem(psbytes, 0);
  998. UUID teid = ps.Texture;
  999. if (teid != UUID.Zero &&
  1000. !ToSkip.Contains(teid) &&
  1001. !FailedUUIDs.Contains(teid))
  1002. {
  1003. GatheredUuids[teid] = (sbyte)AssetType.Texture;
  1004. }
  1005. psbytes = null;
  1006. }
  1007. catch { }
  1008. }
  1009. }
  1010. else if (nodeName.StartsWith(TextureEntryB))
  1011. {
  1012. if (nodeName.EndsWith((byte)'/'))
  1013. continue;
  1014. if (TryGetXMLBinary(data, out byte[] tebytes) && tebytes != null && tebytes.Length > 16)
  1015. {
  1016. try
  1017. {
  1018. Primitive.TextureEntry te = new Primitive.TextureEntry(tebytes, 0, tebytes.Length);
  1019. if (te != null)
  1020. {
  1021. // Get the prim's default texture. This will be used for faces which don't have their own texture
  1022. if (te.DefaultTexture != null)
  1023. RecordTextureEntryAssetUuids(te.DefaultTexture);
  1024. if (te.FaceTextures != null)
  1025. {
  1026. // Loop through the rest of the texture faces (a non-null face means the face is different from DefaultTexture)
  1027. foreach (Primitive.TextureEntryFace texture in te.FaceTextures)
  1028. {
  1029. if (texture != null)
  1030. RecordTextureEntryAssetUuids(texture);
  1031. }
  1032. }
  1033. }
  1034. te = null;
  1035. }
  1036. catch { }
  1037. }
  1038. }
  1039. else if (nodeName.StartsWith(TaskInventoryB))
  1040. {
  1041. if (nodeName.EndsWith((byte)'/'))
  1042. continue;
  1043. while ((next = getxmlNode(data, out nodeName)) > 0)
  1044. {
  1045. if (nodeName.StartsWith(AssetIDB))
  1046. {
  1047. if (TryGetxmlUUIDValue(data, out UUID id) && id != UUID.Zero)
  1048. AddForInspection(id);
  1049. }
  1050. else if (nodeName.StartsWith(endTaskInventoryB))
  1051. break;
  1052. }
  1053. }
  1054. }
  1055. }
  1056. /// <summary>
  1057. /// Get the asset uuid associated with a gesture
  1058. /// </summary>
  1059. /// <param name="gestureAsset"></param>
  1060. private void RecordGestureAssetUuids(AssetBase gestureAsset)
  1061. {
  1062. osUTF8Slice osdata = new osUTF8Slice(gestureAsset.Data);
  1063. if (!osdata.SkipLine()) // version
  1064. return;
  1065. if (!osdata.SkipLine()) // key
  1066. return;
  1067. if (!osdata.SkipLine()) // mask
  1068. return;
  1069. if (!osdata.SkipLine()) // trigger
  1070. return;
  1071. if (!osdata.SkipLine()) // replace
  1072. return;
  1073. if (!osdata.ReadLine(out osUTF8Slice line))
  1074. return;
  1075. if(!osUTF8Slice.TryParseInt(line, out int scount) || scount == 0)
  1076. return;
  1077. for(int i = 0; i < scount; ++i)
  1078. {
  1079. if (!osdata.ReadLine(out osUTF8Slice typeline)) // type
  1080. return;
  1081. typeline.SelfTrim();
  1082. if (!osUTF8Slice.TryParseInt(typeline, out int type))
  1083. return;
  1084. osUTF8Slice id;
  1085. UUID uid;
  1086. switch(type)
  1087. {
  1088. case 0: // animation
  1089. case 1: // sound
  1090. if (!osdata.SkipLine()) // name
  1091. return;
  1092. if (!osdata.ReadLine(out id)) // uuid
  1093. return;
  1094. if (osUTF8Slice.TryParseUUID(id, out uid) && uid != UUID.Zero)
  1095. GatheredUuids[uid] = type == 0 ? (sbyte)AssetType.Animation : (sbyte)AssetType.Sound;
  1096. if (!osdata.SkipLine()) // flags
  1097. return;
  1098. break;
  1099. case 2: // chat
  1100. case 3: // wait
  1101. if (!osdata.SkipLine()) // chat text or wait time
  1102. return;
  1103. if (!osdata.SkipLine()) // flags
  1104. return;
  1105. break;
  1106. default:
  1107. return; // no idea
  1108. }
  1109. }
  1110. }
  1111. /// <summary>
  1112. /// Get the asset uuid's referenced in a material.
  1113. /// </summary>
  1114. private void RecordMaterialAssetUuids(AssetBase materialAsset)
  1115. {
  1116. osUTF8Slice data = new osUTF8Slice(materialAsset.Data);
  1117. int next;
  1118. while ((next = getxmlNode(data, out osUTF8Slice header)) > 0)
  1119. {
  1120. if (header.StartsWith((byte)'/'))
  1121. continue;
  1122. if (header.StartsWith(uuidB))
  1123. {
  1124. if(header.EndsWith((byte)'/'))
  1125. continue;
  1126. int indx = data.IndexOf((byte)'<');
  1127. if(indx < 0)
  1128. continue;
  1129. osUTF8Slice tmp = data.SubUTF8(0, indx);
  1130. if(osUTF8Slice.TryParseUUID(tmp, out UUID id) && id != UUID.Zero)
  1131. GatheredUuids[id] = (sbyte)AssetType.Texture;
  1132. data.SubUTF8Self(indx + 1);
  1133. }
  1134. }
  1135. }
  1136. }
  1137. public class HGUuidGatherer : UuidGatherer
  1138. {
  1139. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  1140. protected string m_assetServerURL;
  1141. public HGUuidGatherer(IAssetService assetService, string assetServerURL)
  1142. : this(assetService, assetServerURL, new Dictionary<UUID, sbyte>()) {}
  1143. public HGUuidGatherer(IAssetService assetService, string assetServerURL, IDictionary<UUID, sbyte> collector)
  1144. : base(assetService, collector)
  1145. {
  1146. m_assetServerURL = assetServerURL;
  1147. }
  1148. protected override AssetBase GetAsset(UUID uuid)
  1149. {
  1150. if (string.IsNullOrWhiteSpace(m_assetServerURL))
  1151. return base.GetAsset(uuid);
  1152. else
  1153. return FetchAsset(uuid);
  1154. }
  1155. public AssetBase FetchAsset(UUID assetID)
  1156. {
  1157. AssetBase asset = m_assetService.Get(assetID.ToString(), m_assetServerURL, true);
  1158. if (asset != null)
  1159. m_log.DebugFormat("[HGUUIDGatherer]: Copied asset {0} from {1} to local asset server", assetID, m_assetServerURL);
  1160. else
  1161. m_log.DebugFormat("[HGUUIDGatherer]: Failed to fetch asset {0} from {1}", assetID, m_assetServerURL);
  1162. return asset;
  1163. }
  1164. }
  1165. }