Skip to content

Commit

Permalink
Added about window and supports multi-steam installs
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkite committed Oct 28, 2013
1 parent 6b11b6a commit 26a493c
Show file tree
Hide file tree
Showing 8 changed files with 181 additions and 10 deletions.
12 changes: 12 additions & 0 deletions Terrafirma/AboutWin.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Window x:Class="Terrafirma.AboutWin"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="AboutWin" Height="201.493" Width="268.657" ResizeMode="NoResize">
<Grid>
<Button Content="Close" HorizontalAlignment="Left" Margin="176,140,0,0" VerticalAlignment="Top" Width="75" IsDefault="True" Click="Button_Click"/>
<Label x:Name="Version" Content="Terrafirma" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="241" FontWeight="Bold" FontFamily="Segoe UI Black"/>
<Label x:Name="Copyright" Content="Copyright" HorizontalAlignment="Left" Margin="10,36,0,0" VerticalAlignment="Top" Width="241" FontStretch="Condensed" FontStyle="Italic" FontSize="10"/>
<TextBlock x:Name="Description" HorizontalAlignment="Left" Margin="10,72,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Height="63" Width="241"/>

</Grid>
</Window>
43 changes: 43 additions & 0 deletions Terrafirma/AboutWin.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Terrafirma
{
/// <summary>
/// Interaction logic for AboutWin.xaml
/// </summary>
public partial class AboutWin : Window
{
public AboutWin()
{
InitializeComponent();

Assembly app = Assembly.GetExecutingAssembly();
AssemblyTitleAttribute title = (AssemblyTitleAttribute)app.GetCustomAttributes(typeof(AssemblyTitleAttribute), false)[0];
AssemblyCopyrightAttribute copy = (AssemblyCopyrightAttribute)app.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false)[0];
AssemblyDescriptionAttribute desc = (AssemblyDescriptionAttribute)app.GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false)[0];
Version version = app.GetName().Version;

Title = String.Format("About {0}", title.Title);
Version.Content = String.Format("{0} Version {1}", title.Title, version.ToString());
Copyright.Content = copy.Copyright.ToString();
Description.Text = desc.Description;
}

private void Button_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}
6 changes: 6 additions & 0 deletions Terrafirma/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
<MenuItem Header="NPCs" IsEnabled="False" Name="NPCs" />
<MenuItem Command="w:MapCommands.FindItem" />
</MenuItem>
<MenuItem Header="_Help">
<MenuItem Command="w:MapCommands.About" />
</MenuItem>
</Menu>
<ToolBarPanel DockPanel.Dock="Top">
<ToolBar>
Expand Down Expand Up @@ -135,5 +138,8 @@
<CommandBinding Command="w:MapCommands.FindItem"
Executed="FindItem_Executed"
CanExecute="MapLoaded" />
<CommandBinding Command="w:MapCommands.About"
Executed="About_Executed"
CanExecute="About_CanExecute" />
</Window.CommandBindings>
</Window>
10 changes: 10 additions & 0 deletions Terrafirma/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2775,6 +2775,16 @@ private void MapLoaded(object sender, CanExecuteRoutedEventArgs e)
e.CanExecute = loaded;
}

private void About_Executed(object sender, ExecutedRoutedEventArgs e)
{
AboutWin about=new AboutWin();
about.ShowDialog();
}
private void About_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = true;
}

