New method in archive manager and shortcut on exit command
This commit is contained in:
@@ -10,7 +10,7 @@ public class Exit : ICommandAction
|
|||||||
{
|
{
|
||||||
public string ActionName => "exit";
|
public string ActionName => "exit";
|
||||||
public string Description => "Exits the bot and saves the config. Use exit help for more info.";
|
public string Description => "Exits the bot and saves the config. Use exit help for more info.";
|
||||||
public string Usage => "exit [help|force]";
|
public string Usage => "exit [help|force (-f)]";
|
||||||
public InternalActionRunType RunType => InternalActionRunType.ON_CALL;
|
public InternalActionRunType RunType => InternalActionRunType.ON_CALL;
|
||||||
|
|
||||||
public async Task Execute(string[] args)
|
public async Task Execute(string[] args)
|
||||||
@@ -29,9 +29,10 @@ public class Exit : ICommandAction
|
|||||||
case "help":
|
case "help":
|
||||||
Console.WriteLine("Usage : exit [help|force]");
|
Console.WriteLine("Usage : exit [help|force]");
|
||||||
Console.WriteLine("help : Displays this message");
|
Console.WriteLine("help : Displays this message");
|
||||||
Console.WriteLine("force : Exits the bot without saving the config");
|
Console.WriteLine("force | -f : Exits the bot without saving the config");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "-f":
|
||||||
case "force":
|
case "force":
|
||||||
Config.Logger.Log("Exiting (FORCE)...", "Exit", LogLevel.WARNING, false);
|
Config.Logger.Log("Exiting (FORCE)...", "Exit", LogLevel.WARNING, false);
|
||||||
Environment.Exit(0);
|
Environment.Exit(0);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Runtime.Serialization.Formatters.Binary;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace PluginManager.Others;
|
namespace PluginManager.Others;
|
||||||
@@ -23,6 +24,41 @@ public static class ArchiveManager
|
|||||||
isInitialized = true;
|
isInitialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Read a file from a zip archive. The output is a byte array
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="fileName">The file name in the archive</param>
|
||||||
|
/// <param name="archName">The archive location on the disk</param>
|
||||||
|
/// <returns>An array of bytes that represents the Stream value from the file that was read inside the archive</returns>
|
||||||
|
public async static Task<byte[]?> ReadStreamFromPakAsync(string fileName, string archName)
|
||||||
|
{
|
||||||
|
if (!isInitialized) throw new Exception("ArchiveManager is not initialized");
|
||||||
|
|
||||||
|
archName = archiveFolder + archName;
|
||||||
|
|
||||||
|
if (!File.Exists(archName))
|
||||||
|
throw new Exception("Failed to load file !");
|
||||||
|
|
||||||
|
byte[]? data = null;
|
||||||
|
|
||||||
|
using (var zip = ZipFile.OpenRead(archName))
|
||||||
|
{
|
||||||
|
var entry = zip.Entries.FirstOrDefault(entry => entry.FullName == fileName || entry.Name == fileName);
|
||||||
|
if (entry is null) throw new Exception("File not found in archive");
|
||||||
|
|
||||||
|
var MemoryStream = new MemoryStream();
|
||||||
|
|
||||||
|
var stream = entry.Open();
|
||||||
|
await stream.CopyToAsync(MemoryStream);
|
||||||
|
data = MemoryStream.ToArray();
|
||||||
|
|
||||||
|
stream.Close();
|
||||||
|
MemoryStream.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Read data from a file that is inside an archive (ZIP format)
|
/// Read data from a file that is inside an archive (ZIP format)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user