Maybe 7Zip extraction? I haven't tested it.

This commit is contained in:
That_One_Nerd 2023-03-30 14:09:25 -04:00
parent 33130bc5f8
commit 471bb54fe0
5 changed files with 39 additions and 5 deletions

View File

@ -1,4 +1,6 @@
global using Nerd_STF.Mathematics; global using Nerd_STF.Mathematics;
global using SharpCompress.Archives.SevenZip;
global using SharpCompress.Readers;
global using SrcMod.Shell; global using SrcMod.Shell;
global using SrcMod.Shell.Modules.ObjectModels; global using SrcMod.Shell.Modules.ObjectModels;
global using System; global using System;

View File

@ -1,8 +1,9 @@
using System.Reflection.Emit; namespace SrcMod.Shell.Modules;
using System.Xml.Linq;
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")] [Module("compress")]
public static class CompressionModule 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}\"" name = $"Compressed a file or folder into a zip archive located at \"{destination}\""
}); });
} }
// 7z can't be compressed.
} }

View File

@ -114,4 +114,32 @@ public static class ExtractionModule
zip.Dispose(); zip.Dispose();
reader.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();
}
} }

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.3"; public const string Version = "Alpha 0.3.0";
public readonly string? ShellDirectory; public readonly string? ShellDirectory;

View File

@ -31,6 +31,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Nerd_STF" Version="2.3.2" /> <PackageReference Include="Nerd_STF" Version="2.3.2" />
<PackageReference Include="SharpCompress" Version="0.33.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>