Added an extraction module, among one other thing.

This commit is contained in:
That_One_Nerd 2023-03-29 10:39:11 -04:00
parent f95e3a89ff
commit 506892b6e0
3 changed files with 30 additions and 5 deletions

View File

@ -20,10 +20,8 @@ public static class CompressionModule
Write(message); Write(message);
Stream writer = new FileStream(destination, FileMode.CreateNew); Stream writer = new FileStream(destination, FileMode.CreateNew);
ZipArchive archive = new(writer, ZipArchiveMode.Create) ZipArchive archive = new(writer, ZipArchiveMode.Create);
{ if (!string.IsNullOrWhiteSpace(comment)) archive.Comment = comment;
Comment = comment
};
archive.CreateEntryFromFile(absSource, Path.GetFileName(absSource), level); archive.CreateEntryFromFile(absSource, Path.GetFileName(absSource), level);
@ -42,6 +40,7 @@ public static class CompressionModule
Stream writer = new FileStream(destination, FileMode.CreateNew); Stream writer = new FileStream(destination, FileMode.CreateNew);
ZipArchive archive = new(writer, ZipArchiveMode.Create); ZipArchive archive = new(writer, ZipArchiveMode.Create);
if (!string.IsNullOrWhiteSpace(comment)) archive.Comment = comment;
List<string> files = new(GetAllFiles(absSource)), List<string> files = new(GetAllFiles(absSource)),
relative = new(); relative = new();

View File

@ -0,0 +1,26 @@
namespace SrcMod.Shell.Modules;
[Module("extract")]
public static class ExtractionModule
{
[Command("zip")]
public static void ExtractZip(string source, string? destination = null)
{
if (!File.Exists(source)) throw new($"No file exists at \"{source}\".");
destination ??= Path.GetDirectoryName(Path.GetFullPath(source));
if (destination is null) throw new("Error detecting destination path.");
if (!Directory.Exists(destination)) Directory.CreateDirectory(destination);
FileStream reader = new(source, FileMode.Open);
ZipArchive zip = new(reader, ZipArchiveMode.Read);
if (!string.IsNullOrWhiteSpace(zip.Comment)) Write(zip.Comment);
zip.ExtractToDirectory(destination, true);
zip.Dispose();
reader.Dispose();
}
}

View File

@ -4,7 +4,7 @@ public class Shell
{ {
public const string Author = "That_One_Nerd"; public const string Author = "That_One_Nerd";
public const string Name = "SrcMod"; public const string Name = "SrcMod";
public const string Version = "Alpha 0.2.2"; public const string Version = "Alpha 0.3.0";
public readonly string? ShellDirectory; public readonly string? ShellDirectory;