Exemplo n.º 1
0
 /// <summary>
 /// Removes the selected row from the dataTable
 /// <see cref="RemoveRow"/>
 /// </summary>
 /// <param name="row">Column number from the dataTable</param>
 public void RemoveRow(int row)
 {
     try
     {
         UserDataGamesCollection.RemoveAt(row);
         UserDataGamesCollection.Refresh();
     }
     catch (Exception e)
     {
         App.Logger.Warning(e, "Failed to remove row from import tool");
     }
 }
Exemplo n.º 2
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;
            }
        }