From d8b2055fbce578884dfac36fca372101c14cd8af Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 7 Jul 2020 00:01:00 +0200 Subject: global-functions: add $VersionToNum --- global-functions | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'global-functions') diff --git a/global-functions b/global-functions index e01d807..0a6b709 100644 --- a/global-functions +++ b/global-functions @@ -41,6 +41,7 @@ :global SendTelegram; :global TimeIsSync; :global UrlEncode; +:global VersionToNum; :global WaitDefaultRouteReachable; :global WaitDNSResolving; :global WaitForFile; @@ -760,6 +761,35 @@ :return $Return; } +# convert version string to numeric value +:set VersionToNum do={ + :local Input [ :tostr $1 ]; + :local Multi 0x1000000; + :local Return 0; + + :global CharacterReplace; + + :set Input [ $CharacterReplace [ $CharacterReplace [ $CharacterReplace $Input \ + "." "," ] "beta" ",beta," ] "rc" ",rc," ]; + + :foreach Value in=([ :toarray $Input ], 0) do={ + :local Num [ :tonum $Value ]; + :if ($Multi = 0x100) do={ + :if ([ :typeof $Num ] = "num") do={ + :set Return ($Return + 0xff00); + :set Multi ($Multi / 0x100); + } else={ + :if ($Value = "beta") do={ :set Return ($Return + 0x3f00); } + :if ($Value = "rc") do={ :set Return ($Return + 0x7f00); } + } + } + :if ([ :typeof $Num ] = "num") do={ :set Return ($Return + ($Value * $Multi)); } + :set Multi ($Multi / 0x100); + } + + :return $Return; +} + # wait for default route to be reachable :set WaitDefaultRouteReachable do={ :global DefaultRouteIsReachable; -- cgit v1.2.3-70-g09d2