예제 #1
0
        /// <summary>
        /// Load user data associated with the game
        /// </summary>
        private void LoadUserData()
        {
            try
            {
                var cred = CredentialManager.GetCredentials(App.CredDb);
                if (cred == null || cred.UserName.Length < 1)
                {
                    return;
                }
                using var db = new LiteDatabase($"{App.GetDbStringWithoutPass}'{cred.Password}'");
                var dbUserData = db.GetCollection <UserDataGames>(DbUserData.UserData_Games.ToString()).Query()
                                 .Where(x => x.Id == VndbContentViewModel.SelectedGame.Id).FirstOrDefault();
                if (dbUserData != null)
                {
                    LastPlayed = TimeDateChanger.GetHumanDate(dbUserData.LastPlayed);
                    PlayTime   = TimeDateChanger.GetHumanTime(dbUserData.PlayTime);

                    GameIcon = ImageHelper.CreateIcon(!string.IsNullOrEmpty(dbUserData.IconPath) ? dbUserData.IconPath : dbUserData.ExePath);
                }
            }
            catch (Exception e)
            {
                App.Logger.Warning(e, "Failed to load Vndb userData");
                SentryHelper.SendException(e, null, SentryLevel.Warning);
            }
        }
예제 #2
0
        /// <summary>
        /// Create NoSource GameCards
        /// </summary>
        /// <param name="userDataArray"></param>
        private void CreateNoSourceCards(UserDataGames[] userDataArray)
        {
            try
            {
                foreach (var entry in userDataArray)
                {
                    //TODO:Add in cover and ratings
                    var card = _gameCard();
                    card.Title            = !string.IsNullOrEmpty(entry.CustomGameName) ? entry.CustomGameName : entry.Title;
                    card.Title            = entry.Title;
                    card.LastPlayedString = $"{App.ResMan.GetString("LastPlayed")}: {TimeDateChanger.GetHumanDate(entry.LastPlayed)}";
                    card.TotalTimeString  = $"{App.ResMan.GetString("PlayTime")}: {TimeDateChanger.GetHumanTime(entry.PlayTime)}";
                    var coverName = $"{Path.Combine(App.AssetDirPath, @"sources\noSource\images\cover\")}{entry.Id}.png";
                    card.CoverImage = File.Exists(coverName) ? new BindingImage {
                        Image = ImageHelper.CreateBitmapFromPath(coverName)
                    } :
                    new BindingImage {
                        Image = ImageHelper.CreateEmptyBitmapImage()
                    };
                    card.UserDataId = entry.Id;

                    _gameCollection.Add(card);
                }
            }
            catch (Exception e)
            {
                App.Logger.Warning(e, "Failed to create Vndb GameCards");
                SentryHelper.SendException(e, null, SentryLevel.Error);
            }
        }
예제 #3
0
        /// <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);
            }
        }
예제 #4
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);
            }
        }
예제 #5
0
 /// <summary>
 /// Load the main NoSource data
 /// </summary>
 private void LoadMainData()
 {
     try
     {
         Title      = _selectedGame.Title;
         GameIcon   = ImageHelper.CreateIcon(!string.IsNullOrEmpty(_selectedGame.IconPath) ? _selectedGame.IconPath : _selectedGame.ExePath);
         LastPlayed = TimeDateChanger.GetHumanDate(_selectedGame.LastPlayed);
         PlayTime   = TimeDateChanger.GetHumanTime(_selectedGame.PlayTime);
         var coverName = $"{Path.Combine(App.AssetDirPath, @"sources\noSource\images\cover\")}{_selectedGame.Id}.png";
         CoverImage           = File.Exists(coverName) ? ImageHelper.CreateBitmapFromPath(coverName) : ImageHelper.CreateEmptyBitmapImage();
         IsStartButtonVisible = Visibility.Visible;
     }
     catch (Exception e)
     {
         App.Logger.Warning(e, "Failed to load NoSource MainData");
         SentryHelper.SendException(e, null, SentryLevel.Error);
     }
 }
