View difference between Paste ID: FxHwzDA1 and UXkvicMx
SHOW: | | - or go back to the newest paste.
1
local args = {...}
2
if not pack then
3
   _G.pack = {}
4
end
5
local function pu()
6
   printError("pack <add/remove/dump/out/read> <input/output>")
7
end
8
9
local cmd = args[1] or ""
10
11
if cmd == "add" then
12
   if fs.exists(args[2]) then
13
      local file = fs.open(args[2],"r")
14
      local r = file.readAll()
15
      pack[tostring(args[2])] = r
16
      file.close()
17
      print("Added File: "..tostring(args[2]))
18
   end
19
elseif cmd == "out" then
20
   local file = fs.open(args[2],"w")
21
   local op = textutils.serialise(pack)
22
   file.write("local FILE = ")
23
   file.write(op)
24
   
25
   file.writeLine(" ")
26
   file.write([[
27
   for k,v in pairs(FILE) do
28
       local file = fs.open(k,'w')
29
       file.write(v)
30
       file.close()
31
	   print("Wrote file: "..k)
32
   end
33
   ]])
34
   
35
   file.close()
36
   print("Created package file: "..tostring(args[2]))
37
elseif cmd == "dump" then
38
   for k,v in pairs(pack) do
39
      print(k)
40
   end
41
elseif cmd == "read" then
42
    if fs.exists(args[2]) then
43
        local file = fs.open(args[2],"r")
44
        local r = file.readAll()
45
        local ret = textutils.unserialise(r)
46
        file.close()
47
        for k,v in pairs(ret) do
48
            local file = fs.open(k,"w")
49
            file.write(v)
50
            file.close()
51
            print("Wrote File: "..k)
52
        end
53
    end
54
elseif cmd == "remove" then
55
   pack[args[2]] = nil
56
   print("Removed File: "..args[2])
57
else
58
   pu()
59
end