Adding version number to the settings dialog

This commit is contained in:
2019-08-25 15:09:08 +01:00
parent 3eddc52c6a
commit 5a0b3bba25
5 changed files with 98 additions and 4 deletions
+90
View File
@@ -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<T>(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<AssemblyTitleAttribute>(assembly);
if (titleAttr != null) Title = titleAttr.Title;
AssemblyDescriptionAttribute assemblyAttr =
GetAssemblyAttribute<AssemblyDescriptionAttribute>(assembly);
if (assemblyAttr != null) Description =
assemblyAttr.Description;
AssemblyCompanyAttribute companyAttr =
GetAssemblyAttribute<AssemblyCompanyAttribute>(assembly);
if (companyAttr != null) Company = companyAttr.Company;
AssemblyProductAttribute productAttr =
GetAssemblyAttribute<AssemblyProductAttribute>(assembly);
if (productAttr != null) Product = productAttr.Product;
AssemblyCopyrightAttribute copyrightAttr =
GetAssemblyAttribute<AssemblyCopyrightAttribute>(assembly);
if (copyrightAttr != null) Copyright = copyrightAttr.Copyright;
AssemblyTrademarkAttribute trademarkAttr =
GetAssemblyAttribute<AssemblyTrademarkAttribute>(assembly);
if (trademarkAttr != null) Trademark = trademarkAttr.Trademark;
var version = assembly.GetName().Version;
AssemblyVersion = $"{version.Major}.{version.Minor}.{version.Build}.{version.Revision}";
AssemblyFileVersionAttribute fileVersionAttr =
GetAssemblyAttribute<AssemblyFileVersionAttribute>(assembly);
if (fileVersionAttr != null) FileVersion =
fileVersionAttr.Version;
GuidAttribute guidAttr = GetAssemblyAttribute<GuidAttribute>(assembly);
if (guidAttr != null) Guid = guidAttr.Value;
NeutralResourcesLanguageAttribute languageAttr =
GetAssemblyAttribute<NeutralResourcesLanguageAttribute>(assembly);
if (languageAttr != null) NeutralLanguage =
languageAttr.CultureName;
ComVisibleAttribute comAttr =
GetAssemblyAttribute<ComVisibleAttribute>(assembly);
if (comAttr != null) IsComVisible = comAttr.Value;
}
}
}
+1
View File
@@ -121,6 +121,7 @@
<Reference Include="System.Windows.Forms" />
</ItemGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.cs" />
<Compile Include="ClassFactory.cs" />
<Compile Include="ConnectionInfo.cs" />
<Compile Include="frmMain.cs">
+1 -1
View File
@@ -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("")]
+5 -2
View File
@@ -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
+1 -1
View File
@@ -178,7 +178,7 @@
<value>12, 9</value>
</data>
<data name="label1.Size" type="System.Drawing.Size, System.Drawing">
<value>123, 31</value>
<value>274, 31</value>
</data>
<data name="label1.TabIndex" type="System.Int32, mscorlib">
<value>2</value>