From fcca83feee77c5c154305564c27829c4e9d841c4 Mon Sep 17 00:00:00 2001 From: Gabisonfire Date: Wed, 12 Oct 2016 12:57:39 -0400 Subject: [PATCH] Simplified code, removed old library scanning --- Game.cs | 21 +++++----- IconParser.cs | 2 +- LauncherWindow.xaml.cs | 27 ++++++------- MainWindow.xaml | 7 +--- MainWindow.xaml.cs | 82 +++------------------------------------- bin/Debug/appconfig.ini | 3 -- bin/Debug/userconfig.ini | 1 - io.cs | 82 ++++++++-------------------------------- 8 files changed, 47 insertions(+), 178 deletions(-) diff --git a/Game.cs b/Game.cs index d2c8fb9..1fb0ac3 100644 --- a/Game.cs +++ b/Game.cs @@ -1,28 +1,25 @@ using System; +using Steam.Local; +using System.IO; namespace Steam_Game_Launcher { - class Game : IComparable + class Game : LocalApp, IComparable { - public string name { get; set; } - public string ID { get; set; } - public string url { get; set; } - public string install_dir { get; set; } public bool Visible { get; set; } + public string Exec { get; set; } + public string SafeName { get; set; } - - public Game(string name, string ID, string install_dir, bool Visible = true) + public Game(string manifest, bool Visible = true): base(manifest) { - this.name = name; - this.ID = ID; - this.install_dir = install_dir; - this.url = "steam://rungameid/" + ID; this.Visible = Visible; + Exec = "steam://rungameid/" + ID.ToString(); + SafeName = new DirectoryInfo(InstallDir).Name; } public int CompareTo(Game other) { - return name.CompareTo(other.name); + return Name.CompareTo(other.Name); } } } diff --git a/IconParser.cs b/IconParser.cs index 42713e8..2e30e37 100644 --- a/IconParser.cs +++ b/IconParser.cs @@ -18,7 +18,7 @@ public static string GetIconURL(string gameID) HtmlWeb web = new HtmlWeb(); HtmlDocument doc = web.Load(Url); - string xpath = io.GetSetting("Advanced", "xpath", Steam_Game_Launcher.io.configType.application); + string xpath = io.GetSetting("Advanced", "xpath", io.configType.application); string iconID = doc.DocumentNode.SelectNodes(xpath)[0].InnerText; if (string.IsNullOrEmpty(iconID)) { diff --git a/LauncherWindow.xaml.cs b/LauncherWindow.xaml.cs index 4fc5a1e..05311cf 100644 --- a/LauncherWindow.xaml.cs +++ b/LauncherWindow.xaml.cs @@ -162,7 +162,7 @@ private void GenerateIcons() foreach (Game game in io.gamesList) { - io.LogToFile("Processing " + game.name); + io.LogToFile("Processing " + game.Name); // Skip hidden games. if (!game.Visible) { continue; } // Try to get the icon @@ -189,7 +189,7 @@ private void GenerateIcons() } catch (InvalidOperationException ex) { - io.LogToFile("Error processing " + game.name + ". " + ex.ToString()); + io.LogToFile("Error processing " + game.Name + ". " + ex.ToString()); continue; } icon.Source = iconSource; @@ -216,7 +216,7 @@ private void GenerateIcons() // Create a label and stack panel TextBlock lbl = new TextBlock(); - lbl.Text = game.name; + lbl.Text = game.Name; lbl.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; lbl.TextAlignment = TextAlignment.Center; lbl.TextTrimming = TextTrimming.CharacterEllipsis; @@ -306,7 +306,7 @@ private void HideIcon(HolderImage icon) try { StackPanel panel = (StackPanel)icon.Parent; - io.hiddenList.Add(icon.game.ID); + io.hiddenList.Add(icon.game.ID.ToString()); panel.Children.RemoveRange(0, panel.Children.Count); WrapPanel mainPanel = (WrapPanel)panel.Parent; mainPanel.Children.Remove(panel); @@ -326,14 +326,14 @@ private string FindIcon(Game game) foreach (string f in io.iconsList) { string file = System.IO.Path.GetFileNameWithoutExtension(f); - string cleanedName = game.name.Replace(":", " ").Replace("?", ""); + string cleanedName = game.Name.Replace(":", " ").Replace("?", ""); // Check first with the ID - if (file == game.ID) + if (file == game.ID.ToString()) { return file; } //Second check is with the installdir name (works well with single word titles) - else if (file == game.install_dir) + else if (file == game.SafeName) { return file; } @@ -350,9 +350,9 @@ private string FindIcon(Game game) } // Last is to download the icon from Steam - if (MainWindow.downloadIcons && DownloadIcon(game) && File.Exists(ICONS_DIR + game.install_dir + ".png")) + if (MainWindow.downloadIcons && DownloadIcon(game) && File.Exists(ICONS_DIR + game.SafeName + ".png")) { - return game.install_dir; + return game.SafeName; } else { @@ -363,7 +363,7 @@ private string FindIcon(Game game) // Download icon after parsing url private bool DownloadIcon(Game game) { - string iconURL = IconParser.GetIconURL(game.ID); + string iconURL = IconParser.GetIconURL(game.ID.ToString()); if (string.IsNullOrEmpty(iconURL)) { return false; @@ -372,19 +372,20 @@ private bool DownloadIcon(Game game) { WebClient Client = new WebClient(); io.LogToFile("Downloading icon from " + iconURL); - Client.DownloadFile(iconURL, ICONS_DIR + game.install_dir + ".png"); + Client.DownloadFile(iconURL, ICONS_DIR + game.SafeName + ".png"); return true; } catch (Exception e) { io.LogToFile(e.ToString() + " GAMEID:" + game.ID); + io.LogToFile(game.SafeName); return false; } } private void LaunchGame(Game game) { - Process.Start(game.url); + Process.Start(game.Exec); WindowState = WindowState.Minimized; Hide(); } @@ -442,7 +443,7 @@ private void ClearLists() { io.gamesList.Clear(); io.manifestsList.Clear(); - io.steamLibrariesList.Clear(); + //io.steamLibrariesList.Clear(); io.iconsList.Clear(); } diff --git a/MainWindow.xaml b/MainWindow.xaml index 666bda2..be5828e 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -8,11 +8,8 @@ mc:Ignorable="d" Title="Settings" Height="475.682" Width="718.808" ResizeMode="NoResize" Initialized="fmSettings_Initialized" ShowInTaskbar="False" Background="#FFDADADA" WindowStartupLocation="CenterScreen" Closing="fmSettings_Closing" Icon="/Resources/icon.ico"> -