Skip to content

Commit

Permalink
Changes for v0.8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
rembound committed Aug 28, 2016
1 parent 317e798 commit a929ec1
Show file tree
Hide file tree
Showing 7 changed files with 824 additions and 724 deletions.
8 changes: 8 additions & 0 deletions ArenaHelper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
<Reference Include="Emgu.Util">
<HintPath>..\..\..\..\CSharp\EmguCV3.0.0.2157\bin\Emgu.Util.dll</HintPath>
</Reference>
<Reference Include="HearthMirror">
<HintPath>..\..\..\..\..\..\Software\Games\Hearthstone Deck Tracker\HearthMirror.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Hearthstone Deck Tracker">
<HintPath>..\..\..\..\..\..\Software\Games\Hearthstone Deck Tracker\Hearthstone Deck Tracker.exe</HintPath>
<Private>False</Private>
Expand All @@ -52,6 +56,7 @@
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.IO.Compression.FileSystem" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Windows.Interactivity">
<HintPath>packages\MahApps.Metro.1.1.2.0\lib\net45\System.Windows.Interactivity.dll</HintPath>
Expand All @@ -69,6 +74,7 @@
<Compile Include="ArenaWindow.xaml.cs">
<DependentUpon>ArenaWindow.xaml</DependentUpon>
</Compile>
<Compile Include="AutoUpdater.cs" />
<Compile Include="Controls\AdviceOverlay.xaml.cs">
<DependentUpon>AdviceOverlay.xaml</DependentUpon>
</Compile>
Expand All @@ -85,6 +91,8 @@
<Compile Include="Controls\ValueOverlay.xaml.cs">
<DependentUpon>ValueOverlay.xaml</DependentUpon>
</Compile>
<Compile Include="Debug.cs" />
<Compile Include="Detection.cs" />
<Compile Include="Plugin.cs" />
<Compile Include="Plugins.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
4 changes: 2 additions & 2 deletions ArenaWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@
<!-- Update -->
<controls:Flyout x:Name="FlyoutUpdate" Header="Update available!" CloseButtonVisibility="Collapsed" Position="Left" Width="400">
<StackPanel Margin="5">
<TextBlock Margin="10,5,10,15" FontWeight="SemiBold" FontSize="13" TextWrapping="Wrap">
<TextBlock x:Name="UpdateText" Margin="10,5,10,15" FontWeight="SemiBold" FontSize="13" TextWrapping="Wrap">
<Run Text="Press &quot;download&quot; to automatically download and install the new update. This will restart Hearthstone Deck Tracker." />
</TextBlock>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<StackPanel x:Name="UpdateButtons" Orientation="Horizontal" HorizontalAlignment="Center">
<Button Name="UpdateDownload" Content="download" Width="70" Margin="0,0,0,0" Height="30" Style="{DynamicResource AccentedSquareButtonStyle}" Click="UpdateDownload_Click"/>
<Button Name="UpdateWebsite" Content="website" Margin="10,0,0,0" Width="70" Height="30" Style="{DynamicResource SquareButtonStyle}" Click="UpdateWebsite_Click"/>
<Button Name="UpdateClose" Content="close" Width="70" Margin="10,0,0,0" Height="30" Style="{DynamicResource SquareButtonStyle}" Click="UpdateClose_Click"/>
Expand Down
106 changes: 106 additions & 0 deletions AutoUpdater.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Net;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using Hearthstone_Deck_Tracker;
using Hearthstone_Deck_Tracker.Utility.Logging;

namespace ArenaHelper
{
class AutoUpdater
{
private static string TempDir = Path.Combine(Config.AppDataPath, "ArenaHelperTemp");
private static string TempPluginDir = Path.Combine(Config.AppDataPath, "ArenaHelperTemp", "ArenaHelper");
private static string TargetPluginDir = Path.Combine(Config.AppDataPath, "Plugins", "ArenaHelper");

public const string userAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)";

public static async Task<bool> Update(string url)
{
bool status = true;
try
{
// Get filename of url
string filename = "update.zip";
Uri uri = new Uri(url);
if (uri.IsFile)
{
filename = System.IO.Path.GetFileName(uri.LocalPath);
}
string filepath = Path.Combine(TempDir, filename);

// Make sure temp directory exists
Log.Info("Creating temporary directory");
if (Directory.Exists(TempDir))
Directory.Delete(TempDir, true);
Directory.CreateDirectory(TempDir);

// Download the file
using (var wc = new WebClient())
{
wc.Headers.Add("user-agent", userAgent);

var lockobj = new object();
Log.Info("Downloading latest version of Arena Helper... ");
await wc.DownloadFileTaskAsync(url, filepath);
}

// Extract file
Log.Info("Extracting files...");
ZipFile.ExtractToDirectory(filepath, TempDir);

// Copy files
CopyFiles(TempDir, TempPluginDir, TargetPluginDir);
}
catch
{
status = false;
}
finally
{
try
{
// Delete temp directory
if (Directory.Exists(TempDir))
Directory.Delete(TempDir, true);

Log.Info("Update installed successfully!");
}
catch
{
Log.Info("Could not delete temporary directory");
}
}
return status;
}

private static void CopyFiles(string dir, string newpath, string targetpath)
{
Log.Info("CopyFiles dir: " + dir);
Log.Info("CopyFiles newpath: " + newpath);
Log.Info("CopyFiles targetpath: " + targetpath);
foreach (var subdir in Directory.GetDirectories(dir))
{
var newdir = subdir.Replace(newpath, targetpath);
if (!Directory.Exists(newdir))
Directory.CreateDirectory(newdir);

foreach (var file in Directory.GetFiles(subdir))
{
// Write file
var newfilepath = file.Replace(newpath, targetpath);
Log.Info("Writing " + newfilepath);
File.Copy(file, newfilepath, true);
}

// Recurse into subdir
CopyFiles(subdir, newpath, targetpath);
}
}
}
}
40 changes: 40 additions & 0 deletions Debug.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ArenaHelper
{
public static class Debug
{
public static Controls.DebugTextBlock debugtext = null;
public static List<System.Windows.Controls.Image> debugimages = null;

public static void SetTextControl(Controls.DebugTextBlock control)
{
debugtext = control;
}

public static void SetImageControls(List<System.Windows.Controls.Image> controls)
{
debugimages = controls;
}

public static void Log(string msg)
{
if (debugtext != null)
{
debugtext.Text = msg;
}
}

public static void AppendLog(string msg)
{
if (debugtext != null)
{
debugtext.Text += msg;
}
}
}
}
Loading

0 comments on commit a929ec1

Please sign in to comment.