Exemplo n.º 1
0
 /// <summary>
 /// Dialog to select a new Icon file
 /// <see cref="BrowseIcon"/>
 /// </summary>
 /// <param name="idCol">Column number from the dataTable</param>
 /// <returns></returns>
 public async Task BrowseIcon(int idCol)
 {
     try
     {
         if (idCol != -1)
         {
             var settings = new OpenFileDialogSettings
             {
                 Title            = $"{App.ResMan.GetString("BrowseForIcon")}",
                 DefaultExt       = ".exe",
                 Filter           = $"{App.ResMan.GetString("Icons")} (*.exe)|*.exe",
                 FileName         = "",
                 DereferenceLinks = true,
                 CheckPathExists  = true,
                 CheckFileExists  = true,
                 ValidateNames    = true
             };
             bool?result = _dialogService.ShowOpenFileDialog(this, settings);
             if (result == true)
             {
                 UserDataGamesCollection[idCol].IconPath = settings.FileName;
                 UserDataGamesCollection.Refresh();
                 UserDataGamesCollection[idCol].ClearAllErrors();
                 await _validator.ValidateAsync(UserDataGamesCollection[idCol]);
             }
         }
     }
     catch (Exception e)
     {
         App.Logger.Warning(e, "Failed to browse for icon");
         throw;
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Dialog to select a new Exe file
 /// <see cref="BrowseExe"/>
 /// </summary>
 /// <param name="idCol">Column number from the dataTable</param>
 /// <returns></returns>
 public async Task BrowseExe(int idCol)
 {
     if (idCol != -1)
     {
         var settings = new OpenFileDialogSettings
         {
             Title            = $"{App.ResMan.GetString("BrowseForGame")}",
             DefaultExt       = ".exe",
             Filter           = $"{App.ResMan.GetString("Applications")} (*.exe)|*.exe",
             FileName         = "",
             DereferenceLinks = true,
             CheckPathExists  = true,
             CheckFileExists  = true,
             ValidateNames    = true,
             Multiselect      = false
         };
         bool?result = _dialogService.ShowOpenFileDialog(this, settings);
         if (result == true)
         {
             UserDataGamesCollection[idCol].ExePath = settings.FileName;
             UserDataGamesCollection.Refresh();
             UserDataGamesCollection[idCol].ClearAllErrors();
             await _validator.ValidateAsync(UserDataGamesCollection[idCol]);
         }
     }
 }
Exemplo n.º 3
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.º 4
0
        /// <summary>
        /// Loads the database, then fills the table with the UserData
        /// </summary>
        /// <param name="filePath">Path to the import database file</param>
        private void LoadDatabase(string filePath)
        {
            string dbError = App.ResMan.GetString("DbError");

            try
            {
                var didExpand = ImportExportHelper.Expand(filePath);
                if (!didExpand)
                {
                    return;
                }
                var dbPath = @$ "{App.AssetDirPath}\Import.db";
                if (!File.Exists(dbPath))
                {
                    return;
                }
                using (var db = new LiteDatabase($"Filename={dbPath};Password={App.ImportExportDbKey}"))
                {
                    IEnumerable <UserDataGames> dbUserData =
                        db.GetCollection <UserDataGames>(DbUserData.UserData_Games.ToString()).FindAll().ToArray();
                    var addList = new List <UserDataGames>();
                    foreach (var item in dbUserData)
                    {
                        var result = _validator.Validate(item);
                        foreach (var error in result.Errors)
                        {
                            item.SetError(error.PropertyName, error.ErrorMessage);
                        }

                        addList.Add(item);
                    }


                    UserDataGamesCollection.AddRange(addList);
                    File.Copy(@$ "{App.AssetDirPath}\Import.db", Path.Combine(App.ConfigDirPath, @"database\Import.db"));
                }

                DatabaseName = Path.GetFileName(filePath);
            }
            catch (IOException)
            {
                var errorStr = App.ResMan.GetString("DbIsLockedProc");
                _windowManager.ShowMessageBox(errorStr, dbError, MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
            catch (Exception ex)
            {
                App.Logger.Warning(ex, "Failed to load database for import");
                SentryHelper.SendException(ex, null, SentryLevel.Error);
                _windowManager.ShowMessageBox($"{App.ResMan.GetString("ImportInvalidDb")}\n{Path.GetFileName(filePath)}",
                                              $"{App.ResMan.GetString("ImportInvalidDbTitle")}", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
        }
Exemplo n.º 5
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;
            }
        }