private void ButtonImportSteamCategories_Click(object sender, RoutedEventArgs e) { if (PlayniteMessageBox.Show("This will overwrite current categories on all Steam games. Do you want to continue?", "Import Categories?", MessageBoxButton.YesNo, MessageBoxImage.Warning) != MessageBoxResult.Yes) { return; } if (ComboSteamCatImport.SelectedValue == null) { PlayniteMessageBox.Show("Cannot import categories, account for import is not selected.", "Import Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } try { var userId = (ulong)ComboSteamCatImport.SelectedValue; var steamLib = new SteamLibrary(); var games = steamLib.GetCategorizedGames(userId); if (GameDatabase.Instance.GamesCollection == null) { throw new Exception("Playnite database is not opened."); } GameDatabase.Instance.ImportCategories(games); PlayniteMessageBox.Show("Import finished.", "Import Successful"); } catch (Exception exc) { logger.Error(exc, "Failed to import Steam categories."); PlayniteMessageBox.Show("Failed to import Steam categories: " + exc.Message, "Import Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
public SteamLibraryViewModel(SteamLibrary model) { _model = model; UpdateDriveInfo(); model.Games.CollectionChanged += Games_CollectionChanged; Refresh(); }
public LibraryView(SteamData steamData, SteamLibrary library) { InitializeComponent(); SteamData = steamData; Library = library; SteamData.ChangesDiscarded += SteamData_ChangesDiscarded; SteamData.AppTargetLibraryChanged += SteamApp_TargetLibraryChanged; SteamData.AppMoved += SteamApp_Moved; // Init labels. UpdateHeader(); // Init grid gridViewItems = new BindingList <GridViewItem>(); dataGrid.DataSource = gridViewItems; dataGrid.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGrid.Columns[0].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft; dataGrid.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; dataGrid.Columns[1].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; UpdateAppList(); }
public static Configuration Load() { if (!File.Exists(GamesFile)) { SaveDefaultGameData(); } var gameData = LoadGameData(); var settingsData = LoadSettingsData(); var library = SteamLibrary.Locate(); var games = SteamGameInfo.LocateGames(gameData, library); if (games.Count == 0) { throw new SteamException("No supported steam games found on this system."); } var users = SteamUserInfo.LocateUsers(library); if (users.Count == 0) { throw new SteamException("No steam users found on this system."); } var settings = ApplicationSettings.FromKeyValue(settingsData, games, users); return(new Configuration(games, users, settings)); }
private LibraryView CreateLibraryView(SteamLibrary library) { LibraryView libraryView = new LibraryView(SteamData, library); libraryView.Parent = layout; libraryView.Dock = DockStyle.Fill; libraryView.Margin = new Padding(3, 3, 0, 3); return(libraryView); }
public void GetSteamUsersTest() { var steamLib = new SteamLibrary(); var users = steamLib.GetSteamUsers(); CollectionAssert.IsNotEmpty(users); var user = users.First(); Assert.IsFalse(string.IsNullOrEmpty(user.AccountName)); Assert.IsFalse(string.IsNullOrEmpty(user.PersonaName)); }
public void GetCategorizedGamesTest() { var steamLib = new SteamLibrary(); var user = steamLib.GetSteamUsers().First(a => a.Recent); var cats = steamLib.GetCategorizedGames(user.Id); var game = cats.First(); CollectionAssert.IsNotEmpty(cats); CollectionAssert.IsNotEmpty(game.Categories); Assert.IsFalse(string.IsNullOrEmpty(game.ProviderId)); Assert.AreEqual(game.Provider, Provider.Steam); }
public void GetInstalledGamesTest() { var steamLib = new SteamLibrary(); var games = steamLib.GetInstalledGames(); Assert.AreNotEqual(0, games.Count); CollectionAssert.AllItemsAreUnique(games); foreach (var game in games) { Assert.IsFalse(string.IsNullOrEmpty(game.Name)); Assert.IsFalse(string.IsNullOrEmpty(game.ProviderId)); Assert.IsFalse(string.IsNullOrEmpty(game.InstallDirectory)); Assert.IsTrue(Directory.Exists(game.InstallDirectory)); Assert.IsNotNull(game.PlayTask); Assert.IsTrue(game.PlayTask.Type == GameTaskType.URL); } }
public void UpdateGameWithMetadataMissingMetadataTest() { var steamLib = new SteamLibrary(); var game = new Game() { Provider = Provider.Steam, ProviderId = "704580" }; Assert.DoesNotThrow(() => steamLib.UpdateGameWithMetadata(game, new SteamSettings())); game = new Game() { Provider = Provider.Steam, ProviderId = "347350" }; Assert.DoesNotThrow(() => steamLib.UpdateGameWithMetadata(game, new SteamSettings())); }
public void GetLibraryFoldersFormatTest() { var format1 = @" ""LibraryFolders"" { ""TimeNextStatsReport"" ""1623148229"" ""ContentStatsID"" ""-4352270281465506412"" ""1"" ""D:\\Steam1"" }"; var format2 = @" ""libraryfolders"" { ""contentstatsid"" ""-4352270281465506412"" ""1"" { ""path"" ""D:\\Steam2"" ""label"" """" ""mounted"" ""1"" ""contentid"" ""5925747603517172"" } }"; using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(format1))) { var kv = new KeyValue(); kv.ReadAsText(stream); var dirs = SteamLibrary.GetLibraryFolders(kv); Assert.AreEqual(@"D:\Steam1", dirs[0]); } using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(format2))) { var kv = new KeyValue(); kv.ReadAsText(stream); var dirs = SteamLibrary.GetLibraryFolders(kv); Assert.AreEqual(@"D:\Steam2", dirs[0]); } }
public void DownloadGameMetadataTest() { var steamLib = new SteamLibrary(); // Existing store var existing = steamLib.DownloadGameMetadata(107410, false); Assert.IsNotNull(existing.ProductDetails); Assert.IsNotNull(existing.StoreDetails); Assert.IsNotNull(existing.Icon.Content); Assert.IsNotNull(existing.Image.Content); Assert.IsNotNull(existing.BackgroundImage); // NonExisting store var nonExisting = steamLib.DownloadGameMetadata(201280, true); Assert.IsNotNull(nonExisting.ProductDetails); Assert.IsNull(nonExisting.StoreDetails); Assert.IsNotNull(nonExisting.Icon.Content); Assert.IsNotNull(nonExisting.Image.Content); Assert.IsNull(nonExisting.BackgroundImage); }
private async void LoadGames(bool downloadLibUpdates) { if (GamesLoaderHandler.ProgressTask != null && GamesLoaderHandler.ProgressTask.Status == TaskStatus.Running) { GamesLoaderHandler.CancelToken.Cancel(); await GamesLoaderHandler.ProgressTask; } GameAdditionAllowed = false; try { if (string.IsNullOrEmpty(Config.DatabasePath)) { return; } var database = GameDatabase.Instance; try { database.OpenDatabase(Config.DatabasePath); } catch (Exception exc) { GameAdditionAllowed = false; PlayniteMessageBox.Show("Failed to open library database: " + exc.Message, "Database Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } LiteDBImageToImageConverter.ClearCache(); GamesView?.Dispose(); GamesView = new GamesCollectionView(database, Config); BindingOperations.EnableCollectionSynchronization(GamesView.Items, gamesLock); try { GamesEditor.Instance.UpdateJumpList(); } catch (Exception exc) { logger.Error(exc, "Failed to set update JumpList data: "); } ListGamesView.ItemsSource = GamesView.CollectionView; ImagesGamesView.ItemsSource = GamesView.CollectionView; GridGamesView.ItemsSource = GamesView.CollectionView; if (downloadLibUpdates) { GamesLoaderHandler.CancelToken = new CancellationTokenSource(); GamesLoaderHandler.ProgressTask = Task.Factory.StartNew(() => { ProgressControl.Visible = Visibility.Visible; ProgressControl.ProgressValue = 0; ProgressControl.Text = "Importing installed games..."; try { if (Config.UplaySettings.IntegrationEnabled) { database.UpdateInstalledGames(Provider.Uplay); NotificationsWin.RemoveMessage(NotificationCodes.UplayInstalledImportError); } } catch (Exception e) when(!PlayniteEnvironment.ThrowAllErrors) { logger.Error(e, "Failed to import installed Uplay games."); NotificationsWin.AddMessage(new NotificationMessage(NotificationCodes.UplayInstalledImportError, "Failed to import installed Uplay games:" + e.Message, NotificationType.Error, () => { })); } try { if (Config.GOGSettings.IntegrationEnabled) { database.UpdateInstalledGames(Provider.GOG); NotificationsWin.RemoveMessage(NotificationCodes.GOGLInstalledImportError); } } catch (Exception e) when(!PlayniteEnvironment.ThrowAllErrors) { logger.Error(e, "Failed to import installed GOG games."); NotificationsWin.AddMessage(new NotificationMessage(NotificationCodes.GOGLInstalledImportError, "Failed to import installed GOG games:" + e.Message, NotificationType.Error, () => { })); } try { if (Config.SteamSettings.IntegrationEnabled) { database.UpdateInstalledGames(Provider.Steam); NotificationsWin.RemoveMessage(NotificationCodes.SteamInstalledImportError); } } catch (Exception e) when(!PlayniteEnvironment.ThrowAllErrors) { logger.Error(e, "Failed to import installed Steam games."); NotificationsWin.AddMessage(new NotificationMessage(NotificationCodes.SteamInstalledImportError, "Failed to import installed Steam games: " + e.Message, NotificationType.Error, () => { })); } try { if (Config.OriginSettings.IntegrationEnabled) { database.UpdateInstalledGames(Provider.Origin); NotificationsWin.RemoveMessage(NotificationCodes.OriginInstalledImportError); } } catch (Exception e) when(!PlayniteEnvironment.ThrowAllErrors) { logger.Error(e, "Failed to import installed Origin games."); NotificationsWin.AddMessage(new NotificationMessage(NotificationCodes.OriginInstalledImportError, "Failed to import installed Origin games: " + e.Message, NotificationType.Error, () => { })); } ProgressControl.Text = "Downloading GOG library updates..."; try { if (Config.GOGSettings.IntegrationEnabled && Config.GOGSettings.LibraryDownloadEnabled) { database.UpdateOwnedGames(Provider.GOG); NotificationsWin.RemoveMessage(NotificationCodes.GOGLibDownloadError); } } catch (Exception e) when(!PlayniteEnvironment.ThrowAllErrors) { logger.Error(e, "Failed to download GOG library updates."); NotificationsWin.AddMessage(new NotificationMessage(NotificationCodes.GOGLibDownloadError, "Failed to download GOG library updates: " + e.Message, NotificationType.Error, () => { })); } ProgressControl.Text = "Downloading Steam library updates..."; try { if (Config.SteamSettings.IntegrationEnabled && Config.SteamSettings.LibraryDownloadEnabled) { if (config.SteamSettings.IdSource == SteamIdSource.Name) { database.SteamUserName = Config.SteamSettings.AccountName; } else { database.SteamUserName = Config.SteamSettings.AccountId.ToString(); } database.UpdateOwnedGames(Provider.Steam); NotificationsWin.RemoveMessage(NotificationCodes.SteamLibDownloadError); } } catch (Exception e) when(!PlayniteEnvironment.ThrowAllErrors) { logger.Error(e, "Failed to download Steam library updates."); NotificationsWin.AddMessage(new NotificationMessage(NotificationCodes.SteamLibDownloadError, "Failed to download Steam library updates: " + e.Message, NotificationType.Error, () => { })); } if (importSteamCatWizard && importSteamCatWizardId != 0) { ProgressControl.Text = "Importing Steam categories..."; try { var steamLib = new SteamLibrary(); GameDatabase.Instance.ImportCategories(steamLib.GetCategorizedGames(importSteamCatWizardId)); } catch (Exception e) when(!PlayniteEnvironment.ThrowAllErrors) { logger.Error(e, "Failed to import Steam categories."); NotificationsWin.AddMessage(new NotificationMessage(NotificationCodes.SteamLibDownloadError, "Failed to import Steam categories: " + e.Message, NotificationType.Error, () => { })); } } ProgressControl.Text = "Downloading Origin library updates..."; try { if (Config.OriginSettings.IntegrationEnabled && Config.OriginSettings.LibraryDownloadEnabled) { database.UpdateOwnedGames(Provider.Origin); NotificationsWin.RemoveMessage(NotificationCodes.OriginLibDownloadError); } } catch (Exception e) when(!PlayniteEnvironment.ThrowAllErrors) { logger.Error(e, "Failed to download Origin library updates."); NotificationsWin.AddMessage(new NotificationMessage(NotificationCodes.OriginLibDownloadError, "Failed to download Origin library updates: " + e.Message, NotificationType.Error, () => { })); } ProgressControl.Text = "Downloading images and game details..."; ProgressControl.ProgressMin = 0; var gamesCount = 0; gamesCount = database.GamesCollection.Count(a => a.Provider != Provider.Custom && !a.IsProviderDataUpdated); if (gamesCount > 0) { gamesCount -= 1; } ProgressControl.ProgressMax = gamesCount; var tasks = new List <Task> { // Steam metada download thread Task.Factory.StartNew(() => { DownloadMetadata(database, Provider.Steam, ProgressControl, GamesLoaderHandler.CancelToken.Token); }), // Origin metada download thread Task.Factory.StartNew(() => { DownloadMetadata(database, Provider.Origin, ProgressControl, GamesLoaderHandler.CancelToken.Token); }), // GOG metada download thread Task.Factory.StartNew(() => { DownloadMetadata(database, Provider.GOG, ProgressControl, GamesLoaderHandler.CancelToken.Token); }), // Uplay metada download thread Task.Factory.StartNew(() => { DownloadMetadata(database, Provider.Uplay, ProgressControl, GamesLoaderHandler.CancelToken.Token); }) }; Task.WaitAll(tasks.ToArray()); ProgressControl.Text = "Library update finished"; Thread.Sleep(1500); ProgressControl.Visible = Visibility.Collapsed; }); await GamesLoaderHandler.ProgressTask; } } finally { GamesEditor.Instance.OnPropertyChanged("LastGames"); GameAdditionAllowed = true; } }
public void GetAppStateTest() { var steamLib = new SteamLibrary(); var state = steamLib.GetAppState(12140); }