Skip to content

Add Information component for UI elements and update GetInfo to include full install version information #446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 7 additions & 18 deletions BHoM_UI/Components/Engine/GetInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string, string, List<string>, List<Type>, List<MethodInfo>, List<Type>, 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<string> libraries = Engine.Base.Query.BHoMAssemblyList()
.Select(x => x.GetName().Name)
.OrderBy(x => x).ToList();
var info = BH.Engine.UI.Query.Information();

List<Type> types = Engine.Base.Query.BHoMTypeList();
List<MethodInfo> methods = Engine.Base.Query.BHoMMethodList();
List<Type> 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
);
}

Expand Down
109 changes: 109 additions & 0 deletions UI_Engine/Query/Information.cs
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

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",
};
}
}
}
1 change: 1 addition & 0 deletions UI_Engine/UI_Engine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
<Compile Include="Create\ParamInfo.cs" />
<Compile Include="Objects\DocumentLoading.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Query\Information.cs" />
<Compile Include="Query\MatchWith.cs" />
<Compile Include="Query\Changes.cs" />
<Compile Include="Query\SelectionIndex.cs" />
Expand Down
41 changes: 41 additions & 0 deletions UI_oM/BHoMInformation.cs
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

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<string> Assemblies { get; set; }
}
}
1 change: 1 addition & 0 deletions UI_oM/UI_oM.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="BHoMInformation.cs" />
<Compile Include="ComponentRequest.cs" />
<Compile Include="Interfaces\IDataAccessor.cs" />
<Compile Include="PreviousNamesFragment.cs" />
Expand Down