public static void LoadAssets() { if (!DownloadManager.hasInternet) { return; } Download dl = DownloadManager.ScheduleDownload("Assets XML", MinecraftData.AssetsUrl, true); string xml = ""; dl.Downloaded += (d) => { xml = Encoding.ASCII.GetString(d.Data); StringReader sr = new StringReader(xml); XmlReader xmlr = XmlReader.Create(sr); MinecraftAsset current = null; try { while (xmlr.Read()) { if (xmlr.Name == "Contents" && xmlr.NodeType == XmlNodeType.Element) { current = new MinecraftAsset(); } else if (xmlr.Name == "Key" && current != null && xmlr.NodeType == XmlNodeType.Element) { xmlr.Read(); current.Key = xmlr.ReadContentAsString(); } else if (xmlr.Name == "ETag" && current != null && xmlr.NodeType == XmlNodeType.Element) { xmlr.Read(); current.md5 = xmlr.ReadContentAsString(); if (current.md5.StartsWith("\"")) { current.md5 = current.md5.Replace("\"", ""); } } else if (xmlr.Name == "Contents" && xmlr.NodeType == XmlNodeType.EndElement) { assets.Add(current); } } ScheduleAssetDownloads(); } catch (Exception ex) { App.Log("An error occured while parsing assets xml: " + ex.ToString()); throw ex; } finally { sr.Close(); } }; }
public static void LoadAssets() { if (!DownloadManager.hasInternet) return; Download dl = DownloadManager.ScheduleDownload("Assets XML", MinecraftData.AssetsUrl, true); string xml = ""; dl.Downloaded += (d) => { xml = Encoding.ASCII.GetString(d.Data); StringReader sr = new StringReader(xml); XmlReader xmlr = XmlReader.Create(sr); MinecraftAsset current = null; try { while (xmlr.Read()) { if (xmlr.Name == "Contents" && xmlr.NodeType == XmlNodeType.Element) { current = new MinecraftAsset(); } else if (xmlr.Name == "Key" && current != null && xmlr.NodeType == XmlNodeType.Element) { xmlr.Read(); current.Key = xmlr.ReadContentAsString(); } else if (xmlr.Name == "ETag" && current != null && xmlr.NodeType == XmlNodeType.Element) { xmlr.Read(); current.md5 = xmlr.ReadContentAsString(); if (current.md5.StartsWith("\"")) { current.md5 = current.md5.Replace("\"", ""); } } else if (xmlr.Name == "Contents" && xmlr.NodeType == XmlNodeType.EndElement) { assets.Add(current); } } ScheduleAssetDownloads(); } catch (Exception ex) { App.Log("An error occured while parsing assets xml: " + ex.ToString()); throw ex; } finally { sr.Close(); } }; }
private static void AssetDownloaded(Download dl) { MinecraftAsset asset = assets.Find(a => a.Url == dl.Url); asset.StoreAsset(dl); }