Exemple #1
0
        private async Task <ImageSource> LoadOfficialAsync(string imageUrl, ImageSource defaultImage)
        {
            // Remove the query part, remove the host part, remove image/Art/2DItems/, trim slashes
            var relevantPart = Regex.Replace(imageUrl, @"(\?.*)|(.*(\.net|\.com)/)|(image/Art/2DItems/)", "").Trim('/');
            var match        = Regex.Match(relevantPart, @"gen/image/.*?/([a-zA-Z0-9]*)/Item\.png");

            if (match.Success)
            {
                // These names are too long.
                // They contain groups of 20 chars (as folders) and end with a unique identifier.
                relevantPart = $"gen/{match.Groups[1]}.png";
            }
            var fileName = string.Format(DownloadedPathFormat, relevantPart);

            if (!File.Exists(fileName))
            {
                if (!_options.DownloadMissingItemImages)
                {
                    return(defaultImage);
                }
                var imgData = await _httpClient.GetByteArrayAsync(imageUrl).ConfigureAwait(false);

                CreateDirectories(fileName);
                WikiApiUtils.SaveImage(imgData, fileName, false);
                Log.Info($"Downloaded item image {fileName} to the file system.");
            }
            return(await Task.Run(() => ImageSourceFromPath(fileName)).ConfigureAwait(false));
        }
Exemple #2
0
        private async Task ReadJson(string wikiClass)
        {
            // for items that have the given class ...
            var conditions = new ConditionBuilder
            {
                { RdfItemClass, wikiClass }
            };
            // ... retrieve name and the icon url
            var task    = WikiApiAccessor.AskAndQueryImageInforUrls(conditions);
            var results = (await task).ToList();

            // download the images from the urls and save them
            foreach (var result in results)
            {
                var data = await HttpClient.GetByteArrayAsync(result.Url);

                foreach (var name in result.Names)
                {
                    var fileName = name + ".png";
                    WikiApiUtils.SaveImage(data, Path.Combine(SavePath, fileName), true);
                }
            }

            Log.Info($"Retrieved {results.Count} images for class {wikiClass}.");
        }
Exemple #3
0
        public void Add(string format, string rdfPredicate)
        {
            var from = WikiApiUtils.SingularValue <float>(_printouts, rdfPredicate, 0);

            if (from.AlmostEquals(0, 0.001)) // stats don't use many decimal places
            {
                return;
            }
            _properties.Add(string.Format(CultureInfo.InvariantCulture, format, from));
        }
Exemple #4
0
        public void Add(string name, string rdfPredicateFrom, string rdfPredicateTo)
        {
            var from = WikiApiUtils.SingularValue <float>(_printouts, rdfPredicateFrom, 0);
            var to   = WikiApiUtils.SingularValue <float>(_printouts, rdfPredicateTo, 0);

            if (from.AlmostEquals(0, 0.001) && to.AlmostEquals(0, 0.001)) // stats don't use many decimal places
            {
                return;
            }
            _properties.Add(new XmlStat
            {
                Name = name,
                From = new[] { @from },
                To   = new[] { to }
            });
        }
Exemple #5
0
        private async Task ReadJson(string wikiClass)
        {
            // for items that have the given class ...
            var where = $"{CargoConstants.ItemClass}='{wikiClass}'";
            // ... retrieve name and the icon url
            var task    = WikiApiAccessor.GetItemImageInfosAsync(where);
            var results = (await task).ToList();

            // download the images from the urls and save them
            foreach (var result in results)
            {
                var data = await HttpClient.GetByteArrayAsync(result.Url);

                foreach (var name in result.Names)
                {
                    var fileName = name + ".png";
                    WikiApiUtils.SaveImage(data, Path.Combine(SavePath, fileName), true);
                }
            }

            Log.Info($"Retrieved {results.Count} images for class {wikiClass}.");
        }
        private async Task <ImageSource> LoadOfficialAsync(string imageUrl, Task <ImageSource> defaultImage)
        {
            // Remove the query part, remove the host part, remove image/Art/2DItems/, trim slashes
            var relevantPart = Regex.Replace(imageUrl, @"(\?.*)|(.*(\.net|\.com)/)|(image/Art/2DItems/)", "").Trim('/');
            var match        = Regex.Match(relevantPart, @"gen/image/.*?/([a-zA-Z0-9]*)/Item\.png");
            var isRelic      = imageUrl.Contains("&relic=1");

            if (match.Success)
            {
                // These names are too long.
                // They contain groups of 20 chars (as folders) and end with a unique identifier.
                relevantPart = $"gen/{match.Groups[1]}.png";
            }
            else if (isRelic)
            {
                // Non-generated images for relics and normal uniques have the same url, the relic flag is in the
                // query part. As the query is removed, the file name needs to be adjusted for relics.
                relevantPart = relevantPart.Replace(".png", "Relic.png");
            }
            var fileName = string.Format(DownloadedPathFormat, relevantPart);

            if (!File.Exists(fileName))
            {
                if (!_options.DownloadMissingItemImages)
                {
                    return(await defaultImage.ConfigureAwait(false));
                }

                var imgData = await _httpClient.GetByteArrayAsync(imageUrl).ConfigureAwait(false);

                CreateDirectories(fileName);
                WikiApiUtils.SaveImage(imgData, fileName, false);
                Log.Info($"Downloaded item image {fileName} to the file system.");
            }
            return(BitmapImageFactory.Create(fileName));
        }