1using System.IO.Compression;
26 throw new NotSupportedException(
"Only virtual file systems are supported");
29 using ZipArchive zip =
new ZipArchive(str, ZipArchiveMode.Update,
true);
31 foreach (
string file
in vfs.GetFiles(path,
"",
true))
34 ZipArchiveEntry e = zip.CreateEntry(file.Remove(0, path.Length));
35 using Stream estr = e.Open();
36 using Stream fstr = vfs.OpenRead(file);
43 using FileStream str =
new FileStream(path, FileMode.Open, FileAccess.Read);
44 fs.ImportZip(str, root);
55 public static void ImportZip(
this IFileSystem fs, Stream str,
string root =
"/", Encoding? encoding =
null)
61 throw new NotSupportedException(
"Only virtual file systems are supported");
64 ZipArchive? arch =
new ZipArchive(str, ZipArchiveMode.Read,
false, encoding ?? Encoding.UTF8);
68 throw new Exception(
"Failed to open zip file");
71 foreach (ZipArchiveEntry entry
in arch.Entries)
73 BadLogger.
Log(
"Importing File: " + entry.FullName,
"BFS");
80 string? dir = Path.GetDirectoryName(entry.FullName);
82 if (dir !=
null && !
string.IsNullOrEmpty(dir))
84 vfs.CreateDirectory(root + dir,
true);
87 using Stream s = entry.Open();
88 using Stream o = vfs.OpenWrite(root + entry.FullName,
BadWriteMode.CreateNew);
Public facing interface for a logger.
static void Log(string message)
Writes a Log to the Message Handler.
File System Helper Extensions.
static void ExportZip(this IFileSystem fs, Stream str, string path="/")
Exports a Virtual File System to a Zip File.
static void ImportZip(this IFileSystem fs, Stream str, string root="/", Encoding? encoding=null)
Imports a Zip File to a Virtual File System.
static void ImportZip(this IFileSystem fs, string path, string root="/")
Virtual File System Implementation for the BadScript Engine.
Implements Operations to read and manipulate File System Paths.
static bool IsDirectory(string path)
Defines the interface for a file system.
Contains Logging system for the BadScript Runtime.
Contains the Implementation of the BadScript Virtual File System.
Contains IO Implementation for the BadScript2 Runtime.
BadWriteMode
The Write Modes of the File System Abstraction.