Skip to content

Commit

Permalink
Remove installers sdk archive when archive fails
Browse files Browse the repository at this point in the history
This will allow the next run to redownload the file.
  • Loading branch information
SignatureBeef committed Nov 24, 2022
1 parent 403677f commit e561158
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions TShockInstaller/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using ICSharpCode.SharpZipLib.GZip;
using ICSharpCode.SharpZipLib.Tar;

Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine($"TShock Installer {typeof(Program).Assembly.GetName().Version}.");

// reference: https://github.com/dotnet/install-scripts/blob/main/src/dotnet-install.sh
Expand Down Expand Up @@ -65,23 +66,37 @@

if (!File.Exists(dotnet_path))
{
Console.WriteLine("Extracting to ./dotnet/");
if (is_targz)
try
{
using var srm_dotnet_file = File.OpenRead(filename);
using var srm_gzip = new GZipInputStream(srm_dotnet_file);

using var tar_archive = TarArchive.CreateInputTarArchive(srm_gzip, System.Text.Encoding.UTF8);
tar_archive.ExtractContents("dotnet");

[DllImport("libc", SetLastError = true)]
static extern int chmod(string pathname, int mode);

chmod(dotnet_path, 755);
Console.WriteLine("Extracting to ./dotnet/");
if (is_targz)
{
using var srm_dotnet_file = File.OpenRead(filename);
using var srm_gzip = new GZipInputStream(srm_dotnet_file);

using var tar_archive = TarArchive.CreateInputTarArchive(srm_gzip, System.Text.Encoding.UTF8);
tar_archive.ExtractContents("dotnet");

[DllImport("libc", SetLastError = true)]
static extern int chmod(string pathname, int mode);

chmod(dotnet_path, 755);
}
else
{
ZipFile.ExtractToDirectory(filename, "dotnet");
}
}
else
catch (Exception ex)
{
ZipFile.ExtractToDirectory(filename, "dotnet");
Console.ForegroundColor = ConsoleColor.Red;
Console.Error.WriteLine($"Failed to extract {filename}. The archive will be removed. Restart the installer to begin the download again.");
Console.Error.WriteLine(ex);

if (File.Exists(filename))
File.Delete(filename);

return;
}
}
else
Expand Down

0 comments on commit e561158

Please sign in to comment.