AssetXferUploader.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  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.IO;
  29. using System.Reflection;
  30. using System.Collections.Generic;
  31. using log4net;
  32. using OpenMetaverse;
  33. using OpenSim.Framework;
  34. using OpenSim.Region.Framework.Interfaces;
  35. using OpenSim.Region.Framework.Scenes;
  36. using OpenSim.Services.Interfaces;
  37. using PermissionMask = OpenSim.Framework.PermissionMask;
  38. namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
  39. {
  40. public class AssetXferUploader
  41. {
  42. private List<UUID> defaultIDs = new List<UUID> {
  43. // Viewer's notion of the default texture
  44. new UUID("5748decc-f629-461c-9a36-a35a221fe21f"), // others == default blank
  45. new UUID("7ca39b4c-bd19-4699-aff7-f93fd03d3e7b"), // hair
  46. new UUID("6522e74d-1660-4e7f-b601-6f48c1659a77"), // eyes
  47. new UUID("c228d1cf-4b5d-4ba8-84f4-899a0796aa97"), // skin
  48. new UUID("8dcd4a48-2d37-4909-9f78-f7a9eb4ef903"), // transparency for alpha
  49. // opensim assets textures possibly obsolete now
  50. new UUID("00000000-0000-1111-9999-000000000010"),
  51. new UUID("00000000-0000-1111-9999-000000000011"),
  52. new UUID("00000000-0000-1111-9999-000000000012"),
  53. // other transparency defined in assets
  54. new UUID("3a367d1c-bef1-6d43-7595-e88c1e3aadb3"),
  55. new UUID("1578a2b1-5179-4b53-b618-fe00ca5a5594"),
  56. };
  57. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  58. /// <summary>
  59. /// Upload state.
  60. /// </summary>
  61. /// <remarks>
  62. /// New -> Uploading -> Complete
  63. /// </remarks>
  64. private enum UploadState
  65. {
  66. New,
  67. Uploading,
  68. Complete
  69. }
  70. /// <summary>
  71. /// Reference to the object that holds this uploader. Used to remove ourselves from it's list if we
  72. /// are performing a delayed update.
  73. /// </summary>
  74. AgentAssetTransactions m_transactions;
  75. private UploadState m_uploadState = UploadState.New;
  76. private AssetBase m_asset;
  77. private UUID InventFolder = UUID.Zero;
  78. private sbyte invType = 0;
  79. private bool m_createItem;
  80. private uint m_createItemCallback;
  81. private bool m_updateItem;
  82. private InventoryItemBase m_updateItemData;
  83. private bool m_updateTaskItem;
  84. private TaskInventoryItem m_updateTaskItemData;
  85. private string m_description = String.Empty;
  86. private bool m_dumpAssetToFile;
  87. private string m_name = String.Empty;
  88. // private bool m_storeLocal;
  89. private uint nextPerm = 0;
  90. private IClientAPI ourClient;
  91. private UUID m_transactionID;
  92. private sbyte type = 0;
  93. private byte wearableType = 0;
  94. private byte[] m_oldData = null;
  95. public ulong XferID;
  96. private Scene m_Scene;
  97. /// <summary>
  98. /// AssetXferUploader constructor
  99. /// </summary>
  100. /// <param name='transactions'>/param>
  101. /// <param name='scene'></param>
  102. /// <param name='transactionID'></param>
  103. /// <param name='dumpAssetToFile'>
  104. /// If true then when the asset is uploaded it is dumped to a file with the format
  105. /// String.Format("{6}_{7}_{0:d2}{1:d2}{2:d2}_{3:d2}{4:d2}{5:d2}.dat",
  106. /// now.Year, now.Month, now.Day, now.Hour, now.Minute,
  107. /// now.Second, m_asset.Name, m_asset.Type);
  108. /// for debugging purposes.
  109. /// </param>
  110. public AssetXferUploader(
  111. AgentAssetTransactions transactions, Scene scene, UUID transactionID, bool dumpAssetToFile)
  112. {
  113. m_asset = new AssetBase();
  114. m_transactions = transactions;
  115. m_transactionID = transactionID;
  116. m_Scene = scene;
  117. m_dumpAssetToFile = dumpAssetToFile;
  118. }
  119. /// <summary>
  120. /// Process transfer data received from the client.
  121. /// </summary>
  122. /// <param name="xferID"></param>
  123. /// <param name="packetID"></param>
  124. /// <param name="data"></param>
  125. /// <returns>True if the transfer is complete, false otherwise or if the xferID was not valid</returns>
  126. public bool HandleXferPacket(ulong xferID, uint packetID, byte[] data)
  127. {
  128. // m_log.DebugFormat(
  129. // "[ASSET XFER UPLOADER]: Received packet {0} for xfer {1} (data length {2})",
  130. // packetID, xferID, data.Length);
  131. if (XferID == xferID)
  132. {
  133. lock (this)
  134. {
  135. int assetLength = m_asset.Data.Length;
  136. int dataLength = data.Length;
  137. if (m_asset.Data.Length > 1)
  138. {
  139. byte[] destinationArray = new byte[assetLength + dataLength];
  140. Array.Copy(m_asset.Data, 0, destinationArray, 0, assetLength);
  141. Array.Copy(data, 0, destinationArray, assetLength, dataLength);
  142. m_asset.Data = destinationArray;
  143. }
  144. else
  145. {
  146. if (dataLength > 4)
  147. {
  148. byte[] buffer2 = new byte[dataLength - 4];
  149. Array.Copy(data, 4, buffer2, 0, dataLength - 4);
  150. m_asset.Data = buffer2;
  151. }
  152. }
  153. }
  154. ourClient.SendConfirmXfer(xferID, packetID);
  155. if ((packetID & 0x80000000) != 0)
  156. {
  157. SendCompleteMessage();
  158. return true;
  159. }
  160. }
  161. return false;
  162. }
  163. /// <summary>
  164. /// Start asset transfer from the client
  165. /// </summary>
  166. /// <param name="remoteClient"></param>
  167. /// <param name="assetID"></param>
  168. /// <param name="transaction"></param>
  169. /// <param name="type"></param>
  170. /// <param name="data">
  171. /// Optional data. If present then the asset is created immediately with this data
  172. /// rather than requesting an upload from the client. The data must be longer than 2 bytes.
  173. /// </param>
  174. /// <param name="storeLocal"></param>
  175. /// <param name="tempFile"></param>
  176. public void StartUpload(
  177. IClientAPI remoteClient, UUID assetID, UUID transaction, sbyte type, byte[] data, bool storeLocal,
  178. bool tempFile)
  179. {
  180. // m_log.DebugFormat(
  181. // "[ASSET XFER UPLOADER]: Initialised xfer from {0}, asset {1}, transaction {2}, type {3}, storeLocal {4}, tempFile {5}, already received data length {6}",
  182. // remoteClient.Name, assetID, transaction, type, storeLocal, tempFile, data.Length);
  183. lock (this)
  184. {
  185. if (m_uploadState != UploadState.New)
  186. {
  187. m_log.WarnFormat(
  188. "[ASSET XFER UPLOADER]: Tried to start upload of asset {0}, transaction {1} for {2} but this is already in state {3}. Aborting.",
  189. assetID, transaction, remoteClient.Name, m_uploadState);
  190. return;
  191. }
  192. m_uploadState = UploadState.Uploading;
  193. }
  194. ourClient = remoteClient;
  195. m_asset.FullID = assetID;
  196. m_asset.Type = type;
  197. m_asset.CreatorID = remoteClient.AgentId.ToString();
  198. m_asset.Data = data;
  199. m_asset.Local = storeLocal;
  200. m_asset.Temporary = tempFile;
  201. // m_storeLocal = storeLocal;
  202. if (m_asset.Data.Length > 2)
  203. {
  204. SendCompleteMessage();
  205. }
  206. else
  207. {
  208. RequestStartXfer();
  209. }
  210. }
  211. protected void RequestStartXfer()
  212. {
  213. XferID = Util.GetNextXferID();
  214. // m_log.DebugFormat(
  215. // "[ASSET XFER UPLOADER]: Requesting Xfer of asset {0}, type {1}, transfer id {2} from {3}",
  216. // m_asset.FullID, m_asset.Type, XferID, ourClient.Name);
  217. ourClient.SendXferRequest(XferID, m_asset.Type, m_asset.FullID, 0, new byte[0]);
  218. }
  219. protected void SendCompleteMessage()
  220. {
  221. // We must lock in order to avoid a race with a separate thread dealing with an inventory item or create
  222. // message from other client UDP.
  223. lock (this)
  224. {
  225. m_uploadState = UploadState.Complete;
  226. bool sucess = true;
  227. if (m_createItem)
  228. {
  229. sucess = CompleteCreateItem(m_createItemCallback);
  230. }
  231. else if (m_updateItem)
  232. {
  233. sucess = CompleteItemUpdate(m_updateItemData);
  234. }
  235. else if (m_updateTaskItem)
  236. {
  237. sucess = CompleteTaskItemUpdate(m_updateTaskItemData);
  238. }
  239. else if (m_asset.Local)
  240. {
  241. m_Scene.AssetService.Store(m_asset);
  242. }
  243. ourClient.SendAssetUploadCompleteMessage(m_asset.Type, sucess, m_asset.FullID);
  244. }
  245. m_log.DebugFormat(
  246. "[ASSET XFER UPLOADER]: Uploaded asset {0} for transaction {1}",
  247. m_asset.FullID, m_transactionID);
  248. if (m_dumpAssetToFile)
  249. {
  250. DateTime now = DateTime.Now;
  251. string filename =
  252. String.Format("{6}_{7}_{0:d2}{1:d2}{2:d2}_{3:d2}{4:d2}{5:d2}.dat",
  253. now.Year, now.Month, now.Day, now.Hour, now.Minute,
  254. now.Second, m_asset.Name, m_asset.Type);
  255. SaveAssetToFile(filename, m_asset.Data);
  256. }
  257. }
  258. private void SaveAssetToFile(string filename, byte[] data)
  259. {
  260. string assetPath = "UserAssets";
  261. if (!Directory.Exists(assetPath))
  262. {
  263. Directory.CreateDirectory(assetPath);
  264. }
  265. FileStream fs = File.Create(Path.Combine(assetPath, filename));
  266. BinaryWriter bw = new BinaryWriter(fs);
  267. bw.Write(data);
  268. bw.Close();
  269. fs.Close();
  270. }
  271. public void RequestCreateInventoryItem(IClientAPI remoteClient,
  272. UUID folderID, uint callbackID,
  273. string description, string name, sbyte invType,
  274. sbyte type, byte wearableType, uint nextOwnerMask)
  275. {
  276. InventFolder = folderID;
  277. m_name = name;
  278. m_description = description;
  279. this.type = type;
  280. this.invType = invType;
  281. this.wearableType = wearableType;
  282. nextPerm = nextOwnerMask;
  283. m_asset.Name = name;
  284. m_asset.Description = description;
  285. m_asset.Type = type;
  286. // We must lock to avoid a race with a separate thread uploading the asset.
  287. lock (this)
  288. {
  289. if (m_uploadState == UploadState.Complete)
  290. {
  291. CompleteCreateItem(callbackID);
  292. }
  293. else
  294. {
  295. m_createItem = true; //set flag so the inventory item is created when upload is complete
  296. m_createItemCallback = callbackID;
  297. }
  298. }
  299. }
  300. public void RequestUpdateInventoryItem(IClientAPI remoteClient, InventoryItemBase item)
  301. {
  302. // We must lock to avoid a race with a separate thread uploading the asset.
  303. lock (this)
  304. {
  305. m_asset.Name = item.Name;
  306. m_asset.Description = item.Description;
  307. m_asset.Type = (sbyte)item.AssetType;
  308. // remove redundante m_Scene.InventoryService.UpdateItem
  309. // if uploadState == UploadState.Complete)
  310. // if (m_asset.FullID != UUID.Zero)
  311. // {
  312. // We must always store the item at this point even if the asset hasn't finished uploading, in order
  313. // to avoid a race condition when the appearance module retrieves the item to set the asset id in
  314. // the AvatarAppearance structure.
  315. // item.AssetID = m_asset.FullID;
  316. // m_Scene.InventoryService.UpdateItem(item);
  317. // }
  318. if (m_uploadState == UploadState.Complete)
  319. {
  320. CompleteItemUpdate(item);
  321. }
  322. else
  323. {
  324. // do it here to avoid the eventual race condition
  325. if (m_asset.FullID != UUID.Zero)
  326. {
  327. // We must always store the item at this point even if the asset hasn't finished uploading, in order
  328. // to avoid a race condition when the appearance module retrieves the item to set the asset id in
  329. // the AvatarAppearance structure.
  330. item.AssetID = m_asset.FullID;
  331. m_Scene.InventoryService.UpdateItem(item);
  332. }
  333. // m_log.DebugFormat(
  334. // "[ASSET XFER UPLOADER]: Holding update inventory item request {0} for {1} pending completion of asset xfer for transaction {2}",
  335. // item.Name, remoteClient.Name, transactionID);
  336. m_updateItem = true;
  337. m_updateItemData = item;
  338. }
  339. }
  340. }
  341. public void RequestUpdateTaskInventoryItem(IClientAPI remoteClient, TaskInventoryItem taskItem)
  342. {
  343. // We must lock to avoid a race with a separate thread uploading the asset.
  344. lock (this)
  345. {
  346. m_asset.Name = taskItem.Name;
  347. m_asset.Description = taskItem.Description;
  348. m_asset.Type = (sbyte)taskItem.Type;
  349. taskItem.AssetID = m_asset.FullID;
  350. if (m_uploadState == UploadState.Complete)
  351. {
  352. CompleteTaskItemUpdate(taskItem);
  353. }
  354. else
  355. {
  356. m_updateTaskItem = true;
  357. m_updateTaskItemData = taskItem;
  358. }
  359. }
  360. }
  361. /// <summary>
  362. /// Store the asset for the given item when it has been uploaded.
  363. /// </summary>
  364. /// <param name="item"></param>
  365. private bool CompleteItemUpdate(InventoryItemBase item)
  366. {
  367. // m_log.DebugFormat(
  368. // "[ASSET XFER UPLOADER]: Storing asset {0} for earlier item update for {1} for {2}",
  369. // m_asset.FullID, item.Name, ourClient.Name);
  370. uint perms = ValidateAssets();
  371. if(perms == 0)
  372. {
  373. string error = string.Format("Not enough permissions on asset(s) referenced by item '{0}', update failed", item.Name);
  374. ourClient.SendAlertMessage(error);
  375. m_transactions.RemoveXferUploader(m_transactionID);
  376. ourClient.SendBulkUpdateInventory(item); // invalid the change item on viewer cache
  377. }
  378. else
  379. {
  380. m_Scene.AssetService.Store(m_asset);
  381. if (m_asset.FullID != UUID.Zero)
  382. {
  383. item.AssetID = m_asset.FullID;
  384. m_Scene.InventoryService.UpdateItem(item);
  385. }
  386. ourClient.SendInventoryItemCreateUpdate(item, m_transactionID, 0);
  387. m_transactions.RemoveXferUploader(m_transactionID);
  388. m_Scene.EventManager.TriggerOnNewInventoryItemUploadComplete(item, 0);
  389. }
  390. return perms != 0;
  391. }
  392. /// <summary>
  393. /// Store the asset for the given task item when it has been uploaded.
  394. /// </summary>
  395. /// <param name="taskItem"></param>
  396. private bool CompleteTaskItemUpdate(TaskInventoryItem taskItem)
  397. {
  398. // m_log.DebugFormat(
  399. // "[ASSET XFER UPLOADER]: Storing asset {0} for earlier task item update for {1} for {2}",
  400. // m_asset.FullID, taskItem.Name, ourClient.Name);
  401. if(ValidateAssets() == 0)
  402. {
  403. m_transactions.RemoveXferUploader(m_transactionID);
  404. string error = string.Format("Not enough permissions on asset(s) referenced by task item '{0}', update failed", taskItem.Name);
  405. ourClient.SendAlertMessage(error);
  406. // force old asset to viewers ??
  407. return false;
  408. }
  409. m_Scene.AssetService.Store(m_asset);
  410. m_transactions.RemoveXferUploader(m_transactionID);
  411. return true;
  412. }
  413. private bool CompleteCreateItem(uint callbackID)
  414. {
  415. if(ValidateAssets() == 0)
  416. {
  417. m_transactions.RemoveXferUploader(m_transactionID);
  418. string error = string.Format("Not enough permissions on asset(s) referenced by item '{0}', creation failed", m_name);
  419. ourClient.SendAlertMessage(error);
  420. return false;
  421. }
  422. m_Scene.AssetService.Store(m_asset);
  423. InventoryItemBase item = new InventoryItemBase();
  424. item.Owner = ourClient.AgentId;
  425. item.CreatorId = ourClient.AgentId.ToString();
  426. item.ID = UUID.Random();
  427. item.AssetID = m_asset.FullID;
  428. item.Description = m_description;
  429. item.Name = m_name;
  430. item.AssetType = type;
  431. item.InvType = invType;
  432. item.Folder = InventFolder;
  433. item.BasePermissions = (uint)(PermissionMask.All | PermissionMask.Export);
  434. item.CurrentPermissions = item.BasePermissions;
  435. item.GroupPermissions=0;
  436. item.EveryOnePermissions=0;
  437. item.NextPermissions = nextPerm;
  438. item.Flags = (uint) wearableType;
  439. item.CreationDate = Util.UnixTimeSinceEpoch();
  440. m_log.DebugFormat("[XFER]: Created item {0} with asset {1}",
  441. item.ID, item.AssetID);
  442. if (m_Scene.AddInventoryItem(item))
  443. ourClient.SendInventoryItemCreateUpdate(item, m_transactionID, callbackID);
  444. else
  445. ourClient.SendAlertMessage("Unable to create inventory item");
  446. m_transactions.RemoveXferUploader(m_transactionID);
  447. return true;
  448. }
  449. private uint ValidateAssets()
  450. {
  451. uint retPerms = 0x7fffffff;
  452. // if(m_Scene.Permissions.BypassPermissions())
  453. // return retPerms;
  454. if (m_asset.Type == (sbyte)CustomAssetType.AnimationSet)
  455. {
  456. AnimationSet animSet = new AnimationSet(m_asset.Data);
  457. retPerms &= animSet.Validate(x => {
  458. const uint required = (uint)(PermissionMask.Transfer | PermissionMask.Copy);
  459. uint perms = (uint)m_Scene.InventoryService.GetAssetPermissions(ourClient.AgentId, x);
  460. // currrent yes/no rule
  461. if ((perms & required) != required)
  462. return 0;
  463. return perms;
  464. });
  465. return retPerms;
  466. }
  467. if (m_asset.Type == (sbyte)AssetType.Clothing ||
  468. m_asset.Type == (sbyte)AssetType.Bodypart)
  469. {
  470. const uint texturesfullPermMask = (uint)(PermissionMask.Modify | PermissionMask.Transfer | PermissionMask.Copy);
  471. string content = System.Text.Encoding.ASCII.GetString(m_asset.Data);
  472. string[] lines = content.Split(new char[] {'\n'});
  473. // on current requiriment of full rigths assume old assets where accepted
  474. Dictionary<int, UUID> allowed = ExtractTexturesFromOldData();
  475. int textures = 0;
  476. foreach (string line in lines)
  477. {
  478. try
  479. {
  480. if (line.StartsWith("textures "))
  481. textures = Convert.ToInt32(line.Substring(9));
  482. else if (textures > 0)
  483. {
  484. string[] parts = line.Split(new char[] {' '});
  485. UUID tx = new UUID(parts[1]);
  486. int id = Convert.ToInt32(parts[0]);
  487. if (defaultIDs.Contains(tx) || tx == UUID.Zero ||
  488. (allowed.ContainsKey(id) && allowed[id] == tx))
  489. {
  490. continue;
  491. }
  492. else
  493. {
  494. uint perms = (uint)m_Scene.InventoryService.GetAssetPermissions(ourClient.AgentId, tx);
  495. if ((perms & texturesfullPermMask) != texturesfullPermMask)
  496. {
  497. m_log.ErrorFormat("[ASSET UPLOADER]: REJECTED update with texture {0} from {1} because they do not own the texture", tx, ourClient.AgentId);
  498. return 0;
  499. }
  500. else
  501. {
  502. retPerms &= perms;
  503. }
  504. }
  505. textures--;
  506. }
  507. }
  508. catch
  509. {
  510. // If it's malformed, skip it
  511. }
  512. }
  513. }
  514. return retPerms;
  515. }
  516. /* not in use
  517. /// <summary>
  518. /// Get the asset data uploaded in this transfer.
  519. /// </summary>
  520. /// <returns>null if the asset has not finished uploading</returns>
  521. public AssetBase GetAssetData()
  522. {
  523. if (m_uploadState == UploadState.Complete)
  524. {
  525. ValidateAssets();
  526. return m_asset;
  527. }
  528. return null;
  529. }
  530. */
  531. public void SetOldData(byte[] d)
  532. {
  533. m_oldData = d;
  534. }
  535. private Dictionary<int,UUID> ExtractTexturesFromOldData()
  536. {
  537. Dictionary<int,UUID> result = new Dictionary<int,UUID>();
  538. if (m_oldData == null)
  539. return result;
  540. string content = System.Text.Encoding.ASCII.GetString(m_oldData);
  541. string[] lines = content.Split(new char[] {'\n'});
  542. int textures = 0;
  543. foreach (string line in lines)
  544. {
  545. try
  546. {
  547. if (line.StartsWith("textures "))
  548. {
  549. textures = Convert.ToInt32(line.Substring(9));
  550. }
  551. else if (textures > 0)
  552. {
  553. string[] parts = line.Split(new char[] {' '});
  554. UUID tx = new UUID(parts[1]);
  555. int id = Convert.ToInt32(parts[0]);
  556. result[id] = tx;
  557. textures--;
  558. }
  559. }
  560. catch
  561. {
  562. // If it's malformed, skip it
  563. }
  564. }
  565. return result;
  566. }
  567. }
  568. }