diff --git a/ZXBSInstaller.Log/Neg/OperatingSystems.cs b/ZXBSInstaller.Log/Neg/OperatingSystems.cs index 0bb97e7..4462305 100644 --- a/ZXBSInstaller.Log/Neg/OperatingSystems.cs +++ b/ZXBSInstaller.Log/Neg/OperatingSystems.cs @@ -8,6 +8,8 @@ public enum OperatingSystems All = 0, Windows = 1, Linux = 2, - MacOS = 3 + MacOS = 3, + MacOS_x64 = 4, + MacOS_arm64 = 5 } } \ No newline at end of file diff --git a/ZXBSInstaller.Log/ServiceLayer.cs b/ZXBSInstaller.Log/ServiceLayer.cs index 7ec4fdc..174a25a 100644 --- a/ZXBSInstaller.Log/ServiceLayer.cs +++ b/ZXBSInstaller.Log/ServiceLayer.cs @@ -7,6 +7,7 @@ using System.Reflection; using System.Reflection.Metadata.Ecma335; using System.Runtime; +using System.Runtime.InteropServices; using System.Text; using System.Text.Json; using System.Text.RegularExpressions; @@ -30,6 +31,8 @@ public static class ServiceLayer private static Action HideStatusPanel = null; private static Action RefreshTools = null; private static Action ShowMessage = null; + private static Action ExitApp = null; + #region Constructor and tools @@ -42,13 +45,15 @@ public static bool Initialize( Action callBackUpdateStatus, Action callBackHideStatusPanel, Action callBackGetExternalTools, - Action callBackShowMessage) + Action callBackShowMessage, + Action callBackExitApp) { ShowStatusPanel = callBackShowStatusPanel; UpdateStatus = callBackUpdateStatus; HideStatusPanel = callBackHideStatusPanel; RefreshTools = callBackGetExternalTools; ShowMessage = callBackShowMessage; + ExitApp = callBackExitApp; GetConfig(); @@ -62,7 +67,14 @@ public static bool Initialize( } else if (OperatingSystem.IsMacOS()) { - CurrentOperatingSystem = OperatingSystems.MacOS; + if (RuntimeInformation.ProcessArchitecture == Architecture.Arm64) + { + CurrentOperatingSystem = OperatingSystems.MacOS_arm64; + } + else if (RuntimeInformation.ProcessArchitecture == Architecture.X64) + { + CurrentOperatingSystem = OperatingSystems.MacOS_x64; + } } return true; @@ -191,7 +203,8 @@ public static void OpenUrlInBrowser(string url) case OperatingSystems.Linux: Process.Start("xdg-open", url); break; - case OperatingSystems.MacOS: + case OperatingSystems.MacOS_x64: + case OperatingSystems.MacOS_arm64: Process.Start("open", url); break; } @@ -646,14 +659,14 @@ private static ExternalTools_Version[] GetBorielZXBSVersions(string versionsUrl, { if (installer) { - if (!fl.Contains("zxbsinstaller")) + if (!fl.Contains("ZXBSInstaller")) { continue; } } else { - if (fl.Contains("zxbsinstaller")) + if (fl.Contains("ZXBSInstaller")) { continue; } @@ -691,6 +704,14 @@ private static ExternalTools_Version GetGitHubZXBSVersion(string fileLink) { version.OperatingSystem = OperatingSystems.Linux; } + else if (fileLink.Contains("osx-x64")) + { + version.OperatingSystem = OperatingSystems.MacOS_x64; + } + else if (fileLink.Contains("osx-arm64")) + { + version.OperatingSystem = OperatingSystems.MacOS_arm64; + } else if (fileLink.Contains("osx") || fileLink.Contains("mac")) { version.OperatingSystem = OperatingSystems.MacOS; @@ -995,6 +1016,13 @@ public static void DownloadAndInstallTool(ExternalTool tool, ExternalTools_Versi } } + // ZXBSInstaller auto install + if (tool.Id == "zxbsinstaller") + { + InstallInstaller(tool, tempFile, installationPath); + return; + } + // Extract file step = $"Installing {tool.Name}"; UpdateStatus($"Installing {tool.Name} version {version.Version}...", 50); @@ -1020,6 +1048,84 @@ public static void DownloadAndInstallTool(ExternalTool tool, ExternalTools_Versi } + private static void InstallInstaller(ExternalTool tool, string tempFile, string installationPath) + { + try + { + // Create batch/bash file + string bash = ""; + string bashFile = ""; + if (CurrentOperatingSystem == OperatingSystems.Windows) + { + bashFile = Path.Combine(GeneralConfig.BasePath, "downloads", "zxbsinstall.bat"); + bash = @" +@echo off +echo Updating installer... +timeout /t 5 /nobreak +echo on +tar -xf ""{tempFile}"" -C ""{installationPath}"" +del ""{tempFile}"" +cd ""{installationPath}"" +start ZXBSInstaller.exe"; + } + else + { + bashFile = Path.Combine(GeneralConfig.BasePath, "downloads", "zxbsinstall.sh"); + bash = @" +#!/bin/bash + +echo ""Updating installer..."" +sleep 5 + +set -x +tar -xf ""{tempFile}"" -C ""{installationPath}"" +rm -f ""{tempFile}"" +cd ""{installationPath}"" || exit 1 + +# Ejecutar sin esperar (en segundo plano) +./ZXBSInstaller.exe &"; + } + bash = bash.Replace("{tempFile}", tempFile).Replace("{installationPath}", installationPath); + File.WriteAllText(bashFile, bash); + + // Set execute attr in Linux/Mac + if (CurrentOperatingSystem != OperatingSystems.Windows) + { + var process = new Process(); + process.StartInfo.FileName = "chmod"; + process.StartInfo.ArgumentList.Add("+x"); + process.StartInfo.ArgumentList.Add(bashFile); + process.StartInfo.RedirectStandardOutput = true; + process.StartInfo.RedirectStandardError = true; + process.StartInfo.UseShellExecute = false; + process.Start(); + process.WaitForExit(); + } + + // Run batch/bash file + { + ProcessStartInfo psi = new ProcessStartInfo + { + FileName = bashFile, + WorkingDirectory = Path.Combine(GeneralConfig.BasePath, "downloads"), + UseShellExecute = true, + }; + var p = new Process { StartInfo = psi }; + p.Start(); + } + + // Exit app + ExitApp(); + } + + catch (Exception ex) + { + HideStatusPanel(); + ShowMessage($"Error installing ZXBSInstaller\r\n{ex.Message}\r\n{ex.StackTrace}"); + } + } + + private static void ExtractFile(string archive, string destination) { if (archive.ToLower().EndsWith(".zip")) @@ -1053,37 +1159,6 @@ private static void ExtractFile(string archive, string destination) return; } } - //if (archive.ToLower().EndsWith(".tar.gz")) - //{ - // Directory.CreateDirectory(destination); - - // using var fileStream = File.OpenRead(archive); - // using var gzipStream = new GZipStream(fileStream, CompressionMode.Decompress); - // using var tarReader = new TarReader(gzipStream); - - // TarEntry? entry; - // while ((entry = tarReader.GetNextEntry()) != null) - // { - // string fullPath = Path.Combine(destination, entry.Name); - - // if (entry.EntryType == TarEntryType.Directory) - // { - // Directory.CreateDirectory(fullPath); - // } - // else - // { - // Directory.CreateDirectory(Path.GetDirectoryName(fullPath)!); - // if (entry.Length == 0) - // { - // File.WriteAllBytes(fullPath, new byte[0]); - // } - // else - // { - // entry.DataStream!.CopyTo(File.Create(fullPath)); - // } - // } - // } - //} } diff --git a/ZXBSInstaller/Controls/MainControl.axaml.cs b/ZXBSInstaller/Controls/MainControl.axaml.cs index 4c3b009..2cd52f0 100644 --- a/ZXBSInstaller/Controls/MainControl.axaml.cs +++ b/ZXBSInstaller/Controls/MainControl.axaml.cs @@ -44,7 +44,7 @@ private void MainControl_Loaded(object? sender, RoutedEventArgs e) private void Initialize() { - ServiceLayer.Initialize(ShowStatusPanel, UpdateStatus, HideStatusPanel, GetExternalTools, ShowMessage); + ServiceLayer.Initialize(ShowStatusPanel, UpdateStatus, HideStatusPanel, GetExternalTools, ShowMessage, ExitApp); Dispatcher.UIThread.Post(() => { @@ -372,16 +372,23 @@ private void Versions_Close(object? sender, RoutedEventArgs e) private void btnPlayZXBS_Click(object? sender, RoutedEventArgs e) { - if (ServiceLayer.RunZXBasicStudio()) + ExitApp(); + } + + + private void ExitApp() + { + Dispatcher.UIThread.Post(() => { if (App.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { desktop.Shutdown(); } - } + }); } + private void btnRefresh_Click(object? sender, RoutedEventArgs e) { new Thread(GetExternalTools).Start(); diff --git a/ZXBSInstaller/Controls/VersionControl.axaml.cs b/ZXBSInstaller/Controls/VersionControl.axaml.cs index cc392b0..bbbda14 100644 --- a/ZXBSInstaller/Controls/VersionControl.axaml.cs +++ b/ZXBSInstaller/Controls/VersionControl.axaml.cs @@ -59,7 +59,20 @@ public VersionControl(ExternalTool tool, ExternalTools_Version toolVersion, Acti txtPlatform.Foreground = ColorGreen; txtStatus.Foreground = ColorGreen; txtVersion.Foreground = ColorGreen; - } + } + if (ServiceLayer.CurrentOperatingSystem == OperatingSystems.MacOS_arm64 || + ServiceLayer.CurrentOperatingSystem == OperatingSystems.MacOS_x64) + { + if(toolVersion.OperatingSystem== OperatingSystems.MacOS_arm64 || + toolVersion.OperatingSystem == OperatingSystems.MacOS_x64 || + toolVersion.OperatingSystem == OperatingSystems.MacOS) + { + btnDownload.Foreground = ColorGreen; + txtPlatform.Foreground = ColorGreen; + txtStatus.Foreground = ColorGreen; + txtVersion.Foreground = ColorGreen; + } + } } } diff --git a/ZXBSInstaller/ZXBSInstaller.csproj b/ZXBSInstaller/ZXBSInstaller.csproj index 1362c0b..008c57a 100644 --- a/ZXBSInstaller/ZXBSInstaller.csproj +++ b/ZXBSInstaller/ZXBSInstaller.csproj @@ -6,7 +6,7 @@ app.manifest true zxbs.ico - 0.0.1.7 + 1.0.0.1