Added an extraction module, among one other thing.
This commit is contained in:
parent
f95e3a89ff
commit
506892b6e0
@ -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<string> files = new(GetAllFiles(absSource)),
|
||||
relative = new();
|
||||
|
||||
26
SrcMod/Shell/Modules/ExtractionModule.cs
Normal file
26
SrcMod/Shell/Modules/ExtractionModule.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user