From 5a0b3bba25df753e541933e84f637ab2d26e1358 Mon Sep 17 00:00:00 2001 From: Colin Date: Sun, 25 Aug 2019 15:09:08 +0100 Subject: [PATCH] Adding version number to the settings dialog --- Meade.net/AssemblyInfo.cs | 90 ++++++++++++++++++++++++++++ Meade.net/Meade.net.csproj | 1 + Meade.net/Properties/AssemblyInfo.cs | 2 +- Meade.net/SetupDialogForm.cs | 7 ++- Meade.net/SetupDialogForm.resx | 2 +- 5 files changed, 98 insertions(+), 4 deletions(-) create mode 100644 Meade.net/AssemblyInfo.cs diff --git a/Meade.net/AssemblyInfo.cs b/Meade.net/AssemblyInfo.cs new file mode 100644 index 0000000..04b5aaf --- /dev/null +++ b/Meade.net/AssemblyInfo.cs @@ -0,0 +1,90 @@ +using System; +using System.Reflection; +using System.Runtime.InteropServices; +using System.Resources; + +namespace ASCOM.Meade.net +{ + public class AssemblyInfo + { + // The assembly information values. + public string Title = "", Description = "", Company = "", + Product = "", Copyright = "", Trademark = "", + AssemblyVersion = "", FileVersion = "", Guid = "", + NeutralLanguage = ""; + public bool IsComVisible = false; + + // Return a particular assembly attribute value. + public static T GetAssemblyAttribute(Assembly assembly) + where T : Attribute + { + // Get attributes of this type. + object[] attributes = + assembly.GetCustomAttributes(typeof(T), true); + + // If we didn't get anything, return null. + if ((attributes == null) || (attributes.Length == 0)) + return null; + + // Convert the first attribute value into + // the desired type and return it. + return (T)attributes[0]; + } + + // Constructors. + public AssemblyInfo() + : this(Assembly.GetExecutingAssembly()) + { + } + + public AssemblyInfo(Assembly assembly) + { + // Get values from the assembly. + AssemblyTitleAttribute titleAttr = + GetAssemblyAttribute(assembly); + if (titleAttr != null) Title = titleAttr.Title; + + AssemblyDescriptionAttribute assemblyAttr = + GetAssemblyAttribute(assembly); + if (assemblyAttr != null) Description = + assemblyAttr.Description; + + AssemblyCompanyAttribute companyAttr = + GetAssemblyAttribute(assembly); + if (companyAttr != null) Company = companyAttr.Company; + + AssemblyProductAttribute productAttr = + GetAssemblyAttribute(assembly); + if (productAttr != null) Product = productAttr.Product; + + AssemblyCopyrightAttribute copyrightAttr = + GetAssemblyAttribute(assembly); + if (copyrightAttr != null) Copyright = copyrightAttr.Copyright; + + AssemblyTrademarkAttribute trademarkAttr = + GetAssemblyAttribute(assembly); + if (trademarkAttr != null) Trademark = trademarkAttr.Trademark; + + var version = assembly.GetName().Version; + AssemblyVersion = $"{version.Major}.{version.Minor}.{version.Build}.{version.Revision}"; + + + AssemblyFileVersionAttribute fileVersionAttr = + GetAssemblyAttribute(assembly); + if (fileVersionAttr != null) FileVersion = + fileVersionAttr.Version; + + GuidAttribute guidAttr = GetAssemblyAttribute(assembly); + if (guidAttr != null) Guid = guidAttr.Value; + + NeutralResourcesLanguageAttribute languageAttr = + GetAssemblyAttribute(assembly); + if (languageAttr != null) NeutralLanguage = + languageAttr.CultureName; + + ComVisibleAttribute comAttr = + GetAssemblyAttribute(assembly); + if (comAttr != null) IsComVisible = comAttr.Value; + } + } +} diff --git a/Meade.net/Meade.net.csproj b/Meade.net/Meade.net.csproj index d8277ba..e1f0cda 100644 --- a/Meade.net/Meade.net.csproj +++ b/Meade.net/Meade.net.csproj @@ -121,6 +121,7 @@ + diff --git a/Meade.net/Properties/AssemblyInfo.cs b/Meade.net/Properties/AssemblyInfo.cs index c121a1e..a2c5fb1 100644 --- a/Meade.net/Properties/AssemblyInfo.cs +++ b/Meade.net/Properties/AssemblyInfo.cs @@ -8,7 +8,7 @@ using System.Runtime.InteropServices; [assembly: AssemblyDescription("ASCOM multi-interface server for Meade.net")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("cjdawson.com")] -[assembly: AssemblyProduct("")] +[assembly: AssemblyProduct("ASCOM Meade Generic")] [assembly: AssemblyCopyright("Copyright © 2019 cjdawson.com")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] diff --git a/Meade.net/SetupDialogForm.cs b/Meade.net/SetupDialogForm.cs index 645ca81..52bd2d5 100644 --- a/Meade.net/SetupDialogForm.cs +++ b/Meade.net/SetupDialogForm.cs @@ -1,8 +1,7 @@ using System; using System.ComponentModel; -using System.Diagnostics; +using System.Reflection; using System.Runtime.InteropServices; -using System.Text; using System.Windows.Forms; namespace ASCOM.Meade.net @@ -13,6 +12,10 @@ namespace ASCOM.Meade.net public SetupDialogForm() { InitializeComponent(); + + var assemblyInfo = new AssemblyInfo(); + + Text = $"{assemblyInfo.Product} Settings ({assemblyInfo.AssemblyVersion})"; } private void cmdCancel_Click(object sender, EventArgs e) // Cancel button event handler diff --git a/Meade.net/SetupDialogForm.resx b/Meade.net/SetupDialogForm.resx index fd6059a..69e65d4 100644 --- a/Meade.net/SetupDialogForm.resx +++ b/Meade.net/SetupDialogForm.resx @@ -178,7 +178,7 @@ 12, 9 - 123, 31 + 274, 31 2