Skip to content
This repository has been archived by the owner on Sep 15, 2021. It is now read-only.

Commit

Permalink
Simplified code, removed old library scanning
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabisonfire committed Oct 12, 2016
1 parent f17efdf commit fcca83f
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 178 deletions.
21 changes: 9 additions & 12 deletions Game.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
using System;
using Steam.Local;
using System.IO;

namespace Steam_Game_Launcher
{
class Game : IComparable<Game>
class Game : LocalApp, IComparable<Game>
{
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);
}
}
}
2 changes: 1 addition & 1 deletion IconParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down
27 changes: 14 additions & 13 deletions LauncherWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
Expand All @@ -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
{
Expand All @@ -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;
Expand All @@ -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();
}
Expand Down Expand Up @@ -442,7 +443,7 @@ private void ClearLists()
{
io.gamesList.Clear();
io.manifestsList.Clear();
io.steamLibrariesList.Clear();
//io.steamLibrariesList.Clear();
io.iconsList.Clear();
}

Expand Down
7 changes: 1 addition & 6 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
<Grid RenderTransformOrigin="0.514,0.515">
<Button x:Name="btBrowseLibrary" Content="Add Steam library" HorizontalAlignment="Left" Margin="132,128,0,0" VerticalAlignment="Top" Width="116" Click="btBrowseLibrary_Click"/>
<ListBox x:Name="lbSteamLibraries" HorizontalAlignment="Left" Height="94" Margin="10,29,0,0" VerticalAlignment="Top" Width="344"/>
<Button x:Name="btLauncher" Content="Launch" HorizontalAlignment="Left" Margin="372,405,0,0" VerticalAlignment="Top" Width="318" Click="btLauncher_Click"/>
<Label x:Name="label" Content="Steam Libraries" HorizontalAlignment="Left" Margin="10,3,0,0" VerticalAlignment="Top" RenderTransformOrigin="-0.239,-0.018"/>
<ListBox x:Name="lbLog" HorizontalAlignment="Left" Height="132" Margin="372,254,0,0" VerticalAlignment="Top" Width="318"/>
<ListBox x:Name="lbLog" HorizontalAlignment="Left" Height="132" Margin="17,10,0,0" VerticalAlignment="Top" Width="318"/>
<GroupBox x:Name="groupBox" Header="Icon Size" HorizontalAlignment="Left" Margin="371,15,0,0" VerticalAlignment="Top" Height="71" Width="115">
<StackPanel HorizontalAlignment="Left" Height="50" VerticalAlignment="Top" Width="102" Margin="0,0,0,2">
<RadioButton x:Name="rb64" Content="64px(small)"/>
Expand Down Expand Up @@ -56,7 +53,5 @@
<Button x:Name="btAddHidden" Content="Remove Selected" HorizontalAlignment="Left" Margin="209,325,0,0" VerticalAlignment="Top" Width="145" Click="btAddHidden_Click"/>
<Label x:Name="label8" Content="Hidden Apps" HorizontalAlignment="Left" Margin="10,297,0,0" VerticalAlignment="Top"/>
<Label x:Name="lblName" Content="Make a selection" HorizontalAlignment="Left" Margin="209,362,0,0" VerticalAlignment="Top" Width="145" Height="63"/>
<Button x:Name="btRemoveLibrary" Content="Remove Selected" HorizontalAlignment="Left" Margin="253,127,0,0" VerticalAlignment="Top" Width="101" Click="btRemoveLibrary_Click"/>
<Button x:Name="btScanLibraries" Content="Scan Libraries" HorizontalAlignment="Left" Margin="10,128,0,0" VerticalAlignment="Top" Width="117" Click="btScanLibraries_Click"/>
</Grid>
</Window>
82 changes: 6 additions & 76 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using System.IO;
using System.Text;
using System.Collections.Generic;
using Steam.Local;

namespace Steam_Game_Launcher
{
Expand All @@ -36,14 +35,13 @@ public partial class MainWindow : Window

const string SETTINGS_FILE = "userconfig.ini";
public const string APPNAME = "SteamGameLauncher";
const string APPVER = "0.4 BETA";
const string APPVER = "0.5 BETA";

public MainWindow()
{
// Set the working directory to the current EXE Path
Environment.CurrentDirectory = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);
InitializeComponent();

}

// First run check for config file.
Expand All @@ -52,8 +50,7 @@ public static void FirstRunCheck()
if (!File.Exists(SETTINGS_FILE) || string.IsNullOrEmpty(File.ReadAllText(SETTINGS_FILE)))
{
try
{

{
File.Copy(SETTINGS_FILE +".default", SETTINGS_FILE);
io.LogToFile("Could not find userconfig.ini, used default.");
}
Expand All @@ -64,22 +61,7 @@ public static void FirstRunCheck()
Environment.Exit(1);
}
}
}

