@@ -260,7 +260,7 @@ public static ExternalTool[] GetExternalTools()
260260 int prg = 10 ;
261261 for ( int n = 0 ; n < max ; n ++ )
262262 {
263- if ( Cancel )
263+ if ( Cancel )
264264 {
265265 return null ;
266266 }
@@ -889,12 +889,15 @@ private static ExternalTools_Version GetBorielBasicVersion(string exePath)
889889 var fileName = Path . Combine ( exePath , "zxbc.exe" ) ;
890890 if ( ! File . Exists ( fileName ) )
891891 {
892- fileName = Path . Combine ( exePath , "zxbc" ) ;
892+ fileName = Path . Combine ( exePath , "zxbc.py " ) ;
893893 }
894894 if ( ! File . Exists ( fileName ) )
895895 {
896896 return null ;
897897 }
898+ return GetVersionFromParameter ( fileName ) ;
899+
900+ #if OLD
898901 // Launch "zxbc.exe --version"
899902 ProcessStartInfo psi = new ProcessStartInfo
900903 {
@@ -928,60 +931,108 @@ private static ExternalTools_Version GetBorielBasicVersion(string exePath)
928931 Version = version ,
929932 VersionNumber = number
930933 } ;
934+ #endif
931935 }
932936 catch ( Exception ex )
933937 {
934938 ShowMessage ( $ "Error getting local Boriel Basic version.\r \n { ex . Message } { ex . StackTrace } ") ;
935939 return null ;
936940 }
937-
938941 }
939942
940943
941944 private static ExternalTools_Version GetZXBSVersion ( string exePath )
942945 {
943946 try
944947 {
945- var fileName = Path . Combine ( exePath , "ZXBasicStudio.exe " ) ;
948+ var fileName = Path . Combine ( exePath , "version.txt " ) ;
946949 if ( ! File . Exists ( fileName ) )
947950 {
948- fileName = Path . Combine ( exePath , "ZXBasicStudio" ) ;
951+ if ( File . Exists ( Path . Combine ( exePath , "ZXBasicStudio.exe" ) )
952+ || File . Exists ( Path . Combine ( exePath , "ZXBasicStudio" ) ) )
953+ {
954+ return new ExternalTools_Version ( )
955+ {
956+ DownloadUrl = "" ,
957+ BetaNumber = 0 ,
958+ OperatingSystem = OperatingSystems . All ,
959+ Version = "OLD version" ,
960+ VersionNumber = 0
961+ } ;
962+ }
963+ return null ;
949964 }
965+ var txt = File . ReadAllText ( fileName ) ;
966+ var v = GetVersionNumber ( txt ) ;
967+
968+ var version = new ExternalTools_Version ( )
969+ {
970+ DownloadUrl = "" ,
971+ BetaNumber = v . Item2 ,
972+ OperatingSystem = OperatingSystems . All ,
973+ Version = txt ,
974+ VersionNumber = v . Item1
975+ } ;
976+ return version ;
977+ }
978+ catch ( Exception ex )
979+ {
980+ ShowMessage ( $ "Error getting local ZXBS version.\r \n { ex . Message } { ex . StackTrace } ") ;
981+ return null ;
982+ }
983+ }
984+
985+
986+ /// <summary>
987+ /// Get version from file using --version parameter
988+ /// </summary>
989+ /// <param name="fileName">Executable filename</param>
990+ /// <returns>ExternalTools_Version with the version info</returns>
991+ private static ExternalTools_Version GetVersionFromParameter ( string fileName )
992+ {
993+ try
994+ {
950995 if ( ! File . Exists ( fileName ) )
951996 {
952997 return null ;
953998 }
954999
955- var fvi = FileVersionInfo . GetVersionInfo ( fileName ) ;
956- if ( fvi != null )
1000+ ProcessStartInfo psi = new ProcessStartInfo
9571001 {
958- // Major, minor, Build, private
959- var version = $ "{ fvi . ProductMajorPart } .{ fvi . ProductMinorPart } .{ fvi . ProductBuildPart } ";
960- if ( fvi . ProductPrivatePart > 0 )
961- {
962- version += $ "-beta{ fvi . ProductPrivatePart } ";
963- }
964- if ( version == "1.0.0" )
965- {
966- version = "1.6.0-beta6.3" ;
967- }
968- var v = GetVersionNumber ( version ) ;
969- var versionNumber = v . Item1 ;
970- var beta = v . Item2 ;
971- return new ExternalTools_Version ( )
972- {
973- DownloadUrl = "" ,
974- BetaNumber = beta ,
975- OperatingSystem = OperatingSystems . All ,
976- Version = version ,
977- VersionNumber = versionNumber
978- } ;
1002+ FileName = fileName ,
1003+ Arguments = "--version" ,
1004+ RedirectStandardOutput = true ,
1005+ RedirectStandardError = true ,
1006+ UseShellExecute = false ,
1007+ CreateNoWindow = true
1008+ } ;
1009+ using Process process = new Process { StartInfo = psi } ;
1010+ process . Start ( ) ;
1011+ string output = process . StandardOutput . ReadToEnd ( ) ;
1012+ string error = process . StandardError . ReadToEnd ( ) ;
1013+ process . WaitForExit ( ) ;
1014+
1015+ if ( string . IsNullOrEmpty ( output ) )
1016+ {
1017+ return null ;
9791018 }
980- return null ;
1019+ var version = output . Replace ( "zxbc.py " , "" ) . Replace ( "\n " , "" ) . Replace ( "\r " , "" ) . Replace ( "v" , "" ) ;
1020+ var v = GetVersionNumber ( version ) ;
1021+ int number = v . Item1 ;
1022+ int beta = v . Item2 ;
1023+
1024+ return new ExternalTools_Version ( )
1025+ {
1026+ DownloadUrl = "" ,
1027+ BetaNumber = beta ,
1028+ OperatingSystem = OperatingSystems . All ,
1029+ Version = version ,
1030+ VersionNumber = number
1031+ } ;
9811032 }
9821033 catch ( Exception ex )
9831034 {
984- ShowMessage ( $ "Error getting local ZXBS version.\r \n { ex . Message } { ex . StackTrace } ") ;
1035+ ShowMessage ( $ "Error getting local Boriel Basic version.\r \n { ex . Message } { ex . StackTrace } ") ;
9851036 return null ;
9861037 }
9871038 }
@@ -1160,7 +1211,7 @@ echo on
11601211 {
11611212 bashFile = Path . Combine ( GeneralConfig . BasePath , "downloads" , "zxbsinstall.sh" ) ;
11621213 bash = @"
1163- #!/bin/bash
1214+ # !/bin/bash
11641215set -e
11651216
11661217echo ""Updating installer...""
@@ -1247,39 +1298,40 @@ exit 1
12471298
12481299 private static void ExtractFile ( string archive , string destination )
12491300 {
1250- try {
1251- if ( archive . ToLower ( ) . EndsWith ( ".zip" ) )
1252- {
1253- System . IO . Compression . ZipFile . ExtractToDirectory ( archive , destination , true ) ;
1254- }
1255- else if ( CurrentOperatingSystem != OperatingSystems . Windows )
1301+ try
12561302 {
1257- Directory . CreateDirectory ( destination ) ;
1258-
1259- var psi = new ProcessStartInfo
1303+ if ( archive . ToLower ( ) . EndsWith ( ".zip" ) )
12601304 {
1261- FileName = "tar" ,
1262- Arguments = $ "-xzf \" { archive } \" -C \" { destination } \" ",
1263- RedirectStandardOutput = true ,
1264- RedirectStandardError = true ,
1265- UseShellExecute = false ,
1266- CreateNoWindow = true
1267- } ;
1305+ System . IO . Compression . ZipFile . ExtractToDirectory ( archive , destination , true ) ;
1306+ }
1307+ else if ( CurrentOperatingSystem != OperatingSystems . Windows )
1308+ {
1309+ Directory . CreateDirectory ( destination ) ;
12681310
1269- using var process = Process . Start ( psi ) ! ;
1311+ var psi = new ProcessStartInfo
1312+ {
1313+ FileName = "tar" ,
1314+ Arguments = $ "-xzf \" { archive } \" -C \" { destination } \" ",
1315+ RedirectStandardOutput = true ,
1316+ RedirectStandardError = true ,
1317+ UseShellExecute = false ,
1318+ CreateNoWindow = true
1319+ } ;
12701320
1271- string stdout = process . StandardOutput . ReadToEnd ( ) ;
1272- string stderr = process . StandardError . ReadToEnd ( ) ;
1321+ using var process = Process . Start ( psi ) ! ;
12731322
1274- process . WaitForExit ( ) ;
1323+ string stdout = process . StandardOutput . ReadToEnd ( ) ;
1324+ string stderr = process . StandardError . ReadToEnd ( ) ;
12751325
1276- if ( process . ExitCode != 0 )
1277- {
1278- ShowMessage ( $ "Error unpacking file { archive } \r \n { stderr } ") ;
1279- return ;
1326+ process . WaitForExit ( ) ;
1327+
1328+ if ( process . ExitCode != 0 )
1329+ {
1330+ ShowMessage ( $ "Error unpacking file { archive } \r \n { stderr } ") ;
1331+ return ;
1332+ }
12801333 }
12811334 }
1282- }
12831335 catch ( Exception ex )
12841336 {
12851337 ShowMessage ( $ "Error unpacking file { archive } on { destination } .\r \n { ex . Message } { ex . StackTrace } ") ;
0 commit comments