diff --git a/BHoM_UI/Components/Engine/GetInfo.cs b/BHoM_UI/Components/Engine/GetInfo.cs index f82d15f..3d8f756 100644 --- a/BHoM_UI/Components/Engine/GetInfo.cs +++ b/BHoM_UI/Components/Engine/GetInfo.cs @@ -75,37 +75,26 @@ public GetInfoCaller() : base(typeof(GetInfoCaller).GetMethod("GetInfo")) { } [MultiOutput(9, "wiki", "Need more details on how to use the BHoM or how to contribute? This is the place to go.")] public static Output, List, List, List, string, string, string> GetInfo() { - string description = "This is the Buildings and Habitats object Model. A collaborative computational development project for the built environment.\n\n" - + "It is crafted as transdisciplinary, software-agnostic and office/region/country independent, and therefore would be nothing without our active community and wide range of contributors.\n\n" - + "To find out more about our collective experiment go to https://bhom.xyz"; - - string version = Engine.Base.Query.BHoMVersion(); - string installer = ""; //TODO: assign properly when that information is made available by the installer - - List libraries = Engine.Base.Query.BHoMAssemblyList() - .Select(x => x.GetName().Name) - .OrderBy(x => x).ToList(); + var info = BH.Engine.UI.Query.Information(); List types = Engine.Base.Query.BHoMTypeList(); List methods = Engine.Base.Query.BHoMMethodList(); List adapters = Engine.Base.Query.AdapterTypeList().ToList(); - string website = "https://bhom.xyz/"; string github = "https://github.com/BHoM"; - string wiki = "https://github.com/BHoM/documentation/wiki"; return Engine.Base.Create.Output ( - description, - version, - installer, - libraries, + info.Description, + info.Version, + info.InstallDate, + info.Assemblies, types, methods, adapters, - website, + info.BHoMWebsite, github, - wiki + info.WikiLink ); } diff --git a/UI_Engine/Query/Information.cs b/UI_Engine/Query/Information.cs new file mode 100644 index 0000000..fd3f9c4 --- /dev/null +++ b/UI_Engine/Query/Information.cs @@ -0,0 +1,109 @@ +/* + * This file is part of the Buildings and Habitats object Model (BHoM) + * Copyright (c) 2015 - 2023, the respective contributors. All rights reserved. + * + * Each contributor holds copyright over their respective contributions. + * The project versioning (Git) records all such contribution source information. + * + * + * The BHoM is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3.0 of the License, or + * (at your option) any later version. + * + * The BHoM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + */ + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Security.Policy; +using System.Text; + +using BH.oM.UI; + +using Microsoft.Win32; +using System.ComponentModel; +using BH.oM.Base.Attributes; + +namespace BH.Engine.UI +{ + public static partial class Query + { + [Description("Obtain the installed version information of BHoM.")] + [Output("info", "The information about BHoM currently installed on this machine.")] + public static BHoMInformation Information() + { + var keyLocation = "SOFTWARE\\WOW6432NODE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"; + var subKeys = Registry.LocalMachine.OpenSubKey(keyLocation); + + var subKeyNames = subKeys.GetSubKeyNames(); + + RegistryKey bhomKey = null; + foreach (var s in subKeyNames) + { + try + { + var keyName = $"{keyLocation}\\{s}"; + subKeys = Registry.LocalMachine.OpenSubKey(keyName); + + var a = subKeys.GetValue("DisplayName"); + if (a != null && a.ToString() == "Buildings and Habitats object Model") + { + bhomKey = subKeys; + break; + } + } + catch (Exception e) + { + + } + } + + string version = ""; + string installDate = ""; + try + { + version = bhomKey.GetValue("DisplayVersion").ToString(); + } + catch { } + + try + { + installDate = bhomKey.GetValue("InstallDate").ToString(); + } + catch { } + + if (string.IsNullOrEmpty(version)) + version = BH.Engine.Base.Query.BHoMVersion(); + + if (!string.IsNullOrEmpty(installDate)) + { + DateTime installDateTime; + var installDateTimeFine = DateTime.TryParseExact(installDate, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None, out installDateTime); + installDate = installDateTime.ToString("dd/MM/yyyy"); + } + else + installDate = "This appears to be a version of BHoM installed using an old installer."; + + return new BHoMInformation() + { + Version = version, + InstallDate = installDate, + BHoMWebsite = "https://bhom.xyz", + WikiLink = "https://bhom.xyz/documentation", + Assemblies = BH.Engine.Base.Query.BHoMAssemblyList().Select(x => x.GetName().Name).OrderBy(x => x).ToList(), + Description = "This is the Buildings and Habitats object Model. A collaborative computational development project for the built environment.\n\n" + + "It is crafted as transdisciplinary, software-agnostic and office/region/country independent, and therefore would be nothing without our active community and wide range of contributors.\n\n" + + "To find out more about our collective experiment go to https://bhom.xyz", + }; + } + } +} diff --git a/UI_Engine/UI_Engine.csproj b/UI_Engine/UI_Engine.csproj index cf7993f..fe0d9fe 100644 --- a/UI_Engine/UI_Engine.csproj +++ b/UI_Engine/UI_Engine.csproj @@ -93,6 +93,7 @@ + diff --git a/UI_oM/BHoMInformation.cs b/UI_oM/BHoMInformation.cs new file mode 100644 index 0000000..7ee295f --- /dev/null +++ b/UI_oM/BHoMInformation.cs @@ -0,0 +1,41 @@ +/* + * This file is part of the Buildings and Habitats object Model (BHoM) + * Copyright (c) 2015 - 2023, the respective contributors. All rights reserved. + * + * Each contributor holds copyright over their respective contributions. + * The project versioning (Git) records all such contribution source information. + * + * + * The BHoM is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3.0 of the License, or + * (at your option) any later version. + * + * The BHoM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + */ + +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Text; +using BH.oM.Base; + +namespace BH.oM.UI +{ + [Description("Object containing information about the BHoM, queried and populated at run time to provide information to the UIs about the installed version of BHoM.")] + public class BHoMInformation : BHoMObject + { + public virtual string Version { get; set; } + public virtual string InstallDate { get; set; } + public virtual string Description { get; set; } + public virtual string BHoMWebsite { get; set; } + public virtual string WikiLink { get; set; } + public virtual List Assemblies { get; set; } + } +} diff --git a/UI_oM/UI_oM.csproj b/UI_oM/UI_oM.csproj index 9b5ba8e..12edf1a 100644 --- a/UI_oM/UI_oM.csproj +++ b/UI_oM/UI_oM.csproj @@ -51,6 +51,7 @@ +