Exemplo n.º 1
0
        /// <summary>
        /// Change the view to the selected NoSource game page
        /// </summary>
        /// <param name="selectedGame"></param>
        public void NavigateToNoSource(UserDataGames selectedGame)
        {
            var vm = this._noSourceFactory();

            vm.SetSelectedGame(selectedGame);
            this.Delegate?.NavigateTo(vm);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Change the view to the selected Vndb game page
        /// </summary>
        /// <param name="selectedGame"></param>
        public void NavigateVndbHost(UserDataGames selectedGame)
        {
            var vm = this._vndbHostFactory();

            vm.SetSelectedGame(selectedGame);
            this.Delegate?.NavigateTo(vm);
        }
Exemplo n.º 3
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;
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Set the selected game
 /// </summary>
 /// <param name="game"></param>
 internal void SetSelectedGame(UserDataGames game)
 {
     _selectedGame = game;
 }
Exemplo n.º 5
0
 internal void SetSelectedGame(UserDataGames selectedGame)
 {
     SelectedGame = selectedGame;
 }
Exemplo n.º 6
0
 /// <summary>
 /// Sets when the currently selected game should be
 /// </summary>
 /// <param name="game"></param>
 internal void SetSelectedGame(UserDataGames game)
 {
     SelectedGame = game;
     VnId         = SelectedGame.GameId;
 }
Exemplo n.º 7
0
 /// <summary>
 /// Closes the Content Host
 /// <see cref="CloseClick"/>
 /// </summary>
 public void CloseClick()
 {
     _navigationController.NavigateToMainGrid();
     SelectedGame = new UserDataGames();
 }
Exemplo n.º 8
0
        /// <summary>
        /// Checks data from import table, then updates the import db
        /// <see cref="ImportDataAsync"/>
        /// </summary>
        /// <returns></returns>
        public async Task ImportDataAsync()
        {
            try
            {
                var entryCount  = UserDataGamesCollection.Count;
                var goodEntries = new List <UserDataGames>();

                if (entryCount < 1)
                {
                    return;
                }
                for (int i = 0; i < entryCount; i++)
                {
                    var entry = UserDataGamesCollection.First();
                    entry.ClearAllErrors();
                    var result = await _validator.ValidateAsync(entry);

                    if (result.Errors.Count > 0)
                    {
                        var error = result.Errors.First();
                        entry.SetError(error.PropertyName, error.ErrorMessage);
                        _windowManager.ShowMessageBox(App.ResMan.GetString("ValidationFailedRecheck"), App.ResMan.GetString("ValidationFailed"));
                        return;
                    }


                    var goodEntry = new UserDataGames()
                    {
                        Index      = entry.Index, Categories = entry.Categories, Title = entry.Title,
                        SourceType = entry.SourceType, IconPath = entry.IconPath,
                        GameId     = entry.GameId, Arguments = entry.Arguments, CoverPath = entry.CoverPath,
                        ExePath    = entry.ExePath, ExeType = entry.ExeType, GameName = entry.GameName, Id = entry.Id,
                        LastPlayed = entry.LastPlayed, PlayTime = entry.PlayTime
                    };
                    goodEntries.Add(goodEntry);



                    UserDataGamesCollection.RemoveAt(0);
                    UserDataGamesCollection.Refresh();
                }
                var cred = CredentialManager.GetCredentials(App.CredDb);
                if (cred == null || cred.UserName.Length < 1)
                {
                    return;
                }
                var dbString = $"Filename={Path.Combine(App.ConfigDirPath, @"database\Import.db")};Password={App.ImportExportDbKey}";
                using (var db = new LiteDatabase(dbString))
                {
                    var userGames = db.GetCollection <UserDataGames>(DbUserData.UserData_Games.ToString());
                    userGames.DeleteAll();
                    userGames.InsertBulk(goodEntries);
                    db.Rebuild(new RebuildOptions {
                        Password = cred.Password
                    });
                }

                File.Delete(Path.Combine(App.ConfigDirPath, App.DbPath));
                File.Move(Path.Combine(App.ConfigDirPath, @"database\Import.db"), Path.Combine(App.ConfigDirPath, App.DbPath));

                if (File.Exists(@$ "{App.AssetDirPath}\Images.zip"))
                {
                    ZipFile.ExtractToDirectory(@$ "{App.AssetDirPath}\Images.zip", @$ "{App.AssetDirPath}\sources");
                    File.Delete(@$ "{App.AssetDirPath}\Images.zip");
                }

                if (File.Exists(@$ "{App.AssetDirPath}\Import.db"))
                {
                    File.Delete(@$ "{App.AssetDirPath}\Import.db");
                }


                _windowManager.ShowMessageBox(App.ResMan.GetString("UserDataImported"), App.ResMan.GetString("ImportComplete"));
                RequestClose();
            }
            catch (Exception ex)
            {
                App.Logger.Error(ex, "Failed to import data");
                SentryHelper.SendException(ex, null, SentryLevel.Error);
                throw;
            }
        }