DisplayMagician/HeliosDisplayManagement/UIForms/SteamGamesForm.cs
temacdonald a9bb295d1f Renamed app to HeliosPlus namespace and more
Renamed app to HeliosPlus namespace so that the updated
changes don't interfere with HeliosDisplayManagement if
that is also installed. The fact that I've changed so much of
the app means that my changes would be unlikely to be
accepted by Soroush, so I'm best to release this work in a
similar way to other projects like Notepad++, by keeping
the same root name, and adding a plus.
    I've also changed the Shortcut form to put all the games
in a single list to reduce the number of clicks a user has to
do in order for them to create a shortcut. I have begun to
prepare the form so that it will support multiple game
libraries, but now I am at a point that I need to fix the Steam
and Uplay game detection mechanisms so that they report
the correct information for the lv_games list view.
2020-04-23 20:16:16 +12:00

83 lines
2.2 KiB
C#

using System;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using HeliosPlus.Steam;
namespace HeliosPlus.UIForms
{
public partial class SteamGamesForm : Form
{
public SteamGamesForm()
{
InitializeComponent();
}
public SteamGame SteamGame { get; private set; }
private void lv_games_DoubleClick(object sender, EventArgs e)
{
if (btn_ok.Enabled)
{
btn_ok.PerformClick();
}
}
private void lv_games_SelectedIndexChanged(object sender, EventArgs e)
{
if (lv_games.SelectedItems.Count > 0)
{
SteamGame = lv_games.SelectedItems[0].Tag as SteamGame;
}
else
{
SteamGame = null;
}
btn_ok.Enabled = SteamGame != null;
}
private async void SteamGamesForm_Load(object sender, EventArgs e)
{
foreach (
var game in
SteamGame.GetAllOwnedGames().OrderByDescending(game => game.IsInstalled).ThenBy(game => game.Name))
{
var iconAddress = await game.GetIcon();
if (!string.IsNullOrWhiteSpace(iconAddress))
{
try
{
using (var fileReader = File.OpenRead(iconAddress))
{
var icon = new Icon(fileReader, il_games.ImageSize);
il_games.Images.Add(icon);
}
}
catch
{
il_games.Images.Add(Properties.Resources.SteamIcon);
}
}
else
{
il_games.Images.Add(Properties.Resources.SteamIcon);
}
if (!Visible)
{
return;
}
lv_games.Items.Add(new ListViewItem
{
Text = game.Name,
Tag = game,
ImageIndex = il_games.Images.Count - 1
});
}
}
}
}