Skip to content

Commit fe4f874

Browse files
committed
ZXBSInstaller: Bug in MAME for Linux
1 parent 0e1f2e6 commit fe4f874

File tree

10 files changed

+195
-63
lines changed

10 files changed

+195
-63
lines changed

ZXBSInstaller.Log/ExternalTools.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"Enabled": true,
7474
"Name": "M.A.M.E.",
7575
"Author": "MAME Development Team",
76-
"Description": "MAME (Multi Arcade Machione Emulator) is a multi-purpose emulation framework.",
76+
"Description": "MAME (Multi Arcade Machione Emulator) is a multi-purpose emulation framework.\nLinux version AppImage by @Samueru-sama from https://github.com/pkgforge-dev/MAME-AppImage",
7777
"SupportedOperatingSystems": [
7878
1,
7979
2,

ZXBSInstaller.Log/ServiceLayer.cs

Lines changed: 107 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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();

ZXBSInstaller/Controls/MainControl.axaml.cs

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ private void ShowData()
144144
{
145145
var groupTools = tools.Where(t => t.Group == "ZX Basic Studio");
146146
{
147-
if(chkBorielGroup == null)
147+
if (chkBorielGroup == null)
148148
{
149149
chkBorielGroup = new CheckBox()
150150
{
@@ -164,8 +164,8 @@ private void ShowData()
164164
});
165165
}
166166
var pnlTools = new WrapPanel();
167-
mainTools.Children.Add(pnlTools);
168-
ShowData_AddTools(pnlTools, groupTools);
167+
mainTools.Children.Add(pnlTools);
168+
ShowData_AddTools(pnlTools, groupTools,"ZX Basic Studio", chkBorielGroup.IsChecked == true);
169169
}
170170

171171
// Next
@@ -178,7 +178,7 @@ private void ShowData()
178178
{
179179
Content = "ZX Spectrum Next",
180180
FontSize = 16,
181-
IsChecked = true,
181+
IsChecked = false,
182182
Margin = new Thickness(10, 10, 0, 0),
183183
Foreground = Yellow
184184
};
@@ -193,7 +193,7 @@ private void ShowData()
193193
}
194194
var pnlTools = new WrapPanel();
195195
mainTools.Children.Add(pnlTools);
196-
ShowData_AddTools(pnlTools, groupTools);
196+
ShowData_AddTools(pnlTools, groupTools,"ZX Spectrum Next", chkNextGroup.IsChecked == true);
197197
}
198198

199199
// Update summary area
@@ -204,39 +204,47 @@ private void ShowData()
204204

205205
private void ZXBorielGropu_Changed(object? sender, RoutedEventArgs e)
206206
{
207-
foreach (var ctrl in toolItemControls)
208-
{
209-
if (ctrl.ExternalTool.Group == "ZX Basic Studio")
210-
{
211-
ctrl.IsSelected = chkBorielGroup.IsChecked == true;
212-
}
213-
}
207+
FixSelections("ZX Basic Studio", chkBorielGroup.IsChecked == true);
214208
}
215209

216210

217211
private void ZXNextGropu_Changed(object? sender, RoutedEventArgs e)
218212
{
219-
foreach(var ctrl in toolItemControls)
213+
FixSelections("ZX Spectrum Next", chkNextGroup.IsChecked == true);
214+
}
215+
216+
217+
private void FixSelections(string groupname, bool chkChecked)
218+
{
219+
foreach (var ctrl in toolItemControls)
220220
{
221-
if (ctrl.ExternalTool.Group == "ZX Spectrum Next")
221+
if (ctrl.ExternalTool.Group == groupname)
222222
{
223-
ctrl.IsSelected = chkNextGroup.IsChecked == true;
223+
if (chkChecked)
224+
{
225+
ctrl.IsSelected = ctrl.ExternalTool.UpdateNeeded;
226+
}
227+
else
228+
{
229+
ctrl.IsSelected = false;
230+
}
224231
}
225232
}
226233
}
227234

228235

229-
private void ShowData_AddTools(WrapPanel panel, IEnumerable<ExternalTool> tools)
236+
private void ShowData_AddTools(WrapPanel panel, IEnumerable<ExternalTool> tools, string groupName, bool chkGroup)
230237
{
231238
Dispatcher.UIThread.Post(() =>
232239
{
233240
foreach (var tool in tools)
234241
{
235242
// Create on ToolItemControl foreach tool
236-
var control = new ToolItemControl(tool, Command_Received);
243+
var control = new ToolItemControl(tool, Command_Received, chkGroup);
237244
toolItemControls.Add(control);
238245
panel.Children.Add(control);
239246
}
247+
FixSelections(groupName, chkGroup);
240248
});
241249
}
242250

ZXBSInstaller/Controls/ToolItemControl.axaml.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public bool IsSelected
5252
/// </summary>
5353
/// <param name="tool">External tool to display</param>
5454
/// <param name="callBackCommand">Command delagate</param>
55-
public ToolItemControl(ExternalTool tool, Action<string, string> callBackCommand)
55+
public ToolItemControl(ExternalTool tool, Action<string, string> callBackCommand, bool chkGroup)
5656
{
5757
InitializeComponent();
5858

@@ -67,9 +67,16 @@ public ToolItemControl(ExternalTool tool, Action<string, string> callBackCommand
6767
txtPath.Text = "Path: " + tool.LocalPath;
6868
txtLicense.Text = "Licence: " + tool.LicenseType;
6969
txtAuthor.Text = "Author(s): " + tool.Author;
70-
70+
7171
// Set chkSelect status
72-
IsSelected = tool.UpdateNeeded;
72+
if (chkGroup)
73+
{
74+
IsSelected = false;
75+
}
76+
else
77+
{
78+
IsSelected = tool.UpdateNeeded;
79+
}
7380
tool.IsSelected = IsSelected;
7481
chkSelect.IsChecked = IsSelected;
7582

ZXBSInstaller/ZXBSInstaller.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<ApplicationManifest>app.manifest</ApplicationManifest>
77
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
88
<ApplicationIcon>zxbs.ico</ApplicationIcon>
9-
<Version>1.0.1.1</Version>
9+
<Version>1.0.1.2</Version>
1010
</PropertyGroup>
1111
<ItemGroup>
1212
<None Remove="Assets\cancel.svg" />

ZXBSInstaller/version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.1.1
1+
1.0.1.2

0 commit comments

Comments
 (0)