diff --git a/SrcMod/Shell/Modules/CompressionModule.cs b/SrcMod/Shell/Modules/CompressionModule.cs index d009282..21aecfc 100644 --- a/SrcMod/Shell/Modules/CompressionModule.cs +++ b/SrcMod/Shell/Modules/CompressionModule.cs @@ -20,10 +20,8 @@ public static class CompressionModule Write(message); Stream writer = new FileStream(destination, FileMode.CreateNew); - ZipArchive archive = new(writer, ZipArchiveMode.Create) - { - Comment = comment - }; + ZipArchive archive = new(writer, ZipArchiveMode.Create); + if (!string.IsNullOrWhiteSpace(comment)) archive.Comment = comment; archive.CreateEntryFromFile(absSource, Path.GetFileName(absSource), level); @@ -42,6 +40,7 @@ public static class CompressionModule Stream writer = new FileStream(destination, FileMode.CreateNew); ZipArchive archive = new(writer, ZipArchiveMode.Create); + if (!string.IsNullOrWhiteSpace(comment)) archive.Comment = comment; List files = new(GetAllFiles(absSource)), relative = new(); diff --git a/SrcMod/Shell/Modules/ExtractionModule.cs b/SrcMod/Shell/Modules/ExtractionModule.cs new file mode 100644 index 0000000..2eb82a2 --- /dev/null +++ b/SrcMod/Shell/Modules/ExtractionModule.cs @@ -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(); + } +} diff --git a/SrcMod/Shell/Shell.cs b/SrcMod/Shell/Shell.cs index 0ea44b3..7275078 100644 --- a/SrcMod/Shell/Shell.cs +++ b/SrcMod/Shell/Shell.cs @@ -4,7 +4,7 @@ public class Shell { public const string Author = "That_One_Nerd"; 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;