Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Arg = {...}
- os.pullEvent=os.pullEventRaw
- -- Start of persistent variables
- --Copyright (C) 2012 Mads Clausen, Tomoyo Apps http://www.tomoyo.uphero.com
- function exists(name)
- if fs.exists('.vars/'..name..'.txt') then
- return true
- end
- end
- function getType(name)
- if exists(name) then
- local file = io.open('.vars/'..name..'.txt', 'r')
- local line = file:read('*l')
- file:close()
- return line
- else
- print('var.getType(): Variable does not exist')
- error()
- end
- end
- function getValue(name)
- if exists(name) then
- if getType(name) ~= 'table' then
- local file = io.open('.vars/'..name..'.txt', 'r')
- local line = file:read('*l')
- line = file:read('*l')
- file:close()
- if getType(name) == 'number' then
- return tonumber(line)
- elseif getType(name) == 'string' then
- return line
- elseif getType(name) == 'boolean' then
- if line == 'true' then
- return true
- elseif line == 'false' then
- return false
- end
- elseif getType(name) == 'nil' then
- return nil
- end
- else
- local file = io.open('.vars/'..name..'.txt', 'r')
- local line = file:read('*l')
- local lines = {}
- local returnTable = {}
- local i = 1
- line = file:read('*l')
- while line ~= nil do
- lines[i] = line
- line = file:read('*l')
- i = i + 1
- end
- for _i = 1, #lines do
- local pos = string.find(lines[_i], '_')
- local _type = string.sub(lines[_i], 1, pos - 1)
- local value = string.sub(lines[_i], pos + 1)
- if _type == 'number' then
- returnTable[_i] = tonumber(value)
- elseif _type == 'string' then
- returnTable[_i] = value
- elseif _type == 'boolean' then
- if value == 'true' then
- returnTable[_i] = true
- elseif value == 'false' then
- returnTable[_i] = false
- end
- elseif _type == 'nil' then
- returnTable[_i] = nil
- elseif _type == 'table' then
- print('var.getValue(): You cannot have a table inside a table')
- end
- end
- return returnTable
- end
- else
- print('var.getValue(): Variable does not exist')
- error()
- end
- end
- function setType(name, _type)
- if string.lower(_type) ~= 'number' and string.lower(_type) ~= 'string' and string.lower(_type) ~= 'boolean' and string.lower(_type) ~= 'nil' and string.lower(_type) ~= 'table' and exists(name) then
- print('var.setType(): Unsupported type, or the variable already exists')
- error()
- else
- local file = io.open('.vars/'..name..'.txt', 'w')
- file:write(_type)
- file:close()
- end
- end
- function setValue(name, value)
- if exists(name) then
- if tostring(type(value)) ~= getType(name) then
- print('var.setValue(): Wrong type: '..type(value))
- error()
- end
- if getType(name) ~= 'table' then
- local file = io.open('.vars/'..name..'.txt', 'r')
- local firstLine = file:read('*l')
- file:close()
- local file = io.open('.vars/'..name..'.txt', 'w')
- file:write(firstLine..'\n'..tostring(value))
- file:close()
- else
- local file = io.open('.vars/'..name..'.txt', 'r')
- local firstLine = file:read('*l')
- file:close()
- local file = io.open('.vars/'..name..'.txt', 'w')
- file:write(firstLine..'\n')
- for i = 1, #value do
- file:write(type(value[i])..'_'..tostring(value[i])..' \n')
- end
- file:close()
- end
- else
- print('var.setValue(): Variable does not exist')
- error()
- end
- end
- function create(name, _type)
- if not fs.exists('.vars') then fs.makeDir('.vars') end
- if string.lower(_type) ~= 'number' and string.lower(_type) ~= 'string' and string.lower(_type) ~= 'boolean' and string.lower(_type) ~= 'nil' and string.lower(_type) ~= 'table' and exists(name) then
- print('var.create(): Unsupported type, or the variable already exists')
- error()
- else
- local file = io.open('.vars/'..name..'.txt', 'w')
- file:write(_type)
- file:close()
- end
- end
- function delete(name)
- if exists(name) then
- fs.delete('.vars/'..name..'.txt')
- else
- print('var.delete(): Variable does not exist')
- error()
- end
- end
- -- End of persistant variables
- function Use()
- print("Use: [FILENAME] <reconf>")
- print("<> optional")
- end
- function FC()
- shell.run("clear")
- print("Welcome to the First Time Configuration")
- if exists("pass") then
- print("Please type the password")
- write("Password: ")
- pass3 = read('*')
- if pass3 == getValue("pass") then
- shell.run("clear")
- writeconf()
- else
- print("Wrong password")
- sleep(2)
- os.reboot()
- end
- else
- writeconf()
- end
- end
- function writeconf()
- print("")
- print("Where is the Redstone-Input located?")
- side = read()
- print("How's the terminal called?")
- write("Name: ")
- termn = read()
- print("Redstone has to be on to start PC?")
- write("y/n: ")
- redon = read()
- print("Please set a config pass")
- write("Password: ")
- pass1 = read("*")
- write("Confirm: ")
- pass2 = read("*")
- if pass1 == pass2 then
- if redon == "Y" then redon = "y" end
- if redon == "N" then redon = "n" end
- shell.run("clear")
- print("Are these options correct?")
- print("")
- print("Side: "..side)
- print("Name of the terminal: "..termn)
- print("Redstone on to start: "..redon)
- print("")
- write("y/n: ")
- confirm = read()
- if confirm == "Y" or confirm == "y" then
- if exists ("pass") then delete("pass") end
- if exists ("fconf") then delete("fconf") end
- if exists ("stside") then delete("stside") end
- if exists ("stredon") then delete("stredon") end
- if exists ("termn") then delete("termn") end
- print("Saving config")
- create("pass", "string")
- create("fconf", "string")
- create("stside", "string")
- create("stredon", "string")
- create("termn", "string")
- setValue("stredon", redon)
- setValue("stside", side)
- setValue("termn", termn)
- setValue("pass", pass1)
- setValue("fconf", "true")
- os.reboot()
- else
- os.reboot()
- end
- else
- print("Passwords do not match")
- sleep(2)
- os.reboot()
- end
- end
- if #Arg == 0 then
- if exists("fconf") then
- if getValue("fconf") == "true" then
- shell.run("clear")
- if getValue("stredon") == "n" then
- print("Welcome to the terminal "..getValue("termn"))
- else
- if rs.getInput(getValue("stside")) == false then
- os.shutdown()
- end
- print("Welcome to terminal "..getValue("termn"))
- end
- else
- FC()
- end
- else
- FC()
- end
- elseif #Arg == 1 and Arg[1] == "reconf" then
- FC()
- else
- Use()
- end
Advertisement
Add Comment
Please, Sign In to add comment