This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
hbomb79's profile picture

multishell error

Started by hbomb79, 31 August 2014 - 12:15 AM
hbomb79 #1
Posted 31 August 2014 - 02:15 AM
Hey there, Havent been hhere in a while XD

Im getting a really weird error, the reason I say that is the fact that im not using mulitshell exclusively (I know it runs automatically but im not using its features) and ive ever seen it before

So bascially when I reboot the computer or shutdown the computer, It more often than not throws the errors below. It only happens when running certain code


Here is a screen shot of the error when holding CTRL+R:
[How do I upload images, Ive seen people with many on their topics and I can only upload two on the entire SITE!]

Imgur Link: http://imgur.com/kEORhaF,gG7LzRj#0

and here is the error when holding CTRL+S:

Imgur Link: http://imgur.com/kEORhaF,gG7LzRj#1

Code Running When Crash Happens: (If I discover any others doing the same I will post them too)
Spoiler

runningProgram = shell.getRunningProgram()
LogFile.i('OpenPDetect Program Successfully Started', runningProgram)
current = {
  sensor = {},
  settings = {
    whiteList = {}
  }
}
Events ={}
current.config = false
termX, termY = term.getSize()
function drawTitle()
  term.clear()
  titleBar.draw('HbombOS Security Suite', 'OpenP Detector Lock', colors.cyan, 256, 128, 256, 1)
end
function setup()
LogFile.i('OpenPDetect Setup Started', runningProgram)
  local function setupWelcome()
    titleBar.draw('HbombOS Security Suite', 'OpenP Detector Lock Setup', colors.cyan, 256, 128, 256, 1)
  end
 
  local function Intro()
    LogFile.i('OpenPDetect Setup Intro', runningProgram)
    setupWelcome()
printer.centered('Welcome To OpenP Detector Setup', 6)
printer.centered('This Program Uses Open Peripherals', 8)
printer.centered('Sensor Block', 9)
printer.centered('Therefore To Use This Program You Need', 11)
printer.centered('Open Peripheral Addons Installed', 12)
printer.centered('Click Anywhere On Screen To Start Setup', 19)
os.pullEvent('mouse_click')
  end
 
  local function setupStart()
    setupWelcome()
