From 0a5c12e366f8e9bce0403d65b967f2c55bb0da82 Mon Sep 17 00:00:00 2001 From: Pavel Shevaev Date: Mon, 3 Mar 2025 15:27:43 +0300 Subject: [PATCH] Making installer more robust --- dotnet.inc.php | 4 ++-- support.inc.php | 20 ++++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/dotnet.inc.php b/dotnet.inc.php index 5278718..b3352b1 100644 --- a/dotnet.inc.php +++ b/dotnet.inc.php @@ -6,8 +6,8 @@ task('dotnet_set_env', ['always' => true], function() { dotnet_set_env(); }); -task('dotnet_install', function() { - DotnetSupport::install(); +task('dotnet_install', function(array $args) { + DotnetSupport::install(isset($args[0]) && $args[0] === '--force'); }); function dotnet_shell($cmd) diff --git a/support.inc.php b/support.inc.php index d51ab60..5136a00 100644 --- a/support.inc.php +++ b/support.inc.php @@ -7,13 +7,12 @@ class DotnetSupport { const VERSION = "8.0.0"; - static function install() + static function install(bool $force = false) { $version = self::VERSION; - $has_dotnet = true; - $dotnet_curr_ver = ""; + //let's add to PATH $prev_path = self::addEnvPath(); try { @@ -22,17 +21,26 @@ class DotnetSupport } catch(\Throwable $th) { - $has_dotnet = false; + $force = true; } finally { + //let's restore prev PATH self::setEnvPath($prev_path); } - if($has_dotnet && version_compare($dotnet_curr_ver, $version) >= 0) + if(!$force) + { + $dotnet_ver_items = explode('.', $dotnet_curr_ver); + $target_ver_items = explode('.', $version); + //let's force install if current major version is not equal + $force = isset($dotnet_ver_items[0]) && $dotnet_ver_items[0] !== $target_ver_items[0]; + } + + if(!$force) return; - print("DOTNET VERSION MISMATCH: $dotnet_curr_ver < $version\n"); + print("DOTNET VERSION MISMATCH: $dotnet_curr_ver is not compatible with $version\n"); $install_file_path = self::getInstallerPath();