Skip to content

Commit

Permalink
Fixed settings not read after update+ clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
lwYeo committed Oct 18, 2018
1 parent 843461d commit d6720fe
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Installer/Product.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<WixVariable Id="WixUILicenseRtf"
Value="License.rtf" />

<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed. Setup will now exit." />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />

<Upgrade Id="$(var._UpgradeCode)">
<UpgradeVersion OnlyDetect="yes"
Expand Down
5 changes: 4 additions & 1 deletion InstallerHelper/CustomAction.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using Microsoft.Deployment.WindowsInstaller;

namespace InstallerHelper
{
public class CustomActions
{
private static string CompanyName => Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyCompanyAttribute>().Company;
private static DirectoryInfo LocalAppParentDir => new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData));
public static DirectoryInfo[] LocalAppDirectories => new DirectoryInfo(Path.Combine(LocalAppParentDir.FullName, "lwyeo@github")).GetDirectories("SoliditySHA3MinerUI*");

public static DirectoryInfo[] LocalAppDirectories => new DirectoryInfo(Path.Combine(LocalAppParentDir.FullName, CompanyName)).GetDirectories("SoliditySHA3MinerUI*");

[CustomAction]
public static ActionResult DeleteLocalAppDir(Session session)
Expand Down
7 changes: 3 additions & 4 deletions SoliditySHA3MinerUI/AboutWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ public AboutWindow(AppTheme theme, Accent accent)
Height *= scaleSize;
Width *= scaleSize;

var assembly = Assembly.GetExecutingAssembly();
var assemblyVersion = assembly.GetName().Version;
var copyright = (assembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), true) as AssemblyCopyrightAttribute[])[0].Copyright;
txbDescription.Text = string.Format(txbDescription.Text, assemblyVersion.Major, assemblyVersion.Minor, assemblyVersion.Build, copyright);
var version = Helper.Processor.GetUIVersion;
var copyright = Helper.Processor.GetCopyright;
txbDescription.Text = string.Format(txbDescription.Text, version.Major, version.Minor, version.Build, copyright);
}
}
}
2 changes: 1 addition & 1 deletion SoliditySHA3MinerUI/Helper/FileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace SoliditySHA3MinerUI.Helper
public static class FileSystem
{
private static DirectoryInfo LocalAppParentDir => new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData));
public static DirectoryInfo LocalAppDirectory => new DirectoryInfo(Path.Combine(LocalAppParentDir.FullName, "lwyeo@github", "SoliditySHA3MinerUI"));
public static DirectoryInfo LocalAppDirectory => new DirectoryInfo(Path.Combine(LocalAppParentDir.FullName, Processor.CompanyName, Processor.ProductName));
public static DirectoryInfo AppDirectory => Directory.GetParent(Assembly.GetExecutingAssembly().Location);

public static DirectoryInfo DownloadDirectory => new DirectoryInfo(Path.Combine(LocalAppDirectory.FullName, "Downloads"));
Expand Down
8 changes: 7 additions & 1 deletion SoliditySHA3MinerUI/Helper/Processor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@ namespace SoliditySHA3MinerUI.Helper
{
public static class Processor
{
public static Version MinimumDotnetCoreVersion => new Version("2.1.3");
public static string ProductName => Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyProductAttribute>().Product;

public static string CompanyName => Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyCompanyAttribute>().Company;

public static string GetCopyright => Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyCopyrightAttribute>().Copyright;

public static Version GetUIVersion => Assembly.GetExecutingAssembly().GetName().Version;

public static Version MinimumDotnetCoreVersion => new Version("2.1.0");

public static Version GetUIVersionCompat
{
get
Expand Down
27 changes: 25 additions & 2 deletions SoliditySHA3MinerUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ public MainWindow()
CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.InvariantCulture;
Language = System.Windows.Markup.XmlLanguage.GetLanguage(CultureInfo.InvariantCulture.Name);

CheckUserConfigFile();

MinerProcessor = new API.MinerProcessor(this);
MinerProcessor.OnResponse += MinerProcessor_OnResponse;
MinerProcessor.OnRequestSettings += MinerProcessor_OnRequestSettings;
Expand Down Expand Up @@ -508,9 +510,9 @@ private void _minerInstance_OnLogUpdated(string updatedLog, string newLog, int r

var newParagraph = new Paragraph();
newParagraph.Inlines.Add(newLog);
newParagraph.Foreground = newLog.StartsWith("[ERROR]")
newParagraph.Foreground = (newLog.IndexOf("[ERROR]") > -1)
? Brushes.Red
: newLog.StartsWith("[WARN]")
: (newLog.IndexOf("[WARN]") > -1)
? Brushes.Yellow
: (Brush)FindResource(SystemColors.ControlTextBrushKey);

Expand Down Expand Up @@ -948,6 +950,27 @@ private async Task StopMiner()

#region Settings

private void CheckUserConfigFile()
{
var configFile = Helper.FileSystem.LocalAppDirectory.
Parent.
GetFiles("user.config", SearchOption.AllDirectories).
FirstOrDefault();

if (configFile != null && new Version(configFile.Directory.Name) < Helper.Processor.GetUIVersion)
{
try
{
var currentPath = new DirectoryInfo(System.IO.Path.Combine(configFile.Directory.Parent.FullName,
Helper.Processor.GetUIVersion.ToString()));
configFile.Directory.MoveTo(currentPath.FullName);

Properties.Settings.Default.Reload();
}
catch { }
}
}

private async Task SaveSettings()
{
if (_isSettingsChanged)
Expand Down

0 comments on commit d6720fe

Please sign in to comment.