BadScript 2
Loading...
Searching...
No Matches
BadFileSystemStack.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.IO.Compression;
4using System.Threading.Tasks;
5using BadScript2.IO;
8using Newtonsoft.Json.Linq;
9
11{
12 public class BadFileSystemStack
13 {
14
15 public static async Task<BadFileSystemStack> FromConfigs(params BadFileSystemStackConfig[] configs)
16 {
17 var stack = new BadFileSystemStack();
18 foreach (var config in configs)
19 {
20 if (config.Type == "Directory")
21 {
22 stack.FromDirectory(config.Source, config.Target ?? "/", config.Name);
23 }
24 else if (config.Type == "Zip")
25 {
26 stack.FromZip(config.Source, config.Target ?? "/", config.Name);
27 }
28 else if (config.Type == "Web")
29 {
30 await stack.FromWebArchive(config.Source, config.Target ?? "/", config.Name);
31 }
32 }
33
34 return stack;
35 }
36
37 private readonly List<Func<BadLayeredFileSystemLayer>> m_FileSystemConfigs = new List<Func<BadLayeredFileSystemLayer>>();
38
39 public BadFileSystemStack ConfigureLayer(Func<BadLayeredFileSystemLayer> config)
40 {
41 m_FileSystemConfigs.Add(config);
42 return this;
43 }
44
45 public BadLayeredFileSystem Create(bool createWritable = false)
46 {
47 var fileSystems = new List<BadLayeredFileSystemLayer>();
48 foreach (var config in m_FileSystemConfigs) fileSystems.Add(config());
49
50 if(!createWritable)
51 fileSystems.Add(new BadLayeredFileSystemLayer
52 {
53 Name = "Writable Layer",
54 FileSystem = new BadVirtualFileSystem(),
55 MetaData = new JObject
56 {
57 ["AutoCreated"] = true
58 }
59 });
60
61 var fs= new BadLayeredFileSystem(fileSystems.ToArray());
62
63 fs.SetCurrentDirectory("/");
64 return fs;
65 }
66 }
67}
BadFileSystemStack ConfigureLayer(Func< BadLayeredFileSystemLayer > config)
BadLayeredFileSystem Create(bool createWritable=false)
static async Task< BadFileSystemStack > FromConfigs(params BadFileSystemStackConfig[] configs)
readonly List< Func< BadLayeredFileSystemLayer > > m_FileSystemConfigs
Virtual File System Implementation for the BadScript Engine.
Contains the Implementation of the BadScript Virtual File System.
Contains IO Implementation for the BadScript2 Runtime.
Contains Runtime Settings Objects.