Beispiel #1
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);
            }
        }
        /// <summary>
        /// Update character data
        /// </summary>
        private void UpdateCharacterData()
        {
            try
            {
                if (_characterId == -1)
                {
                    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 charInfo = db.GetCollection <VnCharacterInfo>(DbVnCharacter.VnCharacter.ToString()).Query()
                                   .Where(x => x.CharacterId == _characterId).FirstOrDefault();
                    var imagePath = $@"{App.AssetDirPath}\sources\vndb\images\characters\{VndbContentViewModel.VnId}\{Path.GetFileName(charInfo.ImageLink)}";
                    CharacterImage = ImageHelper.CreateBitmapFromPath(imagePath);

                    SetupDefaultVisProps();

                    Name = charInfo.Name;
                    SetGenderIcon(charInfo.Gender);
                    if (!string.IsNullOrEmpty(charInfo.Original))
                    {
                        OriginalName = new Tuple <string, Visibility>(charInfo.Original, Visibility.Visible);
                    }

                    if (!string.IsNullOrEmpty(charInfo.Birthday))
                    {
                        Birthday = new Tuple <string, Visibility>($"{App.ResMan.GetString("BirthdayColon")} {charInfo.Birthday}", Visibility.Visible);
                    }
                    if (!string.IsNullOrEmpty(charInfo.Age))
                    {
                        Birthday = new Tuple <string, Visibility>($"{App.ResMan.GetString("AgeColon")} {charInfo.Age}", Visibility.Visible);
                    }

                    if (!string.IsNullOrEmpty(charInfo.BloodType))
                    {
                        BloodType = new Tuple <string, Visibility>($"{App.ResMan.GetString("BloodTypeColon")} {charInfo.BloodType}", Visibility.Visible);
                    }

                    if (!charInfo.Height.Equals(0))
                    {
                        Height = new Tuple <string, Visibility>($"{App.ResMan.GetString("HeightColon")} {charInfo.Height}", Visibility.Visible);
                    }

                    if (!charInfo.Weight.Equals(0))
                    {
                        Weight = new Tuple <string, Visibility>($"{App.ResMan.GetString("WeightColon")} {charInfo.Weight}", Visibility.Visible);
                    }

                    SetBustWaistHips(charInfo);

                    Description = BBCodeHelper.Helper(charInfo.Description);
                }

                UpdateTraits();
            }
            catch (Exception e)
            {
                App.Logger.Error(e, "Failed to update character data");
                SentryHelper.SendException(e, null, SentryLevel.Warning);
            }
        }