diff --git a/SrcMod/Shell/Modules/ExtractionModule.cs b/SrcMod/Shell/Modules/ExtractionModule.cs index ef342cc..e06d826 100644 --- a/SrcMod/Shell/Modules/ExtractionModule.cs +++ b/SrcMod/Shell/Modules/ExtractionModule.cs @@ -50,10 +50,59 @@ public static class ExtractionModule writer.Close(); Console.CursorLeft = 0; - Console.CursorTop -= (message.Length / Console.BufferWidth) + 2; + Console.CursorTop -= (message.Length / Console.BufferWidth) + 1; + if (Console.CursorTop >= Console.BufferHeight - 3) Console.CursorTop--; Write(new string(' ', message.Length), newLine: false); } + [Command("tar")] + [Command("tarball")] + public static void ExtractTar(string source, string? destination = null) + { + if (!File.Exists(source)) throw new($"No file exists at \"{source}\"."); + + if (destination is null) + { + string full = Path.GetFullPath(source); + string folder = Program.Shell!.WorkingDirectory; + string name = Path.GetFileNameWithoutExtension(full); + + destination = $"{folder}\\{name}"; + } + + if (!Directory.Exists(destination)) Directory.CreateDirectory(destination); + + FileStream reader = new(source, FileMode.Open); + TarFile.ExtractToDirectory(reader, Path.GetFileName(destination), true); + + reader.Dispose(); + } + + [Command("targz")] + [Command("tar.gz")] + [Command("tar-gz")] + public static void ExtractTarGz(string source, string? destination = null) + { + if (!File.Exists(source)) throw new($"No file exists at \"{source}\"."); + + if (destination is null) + { + string full = Path.GetFullPath(source); + string folder = Program.Shell!.WorkingDirectory; + string name = Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(full)); + + destination = $"{folder}\\{name}"; + } + + string absSource = Path.GetFullPath(source), + temp = Path.Combine(Path.GetDirectoryName(absSource)!, Path.GetFileNameWithoutExtension(absSource)); + + ExtractGZip(source, temp); + ExtractTar(temp, destination); + + File.Delete(temp); + } + [Command("zip")] public static void ExtractZip(string source, string? destination = null) {