From d6720feb96afa86e2ab778ca1d499693fa722a51 Mon Sep 17 00:00:00 2001 From: lwYeo Date: Thu, 18 Oct 2018 21:46:46 +0800 Subject: [PATCH] Fixed settings not read after update+ clean up code --- Installer/Product.wxs | 2 +- InstallerHelper/CustomAction.cs | 5 ++++- SoliditySHA3MinerUI/AboutWindow.xaml.cs | 7 +++--- SoliditySHA3MinerUI/Helper/FileSystem.cs | 2 +- SoliditySHA3MinerUI/Helper/Processor.cs | 8 ++++++- SoliditySHA3MinerUI/MainWindow.xaml.cs | 27 ++++++++++++++++++++++-- 6 files changed, 41 insertions(+), 10 deletions(-) diff --git a/Installer/Product.wxs b/Installer/Product.wxs index 616126a..0d098c8 100644 --- a/Installer/Product.wxs +++ b/Installer/Product.wxs @@ -27,7 +27,7 @@ - + Assembly.GetExecutingAssembly().GetCustomAttribute().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) diff --git a/SoliditySHA3MinerUI/AboutWindow.xaml.cs b/SoliditySHA3MinerUI/AboutWindow.xaml.cs index 80a71b0..5ee6e7f 100644 --- a/SoliditySHA3MinerUI/AboutWindow.xaml.cs +++ b/SoliditySHA3MinerUI/AboutWindow.xaml.cs @@ -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); } } } \ No newline at end of file diff --git a/SoliditySHA3MinerUI/Helper/FileSystem.cs b/SoliditySHA3MinerUI/Helper/FileSystem.cs index af09cb5..494012b 100644 --- a/SoliditySHA3MinerUI/Helper/FileSystem.cs +++ b/SoliditySHA3MinerUI/Helper/FileSystem.cs @@ -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")); diff --git a/SoliditySHA3MinerUI/Helper/Processor.cs b/SoliditySHA3MinerUI/Helper/Processor.cs index c37b681..24bf7d1 100644 --- a/SoliditySHA3MinerUI/Helper/Processor.cs +++ b/SoliditySHA3MinerUI/Helper/Processor.cs @@ -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().Product; + + public static string CompanyName => Assembly.GetExecutingAssembly().GetCustomAttribute().Company; + + public static string GetCopyright => Assembly.GetExecutingAssembly().GetCustomAttribute().Copyright; public static Version GetUIVersion => Assembly.GetExecutingAssembly().GetName().Version; + public static Version MinimumDotnetCoreVersion => new Version("2.1.0"); + public static Version GetUIVersionCompat { get diff --git a/SoliditySHA3MinerUI/MainWindow.xaml.cs b/SoliditySHA3MinerUI/MainWindow.xaml.cs index 2132b38..1b1891d 100644 --- a/SoliditySHA3MinerUI/MainWindow.xaml.cs +++ b/SoliditySHA3MinerUI/MainWindow.xaml.cs @@ -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; @@ -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); @@ -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)