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...");
        }
Ejemplo n.º 2
0
        public static void ParseXml(Stream xmlData, XboxTitleInfo titleInfo) {
            XboxAssetDownloader.SendStatusChanged("Parsing Title/Asset info...");
            var ret = new List<XboxTitleInfo.XboxAssetInfo>();

            XDocument marketData = XDocument.Load(xmlData);

            var liveXmlNamespace = marketData.Root.Attributes().First(p => p.Name.LocalName == "live");
            string live = liveXmlNamespace.Value;

            var fullTitle = marketData.Descendants(XName.Get("fullTitle", live)).FirstOrDefault();

            if(fullTitle == null) {
                return;
                }

            titleInfo.Title = fullTitle.Value;

            var description = marketData.Descendants(XName.Get("description", live)).First();

            titleInfo.Description = description.Value;

            var assets = marketData.Descendants(XName.Get("image", live));

            foreach(var asset in assets) {
                var fileUrl = asset.Element(XName.Get("fileUrl", live)).Value;

                var fileUri = new Uri(fileUrl);

                var fileName = Path.GetFileNameWithoutExtension(fileUrl);

                if(fileName.StartsWith("banner", StringComparison.CurrentCultureIgnoreCase)) {
                    ret.Add(new XboxTitleInfo.XboxAssetInfo(fileUri, XboxTitleInfo.XboxAssetType.Banner, titleInfo));
                    continue;
                    }

                if(fileName.StartsWith("background", StringComparison.CurrentCultureIgnoreCase)) {
                    ret.Add(new XboxTitleInfo.XboxAssetInfo(fileUri, XboxTitleInfo.XboxAssetType.Background, titleInfo));
                    continue;
                    }

                if(fileName.StartsWith("tile", StringComparison.CurrentCultureIgnoreCase)) {
                    ret.Add(new XboxTitleInfo.XboxAssetInfo(fileUri, XboxTitleInfo.XboxAssetType.Icon, titleInfo));
                    continue;
                    }

                if(fileName.StartsWith("screen", StringComparison.CurrentCultureIgnoreCase)) {
                    ret.Add(new XboxTitleInfo.XboxAssetInfo(fileUri, XboxTitleInfo.XboxAssetType.Screenshot, titleInfo));
                    continue;
                    }
                }

            titleInfo.AssetsInfo = ret.ToArray();
            XboxAssetDownloader.SendStatusChanged("Finished parsing Title/Asset info...");
            }
Ejemplo n.º 3
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);
        }
        public XboxTitleInfo[] GetTitleInfo(string keywords, XboxLocale locale)
        {
            var url = string.Format("http://marketplace.xbox.com/{0}/SiteSearch/xbox/?query={1}&PageSize=5", locale.Locale, HttpUtility.UrlEncode(keywords));
            var wc  = new WebClient();
            var ret = new List <XboxTitleInfo>();

            using (var stream = wc.OpenRead(url)) {
                if (stream == null)
                {
                    return(ret.ToArray());
                }
                var res = (XboxKeywordResponse)_serializer.ReadObject(stream);
                ret.AddRange(from entry in res.Entries where entry.DetailsUrl != null let tid = entry.DetailsUrl.IndexOf("d802", StringComparison.Ordinal) where tid > 0 && entry.DetailsUrl.Length >= tid + 12 select uint.Parse(entry.DetailsUrl.Substring(tid + 4, 8), NumberStyles.HexNumber) into titleId select XboxTitleInfo.FromTitleId(titleId, locale));
            }
            return(ret.ToArray());
        }
 public XboxAssetInfo(Uri assetUrl, XboxAssetType assetType, XboxTitleInfo titleInfo)
 {
     AssetUrl   = assetUrl;
     AssetType  = assetType;
     _titleInfo = titleInfo;
 }
 public XboxTitleInfo[] GetTitleInfo(uint titleId, XboxLocale locale)
 {
     return(new[] {
         XboxTitleInfo.FromTitleId(titleId, locale)
     });
 }
        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...");
        }
 public XboxAssetInfo(Uri assetUrl, XboxAssetType assetType, XboxTitleInfo titleInfo)
 {
     AssetUrl = assetUrl;
     AssetType = assetType;
     _titleInfo = titleInfo;
 }
 private static void ParseXml(Stream xmlData, XboxTitleInfo titleInfo)
 {
     XboxAssetDownloader.SendStatusChanged("Parsing Title/Asset info...");
     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 Title/Asset info...");
 }
 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();
     wc.Proxy = null;
     wc.Headers.Add(HttpRequestHeader.UserAgent, App.UserAgent);
     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)))
         LocalOperations.ParseXml(stream, ret);
     return ret;
 }