74 lines
2.1 KiB
C#
Raw Normal View History

2025-02-21 13:13:35 +03:00
using System.IO.Compression;
using System;
using System.IO;
using SharpCompress.Archives;
using SharpCompress.Common;
using SharpCompress.Readers;
using System.Diagnostics;
using CmlLib.Core;
namespace BlightFlame
{
static public class Utils
{
public static void UnzipTarGzFile(string filePath, string destinationPath)
{
using (Stream stream = File.OpenRead(filePath))
{
using (var reader = ReaderFactory.Open(stream))
{
while (reader.MoveToNextEntry())
{
if (!reader.Entry.IsDirectory)
{
reader.WriteEntryToDirectory(destinationPath, new ExtractionOptions()
{
ExtractFullPath = true,
Overwrite = true
});
}
}
}
}
}
public static void LinuxExec(string cmd)
{
var escapedArgs = cmd.Replace("\"", "\\\"");
using var process = new Process
{
StartInfo = new ProcessStartInfo
{
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden,
FileName = "/bin/bash",
Arguments = $"-c \"{escapedArgs}\""
}
};
process.Start();
process.WaitForExit();
}
public static async Task<List<string>> GetAllMcVersions()
{
return await Task.Run(async() => {
var ln = new MinecraftLauncher();
var result = new List<string>();
foreach (var x in await ln.GetAllVersionsAsync())
{
result.Add(x.Name);
}
return result;
});
}
}
}