Skip to content

Commit 66640d2

Browse files
author
Juan Segura
committed
Bug in .tat.gz unpacking
1 parent 08d263d commit 66640d2

2 files changed

Lines changed: 73 additions & 4 deletions

File tree

ZXBSInstaller.Log/ServiceLayer.cs

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using Microsoft.VisualBasic;
22
using System;
33
using System.Diagnostics;
4+
using System.Formats.Tar;
45
using System.IO;
6+
using System.IO.Compression;
57
using System.Reflection;
68
using System.Reflection.Metadata.Ecma335;
79
using System.Runtime;
@@ -822,7 +824,7 @@ private static ExternalTools_Version GetBorielBasicVersion(string exePath)
822824
var v = GetVersionNumber(version);
823825
int number = v.Item1;
824826
int beta = v.Item2;
825-
827+
826828
return new ExternalTools_Version()
827829
{
828830
DownloadUrl = "",
@@ -990,7 +992,7 @@ public static void DownloadAndInstallTool(ExternalTool tool, ExternalTools_Versi
990992
// Extract file
991993
step = $"Installing {tool.Name}";
992994
UpdateStatus($"Installing {tool.Name} version {version.Version}...", 50);
993-
System.IO.Compression.ZipFile.ExtractToDirectory(tempFile, installationPath, true);
995+
ExtractFile(tempFile, installationPath);
994996

995997
// Set ZXBS Options
996998
step = "Set ZX Basic Studio options";
@@ -1012,6 +1014,73 @@ public static void DownloadAndInstallTool(ExternalTool tool, ExternalTools_Versi
10121014
}
10131015

10141016

1017+
private static void ExtractFile(string archive, string destination)
1018+
{
1019+
if (archive.ToLower().EndsWith(".zip"))
1020+
{
1021+
System.IO.Compression.ZipFile.ExtractToDirectory(archive, destination, true);
1022+
}
1023+
else if (CurrentOperatingSystem != OperatingSystems.Windows)
1024+
{
1025+
Directory.CreateDirectory(destination);
1026+
1027+
var psi = new ProcessStartInfo
1028+
{
1029+
FileName = "tar",
1030+
Arguments = $"-xzf \"{archive}\" -C \"{destination}\"",
1031+
RedirectStandardOutput = true,
1032+
RedirectStandardError = true,
1033+
UseShellExecute = false,
1034+
CreateNoWindow = true
1035+
};
1036+
1037+
using var process = Process.Start(psi)!;
1038+
1039+
string stdout = process.StandardOutput.ReadToEnd();
1040+
string stderr = process.StandardError.ReadToEnd();
1041+
1042+
process.WaitForExit();
1043+
1044+
if (process.ExitCode != 0)
1045+
{
1046+
ShowMessage($"Error unpacking file {archive}\r\n{stderr}");
1047+
return;
1048+
}
1049+
}
1050+
//if (archive.ToLower().EndsWith(".tar.gz"))
1051+
//{
1052+
// Directory.CreateDirectory(destination);
1053+
1054+
// using var fileStream = File.OpenRead(archive);
1055+
// using var gzipStream = new GZipStream(fileStream, CompressionMode.Decompress);
1056+
// using var tarReader = new TarReader(gzipStream);
1057+
1058+
// TarEntry? entry;
1059+
// while ((entry = tarReader.GetNextEntry()) != null)
1060+
// {
1061+
// string fullPath = Path.Combine(destination, entry.Name);
1062+
1063+
// if (entry.EntryType == TarEntryType.Directory)
1064+
// {
1065+
// Directory.CreateDirectory(fullPath);
1066+
// }
1067+
// else
1068+
// {
1069+
// Directory.CreateDirectory(Path.GetDirectoryName(fullPath)!);
1070+
// if (entry.Length == 0)
1071+
// {
1072+
// File.WriteAllBytes(fullPath, new byte[0]);
1073+
// }
1074+
// else
1075+
// {
1076+
// entry.DataStream!.CopyTo(File.Create(fullPath));
1077+
// }
1078+
// }
1079+
// }
1080+
//}
1081+
}
1082+
1083+
10151084
private static void SetZXBSConfig()
10161085
{
10171086
try
@@ -1049,7 +1118,7 @@ private static void SetZXBSConfig()
10491118
{
10501119
exe += ".exe";
10511120
}
1052-
var dir = Path.Combine(GeneralConfig.BasePath, "zxbasic", exe).Replace("\\","\\\\");
1121+
var dir = Path.Combine(GeneralConfig.BasePath, "zxbasic", exe).Replace("\\", "\\\\");
10531122
line = $" \"ZxbasmPath\": \"{dir}\",";
10541123
}
10551124
else if (line.Contains("ZxbcPath"))

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.2</Version>
9+
<Version>0.0.1.5</Version>
1010
</PropertyGroup>
1111
<ItemGroup>
1212
<AvaloniaResource Include="zxbs.ico" />

0 commit comments

Comments
 (0)