public void FillGameList(List <string> games) { try { foreach (string game in games) { using (GameDatabaseConnector gameDatabaseConnector = new GameDatabaseConnector()) { Database.Game gameInfo = gameDatabaseConnector.GetGameInfo(game); ListBoxItem listBoxItem = new ListBoxItem() { Content = gameInfo.Name, Foreground = Brushes.Azure, Opacity = 100 }; listBoxItem.PreviewMouseDown += (sender, args) => { MainWindow.SetGameInfo(game); _selectedGame = game; }; Listbox_TabItem_Games.Items.Add(listBoxItem); } } } catch (Exception) { } }
/// <summary> /// Fügt ein Spiel vom Browser der Datenbank hinzu. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ButtonAddGame_OnClick(object sender, RoutedEventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.ShowDialog(); if (openFileDialog.FileName.EndsWith(".exe") && ChromiumWebBrowser.Address.Contains("https://www.igdb.com/games/")) { LoginWindow.UserDatabaseConnector.AddGame(ChromiumWebBrowser.Address, openFileDialog.FileName); using (GameDatabaseConnector gameDatabaseConnector = new GameDatabaseConnector()) { if (LoginWindow.UserDatabaseConnector.OwnsGame(ChromiumWebBrowser.Address)) { MessageBox.Show( gameDatabaseConnector.GetGameInfo(ChromiumWebBrowser.Address).Name + " erfolgreich hinzugefügt!", ""); } } } }
/// <summary> /// Füllt die Informationen der Spiele aus. /// </summary> /// <param name="igdbUrl">Der Spielelink von igdb.com</param> public GameInfo(string igdbUrl) { InitializeComponent(); _igdbUrl = igdbUrl; GameDatabaseConnector gdc = new GameDatabaseConnector(); Game gameInfo = gdc.GetGameInfo(igdbUrl); ListBoxItemName.Content += gameInfo.Name; foreach (string genre in gameInfo.Genres) { ListBoxItemGenre.Content += genre + "; "; } ListBoxItemDeveloper.Content += gameInfo.Developer; Cover.Source = ImageUtils.BytesToImageSource(gameInfo.Cover); try { TimeSpan playTime = LoginWindow.UserDatabaseConnector.GetPlayTime(igdbUrl); ListBoxItemGametime.Content += $"{Math.Floor(playTime.TotalHours).ToString("00")}:{playTime.Minutes.ToString("00")}"; } catch (Exception) { ListBoxItemGametime.Content += TimeSpan.Zero.ToString(); } StartButton.Click += (sender, args) => { string execPath = LoginWindow.UserDatabaseConnector.GetExecPath(igdbUrl); ProcessStartInfo psi = new ProcessStartInfo(execPath); psi.WorkingDirectory = Path.GetDirectoryName(execPath); Process process = Process.Start(psi); process.EnableRaisingEvents = true; process.Exited += (o, eventArgs) => // Zeigt nach dem beenden des Spiels die Laufzeit an. { TimeSpan playtime = process.ExitTime - process.StartTime; MessageBox.Show(playtime.TotalSeconds.ToString(), "Programm wurde geschlossen."); LoginWindow.UserDatabaseConnector.AddPlayTime(igdbUrl, playtime); }; }; }