Update main with some new compression formats. #37

Merged
That-One-Nerd merged 11 commits from more-compression-options into main 2023-03-31 11:02:30 -04:00
3 changed files with 34 additions and 0 deletions
Showing only changes of commit 559190158a - Show all commits

View File

@ -1,4 +1,5 @@
global using Nerd_STF.Mathematics;
global using SharpCompress.Archives.Rar;
global using SharpCompress.Archives.SevenZip;
global using SharpCompress.Readers;
global using SrcMod.Shell;

View File

@ -82,6 +82,8 @@ public static class CompressionModule
else throw new("No file or directory located at \"source\"");
}
// Rar can't be compressed.
[Command("targz")]
[Command("tar.gz")]
[Command("tar-gz")]

View File

@ -40,6 +40,37 @@ public static class ExtractionModule
Write(new string(' ', message.Length), newLine: false);
}
[Command("rar")]
public static void ExtractRar(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);
RarArchive rar = RarArchive.Open(reader);
IReader data = rar.ExtractAllEntries();
data.WriteAllToDirectory(destination, new()
{
ExtractFullPath = true,
Overwrite = true,
PreserveFileTime = true
});
rar.Dispose();
reader.Dispose();
}
[Command("tar")]
[Command("tarball")]
public static void ExtractTar(string source, string? destination = null)