void WriteIcon(ItemIconData data, string hash)
        {
            var url   = _baseItemIconUrl + hash;
            var bytes = RequestBytes(url);

            ItemIconDatabase.WriteNewIcon(data, bytes);
        }
Esempio n. 2
0
        public static void Initialize(IEnumerable <Saint.Item> items)
        {
            // Load map file.
            var iconDataLines = Utils.Tsv("Supplemental\\item-icon-db.tsv");

            foreach (var line in iconDataLines.Skip(1))
            {
                var iconData = ItemIconData.Parse(line);
                if (iconData.IconId == 0)
                {
                    continue;
                }

                IconDataByItemId[iconData.ItemId] = iconData;
            }

            if (IconDataByItemId.Count > 0)
            {
                _currentIconId = IconDataByItemId.Max(p => p.Value.IconId);
            }

            // Check icon data is valid.
            foreach (var item in items)
            {
                CheckIconData(item);
            }

            // Generate temporaries for icons that have no stored iconId.
            foreach (var item in items.Where(i => !_iconIdByImageFile.ContainsKey(i.Icon)))
            {
                GenerateTemporaryIcon(item);
            }
        }
        string SearchItem(int key, string name, ItemIconData data)
        {
            var url          = string.Format(_baseSearchFormat, HttpUtility.UrlEncode(name));
            var itemUrlRegex = new Regex(string.Format(_itemUrlRegexFormat, SanitizeRegex(name)));

            var html = Request(url);

            var match = itemUrlRegex.Match(html);

            if (!match.Success || match.Groups.Count != 2)
            {
                DatabaseBuilder.PrintLine($"Search match fail on {key}: {name}");
                return(null);
            }

            return(_baseUrl + match.Groups[1].Value);
        }
        string FetchItem(int key, string name, string itemUrl, ItemIconData data)
        {
            var html = Request(itemUrl);

            var match = _iconSuffixRegex.Match(html);

            if (!match.Success || match.Groups.Count != 2)
            {
                DatabaseBuilder.PrintLine($"Fetch match fail on {key}: {name}");
                return(null);
            }
            var iconSuffix = match.Groups[1].Value;

            var hash = match.Groups[1].Value;

            DatabaseBuilder.PrintLine($"{key}: {name} {hash}");
            return(hash);
        }
        public void FetchIcons()
        {
            // Run the process with an initial queue of items.
            var items = new Stack <Item>(ItemIconDatabase.ItemsNeedingIcons);

            while (items.Count > 0)
            {
                var item = items.Pop();

                if (!ItemIconDatabase.IconDataByItemId.TryGetValue(item.Key, out var data))
                {
                    data            = new ItemIconData();
                    data.ItemId     = item.Key;
                    data.RawIconKey = (UInt16)item.GetRaw("Icon");
                    data.Name       = item.Name.ToString();
                    ItemIconDatabase.IconDataByItemId[item.Key] = data;
                }

                // Scrape search data from Lodestone.
                var    itemUrl = SearchItem(item.Key, item.Name, data);
                string hash    = null;
                if (itemUrl != null)
                {
                    hash = FetchItem(item.Key, item.Name, itemUrl, data);
                }

                if (hash == null)
                {
                    // This entry failed.  Enqueue an alternate to search for.
                    var alternate = ItemIconDatabase.DequeueAlternate(item.Icon);
                    if (alternate != null)
                    {
                        items.Push(alternate);
                    }
                    continue;
                }

                // Fetch the icon and write entries.
                WriteIcon(data, hash);
                WriteEntries();
            }
        }
Esempio n. 6
0
 public static void WriteNewIcon(ItemIconData data, byte[] bytes)
 {
     data.IconId = ++_currentIconId;
     File.WriteAllBytes(Config.IconPath + "item\\" + data.IconId + ".png", bytes);
 }