private void JumpToDungeon_Executed(object sender, ExecutedRoutedEventArgs e)
{
curX = dungeonX;
Expand Down
2 changes: 2 additions & 0 deletions Terrafirma/MapCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,7 @@ static class MapCommands
"Jump to Dungeon", "JumpToDungeon", typeof(MapCommands));
public static readonly RoutedUICommand FindItem = new RoutedUICommand(
"Find Item", "FindItem", typeof(MapCommands));
public static readonly RoutedUICommand About = new RoutedUICommand(
"About Terrafirma...", "About", typeof(MapCommands));
}
}
91 changes: 91 additions & 0 deletions Terrafirma/SteamConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Terrafirma
{
class SteamConfig
{
class Element
{
public Dictionary<string, Element> Children { get; set; }
public string Name { get; set; }
public string Value;

private static Regex keyRegex = new Regex("\"[^\"]*\"");

public Element(Queue<string> lines)
{
Children = new Dictionary<string, Element>();
string line = lines.Dequeue();

MatchCollection matches = keyRegex.Matches(line);
if (matches.Count == 0) //corrupt
return;
Name = matches[0].Value.Trim('\"');
if (matches.Count > 1) //value is a string
Value = matches[1].Value.Trim('\"').Replace(@"\\","\\");
line = lines.Peek();
if (line.Contains('{'))
{
lines.Dequeue();
while (true)
{
line = lines.Peek();
if (line.Contains('}'))
{
lines.Dequeue();
return;
}
Element e = new Element(lines);
Children.Add(e.Name, e);
}
}
}
public string Find(string path)
{
string[] kv = path.Split(new char[] { '/' }, 2);
if (kv.Length == 1)
return Children[kv[0]].Value;
return Children[kv[0]].Find(kv[1]);
}
}
Element root = null;
public SteamConfig()
{
Microsoft.Win32.RegistryKey key;
key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\\Valve\\Steam");
if (key != null)
{
string path = key.GetValue("SteamPath") as string;
path = Path.Combine(path, "config");
path = Path.Combine(path, "config.vdf");
if (File.Exists(path))
parse(path);
}
}
public bool Ready { get { return root != null; } }

public string Get(string path)
{
return root.Find(path);
}

private void parse(string path)
{
TextReader read = new StreamReader(path);
Queue<string> lines = new Queue<string>();
String line = read.ReadLine();
while (line != null)
{
lines.Enqueue(line);
line = read.ReadLine();
}
root = new Element(lines);
}

}
}
8 changes: 8 additions & 0 deletions Terrafirma/Terrafirma.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="AboutWin.xaml.cs">
<DependentUpon>AboutWin.xaml</DependentUpon>
</Compile>
<Compile Include="ConnectToServer.xaml.cs">
<DependentUpon>ConnectToServer.xaml</DependentUpon>
</Compile>
Expand All @@ -112,10 +115,15 @@
<Compile Include="SignPopup.xaml.cs">
<DependentUpon>SignPopup.xaml</DependentUpon>
</Compile>
<Compile Include="SteamConfig.cs" />
<Compile Include="Textures.cs" />
<Compile Include="WorldStats.xaml.cs">
<DependentUpon>WorldStats.xaml</DependentUpon>
</Compile>
<Page Include="AboutWin.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="ChestPopup.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
19 changes: 9 additions & 10 deletions Terrafirma/Textures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,22 +264,21 @@ public Textures()
actuators = new Dictionary<int, Texture>();
cacti = new Dictionary<int, Texture>();

// find steam
string path="";
Microsoft.Win32.RegistryKey key;
key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\\Valve\\Steam");
if (key!=null)
path = key.GetValue("SteamPath") as string;
// find terraria install
SteamConfig steam = new SteamConfig();
string path=null;
if (steam.Ready)
path = steam.Get("Software/Valve/Steam/apps/105600/InstallDir");

//no steam key, let's try the default
if (path.Equals("") || !Directory.Exists(path))
if (path==null || !Directory.Exists(path))
{
path = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86);
path = Path.Combine(path, "Steam");
path = Path.Combine(path, "steamapps");
path = Path.Combine(path, "common");
path = Path.Combine(path, "terraria");
}
path = Path.Combine(path, "steamapps");
path = Path.Combine(path, "common");
path = Path.Combine(path, "terraria");
path = Path.Combine(path, "Content");
path = Path.Combine(path, "Images");
if (Directory.Exists(path))
Expand Down

0 comments on commit 26a493c

Please sign in to comment.