// Browse for steam library folders.
private void btBrowseLibrary_Click(object sender, RoutedEventArgs e)
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
fbd.Description = "Select your \"steamapps\" folder.";
if(fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
io.steamLibrariesList.Add(fbd.SelectedPath + "\\");
lbSteamLibraries.Items.Add(fbd.SelectedPath + "\\");
io.manifestsList.Clear();
io.gamesList.Clear();
ParseGames();
}
}
}

// Show Launcher
private void ShowLauncher(bool saveSettings = true)
Expand All @@ -101,19 +83,6 @@ private void btLauncher_Click(object sender, RoutedEventArgs e)

private void LoadSettings()
{
// Load libraries from config
Log("Loading steam libraries...");
string libs = io.GetSetting("Main", "libraries");
if (!string.IsNullOrEmpty(libs))
{
string[] libraries = libs.Split(',');
foreach (string s in libraries)
{
lbSteamLibraries.Items.Add(s);
io.steamLibrariesList.Add(s);
}
}
Log("Loaded " + io.steamLibrariesList.Count.ToString() + " libraries.");

// Icon Size
string size = io.GetSetting("Main", "icon_size");
Expand Down Expand Up @@ -239,7 +208,6 @@ private void LoadSettings()
// Write all settings to ini file (user)
private void SaveSettings()
{
io.WriteSetting("Main", "libraries", string.Join(",",io.steamLibrariesList.ToArray()));
io.WriteSetting("Main", "icon_size", iconSize);
io.WriteSetting("Main", "panel_margin", string.Join(",", panelMargin));
io.WriteSetting("Main", "icon_spacing", string.Join(",", iconSpacing));
Expand Down Expand Up @@ -452,7 +420,7 @@ private void MakeGameVisible(string id)
{
foreach (Game game in io.gamesList)
{
if(game.ID == id)
if(game.ID.ToString() == id)
{
game.Visible = true;
break;
Expand All @@ -465,9 +433,9 @@ private string GetGameName(string id)
{
foreach(Game game in io.gamesList)
{
if(game.ID == id)
if(game.ID.ToString() == id)
{
return game.name;
return game.Name;
}
}
return "Not found.";
Expand All @@ -482,44 +450,6 @@ private void lbHidden_SelectionChanged(object sender, SelectionChangedEventArgs
}
}

private void btRemoveLibrary_Click(object sender, RoutedEventArgs e)
{
int index = lbSteamLibraries.SelectedIndex;
if (index > -1)
{
io.steamLibrariesList.Remove(lbSteamLibraries.Items[index].ToString());
lbSteamLibraries.Items.RemoveAt(index);
}
}

// Scan libraries automatically
private void btScanLibraries_Click(object sender, RoutedEventArgs e)
{
try
{
foreach (string lib in Libraries.Folders)
{
string path = Path.GetFullPath(lib);
DirectoryInfo dinfo = new DirectoryInfo(path);
path = UppercaseFirst(GetProperDirectoryCapitalization(dinfo));
// Check if not already in the list.
if (lbSteamLibraries.Items.IndexOf(path) == -1)
{
lbSteamLibraries.Items.Add(path);
io.steamLibrariesList.Add(path);
}
}
io.manifestsList.Clear();
io.gamesList.Clear();
ParseGames();
}
catch(Exception ex)
{
System.Windows.MessageBox.Show("Unable to scan libraries. " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
io.LogToFile(ex.ToString());
}
}

private static string GetProperDirectoryCapitalization(DirectoryInfo dirInfo)
{
DirectoryInfo parentDirInfo = dirInfo.Parent;
Expand Down
3 changes: 0 additions & 3 deletions bin/Debug/appconfig.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[Advanced]
xpath=//*[@id="info"]/table/tbody/tr[1]/td[2]/a
regexNamePattern=(?<="name"\W*")(.*)(?=")
regexIDPattern=(?<="appid"\W*")(.*)(?=")
regexInstallPattern=(?<="installdir"\W*")(.*)(?=")
steam_cdn=https://steamcdn-a.akamaihd.net/steamcommunity/public/images/apps/
1 change: 0 additions & 1 deletion bin/Debug/userconfig.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[Main]
libraries=C:\Program Files (x86)\Steam\steamapps,D:\Steam\steamapps,E:\Steam\steamapps
icon_size=128
panel_margin=100,10,100,10
icon_spacing=40,40,40,40
Expand Down
Loading

0 comments on commit fcca83f

Please sign in to comment.