@@ -1228,7 +1228,7 @@ public static void DownloadAndInstallTool(ExternalTool tool, ExternalTools_Versi
12281228
12291229 // Download file
12301230 step = $ "Downloading file { version . DownloadUrl } ";
1231- UpdateStatus ( $ "Downloading { version . DownloadUrl } ", 50 ) ;
1231+ UpdateStatus ( $ "Downloading { version . DownloadUrl } ", 33 ) ;
12321232 using ( var httpClient = new HttpClient ( ) )
12331233 {
12341234 using ( var response = httpClient . GetAsync ( version . DownloadUrl ) . GetAwaiter ( ) . GetResult ( ) )
@@ -1241,6 +1241,8 @@ public static void DownloadAndInstallTool(ExternalTool tool, ExternalTools_Versi
12411241 }
12421242 }
12431243
1244+ UpdateStatus ( $ "Installing { tool . Name } version { version . Version } ...", 66 ) ;
1245+
12441246 // ZXBSInstaller auto install
12451247 if ( tool . Id == "zxbsinstaller" )
12461248 {
@@ -1252,7 +1254,6 @@ public static void DownloadAndInstallTool(ExternalTool tool, ExternalTools_Versi
12521254 if ( tool . Unzip )
12531255 {
12541256 step = $ "Installing { tool . Name } ";
1255- UpdateStatus ( $ "Installing { tool . Name } version { version . Version } ...", 50 ) ;
12561257 var destDir = Path . GetDirectoryName ( installationPath ) ;
12571258 if ( ! Directory . Exists ( destDir ) )
12581259 {
@@ -1264,17 +1265,7 @@ public static void DownloadAndInstallTool(ExternalTool tool, ExternalTools_Versi
12641265 {
12651266 if ( tool . Id == "mame" && CurrentOperatingSystem == OperatingSystems . Linux )
12661267 {
1267- var dest = Path . Combine ( GeneralConfig . BasePath , tool . LocalPath , "mame.AppImage" ) ;
1268- var destDir = Path . GetDirectoryName ( dest ) ;
1269- if ( ! Directory . Exists ( destDir ) )
1270- {
1271- Directory . CreateDirectory ( destDir ) ;
1272- }
1273- if ( File . Exists ( dest ) )
1274- {
1275- File . Delete ( dest ) ;
1276- }
1277- File . Move ( tempFile , dest ) ;
1268+ InstallMameLinux ( tool , tempFile ) ;
12781269 }
12791270 else
12801271 {
@@ -1304,6 +1295,12 @@ public static void DownloadAndInstallTool(ExternalTool tool, ExternalTools_Versi
13041295 File . WriteAllText ( fileName , version . Version ) ;
13051296 }
13061297
1298+ if ( tool . Id == "mame" )
1299+ {
1300+ tool . InstalledVersion = new ExternalTools_Version ( ) ;
1301+ tool . InstalledVersion . Version = version . Version ;
1302+ }
1303+
13071304 // Set ZXBS Options
13081305 step = "Set ZX Basic Studio options" ;
13091306 UpdateStatus ( null , 75 ) ;
@@ -1383,6 +1380,80 @@ public static void DownloadAndInstallTool(ExternalTool tool, ExternalTools_Versi
13831380 }
13841381
13851382
1383+ private static void InstallMameLinux ( ExternalTool tool , string tempFile )
1384+ {
1385+ try
1386+ {
1387+ // Move mame to dest folder
1388+ var dest = Path . Combine ( GeneralConfig . BasePath , tool . LocalPath , "mame.AppImage" ) ;
1389+ var destDir = Path . GetDirectoryName ( dest ) ;
1390+ if ( ! Directory . Exists ( destDir ) )
1391+ {
1392+ Directory . CreateDirectory ( destDir ) ;
1393+ }
1394+ if ( File . Exists ( dest ) )
1395+ {
1396+ File . Delete ( dest ) ;
1397+ }
1398+ File . Move ( tempFile , dest ) ;
1399+ // Set execute attr
1400+ {
1401+ var psi = new ProcessStartInfo
1402+ {
1403+ FileName = "chmod" ,
1404+ ArgumentList = { "+x" , dest } ,
1405+ RedirectStandardOutput = true ,
1406+ RedirectStandardError = true ,
1407+ UseShellExecute = false ,
1408+ CreateNoWindow = true
1409+ } ;
1410+ var p = new Process { StartInfo = psi } ;
1411+ p . Start ( ) ;
1412+ p . WaitForExit ( ) ;
1413+ }
1414+ if ( CurrentOperatingSystem == OperatingSystems . Linux )
1415+ {
1416+ DownloadMamePlugins ( destDir ) ;
1417+ }
1418+ }
1419+ catch ( Exception ex )
1420+ {
1421+ ShowMessage ( $ "Error installing MAME on Linux.\r \n { ex . Message } \r \n { ex . StackTrace } ") ;
1422+ }
1423+ }
1424+
1425+
1426+ private static void DownloadMamePlugins ( string destDir )
1427+ {
1428+ // Download plugins for MAME on Linux
1429+ try
1430+ {
1431+ // Download file
1432+ var tempFile = Path . Combine ( GeneralConfig . BasePath , "downloads" , "mame-plugins.zip" ) ;
1433+ UpdateStatus ( $ "Downloading MAME plugins for Linux...", 33 ) ;
1434+ using ( var httpClient = new HttpClient ( ) )
1435+ {
1436+ using ( var response = httpClient . GetAsync ( "https://www.duefectucorp.com/descargas/mame-plugins/mame-plugins.zip" ) . GetAwaiter ( ) . GetResult ( ) )
1437+ {
1438+ response . EnsureSuccessStatusCode ( ) ;
1439+ using ( var fs = new FileStream ( tempFile , FileMode . Create , FileAccess . Write , FileShare . None ) )
1440+ {
1441+ response . Content . CopyToAsync ( fs ) . GetAwaiter ( ) . GetResult ( ) ;
1442+ }
1443+ }
1444+ }
1445+ // Unzip file
1446+ UpdateStatus ( $ "Installing MAME plugins for Linux...", 66 ) ;
1447+ var dest = Path . Combine ( GeneralConfig . BasePath , "mame" ) ;
1448+ ExtractFile ( tempFile , dest ) ;
1449+ }
1450+ catch ( Exception ex )
1451+ {
1452+ ShowMessage ( $ "Error installing MAME plugins on Linux.\r \n { ex . Message } \r \n { ex . StackTrace } ") ;
1453+ }
1454+ }
1455+
1456+
13861457 /// <summary>
13871458 /// Install ZXBSInstaller...
13881459 /// Generate a batch/bash file to expand .zip, decompress and launch ZXBSInstaller
@@ -1639,6 +1710,29 @@ private static void SetZXBSConfig()
16391710 var dir = Path . Combine ( GeneralConfig . BasePath , "zxbasic" , exe ) . Replace ( "\\ " , "\\ \\ " ) ;
16401711 line = $ " \" ZxbcPath\" : \" { dir } \" ,";
16411712 }
1713+ else if ( line . Contains ( "NextEmulatorPath" ) )
1714+ {
1715+ var mameTool = ExternalTools . FirstOrDefault ( d => d . Id == "mame" ) ;
1716+ if ( mameTool != null &&
1717+ mameTool . InstalledVersion != null &&
1718+ mameTool . InstalledVersion . VersionNumber > 0 )
1719+ {
1720+ string dir = "" ;
1721+ if ( CurrentOperatingSystem == OperatingSystems . Linux )
1722+ {
1723+ dir = Path . Combine ( GeneralConfig . BasePath , "mame" , "mame.AppImage" ) . Replace ( "\\ " , "\\ \\ " ) ;
1724+ }
1725+ else if ( CurrentOperatingSystem == OperatingSystems . Windows )
1726+ {
1727+ dir = Path . Combine ( GeneralConfig . BasePath , "mame" , "mame.exe" ) . Replace ( "\\ " , "\\ \\ " ) ;
1728+ }
1729+ else
1730+ {
1731+ dir = Path . Combine ( GeneralConfig . BasePath , "mame" , "mame" ) . Replace ( "\\ " , "\\ \\ " ) ;
1732+ }
1733+ line = $ " \" NextEmulatorPath\" : \" { dir } \" ,";
1734+ }
1735+ }
16421736 sb . AppendLine ( line ) ;
16431737 }
16441738 sr . Close ( ) ;
0 commit comments