From 176c14f2f0b125e8480ae1c02747205faf5602e7 Mon Sep 17 00:00:00 2001 From: Tristan Gerrish Date: Mon, 13 Nov 2023 09:20:48 +0000 Subject: [PATCH 1/3] Added additional Pollination version check --- .../Compute/InstallPythonEnv_LBT.cs | 6 +- .../Query/IsPollinationInstalled.cs | 78 +++++++++++++++++++ 2 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 LadybugTools_Engine/Query/IsPollinationInstalled.cs diff --git a/LadybugTools_Engine/Compute/InstallPythonEnv_LBT.cs b/LadybugTools_Engine/Compute/InstallPythonEnv_LBT.cs index c8c9292f..8f432054 100644 --- a/LadybugTools_Engine/Compute/InstallPythonEnv_LBT.cs +++ b/LadybugTools_Engine/Compute/InstallPythonEnv_LBT.cs @@ -39,9 +39,11 @@ public static PythonEnvironment InstallPythonEnv_LBT(bool run = false, bool rein { // check if referenced Python is installed string referencedExecutable = @"C:\Program Files\ladybug_tools\python\python.exe"; - if (!File.Exists(referencedExecutable)) + + // NOTE - The version number below relates to the ProductVersion field of the "C:\Program Files\ladybug_tools\uninstall.exe" file, and doesn't necessarily reflect the version of the installer/uninstaller + // Pollination 1.35.14 has an uninstaller ProductVersion of 1.38.104 + if (!Query.IsPollinationInstalled(targetPollinationVersion: "1.38.104", includeBuildNumber: false)) { - Base.Compute.RecordError($"Could not find referenced python executable at {referencedExecutable}. Please install Pollination try again."); return null; } diff --git a/LadybugTools_Engine/Query/IsPollinationInstalled.cs b/LadybugTools_Engine/Query/IsPollinationInstalled.cs new file mode 100644 index 00000000..db692425 --- /dev/null +++ b/LadybugTools_Engine/Query/IsPollinationInstalled.cs @@ -0,0 +1,78 @@ +/* + * 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 BH.oM.Base.Attributes; +using BH.oM.LadybugTools; +using System.Linq; +using System.Collections.Generic; +using System.ComponentModel; +using BH.oM.Python; +using System.IO; +using System; +using System.Diagnostics; + +namespace BH.Engine.LadybugTools +{ + public static partial class Query + { + [Description("Return True if Pollination is installed to the currently supported version.")] + [Input("targetPollinationVersion", "The target Pollination build BHoM currently supports.")] + [Input("includeBuildNumber", "If true, the build number will be included in the comparison.")] + [Output("bool", "True if Pollination is installed to the currently supported version.")] + public static bool IsPollinationInstalled(string targetPollinationVersion, bool includeBuildNumber) + { + // check if referenced Python is installed + string referencedExecutable = @"C:\Program Files\ladybug_tools\python\python.exe"; + if (!File.Exists(referencedExecutable)) + { + Base.Compute.RecordError($"Could not find referenced python executable at {referencedExecutable}. Please install Pollination version {targetPollinationVersion} and try again."); + return false; + } + + // obtain version of pollination installed + string referencedUninstaller = @"C:\Program Files\ladybug_tools\uninstall.exe"; + FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(referencedUninstaller); + if (includeBuildNumber) + { + if (versionInfo.ProductVersion != targetPollinationVersion) + { + Base.Compute.RecordError($"Polination version installed ({versionInfo.ProductVersion}) is not the same as the version required for this code to function correctly ({targetPollinationVersion})."); + return false; + } + } + + // check that version matches the target version + int major = int.Parse(targetPollinationVersion.Split('.')[0]); + int minor = int.Parse(targetPollinationVersion.Split('.')[1]); + if (versionInfo.ProductMajorPart != major || versionInfo.ProductMinorPart != minor) + { + if (versionInfo.ProductVersion != targetPollinationVersion) + { + Base.Compute.RecordError($"Polination version installed ({versionInfo.ProductVersion}) is not the same as the version required for this code to function correctly ({targetPollinationVersion})."); + return false; + } + } + + return true; + } + } +} From 33147950bdf531e682682b0391188268e4fb6a2e Mon Sep 17 00:00:00 2001 From: Tristan Gerrish <10939984+tg359@users.noreply.github.com> Date: Mon, 13 Nov 2023 09:25:16 +0000 Subject: [PATCH 2/3] Update IsPollinationInstalled.cs spelling fix --- LadybugTools_Engine/Query/IsPollinationInstalled.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LadybugTools_Engine/Query/IsPollinationInstalled.cs b/LadybugTools_Engine/Query/IsPollinationInstalled.cs index db692425..4edb0f2d 100644 --- a/LadybugTools_Engine/Query/IsPollinationInstalled.cs +++ b/LadybugTools_Engine/Query/IsPollinationInstalled.cs @@ -67,7 +67,7 @@ public static bool IsPollinationInstalled(string targetPollinationVersion, bool { if (versionInfo.ProductVersion != targetPollinationVersion) { - Base.Compute.RecordError($"Polination version installed ({versionInfo.ProductVersion}) is not the same as the version required for this code to function correctly ({targetPollinationVersion})."); + Base.Compute.RecordError($"Pollination version installed ({versionInfo.ProductVersion}) is not the same as the version required for this code to function correctly ({targetPollinationVersion})."); return false; } } From fd8fe115414f554f8ee9a7d382e4c3f61d3a5523 Mon Sep 17 00:00:00 2001 From: Tristan Gerrish Date: Mon, 13 Nov 2023 20:46:37 +0000 Subject: [PATCH 3/3] Updated per comments in PR --- .../Compute/InstallPythonEnv_LBT.cs | 6 ++---- .../Query/IsPollinationInstalled.cs | 17 +++++++---------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/LadybugTools_Engine/Compute/InstallPythonEnv_LBT.cs b/LadybugTools_Engine/Compute/InstallPythonEnv_LBT.cs index 8f432054..91d52dc1 100644 --- a/LadybugTools_Engine/Compute/InstallPythonEnv_LBT.cs +++ b/LadybugTools_Engine/Compute/InstallPythonEnv_LBT.cs @@ -39,10 +39,8 @@ public static PythonEnvironment InstallPythonEnv_LBT(bool run = false, bool rein { // check if referenced Python is installed string referencedExecutable = @"C:\Program Files\ladybug_tools\python\python.exe"; - - // NOTE - The version number below relates to the ProductVersion field of the "C:\Program Files\ladybug_tools\uninstall.exe" file, and doesn't necessarily reflect the version of the installer/uninstaller - // Pollination 1.35.14 has an uninstaller ProductVersion of 1.38.104 - if (!Query.IsPollinationInstalled(targetPollinationVersion: "1.38.104", includeBuildNumber: false)) + + if (!Query.IsPollinationInstalled()) { return null; } diff --git a/LadybugTools_Engine/Query/IsPollinationInstalled.cs b/LadybugTools_Engine/Query/IsPollinationInstalled.cs index db692425..2f65592e 100644 --- a/LadybugTools_Engine/Query/IsPollinationInstalled.cs +++ b/LadybugTools_Engine/Query/IsPollinationInstalled.cs @@ -35,10 +35,10 @@ namespace BH.Engine.LadybugTools public static partial class Query { [Description("Return True if Pollination is installed to the currently supported version.")] - [Input("targetPollinationVersion", "The target Pollination build BHoM currently supports.")] - [Input("includeBuildNumber", "If true, the build number will be included in the comparison.")] + [Input("targetPollinationVersion", "The target Pollination version that BHoM currently supports. Default is 1.35.14 which has an uninstaller ProductVersion of 1.38.104, which is the number that is checked against on the uninstaller that comes bundled with Pollincation.")] + [Input("includeBuildNumber", "If true, the build number (the third number in the X.X.X ProductVersion) will be included in the comparison.")] [Output("bool", "True if Pollination is installed to the currently supported version.")] - public static bool IsPollinationInstalled(string targetPollinationVersion, bool includeBuildNumber) + public static bool IsPollinationInstalled(string targetPollinationVersion = "1.38.104", bool includeBuildNumber = false) { // check if referenced Python is installed string referencedExecutable = @"C:\Program Files\ladybug_tools\python\python.exe"; @@ -51,13 +51,10 @@ public static bool IsPollinationInstalled(string targetPollinationVersion, bool // obtain version of pollination installed string referencedUninstaller = @"C:\Program Files\ladybug_tools\uninstall.exe"; FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(referencedUninstaller); - if (includeBuildNumber) + if (includeBuildNumber && (versionInfo.ProductVersion != targetPollinationVersion)) { - if (versionInfo.ProductVersion != targetPollinationVersion) - { - Base.Compute.RecordError($"Polination version installed ({versionInfo.ProductVersion}) is not the same as the version required for this code to function correctly ({targetPollinationVersion})."); - return false; - } + Base.Compute.RecordError($"Pollination version installed ({versionInfo.ProductVersion}) is not the same as the version required for this code to function correctly ({targetPollinationVersion})."); + return false; } // check that version matches the target version @@ -67,7 +64,7 @@ public static bool IsPollinationInstalled(string targetPollinationVersion, bool { if (versionInfo.ProductVersion != targetPollinationVersion) { - Base.Compute.RecordError($"Polination version installed ({versionInfo.ProductVersion}) is not the same as the version required for this code to function correctly ({targetPollinationVersion})."); + Base.Compute.RecordError($"Pollination version installed ({versionInfo.ProductVersion}) is not the same as the version required for this code to function correctly ({targetPollinationVersion})."); return false; } }