Skip to content

Commit

Permalink
Merge pull request r00telement#21 from zakuciael/master
Browse files Browse the repository at this point in the history
AutoUpdater changes + code cleanup
  • Loading branch information
gabrielefilipp authored Feb 7, 2020
2 parents 87c69b1 + 8ca7e4b commit 17072f5
Show file tree
Hide file tree
Showing 45 changed files with 170 additions and 151 deletions.
37 changes: 14 additions & 23 deletions SmartHunter/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
using SmartHunter.Core;
using SmartHunter.Game;
using SmartHunter.Game.Data.ViewModels;
using SmartHunter.Game.Helpers;
using SmartHunter.Ui.Windows;
using System;
using System;
using System.IO;
using System.Reflection;
using System.Text;
using System.Windows;
using System.Xaml;
using SmartHunter.Core;
using SmartHunter.Game;
using SmartHunter.Game.Data.ViewModels;
using SmartHunter.Game.Helpers;
using SmartHunter.Ui.Windows;
using XamlReader = System.Windows.Markup.XamlReader;

namespace SmartHunter
{
Expand Down Expand Up @@ -42,28 +44,17 @@ protected override void OnStartup(StartupEventArgs e)
try
{
string[] files = Directory.GetFiles(".");
string v = ConfigHelper.Versions.Values.SmartHunter;
foreach (string file in files)
{
if (Path.GetExtension(file).Equals(".exe"))
if (Path.GetExtension(file).Equals(".exe") && file.Contains("SmartHunter_"))
{
if (file.Contains("SmartHunter_"))
{
if (!file.Contains(v))
{
File.Delete(file);
}
}
else if (file.Contains("SmartHunter"))
{
File.Delete(file); // i feel dirty for this but didn't want to do something else :P
}
File.Delete(file);
}
}
}
catch
{

}

m_Overlay = new MhwOverlay(new ConsoleWindow(), new TeamWidgetWindow(), new MonsterWidgetWindow(), new PlayerWidgetWindow());
Expand Down Expand Up @@ -105,16 +96,16 @@ void LoadSkin()
{
ResourceDictionary resourceDictionary = null;

using (var streamReader = new StreamReader(m_SkinFile.FullPathFileName, System.Text.Encoding.UTF8))
using (var streamReader = new StreamReader(m_SkinFile.FullPathFileName, Encoding.UTF8))
{
var xmlReaderSettings = new XamlXmlReaderSettings
{
LocalAssembly = Assembly.GetExecutingAssembly()
};

using (var xamlReader = new XamlXmlReader(streamReader.BaseStream, System.Windows.Markup.XamlReader.GetWpfSchemaContext(), xmlReaderSettings))
using (var xamlReader = new XamlXmlReader(streamReader.BaseStream, XamlReader.GetWpfSchemaContext(), xmlReaderSettings))
{
resourceDictionary = System.Windows.Markup.XamlReader.Load(xamlReader) as ResourceDictionary;
resourceDictionary = XamlReader.Load(xamlReader) as ResourceDictionary;
}
}

Expand Down
4 changes: 1 addition & 3 deletions SmartHunter/Core/AddressRange.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;

namespace SmartHunter.Core
namespace SmartHunter.Core
{
public class AddressRange
{
Expand Down
4 changes: 2 additions & 2 deletions SmartHunter/Core/BytePattern.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using SmartHunter.Game.Config;
using System;
using System;
using System.Collections.Generic;
using System.Globalization;
using SmartHunter.Game.Config;

namespace SmartHunter.Core
{
Expand Down
19 changes: 11 additions & 8 deletions SmartHunter/Core/Config/ConfigContainer.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System;
using System.ComponentModel;
using System.IO;
using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using ErrorEventArgs = Newtonsoft.Json.Serialization.ErrorEventArgs;

namespace SmartHunter.Core.Config
{
Expand All @@ -13,14 +16,14 @@ public class ConfigContainer<T> : FileContainer

public ConfigContainer(string fileName) : base(fileName)
{
bool isDesignInstance = System.ComponentModel.LicenseManager.UsageMode == System.ComponentModel.LicenseUsageMode.Designtime;
bool isDesignInstance = LicenseManager.UsageMode == LicenseUsageMode.Designtime;
if (!isDesignInstance)
{
Load();
}
}

public void HandleDeserializationError(object sender, Newtonsoft.Json.Serialization.ErrorEventArgs args)
public void HandleDeserializationError(object sender, ErrorEventArgs args)
{
Log.WriteException(args.ErrorContext.Error);
args.ErrorContext.Handled = true;
Expand All @@ -40,7 +43,7 @@ void Load()
string contents = null;
using (FileStream stream = File.Open(FullPathFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
using (StreamReader reader = new StreamReader(stream, System.Text.Encoding.UTF8))
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
{
contents = reader.ReadToEnd();
}
Expand All @@ -56,7 +59,7 @@ void Load()
// https://stackoverflow.com/questions/27848547/explanation-for-objectcreationhandling-using-newtonsoft-json
// This has been moved to ContractResolver to target Dictionaries specifically
// settings.ObjectCreationHandling = ObjectCreationHandling.Replace;
settings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter());
settings.Converters.Add(new StringEnumConverter());
settings.Converters.Add(new StringFloatConverter());

JsonConvert.PopulateObject(contents, Values, settings);
Expand Down Expand Up @@ -90,7 +93,7 @@ public void Save()
settings.NullValueHandling = NullValueHandling.Ignore;
settings.ContractResolver = new ContractResolver();

settings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter());
settings.Converters.Add(new StringEnumConverter());
settings.Converters.Add(new StringFloatConverter());

var jsonString = JsonConvert.SerializeObject(Values, settings);
Expand Down
6 changes: 3 additions & 3 deletions SmartHunter/Core/Config/ContractResolver.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System;
using System;
using System.Collections.Generic;
using System.Reflection;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

namespace SmartHunter.Core.Config
{
Expand Down
4 changes: 2 additions & 2 deletions SmartHunter/Core/Config/StringFloatConverter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Newtonsoft.Json;
using System;
using System;
using System.Globalization;
using Newtonsoft.Json;

namespace SmartHunter.Core.Config
{
Expand Down
2 changes: 1 addition & 1 deletion SmartHunter/Core/Data/Bindable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void NotifyPropertyChanged(string propertyName)

protected bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
{
if (object.Equals(storage, value))
if (Equals(storage, value))
{
return false;
}
Expand Down
6 changes: 4 additions & 2 deletions SmartHunter/Core/FileContainer.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.ComponentModel;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows;

Expand Down Expand Up @@ -33,7 +35,7 @@ public FileContainer(string fileName)
{
FileName = fileName;

bool isDesignInstance = System.ComponentModel.LicenseManager.UsageMode == System.ComponentModel.LicenseUsageMode.Designtime;
bool isDesignInstance = LicenseManager.UsageMode == LicenseUsageMode.Designtime;
if (!isDesignInstance)
{
WatchFile(true);
Expand Down Expand Up @@ -127,7 +129,7 @@ virtual protected void OnChanged() { }

public static string GetFullPath()
{
return Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase).Replace("file:\\", "") + "\\";
return Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase).Replace("file:\\", "") + "\\";
}

public static string GetFullPathFileName(string fileName)
Expand Down
3 changes: 2 additions & 1 deletion SmartHunter/Core/Helpers/MemoryHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace SmartHunter.Core.Helpers
{
Expand Down Expand Up @@ -256,7 +257,7 @@ public static string ReadString(Process process, ulong address, uint length)
if (nullTerminatorIndex >= 0)
{
Array.Resize(ref bytes, nullTerminatorIndex);
return System.Text.Encoding.UTF8.GetString(bytes);
return Encoding.UTF8.GetString(bytes);
}

return null;
Expand Down
4 changes: 2 additions & 2 deletions SmartHunter/Core/Helpers/Updater.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using Newtonsoft.Json.Linq;
using System.IO;
using SmartHunter.Game.Helpers;

namespace SmartHunter.Core.Helpers
Expand Down Expand Up @@ -82,7 +82,7 @@ public bool DownloadUpdates()
client.Headers["User-Agent"] = _dummyUserAgent;
if (Path.GetExtension(fileNamePath).Equals(".exe"))
{
client.DownloadFile(url, $"{fileNamePathWithNoExtension}_{hash}.exe");
client.DownloadFile(url, $"{fileNamePathWithNoExtension}_NEW.exe");
}
else
{
Expand Down
3 changes: 2 additions & 1 deletion SmartHunter/Core/Log.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.ComponentModel;
using System.IO;
using System.Security.AccessControl;

Expand All @@ -20,7 +21,7 @@ public static void WriteLine(string message)
LineReceived(null, new GenericEventArgs<string>(line));
}

bool isDesignInstance = System.ComponentModel.LicenseManager.UsageMode == System.ComponentModel.LicenseUsageMode.Designtime;
bool isDesignInstance = LicenseManager.UsageMode == LicenseUsageMode.Designtime;
if (!isDesignInstance)
{
try
Expand Down
20 changes: 10 additions & 10 deletions SmartHunter/Core/MemoryUpdater.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Reflection;
using System.Windows;
using System.Windows.Threading;
using System.Net;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.IO;
using SmartHunter.Core.Helpers;
using SmartHunter.Game.Helpers;

Expand Down Expand Up @@ -131,12 +128,15 @@ void CreateStateMachine()
() =>
{
Log.WriteLine("Restarting Application!");
string file = $".\\SmartHunter_{ConfigHelper.Versions.Values.SmartHunter}.exe";
if (File.Exists(file))
string update = ".\\SmartHunter_NEW.exe";
string exec = Assembly.GetEntryAssembly()?.Location;
if (File.Exists(update) && exec != null && File.Exists(exec))
{
Process.Start(file);
File.Move(exec, "SmartHunter_OLD.exe");
File.Move(update, "SmartHunter.exe");
Process.Start("SmartHunter.exe");
}
System.Environment.Exit(1);
Environment.Exit(1);
})
}));

Expand Down Expand Up @@ -290,7 +290,7 @@ private void Initialize(bool processExited = false)
if (processExited && ShutdownWhenProcessExits)
{
Log.WriteLine("Process exited. Shutting down.");
System.Windows.Application.Current.Shutdown();
Application.Current.Shutdown();
}
}

Expand Down
7 changes: 4 additions & 3 deletions SmartHunter/Core/Overlay.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using SmartHunter.Core.Helpers;
using SmartHunter.Core.Windows;
using System.ComponentModel;
using System.Windows;
using System.Windows.Input;
using SmartHunter.Core.Helpers;
using SmartHunter.Core.Windows;

namespace SmartHunter.Core
{
Expand Down Expand Up @@ -31,7 +32,7 @@ private void MainWindow_Loaded(object sender, RoutedEventArgs e)
UpdateWidgetsFromConfig();
}

private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
private void MainWindow_Closing(object sender, CancelEventArgs e)
{
foreach (var widgetWindow in WidgetWindows)
{
Expand Down
4 changes: 2 additions & 2 deletions SmartHunter/Core/ThreadedMemoryScan.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using SmartHunter.Core.Helpers;
using System;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using SmartHunter.Core.Helpers;

namespace SmartHunter.Core
{
Expand Down
4 changes: 2 additions & 2 deletions SmartHunter/Core/Windows/WidgetWindow.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using SmartHunter.Core.Data;
using System;
using System;
using System.Windows;
using System.Windows.Input;
using SmartHunter.Core.Data;

namespace SmartHunter.Core.Windows
{
Expand Down
2 changes: 1 addition & 1 deletion SmartHunter/Game/Config/LocalizationConfig.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using SmartHunter.Core.Config;
using System.Collections.Generic;
using SmartHunter.Core.Config;

namespace SmartHunter.Config
{
Expand Down
4 changes: 2 additions & 2 deletions SmartHunter/Game/Config/MainConfig.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using SmartHunter.Core.Config;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Windows.Input;
using SmartHunter.Core.Config;

namespace SmartHunter.Game.Config
{
Expand Down
4 changes: 2 additions & 2 deletions SmartHunter/Game/Config/MonsterWidgetConfig.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using SmartHunter.Core.Config;
using System.Text.RegularExpressions;
using System.Text.RegularExpressions;
using SmartHunter.Core.Config;

namespace SmartHunter.Game.Config
{
Expand Down
4 changes: 2 additions & 2 deletions SmartHunter/Game/Config/PlayerWidgetConfig.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using SmartHunter.Core.Config;
using System.Text.RegularExpressions;
using System.Text.RegularExpressions;
using SmartHunter.Core.Config;

namespace SmartHunter.Game.Config
{
Expand Down
6 changes: 3 additions & 3 deletions SmartHunter/Game/Data/Monster.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using System.Collections.ObjectModel;
using System.Linq;
using SmartHunter.Core;
using SmartHunter.Core.Data;
using SmartHunter.Game.Config;
using SmartHunter.Game.Helpers;
using System;
using System.Collections.ObjectModel;
using System.Linq;

namespace SmartHunter.Game.Data
{
Expand Down
Loading

0 comments on commit 17072f5

Please sign in to comment.