diff --git a/SrcMod/Shell/GlobalUsings.cs b/SrcMod/Shell/GlobalUsings.cs index c3222e5..56f20a3 100644 --- a/SrcMod/Shell/GlobalUsings.cs +++ b/SrcMod/Shell/GlobalUsings.cs @@ -1,4 +1,6 @@ global using Nerd_STF.Mathematics; +global using SharpCompress.Archives.SevenZip; +global using SharpCompress.Readers; global using SrcMod.Shell; global using SrcMod.Shell.Modules.ObjectModels; global using System; diff --git a/SrcMod/Shell/Modules/CompressionModule.cs b/SrcMod/Shell/Modules/CompressionModule.cs index 043e653..7415870 100644 --- a/SrcMod/Shell/Modules/CompressionModule.cs +++ b/SrcMod/Shell/Modules/CompressionModule.cs @@ -1,8 +1,9 @@ -using System.Reflection.Emit; -using System.Xml.Linq; - -namespace SrcMod.Shell.Modules; +namespace SrcMod.Shell.Modules; +// Some things that can be extracted can't be compressed by SharpCompress. +// In the future I might replace it with my own, but that'll take a *really* +// long time and I'm already planning to do that for the valve compression formats, +// so I'll seethe for now. [Module("compress")] public static class CompressionModule { @@ -228,4 +229,6 @@ public static class CompressionModule name = $"Compressed a file or folder into a zip archive located at \"{destination}\"" }); } + + // 7z can't be compressed. } diff --git a/SrcMod/Shell/Modules/ExtractionModule.cs b/SrcMod/Shell/Modules/ExtractionModule.cs index a7d8bc7..1a6285b 100644 --- a/SrcMod/Shell/Modules/ExtractionModule.cs +++ b/SrcMod/Shell/Modules/ExtractionModule.cs @@ -114,4 +114,32 @@ public static class ExtractionModule zip.Dispose(); reader.Dispose(); } + + [Command("7z")] + [Command("7zip")] + [Command("sevenzip")] + public static void Extract7Zip(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); + SevenZipArchive zip = SevenZipArchive.Open(source); + + IReader data = zip.ExtractAllEntries(); + data.WriteAllToDirectory(destination); + + zip.Dispose(); + reader.Dispose(); + } } diff --git a/SrcMod/Shell/Shell.cs b/SrcMod/Shell/Shell.cs index 3388eca..e62b406 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.3"; + public const string Version = "Alpha 0.3.0"; public readonly string? ShellDirectory; diff --git a/SrcMod/Shell/Shell.csproj b/SrcMod/Shell/Shell.csproj index 511ed2f..d662f45 100644 --- a/SrcMod/Shell/Shell.csproj +++ b/SrcMod/Shell/Shell.csproj @@ -31,6 +31,7 @@ +