From cc13728457c60c7f30ca17d6bd0b41179a707b84 Mon Sep 17 00:00:00 2001 From: chuongmep <31106432+chuongmep@users.noreply.github.com> Date: Tue, 6 Sep 2022 00:02:32 +0800 Subject: [PATCH] Improve view version --- AddInManager/App.cs | 8 ++-- AddInManager/Model/DefaultSetting.cs | 4 ++ AddInManager/Model/VersionChecker.cs | 48 +++++++++++++++++++++++ AddInManager/View/FrmAddInManager.xaml.cs | 1 + 4 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 AddInManager/Model/VersionChecker.cs diff --git a/AddInManager/App.cs b/AddInManager/App.cs index 7cf4bba..a268f4c 100644 --- a/AddInManager/App.cs +++ b/AddInManager/App.cs @@ -1,7 +1,9 @@ -using Autodesk.Revit.UI; +using System.IO; +using Autodesk.Revit.UI; using RevitAddinManager.Command; using RevitAddinManager.View; using System.Reflection; +using System.Windows; using RevitAddinManager.Model; using RevitAddinManager.View.Control; using RevitAddinManager.ViewModel; @@ -17,12 +19,12 @@ public class App : IExternalApplication public static int ThemId { get; set; } = -1; public static DockablePaneId PaneId => new DockablePaneId(new Guid("942D8578-7F25-4DC3-8BD8-585C1DBD3614")); public static string PaneName => "Debug/Trace Output"; + public Result OnStartup(UIControlledApplication application) { CreateRibbonPanel(application); application.ControlledApplication.DocumentClosed += DocumentClosed; - //EventWatcher eventWatcher = new EventWatcher(application); - + DefaultSetting.Version += VersionChecker.CurrentVersion; DockPanelProvider = new FrmDockablePanel() { DataContext = new DockableViewModel(application) }; if (!DockablePane.PaneIsRegistered(PaneId)) { diff --git a/AddInManager/Model/DefaultSetting.cs b/AddInManager/Model/DefaultSetting.cs index 57a71bd..a28d6c9 100644 --- a/AddInManager/Model/DefaultSetting.cs +++ b/AddInManager/Model/DefaultSetting.cs @@ -7,6 +7,10 @@ namespace RevitAddinManager.Model; /// public static class DefaultSetting { + public static string Application = "RevitAddinManager"; + public static string Version = " "; + public static string NewVersion = ""; + public static bool IsNewVersion = false; public static string AppName = "Revit Add-in Manager"; public static string FileName = "ExternalTool"; public static string FormatExAddin = ".addin"; diff --git a/AddInManager/Model/VersionChecker.cs b/AddInManager/Model/VersionChecker.cs new file mode 100644 index 0000000..48fa338 --- /dev/null +++ b/AddInManager/Model/VersionChecker.cs @@ -0,0 +1,48 @@ +using Microsoft.Win32; + +namespace RevitAddinManager.Model; + +public static class VersionChecker +{ + /// + /// Return Current Version Installed In Computer + /// + public static string CurrentVersion + { + get + { + string displayName; + string registryKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"; + RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(registryKey); + if (key != null) + { + foreach (RegistryKey subkey in key.GetSubKeyNames().Select(keyName => key.OpenSubKey(keyName))) + { + displayName = subkey.GetValue("DisplayName") as string; + if (displayName != null && displayName.Contains(DefaultSetting.Application)) + { + return subkey.GetValue("DisplayVersion") as string; + } + } + key.Close(); + } + + registryKey = @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"; + key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(registryKey); + if (key != null) + { + foreach (RegistryKey subkey in key.GetSubKeyNames().Select(keyName => key.OpenSubKey(keyName))) + { + displayName = subkey.GetValue("DisplayName") as string; + if (displayName != null && displayName.Contains(DefaultSetting.Application)) + { + return subkey.GetValue("DisplayVersion") as string; + } + } + key.Close(); + } + return string.Empty; + } + + } +} \ No newline at end of file diff --git a/AddInManager/View/FrmAddInManager.xaml.cs b/AddInManager/View/FrmAddInManager.xaml.cs index 11ea98a..5f1665f 100644 --- a/AddInManager/View/FrmAddInManager.xaml.cs +++ b/AddInManager/View/FrmAddInManager.xaml.cs @@ -19,6 +19,7 @@ public FrmAddInManager(AddInManagerViewModel vm) viewModel = vm; App.FrmAddInManager = this; ThemManager.ChangeThem(true); + Title += DefaultSetting.Version; } private void TbxDescription_OnLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)