예제 #6
0
        /// <summary>
        /// Saves info when the processes exit
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MainOrChildProcessExited(object sender, EventArgs e)
        {
            try
            {
                var process = (Process)sender;
                if (process == null)
                {
                    return;
                }
                var children = process.GetChildProcesses().ToArray();
                if (children.Length > 0)
                {
                    foreach (var childProcess in children)
                    {
                        childProcess.EnableRaisingEvents = true;
                        childProcess.Exited += MainOrChildProcessExited;
                    }
                    _processList.AddRange(children);
                    _processList = _processList.Where(x => x.HasExited == false).ToList();
                }
                else
                {
                    _gameStopwatch.Stop();
                    var cred = CredentialManager.GetCredentials(App.CredDb);
                    if (cred == null || cred.UserName.Length < 1)
                    {
                        return;
                    }

                    using (var db = new LiteDatabase($"{App.GetDbStringWithoutPass}'{cred.Password}'"))
                    {
                        var dbUserData = db.GetCollection <UserDataGames>(DbUserData.UserData_Games.ToString());
                        var gameEntry  = dbUserData.Query().Where(x => x.Id == _selectedGame.Id).FirstOrDefault();
                        gameEntry.LastPlayed = DateTime.UtcNow;
                        gameEntry.PlayTime   = gameEntry.PlayTime + _gameStopwatch.Elapsed;
                        LastPlayed           = $"{App.ResMan.GetString("LastPlayed")}: {TimeDateChanger.GetHumanDate(gameEntry.LastPlayed)}";
                        PlayTime             = $"{App.ResMan.GetString("PlayTime")}: {TimeDateChanger.GetHumanTime(gameEntry.PlayTime)}";
                        dbUserData.Update(gameEntry);
                        _selectedGame = gameEntry;
                    }
                    _gameStopwatch.Reset();
                    _isGameRunning       = false;
                    IsStartButtonVisible = Visibility.Visible;
                }
            }
            catch (Exception exception)
            {
                App.Logger.Error(exception, "Failed to deal with an exited NoSource process");
                SentryHelper.SendException(exception, null, SentryLevel.Warning);
                throw;
            }
        }
예제 #7
0
        private void MainOrChildProcessExited(object sender, EventArgs e)
        {
            try
            {
                var parent  = (VndbContentViewModel)Parent;
                var process = (Process)sender;
                if (process == null)
                {
                    return;
                }
                var children = process.GetChildProcesses().ToArray();
                if (children.Length > 0)
                {
                    foreach (var childProcess in children)
                    {
                        childProcess.EnableRaisingEvents = true;
                        childProcess.Exited += MainOrChildProcessExited;
                    }
                    parent.ProcessList.AddRange(children);

                    parent.ProcessList = parent.ProcessList.Where(x => x.HasExited == false).ToList();
                }
                else
                {
                    parent.GameStopwatch.Stop();
                    var cred = CredentialManager.GetCredentials(App.CredDb);
                    if (cred == null || cred.UserName.Length < 1)
                    {
                        return;
                    }

                    using (var db = new LiteDatabase($"{App.GetDbStringWithoutPass}'{cred.Password}'"))
                    {
                        var dbUserData = db.GetCollection <UserDataGames>(DbUserData.UserData_Games.ToString());

                        SentrySdk.AddBreadcrumb($"MainChildExited{dbUserData.FindAll().Count()}, VnId:{VndbContentViewModel.SelectedGame.Id}");
                        var gameEntry = dbUserData.Query().Where(x => x.Id == VndbContentViewModel.SelectedGame.Id).FirstOrDefault();
                        gameEntry.LastPlayed = DateTime.UtcNow;
                        gameEntry.PlayTime   = gameEntry.PlayTime + parent.GameStopwatch.Elapsed;
                        LastPlayed           = $"{App.ResMan.GetString("LastPlayed")}: {TimeDateChanger.GetHumanDate(gameEntry.LastPlayed)}";
                        PlayTime             = $"{App.ResMan.GetString("PlayTime")}: {TimeDateChanger.GetHumanTime(gameEntry.PlayTime)}";
                        dbUserData.Update(gameEntry);
                        VndbContentViewModel.SelectedGame = gameEntry;
                    }
                    parent.GameStopwatch.Reset();
                    parent.IsGameRunning = false;
                    IsStartButtonVisible = Visibility.Visible;
                }
            }
            catch (Win32Exception ex)
            {
                App.Logger.Warning(ex, "Failed to exit the process, W32");
            }
            catch (Exception exception)
            {
                App.Logger.Warning(exception, "Failed to deal with an exited Process");
                SentryHelper.SendException(exception, null, SentryLevel.Error);
            }
        }