Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ZXBSInstaller.Log/Neg/OperatingSystems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public enum OperatingSystems
All = 0,
Windows = 1,
Linux = 2,
MacOS = 3
MacOS = 3,
MacOS_x64 = 4,
MacOS_arm64 = 5
}
}
147 changes: 111 additions & 36 deletions ZXBSInstaller.Log/ServiceLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,6 +31,8 @@ public static class ServiceLayer
private static Action HideStatusPanel = null;
private static Action RefreshTools = null;
private static Action<string> ShowMessage = null;
private static Action ExitApp = null;


#region Constructor and tools

Expand All @@ -42,13 +45,15 @@ public static bool Initialize(
Action<string, int> callBackUpdateStatus,
Action callBackHideStatusPanel,
Action callBackGetExternalTools,
Action<string> callBackShowMessage)
Action<string> callBackShowMessage,
Action callBackExitApp)
{
ShowStatusPanel = callBackShowStatusPanel;
UpdateStatus = callBackUpdateStatus;
HideStatusPanel = callBackHideStatusPanel;
RefreshTools = callBackGetExternalTools;
ShowMessage = callBackShowMessage;
ExitApp = callBackExitApp;

GetConfig();

Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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"))
Expand Down Expand Up @@ -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));
// }
// }
// }
//}
}


Expand Down
13 changes: 10 additions & 3 deletions ZXBSInstaller/Controls/MainControl.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(() =>
{
Expand Down Expand Up @@ -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();
Expand Down
15 changes: 14 additions & 1 deletion ZXBSInstaller/Controls/VersionControl.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion ZXBSInstaller/ZXBSInstaller.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<ApplicationManifest>app.manifest</ApplicationManifest>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
<ApplicationIcon>zxbs.ico</ApplicationIcon>
<Version>0.0.1.7</Version>
<Version>1.0.0.1</Version>
</PropertyGroup>
<ItemGroup>
<None Remove="Assets\install.svg" />
Expand Down