diff --git a/Standards/CCSMB-X.md b/Standards/CCSMB-X.md new file mode 100644 index 0000000..3edc038 --- /dev/null +++ b/Standards/CCSMB-X.md @@ -0,0 +1,62 @@ +# CCSMB-X: Virtual File System Archive + +*Author: walksanator (Walker Fowlkes)* + +*Version: 1.0.* + +*Last revised: 2023-01-DD* + +## Quick information + +| Information | | +| ----------- | -----------------------------| +| Version | 1.0.9 | +| Author | walksanator (Walker Fowlkes) | +| Type | Virtual File System Archive | +| MIME | `appilcation/vfs` | +| Extensions | `.vfs` | + +## Technical details + +The VFS file format is a text-based format that represents folder(s) as a Lua table +where the keys of the table are used as file names and values are used for contents. +Directories in VFS are tables, whereas files have their contents embedded as strings. +VFS files should be read and written in binary mode as to prevent converting binary characters to `?`. +VFS archives do not store metadata, programs that need things like modification times will need to seek a alternative. + +## Examples + +A example function that takes a directory and turns it into a VFS could be implemented as. +```lua +local function gen_disk(path) --takes a path to turn into a table + local pth = fs.getName(path) --get the file name + local tree = {} --create a empty tree + for _,v in pairs(fs.list(path)) do --itterate + if fs.isDir(path.."/"..v) then --if it is a dir + tree[v] = gen_disk(path.."/"..v) --call this function on that directory + else-- it is a file + local chandle = fs.open(path.."/"..v,'rb') --read all contents and add to the VFS + tree[v] = chandle.readAll() + chandle.close() + end + end + return tree --return the current VFS +end +``` + +Another example function that takes a root to extract to and VFS to extract from. +```lua +function unpack_vfs(path,files) + fs.makeDir(path) --create the directory that files will live in + shell.setDir(path) -- head into the new directory + for k, v in pairs(files) do --itterate over directory contents in VFS + if type(v) == "table" then + unpack_vfs(path.."/"..k,v) --extract folder + elseif type(v) == "string" then + local fh = fs.open(fs.combine(rpath,fs.combine(path,k)),'wb') --extract file + fh.write(v) + fh.close() + end + end +end +``` diff --git a/Standards/CCSMB-X/Example1.vfs b/Standards/CCSMB-X/Example1.vfs new file mode 100644 index 0000000..359f3ee --- /dev/null +++ b/Standards/CCSMB-X/Example1.vfs @@ -0,0 +1,593 @@ +{["dump.txt"]="{\ + _CC_DEFAULT_SETTINGS = \"\",\ + _CC_DISABLE_LUA51_FEATURES = false,\ + _ENV = table: 7fc1f0189050,\ + _G = table: 7fc1f0189050,\ + _HOST = \"ComputerCraft 1.95.2 (orangebox 1.0)\",\ + _VERSION = \"Lua 5.1\",\ + assert = function: 7fc1f000ff80,\ + bit = {\ + band = function: 7fc1f00163f0,\ + blogic_rshift = function: 7fc1f00167b0,\ + blshift = function: 7fc1f0016690,\ + bnot = function: 7fc1f0016450,\ + bor = function: 7fc1f00164b0,\ + brshift = function: 7fc1f0016390,\ + bxor = function: 7fc1f0016510\ + },\ + bit32 = {\ + arshift = function: 7fc1f0016390,\ + band = function: 7fc1f00163f0,\ + bnot = function: 7fc1f0016450,\ + bor = function: 7fc1f00164b0,\ + btest = function: 7fc1f0016570,\ + bxor = function: 7fc1f0016510,\ + extract = function: 7fc1f00165d0,\ + lrotate = function: 7fc1f0016630,\ + lshift = function: 7fc1f0016690,\ + replace = function: 7fc1f00166f0,\ + rrotate = function: 7fc1f0016750,\ + rshift = function: 7fc1f00167b0\ + },\ + colors = {\ + black = 32768,\ + blue = 2048,\ + brown = 4096,\ + combine = function: 7fc1f01f3260,\ + cyan = 512,\ + gray = 128,\ + green = 8192,\ + lightBlue = 8,\ + lightGray = 256,\ + lime = 32,\ + magenta = 4,\ + orange = 2,\ + packRGB = function: 7fc1f006bdf0,\ + pink = 64,\ + purple = 1024,\ + red = 16384,\ + rgb8 = function: 7fc1f017e8e0,\ + subtract = function: 7fc1f0134da0,\ + test = function: 7fc1f0113bc0,\ + toBlit = function: 7fc1f00e11e0,\ + unpackRGB = function: 7fc1f014cff0,\ + white = 1,\ + yellow = 16\ + },\ + colours = {\ + black = 32768,\ + blue = 2048,\ + brown = 4096,\ + combine = function: 7fc1f01f3260,\ + cyan = 512,\ + green = 8192,\ + grey = 128,\ + lightBlue = 8,\ + lightGrey = 256,\ + lime = 32,\ + magenta = 4,\ + orange = 2,\ + packRGB = function: 7fc1f006bdf0,\ + pink = 64,\ + purple = 1024,\ + red = 16384,\ + rgb8 = function: 7fc1f017e8e0,\ + subtract = function: 7fc1f0134da0,\ + test = function: 7fc1f0113bc0,\ + toBlit = function: 7fc1f00e11e0,\ + unpackRGB = function: 7fc1f014cff0,\ + white = 1,\ + yellow = 16\ + },\ + coroutine = {\ + create = function: 7fc1f0011970,\ + resume = function: 7fc1f00119d0,\ + running = function: 7fc1f0011a30,\ + status = function: 7fc1f0011a90,\ + wrap = function: 7fc1f0011af0,\ + yield = function: 7fc1f0011b50\ + },\ + debug = {\ + debug = function: 7fc1f00156a0,\ + getfenv = function: 7fc1f00156d0,\ + gethook = function: 7fc1f0015700,\ + getinfo = function: 7fc1f0015760,\ + getlocal = function: 7fc1f00157c0,\ + getmetatable = function: 7fc1f0015880,\ + getregistry = function: 7fc1f0015820,\ + getupvalue = function: 7fc1f00158b0,\ + setbreakpoint = function: 7fc1f0015910,\ + setfenv = function: 7fc1f0015970,\ + sethook = function: 7fc1f00159a0,\ + setlocal = function: 7fc1f0015a00,\ + setmetatable = function: 7fc1f0015a60,\ + setupvalue = function: 7fc1f0015a90,\ + traceback = function: 7fc1f0015af0,\ + unsetbreakpoint = function: 7fc1f0015b50,\ + upvalueid = function: 7fc1f0015bb0,\ + upvaluejoin = function: 7fc1f0015c10\ + },\ + disk = {\ + eject = function: 7fc1f021a560,\ + getAudioTitle = function: 7fc1f00e1050,\ + getID = function: 7fc1f00e80f0,\ + getLabel = function: 7fc1f0116bc0,\ + getMountPath = function: 7fc1f01eb2a0,\ + hasAudio = function: 7fc1f0106c10,\ + hasData = function: 7fc1f00c6700,\ + insertDisk = function: 7fc1f0188600,\ + isPresent = function: 7fc1f01959f0,\ + playAudio = function: 7fc1f0141fd0,\ + setLabel = function: 7fc1f015e890,\ + stopAudio = function: 7fc1f01ea150\ + },\ + dofile = function: 7fc1f0210e30,\ + error = function: 7fc1f0010150,\ + fs = {\ + attributes = function: 7fc1f0189280,\ + combine = function: 7fc1f00174a0,\ + complete = function: 7fc1f0022c50,\ + copy = function: 7fc1f01adb70,\ + delete = function: 7fc1f01891e0,\ + exists = function: 7fc1f01d2160,\ + find = function: 7fc1f0189230,\ + getCapacity = function: 7fc1f01892e0,\ + getDir = function: 7fc1f0017590,\ + getDrive = function: 7fc1f01890f0,\ + getFreeSpace = function: 7fc1f0189140,\ + getName = function: 7fc1f0016dc0,\ + getSize = function: 7fc1f01066a0,\ + isDir = function: 7fc1f01adb10,\ + isReadOnly = function: 7fc1f01890a0,\ + list = function: 7fc1f01d2050,\ + makeDir = function: 7fc1f0189190,\ + move = function: 7fc1f015d600,\ + open = function: 7fc1f015ee60,\ + sync = function: 7fc1f0141ae0\ + },\ + getfenv = function: 7fc1f018ab80,\ + getmetatable = function: 7fc1f00103c0,\ + gps = {\ + CHANNEL_GPS = 65534,\ + locate = function: 7fc1f01aa470\ + },\ + help = {\ + completeTopic = function: 7fc1f01f7540,\ + lookup = function: 7fc1f01ac0e0,\ + path = function: 7fc1f01348e0,\ + setPath = function: 7fc1f01728e0,\ + topics = function: 7fc1f0196f20\ + },\ + http = {\ + checkURL = function: 7fc1f00146d0,\ + get = function: 7fc1f0038170,\ + post = function: 7fc1f0038220,\ + request = function: 7fc1f0022a90,\ + websocket = function: 7fc1f00147c0\ + },\ + io = {\ + close = function: 7fc1f0211480,\ + flush = function: 7fc1f013eac0,\ + input = function: 7fc1f01ff280,\ + lines = function: 7fc1f01ff300,\ + open = function: 7fc1f01ff340,\ + output = function: 7fc1f0139090,\ + read = function: 7fc1f01eb9f0,\ + stderr = file (7fc1f0171520),\ + stdin = file (7fc1f01e0c40),\ + stdout = file (7fc1f0134a30),\ + type = function: 7fc1f0107730,\ + write = function: 7fc1f0107620\ + },\ + ipairs = function: 7fc1f00116c0,\ + keys = {\ + a = 30,\ + apostrophe = 40,\ + at = 145,\ + ax = 150,\ + b = 48,\ + backslash = 43,\ + backspace = 14,\ + c = 46,\ + capsLock = 58,\ + cimcumflex = 144,\ + circumflex = 144,\ + colon = 146,\ + comma = 51,\ + convert = 121,\ + d = 32,\ + delete = 211,\ + down = 208,\ + e = 18,\ + eight = 9,\ + [\"end\"] = 207,\ + enter = 28,\ + equals = 13,\ + f = 33,\ + f1 = 59,\ + f10 = 68,\ + f11 = 87,\ + f12 = 88,\ + f13 = 100,\ + f14 = 101,\ + f15 = 102,\ + f2 = 60,\ + f3 = 61,\ + f4 = 62,\ + f5 = 63,\ + f6 = 64,\ + f7 = 65,\ + f8 = 66,\ + f9 = 67,\ + five = 6,\ + four = 5,\ + g = 34,\ + getName = function: 7fc1f01ad1f0,\ + grave = 41,\ + h = 35,\ + home = 199,\ + i = 23,\ + insert = 210,\ + j = 36,\ + k = 37,\ + kana = 112,\ + kanji = 148,\ + l = 38,\ + left = 203,\ + leftAlt = 56,\ + leftBracket = 26,\ + leftCtrl = 29,\ + leftShift = 42,\ + m = 50,\ + minus = 12,\ + multiply = 55,\ + n = 49,\ + nine = 10,\ + noconvert = 123,\ + numLock = 69,\ + numPad0 = 82,\ + numPad1 = 79,\ + numPad2 = 80,\ + numPad3 = 81,\ + numPad4 = 75,\ + numPad5 = 76,\ + numPad6 = 77,\ + numPad7 = 71,\ + numPad8 = 72,\ + numPad9 = 73,\ + numPadAdd = 78,\ + numPadComma = 179,\ + numPadDecimal = 83,\ + numPadDivide = 181,\ + numPadEnter = 156,\ + numPadEquals = 141,\ + numPadSubtract = 74,\ + o = 24,\ + one = 2,\ + p = 25,\ + pageDown = 209,\ + pageUp = 201,\ + pause = 197,\ + period = 52,\ + q = 16,\ + r = 19,\ + [\"return\"] = 28,\ + right = 205,\ + rightAlt = 184,\ + rightBracket = 27,\ + rightCtrl = 157,\ + rightShift = 54,\ + s = 31,\ + scollLock = 70,\ + scrollLock = 70,\ + semiColon = 39,\ + seven = 8,\ + six = 7,\ + slash = 53,\ + space = 57,\ + stop = 149,\ + t = 20,\ + tab = 15,\ + three = 4,\ + two = 3,\ + u = 22,\ + underscore = 147,\ + up = 200,\ + v = 47,\ + w = 17,\ + x = 45,\ + y = 21,\ + yen = 125,\ + z = 44,\ + zero = 11\ + },\ + load = function: 7fc1f01aac20,\ + loadfile = function: 7fc1f0210df0,\ + loadstring = function: 7fc1f01aad90,\ + math = {\ + abs = function: 7fc1f0013e80,\ + acos = function: 7fc1f0013ee0,\ + asin = function: 7fc1f0013f40,\ + atan = function: 7fc1f0014000,\ + atan2 = function: 7fc1f0013fa0,\ + ceil = function: 7fc1f0014060,\ + cos = function: 7fc1f0014120,\ + cosh = function: 7fc1f00140c0,\ + deg = function: 7fc1f0014180,\ + exp = function: 7fc1f000fef0,\ + floor = function: 7fc1f000fec0,\ + fmod = function: 7fc1f0012020,\ + frexp = function: 7fc1f0014a50,\ + huge = inf,\ + ldexp = function: 7fc1f0014ab0,\ + log = function: 7fc1f0014b70,\ + log10 = function: 7fc1f0014b10,\ + max = function: 7fc1f0014bd0,\ + min = function: 7fc1f0014c30,\ + mod = function: 7fc1f0012020,\ + modf = function: 7fc1f0014c90,\ + pi = 3.1415926535898,\ + pow = function: 7fc1f0014cf0,\ + rad = function: 7fc1f0014d50,\ + random = function: 7fc1f0014db0,\ + randomseed = function: 7fc1f0014e10,\ + sin = function: 7fc1f0014ed0,\ + sinh = function: 7fc1f0014e70,\ + sqrt = function: 7fc1f0014f30,\ + tan = function: 7fc1f0014ff0,\ + tanh = function: 7fc1f0014f90\ + },\ + next = function: 7fc1f00107d0,\ + os = {\ + cancelAlarm = function: 7fc1f0115690,\ + cancelTimer = function: 7fc1f01896b0,\ + clock = function: 7fc1f0115760,\ + computerID = function: 7fc1f01a6ca0,\ + computerLabel = function: 7fc1f01156e0,\ + date = function: 7fc1f0011cc0,\ + day = function: 7fc1f00182d0,\ + epoch = function: 7fc1f0018270,\ + getComputerID = function: 7fc1f01a6ca0,\ + getComputerLabel = function: 7fc1f01156e0,\ + loadAPI = function: 7fc1f0210eb0,\ + pullEvent = function: 7fc1f0210ce0,\ + pullEventRaw = function: 7fc1f0210cb0,\ + queueEvent = function: 7fc1f01a6670,\ + reboot = function: 7fc1f0211000,\ + run = function: 7fc1f0210e70,\ + setAlarm = function: 7fc1f0115640,\ + setComputerLabel = function: 7fc1f0115720,\ + shutdown = function: 7fc1f0210f90,\ + sleep = function: 7fc1f0210f60,\ + startTimer = function: 7fc1f0189660,\ + time = function: 7fc1f0018240,\ + unloadAPI = function: 7fc1f0210f20,\ + version = function: 7fc1f0210c80\ + },\ + paintutils = {\ + drawBox = function: 7fc1f019eda0,\ + drawFilledBox = function: 7fc1f018a050,\ + drawImage = function: 7fc1f00f3560,\ + drawLine = function: 7fc1f018dea0,\ + drawPixel = function: 7fc1f01ab2f0,\ + loadImage = function: 7fc1f01346b0,\ + parseImage = function: 7fc1f01cd280\ + },\ + pairs = function: 7fc1f0011760,\ + parallel = {\ + waitForAll = function: 7fc1f01b5390,\ + waitForAny = function: 7fc1f0189d30\ + },\ + pcall = function: 7fc1f0010830,\ + peripheral = {\ + call = function: 7fc1f021b200,\ + find = function: 7fc1f01305f0,\ + getMethods = function: 7fc1f01ea5f0,\ + getName = function: 7fc1f00e9e40,\ + getNames = function: 7fc1f0030690,\ + getType = function: 7fc1f010bde0,\ + hasType = function: 7fc1f006b360,\ + isPresent = function: 7fc1f01dd080,\ + wrap = function: 7fc1f01ffc40\ + },\ + print = function: 7fc1f0210d50,\ + printError = function: 7fc1f0210d80,\ + rawequal = function: 7fc1f00108f0,\ + rawget = function: 7fc1f0010950,\ + rawset = function: 7fc1f00109b0,\ + read = function: 7fc1f0210db0,\ + rednet = {\ + CHANNEL_BROADCAST = 65535,\ + CHANNEL_REPEAT = 65533,\ + MAX_ID_CHANNELS = 65500,\ + broadcast = function: 7fc1f01ad0e0,\ + close = function: 7fc1f01a6bc0,\ + host = function: 7fc1f01cf190,\ + isOpen = function: 7fc1f01acf60,\ + lookup = function: 7fc1f0166940,\ + open = function: 7fc1f01cd170,\ + receive = function: 7fc1f006c590,\ + run = function: 7fc1f0136990,\ + send = function: 7fc1f0173260,\ + unhost = function: 7fc1f014a640\ + },\ + redstone = {\ + getAnalogInput = function: 7fc1f019dcb0,\ + getAnalogOutput = function: 7fc1f019dd00,\ + getAnalogueInput = function: 7fc1f019dcb0,\ + getAnalogueOutput = function: 7fc1f019dd00,\ + getBundledInput = function: 7fc1f019dda0,\ + getBundledOutput = function: 7fc1f019ddf0,\ + getInput = function: 7fc1f0115de0,\ + getOutput = function: 7fc1f019dc10,\ + getSides = function: 7fc1f0115da0,\ + setAnalogOutput = function: 7fc1f019dd50,\ + setAnalogueOutput = function: 7fc1f019dd50,\ + setBundledOutput = function: 7fc1f019de40,\ + setOutput = function: 7fc1f019dc60,\ + testBundledInput = function: 7fc1f019de90\ + },\ + rs = {\ + getAnalogInput = function: 7fc1f0019010,\ + getAnalogOutput = function: 7fc1f00191c0,\ + getAnalogueInput = function: 7fc1f0019280,\ + getAnalogueOutput = function: 7fc1f00192f0,\ + getBundledInput = function: 7fc1f00193d0,\ + getBundledOutput = function: 7fc1f0019430,\ + getInput = function: 7fc1f0018e70,\ + getOutput = function: 7fc1f0018e40,\ + getSides = function: 7fc1f0018de0,\ + setAnalogOutput = function: 7fc1f0019220,\ + setAnalogueOutput = function: 7fc1f0019360,\ + setBundledOutput = function: 7fc1f00194a0,\ + setOutput = function: 7fc1f0018fb0,\ + testBundledInput = function: 7fc1f0019510\ + },\ + select = function: 7fc1f0010f20,\ + setfenv = function: 7fc1f0010f80,\ + setmetatable = function: 7fc1f0010fe0,\ + settings = {\ + clear = function: 7fc1f01ad800,\ + define = function: 7fc1f01e04b0,\ + get = function: 7fc1f01ad6d0,\ + getDetails = function: 7fc1f02133e0,\ + getNames = function: 7fc1f01a28a0,\ + load = function: 7fc1f021ab10,\ + save = function: 7fc1f00f13d0,\ + set = function: 7fc1f01e0660,\ + undefine = function: 7fc1f0189bc0,\ + unset = function: 7fc1f006b6f0\ + },\ + sleep = function: 7fc1f010cac0,\ + string = {\ + byte = function: 7fc1f0010a10,\ + char = function: 7fc1f0010a70,\ + dump = function: 7fc1f0010ad0,\ + find = function: 7fc1f0010b30,\ + format = function: 7fc1f0010b90,\ + gfind = function: 7fc1f0010c50,\ + gmatch = function: 7fc1f0010c50,\ + gsub = function: 7fc1f0010cb0,\ + len = function: 7fc1f0010d10,\ + lower = function: 7fc1f0010d70,\ + match = function: 7fc1f0010dd0,\ + pack = function: 7fc1f0010e30,\ + packsize = function: 7fc1f0010e60,\ + rep = function: 7fc1f0010ec0,\ + reverse = function: 7fc1f00136f0,\ + sub = function: 7fc1f0013750,\ + unpack = function: 7fc1f00137b0,\ + upper = function: 7fc1f00137e0\ + },\ + table = {\ + concat = function: 7fc1f0012360,\ + foreach = function: 7fc1f00123c0,\ + foreachi = function: 7fc1f0012420,\ + getn = function: 7fc1f0012480,\ + insert = function: 7fc1f0012540,\ + maxn = function: 7fc1f00124e0,\ + pack = function: 7fc1f0012690,\ + remove = function: 7fc1f00125a0,\ + setn = function: 7fc1f00125d0,\ + sort = function: 7fc1f0012630,\ + unpack = function: 7fc1f00126f0\ + },\ + term = {\ + blit = function: 7fc1f01367a0,\ + clear = function: 7fc1f021a9f0,\ + clearLine = function: 7fc1f00f1410,\ + current = function: 7fc1f015cd50,\ + drawPixels = function: 7fc1f01ac8b0,\ + getBackgroundColor = function: 7fc1f01bd9f0,\ + getBackgroundColour = function: 7fc1f0210380,\ + getCursorBlink = function: 7fc1f0177d60,\ + getCursorPos = function: 7fc1f012f2f0,\ + getFrozen = function: 7fc1f01ddbd0,\ + getGraphicsMode = function: 7fc1f01ab060,\ + getLine = function: 7fc1f015c7e0,\ + getPaletteColor = function: 7fc1f01ae730,\ + getPaletteColour = function: 7fc1f0173350,\ + getPixel = function: 7fc1f01fb2f0,\ + getPixels = function: 7fc1f006d340,\ + getPosition = function: 7fc1f0173c30,\ + getSize = function: 7fc1f01dda80,\ + getTextColor = function: 7fc1f0171850,\ + getTextColour = function: 7fc1f0127120,\ + isColor = function: 7fc1f019fa70,\ + isColour = function: 7fc1f01780e0,\ + isVisible = function: 7fc1f0189f60,\ + native = function: 7fc1f012be10,\ + nativePaletteColor = function: 7fc1f001b0c0,\ + nativePaletteColour = function: 7fc1f001b130,\ + redirect = function: 7fc1f0171bb0,\ + redraw = function: 7fc1f00f3010,\ + reposition = function: 7fc1f01eaf40,\ + restoreCursor = function: 7fc1f01e67a0,\ + scroll = function: 7fc1f0139840,\ + setBackgroundColor = function: 7fc1f01fade0,\ + setBackgroundColour = function: 7fc1f00e8300,\ + setCursorBlink = function: 7fc1f010c130,\ + setCursorPos = function: 7fc1f013e940,\ + setFrozen = function: 7fc1f01aca20,\ + setGraphicsMode = function: 7fc1f01947f0,\ + setPaletteColor = function: 7fc1f0177d20,\ + setPaletteColour = function: 7fc1f01b5270,\ + setPixel = function: 7fc1f010cef0,\ + setTextColor = function: 7fc1f01af450,\ + setTextColour = function: 7fc1f01cf120,\ + setVisible = function: 7fc1f01d2570,\ + showMouse = function: 7fc1f01cd370,\ + write = function: 7fc1f019f550\ + },\ + textutils = {\ + complete = function: 7fc1f0110490,\ + empty_json_array = [],\ + formatTime = function: 7fc1f010d9c0,\ + json_null = null,\ + pagedPrint = function: 7fc1f014ab70,\ + pagedTabulate = function: 7fc1f01fb110,\ + serialise = function: 7fc1f01b79b0,\ + serialiseJSON = function: 7fc1f00f3230,\ + serialize = function: 7fc1f01b79b0,\ + serializeJSON = function: 7fc1f00f3230,\ + slowPrint = function: 7fc1f01ac880,\ + slowWrite = function: 7fc1f02136e0,\ + tabulate = function: 7fc1f0118b20,\ + unserialise = function: 7fc1f01abcb0,\ + unserialiseJSON = function: 7fc1f003a8c0,\ + unserialize = function: 7fc1f01abcb0,\ + unserializeJSON = function: 7fc1f003a8c0,\ + urlEncode = function: 7fc1f01f8230\ + },\ + tonumber = function: 7fc1f0011040,\ + tostring = function: 7fc1f00110a0,\ + type = function: 7fc1f0011510,\ + unpack = function: 7fc1f0011570,\ + utf8 = {\ + char = function: 7fc1f0015f30,\ + charpattern = \"[\\000-Â-ô][€-¿]*\",\ + codepoint = function: 7fc1f0015ed0,\ + codes = function: 7fc1f0015f90,\ + len = function: 7fc1f0015f60,\ + offset = function: 7fc1f0015e70\ + },\ + vector = {\ + new = function: 7fc1f00e2720\ + },\ + vm = {\ + compressionEnabled = function: 7fc1f0107be0\ + },\ + window = {\ + create = function: 7fc1f01ada50\ + },\ + write = function: 7fc1f0210d10,\ + xpcall = function: 7fc1f00115d0\ +}",empty={["dump.lua"]="local p = require \"cc.pretty\"\ +local f = fs.open(\"dump.txt\",'w')\ +f.write(\ + p.render(\ + p.pretty(_G),\ + ({term.getSize()})[1]\ + )\ +)\ +f.close()",},} \ No newline at end of file diff --git a/Standards/CCSMB-X/vfstool.lua b/Standards/CCSMB-X/vfstool.lua new file mode 100644 index 0000000..52d35e8 --- /dev/null +++ b/Standards/CCSMB-X/vfstool.lua @@ -0,0 +1,158 @@ +local d = shell.getRunningProgram() +local sc = require "cc.shell.completion" + +local pdir = fs.getDir(shell.getRunningProgram()) + +if not shell.getCompletionInfo()[d] then + shell.setCompletionFunction(d,sc.build( + {sc.choice, {"build","extract"}}, + sc.file, + {sc.dirOrFile, many=true} + )) + settings.define("vfstool.overwrite",{default=false,type="boolean",description="whether to skip overwrite prompt"}) + settings.define("vfstool.dir_action",{default="",type="string",description="default action to take when unpacking and dir exists,Merge/Overwrite/Cancle M/O/C"}) +end + +local opts = {...} +if #opts < 4 then + print("vfstool takes atleast 4 arguments") + print("vfstool ...") + print() + print("information:") + print("build takes folders/files from targets and puts it into File") + print("extract takes File and extracts it into the first target") + return +end + +local direction = table.remove(opts,1) +local compression = table.remove(opts,1) +local output = table.remove(opts,1) +local files = opts + +--this function is basically a VFS encoder function +--it takes a path and then recursively adds it to a table +local function gen_disk(path) + sleep() + local path = path or "" + local pth = fs.getName(path) + local tree = {} + for _,v in pairs(fs.list(path)) do + if fs.isDir(path.."/"..v) then + tree[v] = gen_disk(path.."/"..v) + else + local chandle = fs.open(path.."/"..v,'rb') + tree[v] = chandle.readAll() + chandle.close() + end + end + return tree +end +--boilerplate to make sure direction is valid +if not ((direction == "build") or (direction == "extract")) then + error("arg #1 must be either build or extract not "..direction) +end + +if direction == "build" then + --make sure all input files exist + for _,v in ipairs(files) do + local v = shell.resolve(v) + if not fs.exists(v) then error("File/Folder does not exist: "..v) end + end + + --resolve path to output file + local sro = shell.resolve(output) + --check if we are okay to overwrite it + if fs.exists(sro) and (not settings.get("vfstool.overwrite")) then + print(output.." allready exist\nOverwrite Y/N:") + c = read() + if not string.find(c,"Y") then print("Aborted") return end + end + --create the table to store our VFS + local final = {} + print("starting tree gen") + --add all targets to the root of the image + for _,v in ipairs(files) do + local sr = shell.resolve(v) + print("adding: "..v) + if fs.isDir(sr) then + final[fs.getName(v)] = gen_disk(sr) + else --why have diskgen do it when we can do it here + local hand = fs.open(sr,'rb') + local con = hand.readAll() + final[fs.getName(v)] = con + hand.close() + end + end + print("serialising") + local ser = textutils.serialise(final,{compact=true}) + print("writing") + + local handle = fs.open(sro,'wb') --write the serialised data to the file + handle.write(ser) + handle.close() +else + if not fs.exists(shell.resolve(output)) then --make sure input image exist + error("img file does not exist") + end + local rpath = shell.resolve(files[1]) + if fs.isReadOnly(rpath) then --make sure we can write to output + error(files[1].." is not writable") + end + + --really big boilerplate to make sure what we want to do to output + local dir_action = settings.get("vfstool.dir_action") + if fs.exists(rpath) and (dir_action ~= "M") and (dir_action ~= "O") and (dir_action ~= "C") and fs.exists(rpath) then + print("directory "..files[1].."allready exist, Merge,Overwrite,Cancel?") + write(": ") + local pr = read(nil,{"M","O","C"},function (t) require("cc.completion").choice(t,{"M","O","C"})end) + if pr == "M" then + print("Selected Merge") + elseif pr == "O" then + print("selected overwrite") + fs.delete(rpath); + else + print("Cancelled") + return + end + elseif fs.exists(rpath) then + if dir_action == "M" then + print("Selected Merge") + elseif dir_action == "O" then + print("selected overwrite") + local ok = pcall(fs.delete,rpath); + if not ok then print("failed to delete, probally because it is `/` but it is writable so lets go")end + else + print("Cancelled") + return + end + end + + --the sister to gen_disk, takes a the current path we are working in and the files to unpack + --then writes them + function unpack_vfs(path,files) + print("making: "..path) + fs.makeDir(fs.combine(rpath,path)) + shell.setDir(fs.combine(rpath,path)) + for k, v in pairs(files) do + if type(v) == "table" then + unpack_vfs(path.."/"..k,v) + elseif type(v) == "string" then + print("writing:"..k) + local fh = fs.open(fs.combine(rpath,fs.combine(path,k)),'wb') + fh.write(v) + fh.close() + end + end + end + + local diskf = fs.open(shell.resolve(output),"rb") --read content + local content = diskf.readAll() + diskf.close() + local tcontents = textutils.unserialize(content) --decode to table + local sdir = shell.dir() + print("unpacking vfs") + unpack_vfs("",tcontents) --unpack VFS + print("done") + shell.setDir(sdir) --head back to where we were + +end \ No newline at end of file