Skip to content

Commit a8ec61a

Browse files
authored
Merge pull request #50 from boriel-basic/features/installer
v1.0.0-beta 1
2 parents e7df187 + 675a39e commit a8ec61a

File tree

5 files changed

+139
-42
lines changed

5 files changed

+139
-42
lines changed

ZXBSInstaller.Log/Neg/OperatingSystems.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ public enum OperatingSystems
88
All = 0,
99
Windows = 1,
1010
Linux = 2,
11-
MacOS = 3
11+
MacOS = 3,
12+
MacOS_x64 = 4,
13+
MacOS_arm64 = 5
1214
}
1315
}

ZXBSInstaller.Log/ServiceLayer.cs

Lines changed: 111 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Reflection;
88
using System.Reflection.Metadata.Ecma335;
99
using System.Runtime;
10+
using System.Runtime.InteropServices;
1011
using System.Text;
1112
using System.Text.Json;
1213
using System.Text.RegularExpressions;
@@ -30,6 +31,8 @@ public static class ServiceLayer
3031
private static Action HideStatusPanel = null;
3132
private static Action RefreshTools = null;
3233
private static Action<string> ShowMessage = null;
34+
private static Action ExitApp = null;
35+
3336

3437
#region Constructor and tools
3538

@@ -42,13 +45,15 @@ public static bool Initialize(
4245
Action<string, int> callBackUpdateStatus,
4346
Action callBackHideStatusPanel,
4447
Action callBackGetExternalTools,
45-
Action<string> callBackShowMessage)
48+
Action<string> callBackShowMessage,
49+
Action callBackExitApp)
4650
{
4751
ShowStatusPanel = callBackShowStatusPanel;
4852
UpdateStatus = callBackUpdateStatus;
4953
HideStatusPanel = callBackHideStatusPanel;
5054
RefreshTools = callBackGetExternalTools;
5155
ShowMessage = callBackShowMessage;
56+
ExitApp = callBackExitApp;
5257

5358
GetConfig();
5459

@@ -62,7 +67,14 @@ public static bool Initialize(
6267
}
6368
else if (OperatingSystem.IsMacOS())
6469
{
65-
CurrentOperatingSystem = OperatingSystems.MacOS;
70+
if (RuntimeInformation.ProcessArchitecture == Architecture.Arm64)
71+
{
72+
CurrentOperatingSystem = OperatingSystems.MacOS_arm64;
73+
}
74+
else if (RuntimeInformation.ProcessArchitecture == Architecture.X64)
75+
{
76+
CurrentOperatingSystem = OperatingSystems.MacOS_x64;
77+
}
6678
}
6779

6880
return true;
@@ -191,7 +203,8 @@ public static void OpenUrlInBrowser(string url)
191203
case OperatingSystems.Linux:
192204
Process.Start("xdg-open", url);
193205
break;
194-
case OperatingSystems.MacOS:
206+
case OperatingSystems.MacOS_x64:
207+
case OperatingSystems.MacOS_arm64:
195208
Process.Start("open", url);
196209
break;
197210
}
@@ -646,14 +659,14 @@ private static ExternalTools_Version[] GetBorielZXBSVersions(string versionsUrl,
646659
{
647660
if (installer)
648661
{
649-
if (!fl.Contains("zxbsinstaller"))
662+
if (!fl.Contains("ZXBSInstaller"))
650663
{
651664
continue;
652665
}
653666
}
654667
else
655668
{
656-
if (fl.Contains("zxbsinstaller"))
669+
if (fl.Contains("ZXBSInstaller"))
657670
{
658671
continue;
659672
}
@@ -691,6 +704,14 @@ private static ExternalTools_Version GetGitHubZXBSVersion(string fileLink)
691704
{
692705
version.OperatingSystem = OperatingSystems.Linux;
693706
}
707+
else if (fileLink.Contains("osx-x64"))
708+
{
709+
version.OperatingSystem = OperatingSystems.MacOS_x64;
710+
}
711+
else if (fileLink.Contains("osx-arm64"))
712+
{
713+
version.OperatingSystem = OperatingSystems.MacOS_arm64;
714+
}
694715
else if (fileLink.Contains("osx") || fileLink.Contains("mac"))
695716
{
696717
version.OperatingSystem = OperatingSystems.MacOS;
@@ -995,6 +1016,13 @@ public static void DownloadAndInstallTool(ExternalTool tool, ExternalTools_Versi
9951016
}
9961017
}
9971018

1019+
// ZXBSInstaller auto install
1020+
if (tool.Id == "zxbsinstaller")
1021+
{
1022+
InstallInstaller(tool, tempFile, installationPath);
1023+
return;
1024+
}
1025+
9981026
// Extract file
9991027
step = $"Installing {tool.Name}";
10001028
UpdateStatus($"Installing {tool.Name} version {version.Version}...", 50);
@@ -1020,6 +1048,84 @@ public static void DownloadAndInstallTool(ExternalTool tool, ExternalTools_Versi
10201048
}
10211049

10221050

1051+
private static void InstallInstaller(ExternalTool tool, string tempFile, string installationPath)
1052+
{
1053+
try
1054+
{
1055+
// Create batch/bash file
1056+
string bash = "";
1057+
string bashFile = "";
1058+
if (CurrentOperatingSystem == OperatingSystems.Windows)
1059+
{
1060+
bashFile = Path.Combine(GeneralConfig.BasePath, "downloads", "zxbsinstall.bat");
1061+
bash = @"
1062+
@echo off
1063+
echo Updating installer...
1064+
timeout /t 5 /nobreak
1065+
echo on
1066+
tar -xf ""{tempFile}"" -C ""{installationPath}""
1067+
del ""{tempFile}""
1068+
cd ""{installationPath}""
1069+
start ZXBSInstaller.exe";
1070+
}
1071+
else
1072+
{
1073+
bashFile = Path.Combine(GeneralConfig.BasePath, "downloads", "zxbsinstall.sh");
1074+
bash = @"
1075+
#!/bin/bash
1076+
1077+
echo ""Updating installer...""
1078+
sleep 5
1079+
1080+
set -x
1081+
tar -xf ""{tempFile}"" -C ""{installationPath}""
1082+
rm -f ""{tempFile}""
1083+
cd ""{installationPath}"" || exit 1
1084+
1085+
# Ejecutar sin esperar (en segundo plano)
1086+
./ZXBSInstaller.exe &";
1087+
}
1088+
bash = bash.Replace("{tempFile}", tempFile).Replace("{installationPath}", installationPath);
1089+
File.WriteAllText(bashFile, bash);
1090+
1091+
// Set execute attr in Linux/Mac
1092+
if (CurrentOperatingSystem != OperatingSystems.Windows)
1093+
{
1094+
var process = new Process();
1095+
process.StartInfo.FileName = "chmod";
1096+
process.StartInfo.ArgumentList.Add("+x");
1097+
process.StartInfo.ArgumentList.Add(bashFile);
1098+
process.StartInfo.RedirectStandardOutput = true;
1099+
process.StartInfo.RedirectStandardError = true;
1100+
process.StartInfo.UseShellExecute = false;
1101+
process.Start();
1102+
process.WaitForExit();
1103+
}
1104+
1105+
// Run batch/bash file
1106+
{
1107+
ProcessStartInfo psi = new ProcessStartInfo
1108+
{
1109+
FileName = bashFile,
1110+
WorkingDirectory = Path.Combine(GeneralConfig.BasePath, "downloads"),
1111+
UseShellExecute = true,
1112+
};
1113+
var p = new Process { StartInfo = psi };
1114+
p.Start();
1115+
}
1116+
1117+
// Exit app
1118+
ExitApp();
1119+
}
1120+
1121+
catch (Exception ex)
1122+
{
1123+
HideStatusPanel();
1124+
ShowMessage($"Error installing ZXBSInstaller\r\n{ex.Message}\r\n{ex.StackTrace}");
1125+
}
1126+
}
1127+
1128+
10231129
private static void ExtractFile(string archive, string destination)
10241130
{
10251131
if (archive.ToLower().EndsWith(".zip"))
@@ -1053,37 +1159,6 @@ private static void ExtractFile(string archive, string destination)
10531159
return;
10541160
}
10551161
}
1056-
//if (archive.ToLower().EndsWith(".tar.gz"))
1057-
//{
1058-
// Directory.CreateDirectory(destination);
1059-
1060-
// using var fileStream = File.OpenRead(archive);
1061-
// using var gzipStream = new GZipStream(fileStream, CompressionMode.Decompress);
1062-
// using var tarReader = new TarReader(gzipStream);
1063-
1064-
// TarEntry? entry;
1065-
// while ((entry = tarReader.GetNextEntry()) != null)
1066-
// {
1067-
// string fullPath = Path.Combine(destination, entry.Name);
1068-
1069-
// if (entry.EntryType == TarEntryType.Directory)
1070-
// {
1071-
// Directory.CreateDirectory(fullPath);
1072-
// }
1073-
// else
1074-
// {
1075-
// Directory.CreateDirectory(Path.GetDirectoryName(fullPath)!);
1076-
// if (entry.Length == 0)
1077-
// {
1078-
// File.WriteAllBytes(fullPath, new byte[0]);
1079-
// }
1080-
// else
1081-
// {
1082-
// entry.DataStream!.CopyTo(File.Create(fullPath));
1083-
// }
1084-
// }
1085-
// }
1086-
//}
10871162
}
10881163

10891164

ZXBSInstaller/Controls/MainControl.axaml.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ private void MainControl_Loaded(object? sender, RoutedEventArgs e)
4444

4545
private void Initialize()
4646
{
47-
ServiceLayer.Initialize(ShowStatusPanel, UpdateStatus, HideStatusPanel, GetExternalTools, ShowMessage);
47+
ServiceLayer.Initialize(ShowStatusPanel, UpdateStatus, HideStatusPanel, GetExternalTools, ShowMessage, ExitApp);
4848

4949
Dispatcher.UIThread.Post(() =>
5050
{
@@ -372,16 +372,23 @@ private void Versions_Close(object? sender, RoutedEventArgs e)
372372

373373
private void btnPlayZXBS_Click(object? sender, RoutedEventArgs e)
374374
{
375-
if (ServiceLayer.RunZXBasicStudio())
375+
ExitApp();
376+
}
377+
378+
379+
private void ExitApp()
380+
{
381+
Dispatcher.UIThread.Post(() =>
376382
{
377383
if (App.Current?.ApplicationLifetime
378384
is IClassicDesktopStyleApplicationLifetime desktop)
379385
{
380386
desktop.Shutdown();
381387
}
382-
}
388+
});
383389
}
384390

391+
385392
private void btnRefresh_Click(object? sender, RoutedEventArgs e)
386393
{
387394
new Thread(GetExternalTools).Start();

ZXBSInstaller/Controls/VersionControl.axaml.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,20 @@ public VersionControl(ExternalTool tool, ExternalTools_Version toolVersion, Acti
5959
txtPlatform.Foreground = ColorGreen;
6060
txtStatus.Foreground = ColorGreen;
6161
txtVersion.Foreground = ColorGreen;
62-
}
62+
}
63+
if (ServiceLayer.CurrentOperatingSystem == OperatingSystems.MacOS_arm64 ||
64+
ServiceLayer.CurrentOperatingSystem == OperatingSystems.MacOS_x64)
65+
{
66+
if(toolVersion.OperatingSystem== OperatingSystems.MacOS_arm64 ||
67+
toolVersion.OperatingSystem == OperatingSystems.MacOS_x64 ||
68+
toolVersion.OperatingSystem == OperatingSystems.MacOS)
69+
{
70+
btnDownload.Foreground = ColorGreen;
71+
txtPlatform.Foreground = ColorGreen;
72+
txtStatus.Foreground = ColorGreen;
73+
txtVersion.Foreground = ColorGreen;
74+
}
75+
}
6376
}
6477
}
6578

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>0.0.1.7</Version>
9+
<Version>1.0.0.1</Version>
1010
</PropertyGroup>
1111
<ItemGroup>
1212
<None Remove="Assets\install.svg" />

0 commit comments

Comments
 (0)