private static void ParseXml(Stream xmlData, XboxTitleInfo titleInfo)
        {
            XboxAssetDownloader.SendStatusChanged("Parsing online asset information, please wait...");
            var ret = new List <XboxAssetInfo>();

            using (var xml = XmlReader.Create(xmlData)) {
                while (xml.Read())
                {
                    if (!xml.IsStartElement())
                    {
                        continue;
                    }
                    var name = xml.Name.ToLower();
                    if (!name.StartsWith("live:"))
                    {
                        continue;
                    }
                    name = name.Substring(5);
                    if (name == "fulltitle")
                    {
                        xml.Read();
                        titleInfo.Title = xml.Value;
                    }
                    if (name != "image")
                    {
                        continue;
                    }
                    while (xml.Read() && !(!xml.IsStartElement() && xml.Name.ToLower() == "live:image"))
                    {
                        if (!xml.IsStartElement() || xml.Name.ToLower() != "live:fileurl")
                        {
                            continue;
                        }
                        xml.Read();
                        var url   = new Uri(xml.Value);
                        var fname = Path.GetFileNameWithoutExtension(url.LocalPath);
                        if (fname.StartsWith("banner", StringComparison.CurrentCultureIgnoreCase))
                        {
                            ret.Add(new XboxAssetInfo(url, XboxAssetType.Banner, titleInfo));
                        }
                        else if (fname.StartsWith("background", StringComparison.CurrentCultureIgnoreCase))
                        {
                            ret.Add(new XboxAssetInfo(url, XboxAssetType.Background, titleInfo));
                        }
                        else if (fname.StartsWith("tile", StringComparison.CurrentCultureIgnoreCase))
                        {
                            ret.Add(new XboxAssetInfo(url, XboxAssetType.Icon, titleInfo));
                        }
                        else if (fname.StartsWith("screen", StringComparison.CurrentCultureIgnoreCase))
                        {
                            ret.Add(new XboxAssetInfo(url, XboxAssetType.Screenshot, titleInfo));
                        }
                        //Ignore anything else
                        break; // We're done with this image
                    }
                }
            }
            titleInfo.AssetsInfo = ret.ToArray();
            XboxAssetDownloader.SendStatusChanged("Finished parsing asset information...");
        }
Esempio n. 2
0
        public static XboxTitleInfo FromTitleId(uint titleId, XboxLocale locale)
        {
            var ret = new XboxTitleInfo {
                TitleId = string.Format("{0:X08}", titleId),
                Locale  = locale.ToString()
            };
            var wc  = new WebClient();
            var url =
                string.Format(
                    "http://catalog.xboxlive.com/Catalog/Catalog.asmx/Query?methodName=FindGames&Names=Locale&Values={0}&Names=LegalLocale&Values={0}&Names=Store&Values=1&Names=PageSize&Values=100&Names=PageNum&Values=1&Names=DetailView&Values=5&Names=OfferFilterLevel&Values=1&Names=MediaIds&Values=66acd000-77fe-1000-9115-d802{1:X8}&Names=UserTypes&Values=2&Names=MediaTypes&Values=1&Names=MediaTypes&Values=21&Names=MediaTypes&Values=23&Names=MediaTypes&Values=37&Names=MediaTypes&Values=46",
                    locale.Locale, titleId);

            XboxAssetDownloader.SendStatusChanged("Downloading title/asset information...");
            using (var stream = new MemoryStream(wc.DownloadData(url)))
                ParseXml(stream, ret);
            return(ret);
        }
        private static void ParseHtml(string url, XboxTitleInfo titleInfo)
        {
            XboxAssetDownloader.SendStatusChanged("Fetching online assets, please wait...");
            var ret = new List <XboxAssetInfo>();

            try
            {
                var wc   = new WebClient();
                var tmp  = new List <string>();
                var data = Encoding.UTF8.GetString(wc.DownloadData(url)).Split('>');
                for (var i = 0; i < data.Length; i++)
                {
                    //game title
                    if (data[i].ToLower().Contains("div id=\"gamedetails\""))
                    {
                        var name = data[i + 1];
                        if (name.ToLower().Contains("<h1"))
                        {
                            name            = data[i + 2];
                            titleInfo.Title = name.Substring(0, name.Length - 4);
                        }
                    }

                    //banner image
                    if (data[i].ToLower().Contains("bannerimage.src = "))
                    {
                        var index = data[i].ToLower().IndexOf("http\\x3a", StringComparison.Ordinal);
                        if (index > 0)
                        {
                            var index_end = data[i].ToLower().IndexOf("banner.png';", index, StringComparison.Ordinal);
                            if (index_end > 0)
                            {
                                var name = data[i].Substring(index, index_end - index + 10);
                                name = name.Replace("\\x3a", ":");
                                name = name.Replace("\\x2f", "/");
                                var banner_url = new Uri(name);
                                ret.Add(new XboxAssetInfo(banner_url, XboxAssetType.Banner, titleInfo));
                            }
                        }
                    }

                    //background image
                    if (data[i].ToLower().Contains("style=\\\"background-image: url("))
                    {
                        var index = data[i].ToLower().IndexOf("style=\\\"background-image: url(", StringComparison.Ordinal) + 30;
                        if (index > 0)
                        {
                            var index_end = data[i].ToLower().IndexOf("background.jpg", index, StringComparison.Ordinal);
                            if (index_end > 0)
                            {
                                var name       = data[i].Substring(index, index_end - index + 14);
                                var backgr_url = new Uri(name);
                                ret.Add(new XboxAssetInfo(backgr_url, XboxAssetType.Background, titleInfo));
                            }
                        }
                    }

                    //screenshots
                    if (data[i].ToLower().Contains("div id=\"mediacontrol\" class=\"grid-18"))
                    {
                        int w = i + 1, n = 0;
                        while (data[w + n].ToLower().Contains("div id=\"image"))
                        {
                            var index = data[w + n + 1].ToLower().IndexOf("http://", StringComparison.Ordinal);
                            if (index > 0)
                            {
                                var index_end = data[w + n + 1].ToLower().IndexOf("screenlg", index, StringComparison.Ordinal);
                                if (index_end > 0)
                                {
                                    index_end = data[w + n + 1].ToLower().IndexOf(".jpg", index_end, StringComparison.Ordinal);
                                    var name = data[w + n + 1].Substring(index, index_end - index + 4);

                                    var screen_url = new Uri(name);
                                    ret.Add(new XboxAssetInfo(screen_url, XboxAssetType.Screenshot, titleInfo));
                                }
                            }
                            n += 3;
                        }
                        i = w + n;
                    }
                }
            }
            catch {  }

            titleInfo.AssetsInfo = ret.ToArray();
            XboxAssetDownloader.SendStatusChanged("Finished parsing asset information...");
        }