printer.centered('Welcome To The Detector Setup')
printer.centered('Click Anywhere To Begin Setup')
os.pullEvent('mouse_click')
  end
 
  local function whitelistAdd()
  LogFile.i('OpenPDetect whitelist Add Start', runningProgram)
  while true do
    local function addNames()
    while true do
   inList = false
	  setupWelcome()
   printer.centered('Enter The Names You Would Like To', 6)
   printer.centered('Add To The Detector WhiteList', 7)
   printer.centered('These Are The Players Who Will Have Access', 9)
   printer.centered('Enter The Username, And Hit Enter To Add', 10)
   printer.centered('Then Press [alt] To Continue To The Next Step',19)
   term.setCursorPos(termX/2-#'Username: ', 13)
   write('Username: ')
   local input = read()
	 if input and input ~= "" then
    for _, entry in ipairs(current.settings.whiteList) do
	  if entry == input then
	 inList = true
	 printer.centered('Username Already In Whitelist', 19)
	 LogFile.w('User Tried To Add Username To Whitelist That Already Existed', runningProgram)
	 sleep(1)
   end
    end
    if inList == false then
	  printer.centered('Adding Username To whitelist', 19)
   LogFile.i('Adding Username: '..input..' Into Whitelist', runningProgram)
	 if current.settings.whiteList then
		  table.insert(current.settings.whiteList, input)
    printer.centered('Username Inserted Into Whitelist', 19)
    sleep(0.5)
	 else
	   LogFile.e('Whitelist Table Is Missing.. Fatal', runningProgram)
	   error'Table Appears To Be Missing'
	 end
    end
  end
    end
end

local function nextStep()
   while true do
	 local event, key = os.pullEvent('key')
    if key == keys.leftAlt or key == keys.rightAlt then
	  if #current.settings.whiteList <= 0 then
	 term.setCursorBlink(false)
		   printer.centered('Please Register At Least ONE Username', 19)
	 LogFile.w('User Tried To Skip Whitelist When 0 Usernames Are In Table', runningProgram)
		   sleep(0.5)
	 lessThanOne = true
	 return
		 else
	 lessThanOne = false
	 return key
   end
    end
   end
end

parallel.waitForAny(nextStep, addNames)
if not lessThanOne then LogFile.i('Whitelist Complete', runningProgram) break end
  end
  return
  end
 
  local function ouputOption()
    term.setCursorBlink(false)
    setupWelcome()
printer.centered('Do You Want The Computer To Ouput', 6)
printer.centered('A Redstone Signal When The Players Is', 7)
printer.centered('On The Whitelist', 8)
printer.centered('Y/N', 10)
printer.centered('You Pick What Side It Outputs From Next Step', 19)
   while true do
	 local event, key = os.pullEvent('key')
    if key == keys.y then
	  current.settings.outputOption = true
   LogFile.i('Output Option: true', runningProgram)
   return true
    elseif key == keys.n then
	  current.settings.outputOption = false
   LogFile.i('Output Option: false', runningProgram)
   return false
    end
   end
  end
 
  local function outputSide()
    while true do
sleep(0)
    setupWelcome()
printer.centered("Redstone Output Side", 6)
term.setCursorPos(termX/2-#'Output Side: ',10)
   write ('Output Side: ')
   local vside = false
  current.settings.redstoneSide = read()
  for k,v in pairs(rs.getSides()) do
   if v == current.settings.redstoneSide then
    vside = true
    break
   end
  end
  if vside then LogFile.i('Redstone Side Set To: '..current.settings.redstoneSide, runningProgram) break end
    printer.centered("Invalid side!", 11)
    sleep(0.5)
    term.clear()
  end
  return
  end
 
  local function alarmOption()
    term.setCursorBlink(false)
    setupWelcome()
printer.centered('Do You Want The Computer To Ouput', 6)
printer.centered('A Redstone Signal When The Players Is', 7)
printer.centered('NOT On The Whitelist', 8)
printer.centered('Y/N', 10)
printer.centered('You Pick What Side It Outputs From Next Step', 19)
   while true do
	 local event, key = os.pullEvent('key')
    if key == keys.y then
	  current.settings.alarmOption = true
   LogFile.i('Alarm Side Option: true', runningProgram)
   return true
    elseif key == keys.n then
	  current.settings.alarmOption = false
   LogFile.i('Alarm Side Option: false', runningProgram)
   return false
    end
   end
  end
 
  local function alarmOutput()
    while true do
sleep(0)
    setupWelcome()
printer.centered("Alarm Redstone Output Side", 6)
term.setCursorPos(termX/2-(#'Alarm Side: '),10)
   write ('Alarm Side: ')
   local vside = false
  current.settings.alarmRedstoneSide = read()
  for k,v in pairs(rs.getSides()) do
   if v == current.settings.alarmRedstoneSide then
    vside = true
    break
   end
  end
  if vside then LogFile.i('Alarm Side: '..current.settings.alarmRedstoneSide, runningProgram) break end
    printer.centered("Invalid side!", 11)
    sleep(0.5)
    term.clear()
  end
  return
  end
 
  local function setupSave()
    LogFile.i('Setup Complete', runningProgram)
    setupWelcome()
    printer.centered('Thanks For Completing Setup', 6)
    printer.centered('Please Wait While Your Preferences', 8)
    printer.centered('Are Saved To File', 9)
    printer.centered('Saving Settings', 19)
SaveSettings()
printer.centered('Settings Saved, Click To Continue', 19)
os.pullEvent('mouse_click')
loadSettings()
current.config = false
  end
 
Intro()
whitelistAdd()
if ouputOption() == true then outputSide() end
if alarmOption() == true then alarmOutput() end
setupSave()
term.clear()
drawTitle()
scanSensor()
eventLoop()
end
function loadSettings()
  LogFile.i('Loading Settings', runningProgram)
  if fs.exists('systemFiles/Programs/detectorConfig') then
  local f = fs.open('systemFiles/Programs/detectorConfig', 'r')
  if f then
   current.settings = textutils.unserialize(f.readAll())
  end
  f.close()
else
  setup()
end
end
function SaveSettings()
    LogFile.i('Saving Settings', runningProgram)
current.settings = current.settings or {}
local f = fs.open('systemFiles/Programs/detectorConfig', 'w')
if f then
  f.write(textutils.serialize(current.settings))
end
f.close()
end
--Sensor Peripheral: openperipheral_sensor
function scanSensor()
  LogFile.i('Searching For OpenP Scanner', runningProgram)
  localPeripherals = peripheral.getNames()
    for i = 1, #localPeripherals do
   if peripheral.getType(localPeripherals[i]) == 'openperipheral_sensor' then
  Sensor = peripheral.find('openperipheral_sensor')
  LogFile.i('Sensor Found', runningProgram)
  current.sensor.isPresent = true
  return true
   end
end
LogFile.w('Sensor Missing', runningProgram)
current.sensor.isPresent = false
noSensor()
end
function noSensor()
  LogFile.w('There Is No Sensor Present', runningProgram)
  drawTitle()
  if current.settings.redstoneSide then rs.setOutput(current.settings.redstoneSide, false) end
  if current.settings.alarmRedstoneSide then rs.setOutput(current.settings.alarmRedstoneSide, false) end
  printer.centered('It Seems There Is No OpenPeripheral Sensor', 6)
  printer.centered('Attached To This Computer', 7)
  printer.centered('Please Attach One', 8)
  printer.centered('Well Look Automatically When You Attach One', 10)
  printer.centered('Attach A Sensor To Continue', 19)
  while true do
    local event = os.pullEvent()
   if event == 'peripheral' or event == 'peripheral_detach' then
	 printer.centered('Scanning For Sensor', 19)
  sleep(2)
	 scanSensor()
  drawTitle()
  closeAllSides()
  checkScanner()
  break
   end
  end
end
function checkScanner()
    allowPlayer = false
denyPlayer = false
    nearbyPlayers = Sensor.getPlayerNames()
if nearbyPlayers then
   for _, entry in ipairs(nearbyPlayers) do
	 for _, v in ipairs (current.settings.whiteList) do
    if entry == v then
	  openSide()
   allowPlayer = true
    else
	  if not allowPlayer then
	    openAlarmSide()
	 denyPlayer = true
   end
    end
  end
   end
end
scanPlayers = os.startTimer(0.1)
if denyPlayer or allowPlayer then return true else return false end
end
function eventRegister(event, functionToRun)
if not Events[event] then
  Events[event] = {}
end
table.insert(Events[event], functionToRun)
end
function drawScreen()
  if current.status == 'System Ready' then term.setTextColor(colors.blue)
  elseif current.status == 'Access Granted' then term.setTextColor(colors.lime)
  elseif current.status == 'Access Denied' then term.setTextColor(colors.red) end
  printer.centered(current.status, 8)
  term.setTextColor(256)
  term.setBackgroundColor(128)
  term.setCursorPos(termX-#'[alt] Setup', 1)
  write('[alt] Setup')
  term.setTextColor(1) 
  term.setBackgroundColor(256)
  printer.centered('System Monitoring Nearby Entities', 19)
  printer.centered('Detector System', 6)
end
function eventLoop()
drawTitle()
current.status = 'System Ready'  
allowPlayer = false
scanSensor()
checkScanner()
  while true do
  drawScreen()
local event, arg1, arg2, arg3, arg4, arg5, arg6 = os.pullEventRaw()
   if Events[event] then
  for i, e in ipairs(Events[event]) do
    e(event, arg1, arg2, arg3, arg4, arg5, arg6)
  end
	  end
   end
end
function openSide()
  current.status = 'Access Granted'
  if current.settings.redstoneSide then rs.setOutput(current.settings.redstoneSide, true) end
end
function openAlarmSide()
  current.status = 'Access Denied'
  if current.settings.alarmRedstoneSide then rs.setOutput(current.settings.alarmRedstoneSide, true) end
end
function closeAllSides()
  if not checkScanner() then
    allowPlayer = false
denyPlayer = false
    current.status = 'System Ready'
    if current.settings.redstoneSide then rs.setOutput(current.settings.redstoneSide, false) end
    if current.settings.alarmRedstoneSide then rs.setOutput(current.settings.alarmRedstoneSide, false) end
  end
end
function timerHandle(event, timer)
  if timer == closeSide then
    closeAllSides()
  elseif timer == scanPlayers then
    closeAllSides()
    checkScanner()
  end
end
function whitelistAdd()
LogFile.i('Whitelist Add Called', runningProgram)
  while true do
    local function addNames()
    while true do 
titleBar.draw('HbombOS Security Suite', 'OpenP Detector Settings', colors.cyan, 256, 128, 256, 1)
   inList = false
   printer.centered('Enter The Names You Would Like To', 6)
   printer.centered('The Detector WhiteList', 7)
   printer.centered('These Are The Players Who Will Have Access', 9)
   printer.centered('Enter The Username, And Hit Enter To Add', 10)
   printer.centered('Then Press [alt] To Save And Return',19)
   term.setCursorPos(termX/2-#'Username: ', 13)
   write('Username: ')
   local input = read()
	 if input and input ~= "" then
    for _, entry in ipairs(current.settings.whiteList) do
	  if entry == input then
	 inList = true
	 printer.centered('Username Already In Whitelist', 19)
	 LogFile.w('Username: '..input..' Already In Whitelist', runningProgram)
	 sleep(1)
   end
    end
    if inList == false then
	  printer.centered('Adding Username To whitelist', 19)
   LogFile.i('Adding: '..input.. 'Into Whitelist', runningProgram)
	 if current.settings.whiteList then
		  table.insert(current.settings.whiteList, input)
    printer.centered('Username Inserted Into Whitelist', 19)
    sleep(0.5)
	 else
	   LogFile.i('Whitelist Table Missing!', runningProgram)
	   error'Table Appears To Be Missing'
	 end
    end
  end
    end
end

local function nextStep()
   while true do
	 local event, key = os.pullEvent('key')
    if key == keys.leftAlt or key == keys.rightAlt then
	  if #current.settings.whiteList <= 0 then
	 term.setCursorBlink(false)
		   printer.centered('Please Register At Least ONE Username', 19)
	 LogFile.i('User Tried To Add 0 Usernames', runningProgram)
		   sleep(0.5)
	 lessThanOne = true
	 return
		 else
	 lessThanOne = false
	 return key
   end
    end
   end
end

parallel.waitForAny(nextStep, addNames)
if not lessThanOne then break end
  end
  SaveSettings()
  configMenu()
end
function whitelistRemove()
LogFile.i('Remove Whitelist Username Open', runningProgram)
  local function removeNames()
    while true do
   inList = false
   titleBar.draw('HbombOS Security Suite', 'OpenP Detector Lock Settings', colors.cyan, 256, 128, 256, 1)
   printer.centered('Enter The Names You Would Like To', 6)
   printer.centered('Remove From The Detector WhiteList', 7)
   printer.centered('These Are The Players Who Will Not Have Access', 9)
   printer.centered('Enter The Username, And Hit Enter To Remove', 10)
   printer.centered('Then Press [alt] To Save And Return',19)
   term.setCursorPos(termX/2-#'Username: ', 13)
   write('Username: ')
   local input = read()
	 if input and input ~= "" then
    for _, entry in ipairs(current.settings.whiteList) do
	  if entry == input then
	 if #current.settings.whiteList - 1 >0 then
	   printer.centered('Removing Username From whitelist', 19)
	   table.remove(current.settings.whiteList, _)
	   SaveSettings()
	   printer.centered('Removed Username From Whitelist', 19)
	   sleep(0.5)
	   break
	 else
	   LogFile.i('User Tried To Remove LAST Username From Whitelist', runningProgram)
	   printer.centered('There Has To Be Atleast One Username', 18)
	   printer.centered('In Whitelist', 19)
    sleep(1)
	 end
   end
    end
	    end
    end
  end

local function completeStage()
   while true do
	 local event, key = os.pullEvent('key')
    if key == keys.leftAlt or key == keys.rightAlt then
	  return key
    end
   end
end

parallel.waitForAny(completeStage, removeNames)
SaveSettings()
configMenu()
end
function configMenu()
  LogFile.i('Config Menu Open', runningProgram)
  term.setCursorBlink(false)
  titleBar.draw('HbombOS Security Suite', 'OpenP Detector Settings', colors.cyan, 256, 128, 256, 1)
  printer.centered('Pick An Option Below', 6)
  local continue = false
  current.config = true
  local options = {
  {'Edit Settings', function()
    setup()
  end},
  {'Whitelist Users', function()
    whitelistAdd()
  end},
  {'Un-Whitelist Users', function()
    whitelistRemove()
  end},
  {'Reset Configuration', function()
    LogFile.i('Config Reset', runningProgram)
    fs.delete('systemFiles/Programs/detectorConfig')
    os.reboot()
  end},
  {'Cancel And Return', function()
    current.config = false
    eventLoop()
  end}
}
local selected = 1
local function draw()
  for i, v in ipairs(options) do
   local bg = 256
   local tc = colours.white
   if i == selected then
    bg = 256
    tc = colours.blue
   end
   term.setTextColor(tc)
   term.setBackgroundColor(bg)
   PrintCentered(' '..v[1]..' ', math.floor(#options/2) + i + 6)
  end
end
local wait = true
draw()
while true do
  local event, key = os.pullEvent('key')
  if key == keys.up then
   selected = selected - 1
   if selected < 1 then
    selected = 1
   end
  elseif key == keys.down then
   selected = selected + 1
   if selected > #options then
    selected = #options
   end
  elseif key == keys.enter then
    options[selected][2]()
    wait = false
    break
  end
  draw()
end
end
function ConfigLogin()
  LogFile.i('Config Login', runningProgram)
  closeAllSides()
  current.config = true
  local f = fs.open('systemFiles/Security/adminPass', 'r')
  adminPassLoaded = f.readLine()
  f.close()
  titleBar.draw('HbombOS Security Suite', 'OpenP Detector Settings', colors.cyan, 256, 128, 256, 1)
  printer.centered('Please Enter Your Admin Password', 4)
  printer.centered('Linked To Your Security Suite To Access', 5)
  printer.centered('The Settings Menu', 6)
  printer.centered('Press [alt] To Return', 19)
 
  local function LoginInput()
    while true do
	  term.setCursorPos(termX/2-#'Password: ', 10)
   term.clearLine()
   write('Password: ')
   local input = read('*')
	 if input == adminPassLoaded then
    LogFile.i('Admin Password Correct', runningProgram)
    current.config = true
    break
	 end
    end
  end
 
  local function keyExit()
    while true do
   local event, key = os.pullEvent('key')
	    if key == keys.leftAlt or keys == keys.rightAlt then
    term.setCursorBlink(false)
    current.config = false
		  break
   end
end
  end
    parallel.waitForAny(LoginInput, keyExit)
    if current.config then configMenu() else eventLoop() end
  end
function keyHandler(event, key)
  if event == 'key' and key == keys.leftAlt or key == keys.rightAlt then
    if current.config == false then ConfigLogin() end
  end
end
function init()
LogFile.i('main Init function started', runningProgram)
eventRegister('timer', timerHandle)
eventRegister('key', keyHandler)
eventRegister('terminate', function(event) errora.err('Termination Detected', 'You Attempted To Terminate The Program', true) end)
eventRegister('peripheral', scanSensor)
eventRegister('peripheral_detach', scanSensor)
loadSettings()
eventLoop()
end
  local _, err = pcall(init) --Error Catching, All Functions Are Called From initialise() at some point...
  if err then
    term.setCursorBlink(false)
LogFile.e('Error Detected: '..err, runningProgram)
errora.err(err, 'Detector Lock Crashed, Report Error Above', true) --BSoD for protection, the 'true' is an auto-reboot option to prevent the door waiting for a prompt
  end

The LogFile.blahblah want there when I discovered this although I never experienced the CTRL+S version without them, although I dont remeber testing

The file that starts this one is here:
Spoiler

-- This script loads the APIs Required as well as checks for missing files and updates via GitHub
-- The Installer Will Check If The Computer is compatible
runningProgram = shell.getRunningProgram()
os.pullEvent = os.pullEventRaw
termX, termY = term.getSize()
os.loadAPI('api/LogFile')
-- Fade In!
LogFile.Initialise()
LogFile.i('Loading Boot Screen', runningProgram)
LogFile.i('Fading Screen', runningProgram)
term.setBackgroundColour(colours.black)
term.clear()
sleep(0.1)
term.setBackgroundColour(colours.grey)
term.clear()
sleep(0.1)
term.setBackgroundColour(colours.lightGrey)
term.clear()
sleep(0.1)
function RecieveStartupKey()
while true do
   local event, arg = os.pullEvent()
   if event == 'BootDone' then
	 return nil
   elseif event == "key" then
	 if arg == keys.leftAlt or key == keys.rightAlt then
  bootKey = true
  checkStartKey()
    return arg
  end
   end
  
end
end
function checkStartKey()
  term.setBackgroundColor(128)
  term.setTextColor(256)
  if bootKey then
    Boottext = "Entering Setup"
  else
    Boottext = "[alt] Setup"
  end
    term.setCursorPos(termX-(#Boottext+1), 1)
    write(Boottext)
  term.setBackgroundColor(256)
  term.setTextColor(1)
end
function initBackground(color) --Use To Quickly assemble GUI
  term.setBackgroundColor(color)
  term.clear() 
  drawTitleBar()
end
function start()
  printer.centered("Password Changer", 4)
  printer.centered("Here you may change your admin password", 6)
  printer.centered("In just a few simple clicks and hits...", 7)
end
function newPassword2()
while newPassword2Wait do
   term.clear()
   start()
   printer.centered("Re-type your new password", 10)
   local newPassConfirm = "New Pass Again: "
   term.setCursorPos(termX/2-#newPassConfirm, 12)
   write (newPassConfirm)
   newPass = read("*")
   if newPass == newPass1 then break else printer.centered("Passwords Don't Match!", 19) sleep(0.6) newPassword() end
    end
  save(newPass)
end
   
function newPassword()
  while newPassWait do
    term.clear()
start()
printer.centered("Type your new password", 10)
local newPassText = "New Pass: "
term.setCursorPos(termX/2-#newPassText, 12)
write (newPassText)
newPass1 = read("*")
if newPass1 == "" or newPass1 == nil then
   printer.centered("Cannot Be NIL!", 19)
elseif newPass1 ~= "" or newPass ~= nil then
   printer.centered("Accepted", 19)   
   newPassword2()
else
   errora.err("generic", "Unknown Exception, Cannot Handle Input: "..newPass1)
end
  end
end
   
   
function oldPassword()
  while oldPassWait do
    printer.centered("Type your current password to get started", 10)
local oldPassText = "Current Pass: "
    term.setCursorPos(termX/2-#oldPassText, 12)
write(oldPassText)
oldPass = read("*")
if oldPass == adminPassword then oldPassWait = false break end
    end
    newPassword()
end
   
  
function save(password)
  if password then
printer.centered("Saving!", 18)
sleep(0)
printer.centered("Opening File Handler", 19)
sleep(0)
local f = fs.open('systemFiles/Security/adminPass', "w")
printer.centered("Preparing Write", 19)
sleep(0)
printer.centered("Writing To File", 19)
sleep(0)
f.writeLine(password)
printer.centered("File Data Written", 19)
sleep(0)
    printer.centered("Closing File Handler", 19)
sleep(0)
f.close()
printer.centered("Data Saved", 19)
sleep(0)
printer.centered("Done... Rebooting", 19)
    sleep(2)
    os.reboot()
  else
errora.err("generic", "Save Data invalid / NIL")
  end
end
bootX = termX/2-7
bootY = termY/2-4
-- Loads All Boot Images
LogFile.i('Loading Boot Images', runningProgram)
BL0 = paintutils.loadImage("systemFiles/BootLogos/boot0.nfp")
BL1 = paintutils.loadImage("systemFiles/BootLogos/boot1.nfp")
BL2 = paintutils.loadImage("systemFiles/BootLogos/boot2.nfp")
BL3 = paintutils.loadImage("systemFiles/BootLogos/boot3.nfp")
BL4 = paintutils.loadImage("systemFiles/BootLogos/boot4.nfp")
BL5 = paintutils.loadImage("systemFiles/BootLogos/boot5.nfp")
BL6 = paintutils.loadImage("systemFiles/BootLogos/boot6.nfp")
BL7 = paintutils.loadImage("systemFiles/BootLogos/boot7.nfp")
BL8 = paintutils.loadImage("systemFiles/BootLogos/boot8.nfp")
BLFinal = paintutils.loadImage('systemFiles/bootFail.nfp')
function bootLogo (state, x, y, bgcolor)
  if state == 0 then
    paintutils.drawImage(BL0, x, y)
  elseif state == 1 then
    paintutils.drawImage(BL1, x, y)
  elseif state == 2 then
    paintutils.drawImage(BL2, x, y)
  elseif state == 3 then
    paintutils.drawImage(BL3, x, y)
  elseif state == 4 then
    paintutils.drawImage(BL4, x, y)
  elseif state == 5 then
    paintutils.drawImage(BL5, x, y)
  elseif state == 6 then
    paintutils.drawImage(BL6, x, y)
  elseif state == 7 then
    paintutils.drawImage(BL7, x, y)
  elseif state == 8 then
    paintutils.drawImage(BL8, x, y)
  elseif state == 9 then
    paintutils.drawImage(BLFinal, x, y)
  end
  term.setBackgroundColor(bgcolor)
end
function PrintCentered(text, y)
local w, h = term.getSize()
    x = math.ceil(math.ceil((w / 2) - (#text / 2)), 0)+1
    term.setCursorPos(x, y)
term.clearLine()
    write(text)
end
if not fs.exists("systemFiles/Security/adminPass") then
LogFile.i('Admin Password Set Open', runningProgram)
while true do
  PrintCentered("SECURITY VULNERABLITLTY NOTICE", 4)
  PrintCentered("The Administrator Password Has Not Been Set", 6)
  PrintCentered("Please Set It Below, You Can Change It", 7)
  PrintCentered("Whilst Booting If You Press [ALT]", 8)
  adminPassText = "Password: "
  term.setCursorPos(termX/2-(#adminPassText), 10)
  write(adminPassText)
  adminPassIn = read("*")
  if adminPassIn ~= "" then
    LogFile.i('Admin Password Creation Complete', runningProgram)
    PrintCentered("Saving Password...", 19)
    sleep(0)
    PrintCentered("Opening File Handle", 19)
    local f = fs.open("systemFiles/Security/adminPass", "w")
    PrintCentered("File Handle Open", 19)
    PrintCentered("Writing To File", 19)
    f.writeLine(adminPassIn)
    PrintCentered("Complete", 19)
break
  end
end
  if fs.exists('systemFiles/Install/updateConfig') then
    LogFile.i('Update Config Already Exists! Rebooting', runningProgram)
    os.reboot()
  end
else --The Files Exists
  local file = fs.open("systemFiles/Security/adminPass", "r")
  adminPassword = file.readLine()
  file.close()
end
function saveUpdate()
  local f = fs.open('systemFiles/Install/updateConfig', 'w')
  f.writeLine(tostring(quietUse))
  f.close()
  sleep(0)
  PrintCentered("Settings Saved, Setting set to: "..tostring(quietUse), 19)
  sleep(1)
  os.reboot()
end
if not fs.exists('systemFiles/Install/updateConfig') then
  LogFile.i('Updater Selection Set Open', runningProgram)
  term.clear()
  PrintCentered("Updater Mode Selection", 4)
  PrintCentered("Would you like the enable quiet updating", 6)
  PrintCentered("which will prevent the updater asking you for", 7)
  PrintCentered("your decision on whether you would like to update", 8)
  PrintCentered("Instead, it will do it automatically!", 9)
  PrintCentered("Press Y to enable or N to disable this setting", 11)
  updateLoop = true
  while updateLoop do
    event, press = os.pullEvent("key")
	  if press == keys.y then
	    quietUse = true
  saveUpdate()
   elseif press == keys.n then
	 quietUse = false
  saveUpdate()
	  end
  end
end
function loadAPIs()  --Auto Loads ALL APIs It Can As Long As They Are In /api
  drawTitleBar()
  local currentImage = -1
local total = #fs.list("/api")
term.setBackgroundColor(256)
PrintCentered("Loading APIs", 17)
for _, fileApi in pairs(fs.list('/api')) do
  if string.sub(fileApi,1,1) ~= "." then
   if math.floor(_*(8/total)) ~= currentImage then
    currentImage = math.floor(_*(8/total))
    local image = paintutils.loadImage('systemFiles/BootLogos/boot'..currentImage..'.nfp')
    paintutils.drawImage(image, bootX, bootY)
   end 
   LogFile.i('Loading: '..fileApi, runningProgram)
   if os.loadAPI('/api/'..fileApi) then
   sleep(0)
   term.setBackgroundColor(256)
   term.setTextColor(colors.white)
		    term.setCursorPos(1,19)
   term.clearLine()
   term.setCursorPos(1,18)
   term.clearLine()
   PrintCentered(fileApi.." Loaded!", 18)
   LogFile.i(fileApi..'Api Loaded', runningProgram)
	  else
	 LogFile.e('Failed To Load API: '..fileApi, runningProgram)
	 error ("Error Occurred Whilst Loading API: "..fileApi)
   end
  end
end
sleep(0.1)
term.clear()
initBackground(256)
drawTitleBar()
return true
end
function drawTitleBar()
  LogFile.i('Drew Title Bar', runningProgram)
  term.setBackgroundColor(128)
  term.setCursorPos(1,1)
  term.clearLine()
  term.setTextColor(colors.cyan)
  write "HbombOS Security Suite"
  term.setCursorPos(1,2)
  term.clearLine()
  term.setTextColor(256)
  write "Startup"
  checkStartKey()
end

function programMenu()
    LogFile.i('Program Selection Menu Open', runningProgram)
    drawTitleBar()
    term.setTextColor(1)
    term.setBackgroundColor(256)
    term.clear()
PrintCentered("HbombOS Security Suite", 2)
PrintCentered("Programs", 3)
PrintCentered("The Suite Offers Several Programs For You To Use", 5)
PrintCentered("Select One You Would Like To Use", 6)
PrintCentered("You Can Change It At Any Time Using The BootMenu", 7)
PrintCentered("Use Your Arrow Keys To Select, Enter To Confirm", 19)
local continue = false
local options = {
  {'PIN', function()
    term.setTextColor(1)
    printer.centered("Opening File Handler", 19)
    sleep(0)
    local f = fs.open('systemFiles/Programs/configuration', "w")
    printer.centered("File Handler Open", 19)
    sleep(0)
    printer.centered("Writing To File", 19)
    sleep(0)
    f.writeLine('systemFiles/Programs/pin')
    printer.centered("File written", 19)
    sleep(0)
    LogFile.i('Program: PIN Selected', runningProgram)
    printer.centered("Closing Handler", 19)
    f.close()
    printer.centered("Saved, Rebooting!", 19)
    sleep(2)
    os.reboot()
  end},
  {'Digital Lock', function()
    term.setTextColor(1)
    printer.centered("Opening File Handler", 19)
    sleep(0)
    local f = fs.open('systemFiles/Programs/configuration', "w")
    printer.centered("File Handler Open", 19)
    sleep(0)
    printer.centered("Writing To File", 19)
    sleep(0)
    f.writeLine('systemFiles/Programs/dualKey')
    printer.centered("File written", 19)
    sleep(0)
    LogFile.i('Program: DualKey Selected', runningProgram)
    printer.centered("Closing Handler", 19)
    f.close()
    printer.centered("Saved, Rebooting!", 19)
    sleep(2)
    os.reboot()
  end},
  {'Reactor Control', function()
    term.setTextColor(1)
    printer.centered("Opening File Handler", 19)
    sleep(0)
    local f = fs.open('systemFiles/Programs/configuration', "w")
    printer.centered("File Handler Open", 19)
    sleep(0)
    printer.centered("Writing To File", 19)
    sleep(0)
    f.writeLine('systemFiles/Programs/reactor')
    printer.centered("File written", 19)
    sleep(0)
    LogFile.i('Program: reactor Selected', runningProgram)
    printer.centered("Closing Handler", 19)
    f.close()
    printer.centered("Saved, Rebooting!", 19)
    sleep(2)
    os.reboot()
  end},
  {'Keycard Lock', function()
    term.setTextColor(1)
    printer.centered("Opening File Handler", 19)
    sleep(0)
    local f = fs.open('systemFiles/Programs/configuration', "w")
    printer.centered("File Handler Open", 19)
    sleep(0)
    printer.centered("Writing To File", 19)
    sleep(0)
    f.writeLine('systemFiles/Programs/keycard')
    printer.centered("File written", 19)
    sleep(0)
    LogFile.i('Program" keycard Selected', runningProgram)
    printer.centered("Closing Handler", 19)
    f.close()
    printer.centered("Saved, Rebooting!", 19)
    sleep(2)
    os.reboot()
  end},
  {'PDA Range Lock', function()
    term.setTextColor(1)
    printer.centered("Opening File Handler", 19)
    sleep(0)
    local f = fs.open('systemFiles/Programs/configuration', "w")
    printer.centered("File Handler Open", 19)
    sleep(0)
    printer.centered("Writing To File", 19)
    sleep(0)
    f.writeLine('systemFiles/Programs/rangeLock')
    printer.centered("File written", 19)
    sleep(0)
    LogFile.i('Program: rangeLock Selected', runningProgram)
    printer.centered("Closing Handler", 19)
    f.close()
    printer.centered("Saved, Rebooting!", 19)
    sleep(2)
    os.reboot()
  end},
  {'Dual KeyCard Lock', function()
    term.setTextColor(1)
    printer.centered("Opening File Handler", 19)
    sleep(0)
    local f = fs.open('systemFiles/Programs/configuration', "w")
    printer.centered("File Handler Open", 19)
    sleep(0)
    printer.centered("Writing To File", 19)
    sleep(0)
    f.writeLine('systemFiles/Programs/keycardDual')
    printer.centered("File written", 19)
    sleep(0)
    LogFile.i('Program: keycardDual Selected', runningProgram)
    printer.centered("Closing Handler", 19)
    f.close()
    printer.centered("Saved, Rebooting!", 19)
    sleep(2)
    os.reboot()
  end},
  {'OpenP Detector Lock', function()
    term.setTextColor(1)
    printer.centered("Opening File Handler", 19)
    sleep(0)
    local f = fs.open('systemFiles/Programs/configuration', "w")
    printer.centered("File Handler Open", 19)
    sleep(0)
    printer.centered("Writing To File", 19)
    sleep(0)
    f.writeLine('systemFiles/Programs/OpenPDetect')
    printer.centered("File written", 19)
    sleep(0)
    LogFile.i('Program: OpenPDetect Selected', runningProgram)
    printer.centered("Closing Handler", 19)
    f.close()
    printer.centered("Saved, Rebooting!", 19)
    sleep(2)
    os.reboot()
  end}
}
local selected = 1
local function draw()
  for i, v in ipairs(options) do
   local bg = 256
   local tc = colours.white
   if i == selected then
    bg = 256
    tc = colours.blue
   end
   term.setTextColor(tc)
   term.setBackgroundColor(bg)
   PrintCentered(' '..v[1]..' ', math.floor(#options/2) + i + 6)
  end
end
local wait = true
draw()
while wait do
  local event, key = os.pullEvent('key')
  if key == keys.up then
   selected = selected - 1
   if selected < 1 then
    selected = 1
   end
  elseif key == keys.down then
   selected = selected + 1
   if selected > #options then
    selected = #options
   end
  elseif key == keys.enter then
    options[selected][2]()
    wait = false
  end
  draw()
end
return continue
end
function programCheckConfig()
LogFile.i('Checking Program Config', runningProgram)
  if not fs.exists('systemFiles/Programs/configuration') then programMenu() else
    local f = fs.open('systemFiles/Programs/configuration', "r")
programStart = f.readLine()
f.close()
if not programStart then programMenu() else
   if programStart == "" then programMenu() else
	 local f = fs.open('systemFiles/Programs/configuration', 'r')
  fileStartup = f.readLine()
  f.close()
   end
end
  end
end

function main() --The main function, calls all child functions
  --First all APIs must be loaded to perform the system checks later on
  LogFile.i('Main Initialise Function Started', runningProgram)
  i = 0
  loadAPIs()
  programCheckConfig()
  term.setBackgroundColor(256)
  term.setTextColor(1)
  bootLogo(1, bootX, bootY, 256)
  PrintCentered("Checking For Colour Support", 18)
  if systemCheck.checkColor() then PrintCentered("Computer Supports Colour", 19) end
  bootLogo(3, bootX, bootY, 256)
  sleep(0)
  bootLogo(4, bootX, bootY, 256)
  PrintCentered("Checking If Pocket", 18)
  sleep(0)
  if systemCheck.checkPocket() then
  bootLogo(6, bootX, bootY, 256)
  PrintCentered("Computer Is Not Pocket", 19)
  end
  sleep(0)
  bootLogo(7, bootX, bootY, 256)
  PrintCentered("Checking If Supports HTTP", 18)
  sleep(0)
  bootLogo(8, bootX, bootY, 256)
  if systemCheck.checkhttp() then PrintCentered("System Check Complete!", 19) end
  sleep(0)
  PrintCentered("", 19)
  updateChecker()
  return true
end
function latestVer()
    PrintCentered("You Are Running The Latest STABLE Version!", 19)
printer.centered("Reading Config File..", 19)
sleep(0.1)
return true
end
function updateAvail()
    PrintCentered("An Update Has Been Detected", 6)
sleep(0)
    PrintCentered("Obtaining Latest Update From GitHub", 18)
PrintCentered("Seeking URL", 19)
sleep(0)
PrintCentered("Parsed", 19)
sleep(0)
PrintCentered("Downloading New Updater", 19)
if not download.git("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/systemFiles/Install/updater", "systemFiles/Install/updater") then printer.centered('Error Occured While Downloading Updater!', 19) sleep(1) os.reboot() end
PrintCentered("Download Complete, Running Updater",18)
local f = fs.open('systemFiles/Install/updateConfig', 'r')
useSettingQuiet = f.readLine()
f.close()
if useSettingQuiet == "true" then shell.run("systemFiles/Install/updater", "quiet") elseif useSettingQuiet == "false" then shell.run("systemFiles/Install/updater") else errora.err(nil, "The Updater Launch Script Failed To Launch the Updater, Returned: "..tostring(useSettingQuiet)) end
   if request_code == 'Cancelled' then
	 return 'Cancel'
   elseif request_code == 'Error' then
	 i = i + 1
  if i < 4 then
	   term.setBackgroundColor(256)
	   term.clear()
		  drawTitleBar()
		  printer.centered('The Updater Is Experiencing Issues', 6)
		  printer.centered('Please Ensure You Are Connected To The Internet', 8)
		  printer.centered('If You Have An Active Internet Connection', 10)
		  printer.centered('Then Report On Forum Page', 11)
		  printer.centered('Retry Attempt: '..i, 19)
		  sleep(3)
  else
    term.setBackgroundColor(256)
	   term.clear()
		  drawTitleBar()
		  printer.centered('The Updater Isnt Able To Connect', 6)
		  printer.centered('Due To Retrying 3 Times, The System Has', 8)
		  printer.centered('Decided To Skip The Update...', 10)
		  printer.centered('Please Connect To Internet', 11)
		  for x = 3, 1, -1 do
	  if x == 1 then
	    printer.centered('Skipping In: '..x..' Second', 19)
   elseif x > 1 then
	 printer.centered('Skipping In: '..x..'Seconds', 19)
   else break end
   sleep(1)
    end
    return 'Cancel'
  end
  return 'Error'
   end
end
function updateChecker()
LogFile.i('Checking For Updates', runningProgram)
  while true do
term.setBackgroundColor(256)
term.clear()
    drawTitleBar()
printer.centered('Checking For Software Updates', 6)
printer.centered('Please Wait...', 19)
    updateState = update.Check()
    if updateState == true then
	  if updateAvail() == 'Cancel' then
	 break
   end
    elseif updateState == false then
	 break
    elseif updateState == 'ERROR' then
LogFile.w('Updater Error Occured', runningProgram)
   i = i + 1
  if i < 4 then
	   term.setBackgroundColor(256)
	   term.clear()
		  drawTitleBar()
		  printer.centered('The Updater Is Experiencing Issues', 6)
		  printer.centered('Please Ensure You Are Connected To The Internet', 8)
		  printer.centered('If You Have An Active Internet Connection', 10)
		  printer.centered('Then Report On Forum Page', 11)
		  printer.centered('Retry Attempt: '..i, 19)
		  for x = 3, 1, -1 do
	  if x == 1 then
	    printer.centered('Retrying In: '..x..' Second', 19)
   elseif x > 1 then
	 printer.centered('Retrying In: '..x..' Seconds', 19)
   else break end
   sleep(1)
    end
  else
  LogFile.w('Updater Skipping Due To Failed Connection', runningProgram)
    term.setBackgroundColor(256)
	   term.clear()
		  drawTitleBar()
		  printer.centered('The Updater Isnt Able To Connect', 6)
		  printer.centered('Due To Retrying 3 Times, The System Has', 8)
		  printer.centered('Decided To Skip The Update...', 10)
		  printer.centered('Please Connect To Internet', 11)
		  printer.centered('When Possible', 12)
		  for x = 5, 1, -1 do
	  if x == 1 then
	    printer.centered('Skipping In: '..x..' Second', 19)
   elseif x > 1 then
	 printer.centered('Skipping In: '..x..' Seconds', 19)
   else break end
   sleep(1)
    end
    return 'Cancel'
   end
    else
   LogFile.e('Updater Unknown Return', runningProgram)
	  error 'Error Occured When Updating'
    end
  end
  return true
end
function bootMenu()
LogFile.i('Boot Menu Entered', runningProgram)
while true do
  term.clear()
  titleBar.draw("HbombOS Security Suite", "BIOS Login", colors.cyan, 256, 128, 256, 1)
  function adminPasswordE()
    PrintCentered("HbombOS Security Suite", 4)
    PrintCentered("Boot Options", 5)
    PrintCentered("Type In Admin Password To Continue", 18)
    PrintCentered("Or Reboot (CTRL+R) To Cancel", 19)
    adminPassText = "Password: "
    term.setCursorPos(termX/2-#adminPassText, 7)
    write (adminPassText)
    local input = read("*")
	  if input == adminPassword then
	   return true
   end
  end
  if adminPasswordE() then
    return true
  else
    LogFile.w('Incorrect Admin Password In BootMenu', runningProgram)
    printer.centered("Incorrect!", 8)
sleep(0.5)
  end
end
end
function bootMenuOptions(continue)
    LogFile.i('Boot Menu Option Opened', runningProgram)
    if not bootMenu() then bootMenu() end
    term.setTextColor(1)
    term.setBackgroundColor(256)
    term.clear()
    titleBar.draw("HbombOS Security Suite", "Settings", colors.cyan, 256, 128, 256, 1)
PrintCentered("HbombOS Security Suite", 4)
PrintCentered("Boot Options", 5)
PrintCentered("Use Your Arrow Keys To Select, Enter To Confirm", 19)
local continue = false
local options = {
	 {'Reset Settings', function()
  LogFile.w('Removing System Settings', runningProgram)
  term.clear()
  PrintCentered("Removing Settings", 6)
  sleep(0)
  PrintCentered("Removing Administrator Password", 18)
  sleep(1)
  if fs.exists('/systemFiles/Security/adminPass') then fs.delete('/systemFiles/Security/adminPass') end
  PrintCentered("Removing Program Settings", 18)
  sleep(0.2)
  if fs.exists('/systemFiles/Programs/pinConfig') then fs.delete ('systemFiles/Programs/pinConfig') end
  PrintCentered("Removing Reactor Configuration", 18)
  sleep(0)
  if fs.exists('/systemFiles/Programs/reactorConfig') then fs.delete ('systemFiles/Programs/reactorConfig') end
  PrintCentered("Removing Keycard Configuration", 18)
  sleep(0)
  if fs.exists('/systemFiles/Programs/keycardConfig') then fs.delete ('systemFiles/Programs/keycardConfig') end
  PrintCentered("Removing DualKey Configuration", 18)
  sleep(0.5)
  if fs.exists('/systemFiles/Programs/dualKeyConfig') then fs.delete ('systemFiles/Programs/dualKeyConfig') end
  PrintCentered("Removing KeyCard Dual Configuration", 18)
  sleep(0.5) 
  if fs.exists('/systemFiles/Programs/KeyDualConfig') then fs.delete ('systemFiles/Programs/KeyDualConfig') end
  PrintCentered("Removing RangeLock Configuration", 18)
  sleep(0.5)
  if fs.exists('/systemFiles/Programs/rangeLockSettings') then fs.delete ('systemFiles/Programs/rangeLockSettings') end
  PrintCentered("Removing Updater Configuration", 18)
  sleep(1)
	 if fs.exists('/systemFiles/Install/updateConfig') then fs.delete ('systemFiles/Install/updateConfig') end
  PrintCentered("Removing System Configuration", 18)
  sleep(2)
  if fs.exists('/systemFiles/Programs/configuration') then fs.delete ('systemFiles/Programs/configuration') end
  PrintCentered("Settings Reset, Rebooting!", 18)
  LogFile.i('Settings Reset', runningProgram)
  sleep(2)
  os.reboot()
  end},
 
  {'Uninstall Security Suite', function()
	  LogFile.i('Wiping Computer', runningProgram)
   term.setCursorPos(1,1)
   term.setBackgroundColor(256)
   term.setTextColor(colours.white)
   term.clear()
   titleBar.draw("HbombOS BIOS", "Uninstaller", colors.cyan, 256, 128, 256, 1)
   printer.centered("Please Wait While We Uninstall Security Suite 2014", 6)
   sleep(4)
   local function rmFold(path)
    if path == '/rom' or path == "/openp" then
	 return
    end
    for i, v in ipairs(fs.list(path)) do
	 sleep(0.5)
	  term.setTextColor(1)
	  term.setBackgroundColor(256)
	 if fs.isDir(path..'/'..v) then
	  rmFold(path..'/'..v)
	 else
	  if fs.delete(path..'/'..v) then
	    term.setTextColor(1)
	    PrintCentered('Removed: '..path..'/'..v, 18)
	    LogFile.i('Removed: '..path, runningProgram)
	    sleep(0.5)
	  end
	 end
    end
    if path ~= '' then
	 fs.delete(path)
    end
   end
   rmFold('')
  
  end},
  {'Use Shell/CraftOS', function() term.setBackgroundColor(colors.black) term.clear() term.setCursorPos(1,1) LogFile.i('Shell Opened', runningProgram) shell.run ("shell") end},
  {'Change Admin Password', function() 
   term.clear()
   titleBar.draw("HbombOS Security Suite", "Password Management", colors.cyan, 256, 128, 256, 1)
   newPassword2Wait = true
   newPassWait = true
   oldPassWait = true
   start()
   oldPassword()
   LogFile.e('Password Changer Crash', runningProgram)
   error("Password Changer CRASH Report If Not Your Fault")
  end},
  {'Force Update', function()
    LogFile.i('Force Updating Client', runningProgram)
    term.clear()
    titleBar.draw("HbombOS Security Suite", "Force Updating", colors.cyan, 256, 128, 256, 1)
	   printer.centered("Downloading New Update Firmware", 19)
    printer.centered("Force Updating Client", 6)
		  sleep(1)
    download.git("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/systemFiles/Install/updater", "systemFiles/Install/updater")
    printer.centered("Running Updater", 19)
    sleep(0)
    shell.run("systemFiles/Install/updater")
    sleep(4)
    continue = true
  end},
  {'Change Startup File', function() programMenu() end},
  {'Continue Boot', function() LogFile.i('Left Boot Menu', runningProgram) continue = true end}
}
local selected = 1
local function draw()
  for i, v in ipairs(options) do
   local bg = 256
   local tc = colours.white
   if i == selected then
    bg = 256
    tc = colours.blue
   end
   term.setTextColor(tc)
   term.setBackgroundColor(bg)
   PrintCentered(' '..v[1]..' ', math.floor(#options/2) + i + 4)
  end
end
local wait = true
draw()
while wait do
  local event, key = os.pullEvent('key')
  if key == keys.up then
   selected = selected - 1
   if selected < 1 then
    selected = 1
   end
  elseif key == keys.down then
   selected = selected + 1
   if selected > #options then
    selected = #options
   end
  elseif key == keys.enter then
   if options[selected][1] == 'Uninstall Security Suite' then
	 term.setTextColor(1)
			  term.setBackgroundColor(256)
			  term.clear()
	 titleBar.draw("HbombOS Security Suite", "Settings", colors.cyan, 256, 128, 256, 1)
		   PrintCentered("HbombOS Security Suite", 4)
		   PrintCentered("Boot Options", 5)
		   PrintCentered("Use Your Arrow Keys To Select, Enter To Confirm", 19)
		   PrintCentered("Are You Sure, ALL Files Will Be Removed", 10)
		   PrintCentered("Including Files Not From Security Suite", 11)
		   PrintCentered("Y To Continue, N To Cancel", 15)
	 PrintCentered("", 19)
    local _ = true
    while _ do
	 local ev, key = os.pullEvent('char')
	 if key == 'y' then
		 sleep(0)
	  term.clear()
	  term.setTextColor(1)
	  term.setBackgroundColor(256)
		 titleBar.draw("HbombOS Security Suite", "Uninstall", colors.cyan, 256, 128, 256, 1)
	  PrintCentered("Removing HbombOS Security Suite", 6)
	  options[selected][2]()
	  term.clear()
		 titleBar.draw("HbombOS Security Suite", "Uninstall", colors.cyan, 256, 128, 256, 1)
	  printer.centered("Thanks For Using Security Suite", 6)
	  printer.centered("If Bugs Made You Uninstall, Please Report Them!", 8)
	  printer.centered("Click Anywhere On-screen To Reboot", 19)
		 os.pullEvent("mouse_click")
	  os.reboot()
	 elseif key == 'n' then
	  _ = false
	  term.clear()
	  titleBar.draw("HbombOS Security Suite", "Settings", colors.cyan, 256, 128, 256, 1)
		    PrintCentered("HbombOS Security Suite", 4)
					 PrintCentered("Boot Options", 5)
					 PrintCentered("Use Your Arrow Keys To Select, Enter To Confirm", 19)
	  --bootMenuOptions(true)
	 end
    end
    term.setTextColor(colors.red)
    term.setBackgroundColor(colors.white)
    PrintCentered('						  ', 0)
    term.setTextColor(1)
    term.setBackgroundColor(256)
   else
    options[selected][2]()
    wait = false
   end
  end
  draw()
end
term.setTextColor(colors.white)
printer.centered("Continuing Boot...", 19)
sleep(0.1)
printer.centered("Returning continue Variable", 19)
return continue
end
function Start()
  checkStartKey()
  local key = nil
  local success = false
  parallel.waitForAll(function()success = main() os.queueEvent('BootDone') end, function() key = RecieveStartupKey() end)
if success and key == keys.leftAlt or key == keys.rightAlt then
	  success = bootMenuOptions()
end
   return success
  end
  
function readFiles()
  LogFile.i('Reading System Config', runningProgram)
  printer.centered("Reading Configuration Files", 19)
  local f = fs.open('systemFiles/Programs/configuration', 'r') --Opens Config
  fileStartup = f.readLine()
  f.close()
   if fileStartup then --Checks If The User Has A File Chosen
   printer.centered("Running: "..fileStartup, 19)
   LogFile.i('Running User File: '..fileStartup, runningProgram)
   --shell.run(''..fileStartup..'')
   shell.run(fileStartup) --Runs User Specified Program
   sleep(4)
   LogFile.e('Program: '..fileStartup..' Crashed', runningProgram)
   error("The Program: "..fileStartup.." Appears To Have Crashed") --Preliminary BSoD Catching Program Closure
end
  printer.centered("No Default File Stored", 19)
  sleep(1)
  os.reboot() --Reboots So User Can Pick There Program
end
function initialise() --Function Used To Trace Error Catching
  term.setBackgroundColor(256)
  term.clear()
  drawTitleBar()
  if Start() then
    readFiles()
  else
    errora.err("Uh Oh! Booting Failed", "The start-up process failed when waiting")
  end
end
local _, err = pcall(initialise) --Error Catching, All Functions Are Called From initialise() at some point...
  if err then
    LogFile.e('XPCALL Error Caught: '..err, runningProgram)
    term.setCursorBlink(false)
errora.err(err, 'Startup Has Crashed! Please Report Above Error', true) --BSoD for protection, the 'true' is an auto-reboot option to prevent the door waiting for a prompt
  end

Thanks In Advance - Harry
Bomb Bloke #2
Posted 31 August 2014 - 02:38 AM
Well that'll be a fun one to untangle.

The function bombing out is this one, within the multishell API:

function multishell.setTitle( n, sTitle )
    if n >= 1 and n <= #tProcesses then
        setProcessTitle( n, sTitle )
        redrawMenu()
    end
end

Why it'd run when you attempt to reboot, I dunno.

I suppose a good start would be to edit that API - first get it to open a text file and output the types and values of n, sTitle and tProcesses there every time it's called. Then, rig it to specifically call error() and identify the calling function if it detects one of those is nil but shouldn't be.

Regarding images, you can usually embed them with IMG tags:

Spoiler

Quote this post to see the code. Note that some imaging sites don't allow "hotlinking" in this manner and specifically prevent the images from loading.
hbomb79 #3
Posted 31 August 2014 - 02:51 AM
I suppose a good start would be to edit that API - first get it to open a text file and output the types and values of n, sTitle and tProcesses there every time it's called. Then, rig it to specifically call error() and identify the calling function if it detects one of those is nil but shouldn't be.

Thanks, Ill try to edit it, although ive never done this before, Ill see what I can do
Edited on 31 August 2014 - 12:52 AM
hbomb79 #4
Posted 31 August 2014 - 03:11 AM
After making it output N and sTitle to a file this is what I got:


N: 1 sTitle: shell N: 1 sTitle: startup N: 1 sTitle: startup N: 1 sTitle: OpenPDetect N: 1 sTitle: shell N: 1 sTitle: startup N: 1 sTitle: startup N: 1 sTitle: OpenPDetect N: 1 sTitle: shell N: 1 sTitle: startup N: 1 sTitle: startup N: 1 sTitle: OpenPDetect N: 1 sTitle: shell N: 1 sTitle: startup

Pretty much over and over… Your next step I dont understand, What do you mean rig error() to the calling function, How do I do the calling function part, I understand how to use error() just where you want me to is confusing

EDIT: As far as I can tell, Nothing is ever calling multishell.getTitle() although I dont know how it works so it might be called through a metatable or something
Edited on 31 August 2014 - 01:15 AM
hbomb79 #5
Posted 31 August 2014 - 03:29 AM
After changing the section to this:


function multishell.setTitle( n, sTitle )
    if n >= 1 and n <= #tProcesses then
	    setProcessTitle( n, sTitle )
	   local h = fs.open('multiShellOutput', 'a')
h.write(' N: '..n..' sTitle: '..sTitle)
h.close()
	    redrawMenu()
    end
end

Nothing Changed Although Changing It To This:


function multishell.setTitle( n, sTitle )
    local h = fs.open('multiShellOutput', 'a')
h.write(' N: '..n..' sTitle: '..sTitle)
h.close()
    if n >= 1 and n <= #tProcesses then
	    setProcessTitle( n, sTitle )
	    redrawMenu()
    end
end
Has Stopped The Problem So Far, Alhough This Is Just A Workaround, This will still occur to others using my security suite… Any ideas anybody?
Bomb Bloke #6
Posted 31 August 2014 - 04:48 AM
The former change doesn't affect anything because you're attempting to perform the write after the point where the crash has already occurred.

The latter change "shouldn't" affect anything, and the fact that it does will only make it harder to track down the root of the problem. Still - what gets written to the file???

What I said about setting error levels before still stands. Once you've picked up some patterns from your output file, switch out the file writing code with error detection code.
hbomb79 #7
Posted 31 August 2014 - 05:08 AM
What I said about setting error levels before still stands. Once you've picked up some patterns from your output file, switch out the file writing code with error detection code.

What do you mean by error detection, Wont it just error before it crashes… This is whats in the output file:


N: 1 sTitle: shell N: 1 sTitle: startup N: 1 sTitle: startup N: 1 sTitle: OpenPDetect N: 1 sTitle: shell N: 1 sTitle: startup N: 1 sTitle: startup N: 1 sTitle: OpenPDetect

This is repeated over and over with no real differnece… There is never any new variable names, The N and sTitile were in the mulitshell api and it was what it was checking in the if statement, so that it was i recorded

Ill revert the changes to the API and see if the problem persists… It probably will but just out of curiosity
Edited on 31 August 2014 - 03:14 AM
Bomb Bloke #8
Posted 31 August 2014 - 05:32 AM
Sorry, looks like a missed a post - so we've got script titles of "startup" and "OpenPDetect", those being your two script files. At least we know there's nothing else hiding in there.

The deal with the error traceback is explained in the guide I linked. We know multishell.setTitle() is crashing, and we can also reasonably assume that's because it's being passed invalid data to work with - so we want to know which function is making that call.

We do this by checking the data and manually throwing an error indicating the caller if there's a problem with it:

function multishell.setTitle( n, sTitle )
    if not n then error("Bad call to multishell.setTitle()",2) end

    if n >= 1 and n <= #tProcesses then
        setProcessTitle( n, sTitle )
        redrawMenu()
    end
end

By messing with the error levels, you'll hopefully be able to work out the point where the actions of your code starts to matter.
hbomb79 #9
Posted 31 August 2014 - 06:05 AM
By messing with the error levels, you'll hopefully be able to work out the point where the actions of your code starts to matter.

Ahh, I see, I will try messing with the levels until I find the first program that I have coded and report back to you
hbomb79 #10
Posted 31 August 2014 - 06:16 AM
After changing the multishell to this:


function multishell.setTitle( n, sTitle )
	if not n then error('Invalid Call to multishell.setTitle()', 3) end
	if n >= 1 and n <= #tProcesses then
		setProcessTitle( n, sTitle )
		redrawMenu()
	end
end

And I Also tried:

function multishell.setTitle( n, sTitle )
	if not n then error('Invalid Call to multishell.setTitle()', 2) end
	if n >= 1 and n <= #tProcesses then
		setProcessTitle( n, sTitle )
		redrawMenu()
	end
end

All it says is this:

http://imgur.com/GJuVIOT
Edited on 31 August 2014 - 04:16 AM
Bomb Bloke #11
Posted 31 August 2014 - 06:59 AM
Lovely. Doesn't want to reveal much, does it?

It may be worth trying your code on a system that isn't using multishell. Assuming for whatever reason you don't have easy access to a suitable computer (eg in a world with an older version of ComputerCraft), you can kill it by editing this segment down the bottom of bios.lua:

-- Run the shell
local ok, err = pcall( function()
    parallel.waitForAny( 
        function()
            if term.isColour() then
                os.run( {}, "rom/programs/advanced/multishell" )
            else
                os.run( {}, "rom/programs/shell" )
            end
            os.run( {}, "rom/programs/shutdown" )
        end,
        function()
            rednet.run()
        end )
end )

With multishell out of the way, see if your code still generates any weirdness. If not, then I'd say multishell is entirely to blame and you can log it as a bug. If so, then it should hopefully be easier to fix things within your own code.
hbomb79 #12
Posted 31 August 2014 - 07:22 AM
After disabling Multishell by:


-- Run the shell
local ok, err = pcall( function()
    parallel.waitForAny(
	    function()
		    if term.isColour() then
			    --os.run( {}, "rom/programs/advanced/multishell" )
    os.run( {}, "rom/programs/shell" )
		    else
			    os.run( {}, "rom/programs/shell" )
		    end
		    os.run( {}, "rom/programs/shutdown" )
	    end,
	    function()
		    rednet.run()
	    end )
end )

The Error Of:

http://imgur.com/rQ0J7Ot

Appears On Screen… It Just Doesnt Give Up Does It!
Bomb Bloke #13
Posted 31 August 2014 - 07:33 AM
That appears when you try to reboot, or…?

What are your non-advanced computers doing?
hbomb79 #14
Posted 31 August 2014 - 11:57 PM
My security suite doesn't run in non advanced machines, It uses too much color…
Bomb Bloke #15
Posted 01 September 2014 - 02:00 AM
Should I take that to mean that an advanced computer without your code on it - with the exception of your BIOS alteration - still works fine?
hbomb79 #16
Posted 01 September 2014 - 05:13 AM
Should I take that to mean that an advanced computer without your code on it - with the exception of your BIOS alteration - still works fine?

As far as I know, Rebooting And Shutting Down an advanced computer is fine, Even with my security suite running another program, It ONLY the detector lock that does this which is why its so confusing
Bomb Bloke #17
Posted 01 September 2014 - 05:43 AM
Righto. Where exactly is "errora" defined?
hbomb79 #18
Posted 01 September 2014 - 06:43 AM
Righto. Where exactly is "errora" defined?

errora is an API that is loaded by the startup file
Bomb Bloke #19
Posted 01 September 2014 - 06:57 AM
Pastebin links to each such loaded API may be useful.
hbomb79 #20
Posted 01 September 2014 - 07:04 AM
All the files for my Security Suite are on pastebin, Heres the link: https://github.com/hbomb79/securitySystemPro
Bomb Bloke #21
Posted 01 September 2014 - 01:59 PM
Do you have the same issue if you don't overwrite os.pullEvent with os.pullEventRaw in errora?
hbomb79 #22
Posted 02 September 2014 - 05:40 AM
Do you have the same issue if you don't overwrite os.pullEvent with os.pullEventRaw in errora?

What do you mean overwrite, I can find the use of os.pullEvent in the errora API
Bomb Bloke #23
Posted 02 September 2014 - 06:18 AM
On line 1 of errora, you overwrite the os.pullEvent pointer with os.pullEventRaw. What happens if you eg comment out that line?
hbomb79 #24
Posted 02 September 2014 - 09:44 PM
I'll try that when I get home, although how will I stop the user from terminating the script?
Dragon53535 #25
Posted 02 September 2014 - 10:38 PM
You're loading it only as an API, it's being called by the main script, and so you can just put it at the top of the file calling it which would stop the termination.
Bomb Bloke #26
Posted 03 September 2014 - 01:49 AM
No, don't put it in at all - the point is to see whether the same errors occur when it's removed. Forget about what users might do for now. I'm not saying to commit the change to git.
hbomb79 #27
Posted 18 September 2014 - 10:04 PM
Right, I'll change it soon and then get back to you, I have been on holiday for a bit and forgot all about this :P/>