/// <summary>
        /// Get Vndb GameCards
        /// </summary>
        /// <param name="userDataArray"></param>
        /// <param name="vndbInfo"></param>
        private void GetVndbData(UserDataGames[] userDataArray, VnInfo[] vndbInfo)
        {
            try
            {
                foreach (var entry in userDataArray)
                {
                    var game = vndbInfo.FirstOrDefault(x => x.VnId == entry.GameId);
                    if (game == null)
                    {
                        continue;
                    }
                    var coverPath = $@"{App.AssetDirPath}\sources\vndb\images\cover\{game.VnId}.jpg";

                    var rating = NsfwHelper.RawRatingIsNsfw(game.ImageRating);

                    var card = _gameCard();
                    card.UserDataId = entry.Id;
                    card.ShouldDisplayNsfwContent = !NsfwHelper.UserIsNsfw(game.ImageRating);
                    card.Title            = !string.IsNullOrEmpty(entry.CustomGameName) ? entry.CustomGameName : game.Title;
                    card.LastPlayedString = $"Last Played: {TimeDateChanger.GetHumanDate(entry.LastPlayed)}";
                    card.TotalTimeString  = $"Play Time: {TimeDateChanger.GetHumanTime(entry.PlayTime)}";

                    if (rating == true && File.Exists($"{coverPath}.aes"))
                    {
                        var imgBytes  = File.ReadAllBytes($"{coverPath}.aes");
                        var imgStream = Secure.DecStreamToStream(new MemoryStream(imgBytes));
                        var imgNsfw   = ImageHelper.CreateBitmapFromStream(imgStream);
                        var bi        = new BindingImage {
                            Image = imgNsfw, IsNsfw = NsfwHelper.RawRatingIsNsfw(game.ImageRating)
                        };

                        card.CoverImage = bi;
                    }
                    else
                    {
                        if (File.Exists(coverPath))
                        {
                            var bi = new BindingImage {
                                Image = ImageHelper.CreateBitmapFromPath(coverPath), IsNsfw = false
                            };
                            card.CoverImage = bi;
                        }
                        else
                        {
                            var bi = new BindingImage {
                                Image = ImageHelper.CreateEmptyBitmapImage(), IsNsfw = false
                            };
                            card.CoverImage = bi;
                        }
                    }
                    _gameCollection.Add(card);
                }
            }
            catch (Exception e)
            {
                App.Logger.Warning(e, "Failed to create Vndb GameCards");
                SentryHelper.SendException(e, null, SentryLevel.Warning);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Get the main Vndb data
        /// </summary>
        private void LoadMainData()
        {
            try
            {
                if (VndbContentViewModel.VnId == 0)
                {
                    return;
                }
                var cred = CredentialManager.GetCredentials(App.CredDb);
                if (cred == null || cred.UserName.Length < 1)
                {
                    return;
                }
                using (var db = new LiteDatabase($"{App.GetDbStringWithoutPass}'{cred.Password}'"))
                {
                    var vnInfoEntry = db.GetCollection <VnInfo>(DbVnInfo.VnInfo.ToString()).Query().Where(x => x.VnId == VndbContentViewModel.VnId).FirstOrDefault();
                    Title        = vnInfoEntry.Title;
                    MainTitle    = vnInfoEntry.Title;
                    Aliases      = vnInfoEntry.Aliases;
                    ReleasedDate = TimeDateChanger.GetHumanDate(DateTime.Parse(vnInfoEntry.Released, CultureInfo.InvariantCulture));
                    VnLength     = vnInfoEntry.Length;
                    Popularity   = $"{vnInfoEntry.Popularity:F}";
                    Rating       = $"{vnInfoEntry.Rating:F}";
                    LoadLanguages(ref vnInfoEntry);
                    var coverPath = $@"{App.AssetDirPath}\sources\vndb\images\cover\{vnInfoEntry.VnId}.jpg";

                    var rawRating = NsfwHelper.RawRatingIsNsfw(vnInfoEntry.ImageRating);
                    if (rawRating && File.Exists($"{coverPath}.aes"))
                    {
                        var imgBytes  = File.ReadAllBytes($"{coverPath}.aes");
                        var imgStream = Secure.DecStreamToStream(new MemoryStream(imgBytes));
                        var imgNsfw   = ImageHelper.CreateBitmapFromStream(imgStream);
                        CoverImage = imgNsfw;
                        if (NsfwHelper.UserIsNsfw(vnInfoEntry.ImageRating))
                        {
                            const int blurWeight = 10;
                            SentrySdk.AddBreadcrumb($"BlurCoverImage-{VndbContentViewModel.VnId}");
                            CoverImage = ImageHelper.BlurImage(imgNsfw, blurWeight);
                        }
                    }
                    else
                    {
                        CoverImage = File.Exists(coverPath) ? ImageHelper.CreateBitmapFromPath(coverPath) : ImageHelper.CreateEmptyBitmapImage();
                    }

                    DescriptionInLine = BBCodeHelper.Helper(vnInfoEntry.Description);
                }
            }
            catch (Exception e)
            {
                App.Logger.Warning(e, "Failed to load Main Vndb Data");
                SentryHelper.SendException(e, null, SentryLevel.Warning);
            }
        }