Advertisement
Guest User

installer

a guest
Jan 8th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 98.13 KB | None | 0 0
  1. inputTable = {
  2.   usrData = {
  3.     login = "{\
  4.  {\
  5.    name = \"main\",\
  6.    pass = \"pass\",\
  7.  },\
  8. }",
  9.     preferences = "{\
  10.  main = {\
  11.    mainColour = 16384,\
  12.    homeApps = {\
  13.      {\
  14.        path = \".kernel/programs/settings\",\
  15.        settings = {\
  16.          fullRights = true,\
  17.          sandboxFiles = false,\
  18.          fullscreen = false,\
  19.        },\
  20.        image = \".kernel/core/files/images/settingsIcon\",\
  21.      },\
  22.      default = {\
  23.        path = \"\",\
  24.        settings = {\
  25.          fullRights = false,\
  26.          sandboxFiles = true,\
  27.          fullscreen = false,\
  28.        },\
  29.        image = \".kernel/core/files/images/homeAppsDefaultImage\",\
  30.      },\
  31.    },\
  32.    secColour = 2048,\
  33.    name = \"main\",\
  34.  },\
  35. }",
  36.   },
  37.   other = {
  38.     tmpCache = "os:41: Expected string",
  39.   },
  40.   [ ".mdata" ] = {
  41.     plist = "{}",
  42.   },
  43.   apis = {
  44.     cinter = "function reboot(originalWindow)\
  45.  term.redirect(originalWindow)\
  46.  local des = gui.popup(1, 'Are you sure you want to reboot the PC?', 'Reboot')\
  47.  if des == true then\
  48.    rebootPC(originalWindow)\
  49.  else\
  50.    term.setBackgroundColor(colors.black)\
  51.    term.clear()\
  52.    term.setCursorPos(1, 1)\
  53.    redrawTaskbar()\
  54.  end\
  55. end\
  56. \
  57. function shutdown(originalWindow)\
  58.  term.redirect(originalWindow)\
  59.  local des = gui.popup(1, 'Are you sure you want to       shutdown?', 'Shutdown')\
  60.  if des == true then\
  61.    shutdownPC(originalWindow)\
  62.  else\
  63.    term.setBackgroundColor(colors.black)\
  64.    term.clear()\
  65.    term.setCursorPos(1, 1)\
  66.    redrawTaskbar()\
  67.  end\
  68. end\
  69. \
  70. function logout()\
  71.  _G.endAll = true\
  72. end\
  73. \
  74. function shutdownPC(originalWindow)\
  75.  term.redirect(originalWindow)\
  76.  term.setBackgroundColor(colors.white)\
  77.  term.clear()\
  78.  term.setTextColor(colors.black)\
  79.  txt.ctxt(\"Shutting down.\", 8)\
  80.  txt.ctxt(\"BASE 2\", 19)\
  81.  sleep(1)\
  82.  oldOS.shutdown(originalWindow)\
  83. end\
  84. \
  85. function rebootPC(originalWindow)\
  86.  term.redirect(originalWindow)\
  87.  term.setBackgroundColor(colors.white)\
  88.  term.clear()\
  89.  term.setTextColor(colors.black)\
  90.  txt.ctxt(\"Rebooting your PC.\", 8)\
  91.  txt.ctxt(\"BASE 2\", 19)\
  92.  sleep(1)\
  93.  oldOS.reboot()\
  94. end",
  95.     graphics = "--[[\
  96.  Core OS Graphics API. Used for minmising redraws, amongst other things.\
  97. ]]\
  98. \
  99. local screen = {}\
  100. for i = 1, 19 do\
  101.  screen[i] = {\" \", 1, 2}\
  102. end\
  103. \
  104. local function redraw()\
  105.  for i = 1, 19 do\
  106.    for i2 = 1, 51 do\
  107.      core.setCursorPos(i2, i)\
  108.      core.blit(unpack(screen[i2][i]))\
  109.    end\
  110.  end\
  111. end",
  112.     strings = "function split(text, length)\
  113.  local tmpTbl = {}\
  114.  for i = 1, #text do\
  115.    if (i - 1) % length == 0 then\
  116.      local txt = string.sub(text, i, i + (length - 1))\
  117.      table.insert(tmpTbl, txt)\
  118.    end\
  119.  end\
  120.  return tmpTbl\
  121. end",
  122.     baseForms = "local function unserialiseProgram(s)\
  123.    local func = load( \"return \"..s, \"unserialize\", \"t\", _G ) -- use _G here instead of {}\
  124.    if func then\
  125.        local ok, result = pcall(func)\
  126.        if ok then\
  127.            return result\
  128.        end\
  129.    end\
  130.    return nil\
  131. end\
  132. \
  133. local function processAppResults(resultsTbl)\
  134.  local finTbl = {}\
  135.  for i = 1, #resultsTbl do\
  136.    finTbl[i] = {}\
  137.    local tbl = resultsTbl[i]\
  138.    for i2 = 1, #tbl do\
  139.      if type(tbl[i2]) == \"table\" and tbl[i2].type == \"toggleSwitch\" and tbl[i2].name ~= nil then\
  140.        finTbl[i][tbl[i2].name] = tbl[i2]\
  141.      end\
  142.    end\
  143.  end\
  144.  if resultsTbl['functions'] ~= nil then\
  145.    if resultsTbl.functions['onExit'] ~= nil then\
  146.      finTbl.onExit = resultsTbl.functions.onExit\
  147.    end\
  148.  end\
  149.  return finTbl\
  150. end\
  151. \
  152. function runFromTable(progTable)\
  153.  if type(progTable) == \"table\" then\
  154.    local endTable = launchApp(progTable)\
  155.    returnVals = processAppResults(endTable)\
  156.    if returnVals.onExit ~= nil then\
  157.      returnVals.onExit(returnVals)\
  158.    end\
  159.  else\
  160.    os.reboot()\
  161.  end\
  162. end\
  163. \
  164. function run(path)\
  165.  local returnVals = {}\
  166.  if fs.exists(path) then\
  167.    local h = fs.open(path, \"r\")\
  168.    local raw = h.readAll()\
  169.    h.close()\
  170.    local programTable = unserialiseProgram(raw)\
  171.    if type(programTable) == \"table\" then\
  172.      local endTable = launchApp(programTable)\
  173.      returnVals = processAppResults(endTable)\
  174.      if returnVals.onExit ~= nil then\
  175.        returnVals.onExit(returnVals)\
  176.      end\
  177.    else\
  178.      return false, 2, \"Invalid baseForms application: \" .. type(programTable)\
  179.    end\
  180.  else\
  181.    return false, 1, \"Path not specified.\"\
  182.  end\
  183. end\
  184. \
  185. function launchApp(table)\
  186.  title = \"-- Unnamed baseForms Application --\"\
  187.  -- Now, to create the windows.\
  188.  -- Also atm, it does not accomodate full-screen apps\
  189.  curWin = term.current()\
  190.  endApp = false\
  191.  local appPage = 1\
  192.  maxPage = #table\
  193.  w, height = term.getSize()\
  194.  appAccessibleFunctions = {}\
  195.  topBar = window.create(curWin, 1, 1, 51, 1)\
  196.  mainArea = window.create(curWin, 1, 2, 51, (height - 1))\
  197. \
  198.  if table.functions ~= nil then\
  199.    for k, v in pairs(table.functions) do -- Initalise custom app functions. These can be used to carry out custom actions.\
  200.      appAccessibleFunctions[k] = v\
  201.    end\
  202.  end\
  203.  \
  204.  local h = fs.open(\"funcs\", \"w\")\
  205.  h.write(appAccessibleFunctions)\
  206.  h.close()\
  207. \
  208.  local function drawMain(drawTable)\
  209.    if drawTable.title ~= nil then\
  210.      title = drawTable.title\
  211.    end\
  212.    if drawTable.titleBackgroundColor ~= nil then\
  213.      backgroundColor = drawTable.titleBackgroundColor\
  214.    else\
  215.      backgroundColor = colors.gray\
  216.    end\
  217.    if drawTable.pageControlColor ~= nil then\
  218.      pageControlColor = drawTable.pageControlColor\
  219.    else\
  220.      pageControlColor = colors.gray\
  221.    end\
  222.    term.redirect(topBar)\
  223.    term.setBackgroundColor(backgroundColor)\
  224.    term.clear()\
  225.    term.setTextColor(colors.black)\
  226.    txt.ctxt(title, 1)\
  227.    term.setTextColor(colors.red)\
  228.    txt.ptxt(\"x\", 51, 1)\
  229.    paintutils.drawPixel(1, 1, pageControlColor)\
  230.    paintutils.drawPixel(50, 1, pageControlColor)\
  231.    term.setTextColor(colors.white)\
  232.    txt.ptxt(\"<\", 1, 1)\
  233.    txt.ptxt(\">\", 50, 1)\
  234.    \
  235.    term.redirect(mainArea)\
  236.    if drawTable.backgroundColor ~= nil then\
  237.      backgroundColor = drawTable.backgroundColor\
  238.    else\
  239.      backgroundColor = colors.white\
  240.    end\
  241.    term.setBackgroundColor(backgroundColor)\
  242.    term.clear()\
  243.    term.setTextColor(colors.black)\
  244. \
  245.    for i=1, (height - 1) do\
  246.      if drawTable[i] ~= nil then\
  247.        local currBar = drawTable[i]\
  248.        if currBar.type == nil then\
  249.        elseif currBar.type == \"text\" then\
  250.          if currBar.textColor ~= nil then\
  251.            textColour = currBar.textColor\
  252.          else\
  253.            textColour = colors.black\
  254.          end\
  255.          if currBar.backgroundColor ~= nil then\
  256.            currBackgroundColor = currBar.backgroundColor\
  257.          else\
  258.            currBackgroundColor = backgroundColor\
  259.          end\
  260.          paintutils.drawLine(1, i, 51, i, currBackgroundColor)\
  261.          term.setTextColor(textColour)\
  262.          txt.ctxt(currBar.text, i)\
  263. \
  264.        elseif currBar.type == \"toggleSwitch\" then\
  265.          if currBar.backgroundColor ~= nil then\
  266.            paintutils.drawLine(1, i, 51, i, currBar.backgroundColor)\
  267.          else\
  268.            term.setBackgroundColor(backgroundColor)\
  269.          end\
  270.          if currBar.textColor ~= nil then\
  271.            textColor = currBar.textColor\
  272.          else\
  273.            textColor = colors.black\
  274.          end\
  275.          term.setTextColor(textColor)\
  276.          if currBar.state == true then\
  277.            txt.ptxt(currBar.text, 2, i)\
  278.            paintutils.drawPixel(50, i, colors.gray)\
  279.            paintutils.drawLine(47, i, 49, i, colors.green)\
  280.          else\
  281.            txt.ptxt(currBar.text, 2, i)\
  282.            paintutils.drawPixel(47, i, colors.gray)\
  283.            paintutils.drawLine(48, i, 50, i, colors.red)\
  284.          end\
  285. \
  286.        elseif currBar.type == \"fullButton\" then\
  287.          if currBar.buttonColor ~= nil then\
  288.            barColour = currBar.buttonColor\
  289.          else\
  290.            barColour = colors.blue\
  291.          end\
  292.          \
  293.          if currBar.backgroundColor ~= nil then\
  294.            currBackgroundColor = currBar.backgroundColor\
  295.          else\
  296.            currBackgroundColor = backgroundColor\
  297.          end\
  298.          \
  299.          paintutils.drawLine(1, i, 51, i, currBackgroundColor)\
  300.          paintutils.drawLine(2, i, 50, i, barColour)\
  301.          \
  302.          if currBar.textColor ~= nil then\
  303.            textColor = currBar.textColor\
  304.          else\
  305.            textColor = colors.black\
  306.          end\
  307.          term.setTextColor(textColor)\
  308.          txt.ctxt(currBar.text, i)\
  309.          term.setBackgroundColor(colors.white)\
  310. \
  311.        elseif currBar.type == \"fullLgButtonTop\" then\
  312.          --if currBar\
  313.        end\
  314.      end\
  315.    end\
  316.  end -- End of drawMain\
  317. \
  318.  repeat\
  319.    drawMain(table[appPage])\
  320.    local _, button, x, y = os.pullEvent(\"mouse_click\")\
  321.    if button == 1 then\
  322.      if x==51 and y==1 then\
  323.        endApp = true\
  324.      elseif x==1 and y==1 then\
  325.        if appPage > 1 then\
  326.          appPage = appPage - 1\
  327.        end\
  328.      elseif x==50 and y == 1 then\
  329.        if appPage < maxPage then\
  330.          appPage = appPage + 1\
  331.        end\
  332.      elseif y>1 then\
  333.        local y = y-1\
  334.        if table[appPage][y] ~= nil then\
  335.          local bar = table[appPage][y]\
  336.          if bar.type ~= nil then\
  337.            if bar.type == \"fullButton\" then\
  338.              if x>=2 and x<=50 then\
  339.                if bar.action ~= nil and bar.action == \"exit()\" then\
  340.                  endApp = true\
  341.                else\
  342.                  if type(appAccessibleFunctions[bar.action]) == \"function\" then\
  343.                    appAccessibleFunctions[bar.action]()\
  344.                  end\
  345.                end\
  346.              end\
  347.            elseif bar.type == \"toggleSwitch\" then\
  348.              if x>=47 and x<=50 then\
  349.                if bar.state == true then\
  350.                  bar.state = false\
  351.                else\
  352.                  bar.state = true\
  353.                end\
  354.                table[appPage][y] = bar\
  355.              end\
  356.            end\
  357.          end\
  358.        end\
  359.      end\
  360.    end\
  361.  until endApp\
  362.  return table\
  363. end",
  364.     txt = "function center(text, y)\
  365.  local w, h = term.getSize()\
  366.  local x = ((w/2)-(#text/2))+1\
  367.  term.setCursorPos(x, y)\
  368.  write(text)\
  369. end\
  370. \
  371. function ctxt(txt, y)\
  372.  center(txt, y)\
  373. end\
  374. \
  375. function pwrite(text, x, y)\
  376.  term.setCursorPos(x, y)\
  377.  write(text)\
  378. end\
  379. \
  380. function ptxt(txt, x, y)\
  381.  pwrite(txt, x, y)\
  382. end\
  383. \
  384. function entryBox(x, y, xS, fG, bG, shield)\
  385.  local beginWin = term.current()\
  386.  local tempWin = window.create(beginWin, x, y, (xS-x)+1, 1)\
  387.  term.redirect(tempWin)\
  388.  term.setBackgroundColor(bG)\
  389.  term.clear()\
  390.  --term.setTextColor(fG)\
  391.  local tmpVal = read(shield)\
  392.  term.redirect(beginWin)\
  393.  tempWin = nil\
  394.  return tmpVal\
  395. end",
  396.     fileSystem = "--File Selection Dialog, version 1.0\
  397. \
  398. local function dropDown(tbl, x, y)\
  399.  for i=1, #tbl do\
  400.    paintutils.drawLine(x, (y+i)-1, x+10, (y+i)-1, colors.lightGray)\
  401.    ptxt(tbl[i], x, (y+i)-1)\
  402.  end\
  403.  paintutils.drawLine(x+11, y+1, x+11, y+#tbl, colors.black)\
  404.  paintutils.drawLine(x+1, y+#tbl, x+11, y+#tbl, colors.black)\
  405.  local _, b, xP, yP = os.pullEvent(\"mouse_click\")\
  406.  local yP = yP-2\
  407.  local xP = xP-4\
  408.  if b==1 then\
  409.    if xP>=x and xP<=x+9 and yP>=y and yP<=(y+#tbl)-1 then\
  410.      return (yP-y)+1\
  411.    end\
  412.  end\
  413. end\
  414. \
  415. local function ctxt(text, y)\
  416.  local w, h = term.getSize()\
  417.  local x = ((w/2)-(#text/2))+1\
  418.  term.setCursorPos(x, y)\
  419.  write(text)\
  420. end\
  421. \
  422. function ptxt(text, x, y)\
  423.  term.setCursorPos(x, y)\
  424.  write(text)\
  425. end\
  426. \
  427. local function click()\
  428.  _, b, x, y = os.pullEvent(\"mouse_click\")\
  429. end\
  430. \
  431. local function scroll()\
  432.  _, sPos, x, y = os.pullEvent(\"mouse_scroll\")\
  433. end\
  434. \
  435. local function display(mode)\
  436. \
  437.  curDir = \"/\"\
  438.  \
  439.  local beg = term.current()\
  440.  local newWin = window.create(beg, 5, 3, 43, 15)\
  441.  paintutils.drawLine(48, 4, 48, 17, colors.gray)\
  442.  paintutils.drawLine(6, 18, 48, 18, colors.gray)\
  443.  term.redirect(newWin)\
  444.    \
  445.  pos = 1\
  446.  \
  447.  while true do\
  448.  \
  449.    term.setBackgroundColor(colors.white)\
  450.    term.clear()\
  451.  \
  452.    term.setTextColor(colors.black)\
  453.    if fileSelect ~= nil then\
  454.      paintutils.drawLine(1, 15, 21, 15, colors.green)\
  455.      ptxt(\"Select\", 8, 15)\
  456.    else\
  457.      paintutils.drawLine(1, 15, 21, 15, colors.gray)\
  458.      ptxt(\"Select\", 8, 15)\
  459.    end\
  460.    \
  461.    if fileSelect ~= nil then\
  462.      if fs.isDir(fs.combine(curDir, fileSelect)) then\
  463.        paintutils.drawLine(22, 15, 43, 15, colors.lightGray)\
  464.        ptxt(\"Enter Folder\", 26, 15)\
  465.      else\
  466.        paintutils.drawLine(22, 15, 43, 15, colors.gray)\
  467.        ptxt(\"Enter Folder\", 26, 15)\
  468.      end\
  469.    else\
  470.      paintutils.drawLine(22, 15, 43, 15, colors.gray)\
  471.      ptxt(\"Enter Folder\", 26, 15)\
  472.    end\
  473.    \
  474.    term.setBackgroundColor(colors.white)\
  475.  \
  476.    --local curDir = shell.dir() --Don't know why, but it doesn't work.\
  477. \
  478.    \
  479.  \
  480.    local dirList = fs.list(curDir)\
  481.    \
  482.    local files = {}\
  483.    local folds = {}\
  484.    \
  485.    for i=1, #dirList do\
  486.      if fs.isDir(fs.combine(curDir, dirList[i])) then\
  487.        table.insert(folds, dirList[i])\
  488.      else\
  489.        table.insert(files, dirList[i])\
  490.      end\
  491.    end\
  492.    \
  493.    table.sort(files)\
  494.    table.sort(folds)\
  495.    \
  496.    term.setCursorPos(1, 1)\
  497. \
  498.    tPos = 1\
  499. \
  500.    for i=pos, pos+13 do\
  501. \
  502.      if dirList[i] ~= nil then\
  503. \
  504.        if fs.isDir(fs.combine(curDir, dirList[i])) then\
  505.          if fileSelect == dirList[i] then\
  506.            term.setTextColor(colors.lightGray)\
  507.          else\
  508.            term.setTextColor(colors.black)\
  509.          end\
  510.          write('[] ' .. string.sub(dirList[i], 1, 40) .. '\\n')\
  511.        else\
  512.          if fileSelect == dirList[i] then\
  513.            term.setTextColor(colors.lightGray)\
  514.          else\
  515.            term.setTextColor(colors.black)\
  516.          end\
  517.          write(\"() \" .. string.sub(dirList[i], 1, 40) .. '\\n')\
  518.        end\
  519. \
  520.      end\
  521. \
  522.    end\
  523.    \
  524.    paintutils.drawPixel(43, 1, colors.red)\
  525.    ptxt('x', 43, 1)\
  526. \
  527.    local pid = parallel.waitForAny(click, scroll)\
  528. \
  529.    if pid == 2 then\
  530. \
  531.      if sPos == 1 then\
  532. \
  533.        if pos+13 < #files+#folds then\
  534.          pos = pos+1\
  535.        end\
  536. \
  537.      elseif sPos==-1 then\
  538. \
  539.        if pos>1 then\
  540.          pos=pos-1\
  541.        end\
  542. \
  543.      end\
  544. \
  545.    elseif pid == 1 then\
  546.    \
  547.      x = x-4\
  548.      y = y-2\
  549.      if b==1 then\
  550.        if x>=1 and x<=43 then\
  551.          if x==43 and y==1 then\
  552.            error()\
  553.          end\
  554.          if y>=1 and y<=14 then\
  555.            if dirList[(y+pos)-1] ~= nil then\
  556.              fileSelect = dirList[(y+pos)-1]\
  557.            else\
  558.              fileSelect = '/'\
  559.            end\
  560.          elseif y==15 then\
  561.            if x>=1 and x<=21 and fileSelect ~= nil then\
  562.              return fs.combine(curDir, fileSelect)\
  563.            elseif x>=22 and x<=43 and fs.isDir(fs.combine(curDir, fileSelect)) then\
  564.              curDir = fs.combine(curDir, fileSelect)\
  565.            end\
  566.          end\
  567.        end\
  568.      elseif b==2 then\
  569.        if x>=1 and x<=43 and y>=1 and y<=15 then\
  570.          local op = dropDown({\"Back up\", \"Cancel\"}, x, y)\
  571.          if op == 1 then\
  572.            curDir = fs.getDir(curDir)\
  573.          end\
  574.        end\
  575.      end\
  576. \
  577.    end --End of pid\
  578.      \
  579.  end\
  580.  \
  581.  term.redirect(beg)\
  582. end\
  583. \
  584. function folder()\
  585.  display()\
  586. end",
  587.     tasks = "--[[\
  588.  BASE 2 Multitasking core\
  589. ]]--\
  590. \
  591. local activeTasks = {}\
  592. local isActive = false\
  593. currentTask = 1\
  594. \
  595. function returnTasks()\
  596.  return activeTasks\
  597. end\
  598. \
  599. function bringToFront(taskID)\
  600. \009if activeTasks[taskID] ~= nil then\
  601. \009\009currentTask = taskID\
  602. \009\009screenManage.redirectScreen(activeTasks[taskID].screenID)\
  603. \009end\
  604. end\
  605. \
  606. function launchBackgroundTaskAsAPI(pathOfAPI, pathOfManager)\
  607. \009if pathOfAPI ~= nil and pathOfManager ~= nil and fs.exists(pathOfAPI) and fs.exists(pathOfManager) then\
  608. \009\009local h = fs.open(pathOfAPI, \"r\")\
  609. \009\009local data = h.readAll()\
  610. \009\009h.close()\
  611. \009\009local data = loadstring(data)\
  612. \009\009local APIName = fs.getName(pathOfAPI)\
  613. \009\009_G.APIName = data\
  614. \009\009--newTask(loadstring(data), true)\
  615. \009end\
  616. end\
  617. \
  618. function newTask(func, referral)\
  619.  if type(func) == \"function\" then\
  620.    local co = coroutine.create(func)\
  621. \009if referral ~= true then\
  622. \009\009local screenID = screenManage.newScreen(18, 51)\
  623. \009end\
  624.    local routineTable = {\
  625.      routine = co,\
  626.      id = #activeTasks + 1,\
  627.      filter = nil,\
  628. \009  screenID = screenID,\
  629.    }\
  630.    activeTasks[#activeTasks + 1] = routineTable\
  631.    return #activeTasks\
  632.  end\
  633. end\
  634. \
  635. function removeTask(id)\
  636.  if activeTasks[id] ~= nil then\
  637.    activeTasks[id] = nil\
  638.    return true\
  639.  else\
  640.    return false\
  641.  end\
  642. end\
  643. \
  644. function startX()\
  645.  if isActive then\
  646.    error(\"Multitasking core already running!\")\
  647.  end\
  648.  isActive = true\
  649.  local pID = tasks.newTask(loadfile(\".kernel/core/os.main\"))\
  650.  bringToFront(pID)\
  651.  while true do\
  652. \009local ok, err = pcall(screenManage.redraw)\
  653. \009if not ok then local h = fs.open(\"/.latest\", \"w\")\
  654. \009\009h.write(err)\
  655. \009\009h.close()\
  656. \009\009os.shutdown()\
  657. \009end\
  658.    local evt = {os.pullEvent()}\
  659.    for i=1, #activeTasks do\
  660.      local v = activeTasks[i]\
  661.      if (evt[1] == \"terminate\" or v.filter == evt[1] or v.filter == nil) then\
  662.        local ok, filter = coroutine.resume(v.routine, unpack(evt))\
  663.        v.filter = filter\
  664.      end\
  665.      activeTasks[i] = v\
  666.      if coroutine.status(v.routine) == \"dead\" then\
  667.        activeTasks[i] = nil\
  668.      end\
  669.    end\
  670.  end\
  671. end\
  672. \
  673. function start()\
  674. \009local ok, err = pcall(startX)\
  675. \009if not ok then local h = fs.open(\"/.latest\", \"w\")\
  676. \009\009h.write(err)\
  677. \009\009h.close()\
  678. \009\009os.shutdown()\
  679. \009end\
  680. end\
  681. \
  682. --End of file",
  683.     screenManage = "--[[\
  684. \009BASE 2 Screen-Managing file.\
  685. \009This makes sure that apps only draw to their screens, and not to the current one, if they are not currently selected. This file handles all drawing requests from programs, and minimises the amount of drawing calls that\
  686. \009eventually have to be made, therefore resulting in less flickering, and in some circumstances, better performance.\
  687. ]]--\
  688. \
  689. local screens = {}\
  690. local currentlyDrawn = {}\
  691. local h = 19\
  692. local w = 51\
  693. for i = 1, h do\
  694. \009currentlyDrawn[i] = {}\
  695. \009for i2 = 1, w do\
  696. \009\009currentlyDrawn[i][i2] = {}\
  697. \009end\
  698. end\
  699. local currentScreen = 1\
  700. local currentBackgroundColor = colors.black\
  701. local currentForegroundColor = colors.white\
  702. \
  703. function newScreen(height, width)\
  704. \009if height == nil then\
  705. \009\009height = 18\
  706. \009end\
  707. \009if width == nil then\
  708. \009\009width = 51\
  709. \009end\
  710. \009local tmp = {}\
  711. \009for i = 1, height do\
  712. \009\009tmp[i] = {}\
  713. \009\009for i2 = 1, width do\
  714. \009\009\009tmp[i][i2] = {\" \", colors.white, colors.white}\
  715. \009\009end\
  716. \009end\
  717. \009screens[#screens + 1] = {graphics = tmp, currentPos = {x = 1, y = 1}, width = width, height = height}\
  718. \009return #screens\
  719. end\
  720. \
  721. function redrawTaskbar()\
  722. \009base_core.graphics.oldTerm.setCursorPos(1, 19)\
  723. \009base_core.graphics.oldTerm.setBackgroundColor(colors.lightGray)\
  724. \009base_core.graphics.oldTerm.write(\"[v]\")\
  725. \009for i = 1, 48 do\
  726. \009\009base_core.graphics.oldTerm.write(\" \")\
  727. \009end\
  728. end\
  729. \
  730. function redirectScreen(id)\
  731. \009if screens[id] ~= nil then\
  732. \009\009currentScreen = id\
  733. \009\009return true\
  734. \009end\
  735. end\
  736. \
  737. function redraw()\
  738. \009--local beg = base_core.graphics.oldTerm.current()\
  739. \009--base_core.graphics.oldTerm.redirect(base_core.graphics.oldTerm.native())\
  740. \009if screens[currentScreen] ~= nil then\
  741. \009\009local screen = screens[currentScreen].graphics\
  742. \009\009width = screens[currentScreen].width\
  743. \009\009height = screens[currentScreen].height\
  744. \009\009for i = 1, height do\
  745. \009\009\009for i2 = 1, width do\
  746. \009\009\009\009if currentlyDrawn[i][i2] ~= screen[i][i2] then\
  747. \009\009\009\009\009base_core.graphics.blit(screen[i][i2][1], screen[i][i2][2], screen[i][i2][3], i2, i)\
  748. \009\009\009\009\009currentlyDrawn[i][i2] = screen[i][i2]\
  749. \009\009\009\009end\
  750. \009\009\009end\
  751. \009\009end\
  752. \009\009--base_core.graphics.oldTerm.redirect(beg)\
  753. \009\009redrawTaskbar()\
  754. \009\009return true\
  755. \009end\
  756. \009--base_core.graphics.oldTerm.redirect(beg)\
  757. end\
  758. \
  759. function deleteScreen(id)\
  760. \009if screens[id] ~= nil then\
  761. \009\009screens[id] = nil\
  762. \009\009return true\
  763. \009end\
  764. end\
  765. \
  766. \
  767. --[[ BEGIN TERM REPLACEMENTS ]]--\
  768. \
  769. function setCursorPos(x, y)\
  770. \009if screens[currentScreen] ~= nil then\
  771. \009\009screens[currentScreen].currentPos = {x = x, y = y}\
  772. \009\009return true\
  773. \009end\
  774. \009return false\
  775. end\
  776. \
  777. function write(text)\
  778. \009local screen = screens[currentScreen]\
  779. \009if screen ~= nil then\
  780. \009\009local textTable = string.sub(screen, \".+\")\
  781. \009\009local cont = screen.width - screen.currentPos.x + 1\
  782. \009\009for i = 1, cont do\
  783. \009\009\009if textTbl[i] ~= nil then\
  784. \009\009\009\009local tbl = {textTable[i], currentForegroundColor, currentBackgroundColor}\
  785. \009\009\009\009screen.graphics[screen.currentPos.y][screen.currentPos.x] = tbl\
  786. \009\009\009end\
  787. \009\009end\
  788. \009end\
  789. \009screens[currentScreen] = screen\
  790. end\
  791. \
  792. function setBackgroundColor(colour)\
  793. \009currentBackgroundColor = colour\
  794. end\
  795. \
  796. function setTextColor(colour)\
  797. \009currentForegroundColor = colour\
  798. end\
  799. \
  800. function clear()\
  801. \009if currentBackgroundColor ~= nil and screens[currentScreen] ~= nil then\
  802. \009\009local redrawTbl = {\" \", currentForegroundColor, currentBackgroundColor}\
  803. \009\009screen = screens[currentScreen]\
  804. \009\009for i = 1, screen.height do\
  805. \009\009\009for i2 = 1, screen.width do\
  806. \009\009\009\009if screen.graphics[i][i2] ~= redrawTbl then\
  807. \009\009\009\009\009screen.graphics[i][i2] = redrawTbl\
  808. \009\009\009\009end\
  809. \009\009\009end\
  810. \009\009end\
  811. \009\009screens[currentScreen] = screen\
  812. \009end\
  813. end",
  814.     gui = "local function pop(mode, text, title, shield)\
  815.  term.redirect(_G.originalWindow)\
  816.  term.setTextColor(colors.black)\
  817.  term.setBackgroundColor(colors.black)\
  818.  term.clear()\
  819.  \
  820.  paintutils.drawLine(10, 8, 40, 8, colors.gray)\
  821.  txt.center(title, 8)\
  822.  paintutils.drawPixel(41, 8, colors.red)\
  823.  txt.pwrite('x', 41, 8)\
  824.  \
  825.  for i=9, 12 do\
  826.    paintutils.drawLine(10, i, 41, i, colors.white)\
  827.  end\
  828.  \
  829.  local tmpTxt = strings.split(text, 31)\
  830.  \
  831.  for i=1, #tmpTxt do\
  832.    --term.setCursorPos(10, (9+i)-1)\
  833.    txt.center(tmpTxt[i], (9+i)-1)\
  834.  end\
  835.  \
  836.  paintutils.drawLine(42, 9, 42, 12, colors.lightGray)\
  837.  paintutils.drawLine(11, 13, 42, 13, colors.lightGray)\
  838.  \
  839.  if mode == 1 then -- Boolean\
  840.  \
  841.    paintutils.drawLine(10, 12, 25, 12, colors.green)\
  842.    txt.pwrite('Yes', 17, 12)\
  843.    paintutils.drawLine(26, 12, 41, 12, colors.red)\
  844.    txt.pwrite('No', 33, 12)\
  845.    \
  846.    while true do\
  847.    local event, button, x, y = oldOsPull('mouse_click')\
  848.    \
  849.    if x>=10 and x<=25 and y==12 then\
  850.      paintutils.drawLine(10, 12, 25, 12, colors.gray)\
  851.      txt.pwrite('Yes', 17, 12)\
  852.      sleep(.15)\
  853.      redrawTaskbar()\
  854.      return true\
  855.    elseif x==41 and y==8 then\
  856.      paintutils.drawPixel(41, 8, colors.gray)\
  857.      txt.pwrite('x', 41, 8)\
  858.      sleep(.15)\
  859.      redrawTaskbar()\
  860.      return false\
  861.    elseif x>=26 and x<=41 and y==12 then\
  862.      paintutils.drawLine(26, 12, 41, 12, colors.gray)\
  863.      txt.pwrite('No', 33, 12)\
  864.      sleep(.15)\
  865.      redrawTaskbar()\
  866.      return false\
  867.    end\
  868.    end\
  869.  elseif mode == 2 then -- Text Entry\
  870.    paintutils.drawLine(10, 12, 41, 12, colors.gray)\
  871.    --term.setCursorPos(10, 12)\
  872.    local tmpTxt = txt.entryBox(10, 12, 41, colors.white, colors.gray, shield)\
  873.    redrawTaskbar()\
  874.    return tmpTxt\
  875.  elseif mode == 3 then\
  876.    paintutils.drawLine(10, 12, 41, 12, colors.red)\
  877.    txt.center('Reboot', 12)\
  878.    while true do\
  879.      local event, button, x, y = oldOsPull('mouse_click')\
  880.      if x>=10 and x<=41 and y==12 then\
  881.        paintutils.drawLine(10, 12, 41, 12, colors.gray)\
  882.        txt.center('Reboot', 12)\
  883.        sleep(.15)\
  884.        os.reboot()\
  885.      elseif x==41 and y==8 then\
  886.        paintutils.drawPixel(41, 8, colors.gray)\
  887.        txt.pwrite('x', 41, 8)\
  888.        sleep(.15)\
  889.        os.reboot()\
  890.      end\
  891.    end\
  892.  end\
  893.  \
  894. end\
  895. \
  896. function popup(mode, text, title, shield)\
  897.  local old = term.native()\
  898.  local p = pop(mode, text, title, shield)\
  899.  term.redirect(old)\
  900.  return p\
  901. end",
  902.     sys = "LoadAPI = function(path)\
  903. \009local name = fs.name(path)\
  904. \009if fs.exists(path) then\
  905. \009\009local h = fs.open(path, \"r\")\
  906. \009\009local raw = h.readAll()\
  907. \009\009h.close()\
  908. \009\009_G.name = loadstring(raw)\
  909. \009\009return true\
  910. \009else\
  911. \009\009error(\"API at path specified does not exist! (4)\")\
  912. \009end\
  913. end\
  914. \
  915. loadAPIWithName = function(path, name)\
  916. \009if fs.exists(path) then\
  917. \009\009local h = fs.open(path, \"r\")\
  918. \009\009local raw = h.readAll()\
  919. \009\009h.close()\
  920. \009\009_G.name = loadstring(raw)\
  921. \009else\
  922. \009\009error(\"API at path specified does not exist! (4)\")\
  923. \009end\
  924. end\
  925. \
  926. launch = function(program, window)\
  927. \009local progs = {\
  928. \009\009fileBrowser = \"/.kernel/programs/explorer\",\
  929. \009\009console = \"/.kernel/core/console\",\
  930. \009}\
  931. \
  932. \009if progs[program] ~= nil then\
  933. \009\009local path = progs[program]\
  934. \009\009if not fs.exists(progs[program]) then\
  935. \009\009\009term.setBackgroundColor(colors.white)\
  936. \009\009\009term.clear()\
  937. \009\009\009term.setTextColor(colors.black)\
  938. \009\009\009txt.ctxt(\"File not found\", 1)\
  939. \009\009\009os.pullEvent(\"mouse_click\")\
  940. \009\009else\
  941. \009\009\009local h = fs.open(path, \"r\")\
  942. \009\009\009local raw = h.readAll()\
  943. \009\009\009h.close()\
  944. \009\009\009raw = \"args = {...}\\n _G.shell = args[1]\\n\" .. raw\
  945. \009\009\009local ok, err = pcall(loadstring(raw)(shell))\
  946. \009\009\009if not ok then\
  947. \009\009\009\009local h = fs.open(\".kernel/dumps/prog\", \"w\")\
  948. \009\009\009\009h.write(err)\
  949. \009\009\009\009h.close()\
  950. \009\009\009end\
  951. \009\009end\
  952. \009end\
  953. end\
  954. \
  955. function deleteAccount(user)\
  956. \009local users = sys.load(sys.var(\"userLogins\"))\
  957. \009for i = 1, #users do\
  958. \009\009if users[i] ~= nil then\
  959. \009\009\009if users[i].name == user then\
  960. \009\009\009\009users[i] = nil\
  961. \009\009\009\009break\
  962. \009\009\009end\
  963. \009\009end\
  964. \009end\
  965. \009sys.save(sys.var(\"userLogins\"), users)\
  966. end\
  967. \
  968. userExists = function(user, users)\
  969. \009for i = 1, #users do\
  970. \009\009if users[i] ~= nil then\
  971. \009\009\009if users[i].name == user then\
  972. \009\009\009\009return true\
  973. \009\009\009end\
  974. \009\009end\
  975. \009end\
  976. \009return false\
  977. end\
  978. \
  979. save = function(path, data)\
  980. \009local h = fs.open(path, \"w\")\
  981. \009h.write(data)\
  982. \009h.close()\
  983. end\
  984. \
  985. newUser = function(user, pass, users)\
  986. \009local newUser = {\
  987. \009\009name = user,\
  988. \009\009pass = pass,\
  989. \009}\
  990. \009users[#users + 1] = newUser\
  991. \009sys.save(sys.var(\"userLogins\"), textutils.serialise(users))\
  992. \009local prefs = sys.load(sys.var(\"userPrefs\"))\
  993. \009local tmp = {\
  994. \009\009mainColour = colors.red,\
  995. \009\009secColour = colors.blue,\
  996. \009\009name = user,\
  997. \009\009homeApps = {\
  998. \009\009\009default = {\
  999. \009\009\009\009image = sys.var(\"homeAppsDefaultImage\"),\
  1000. \009\009\009\009path = \"\",\
  1001. \009\009\009\009settings = {\
  1002. \009\009\009\009\009fullscreen = false,\
  1003. \009\009\009\009\009sandboxFiles = true,\
  1004. \009\009\009\009\009fullRights = false,\
  1005. \009\009\009\009},\
  1006. \009\009\009},\
  1007. \009\009\009{\
  1008. \009\009\009\009image = sys.var(\"homeAppsSettingsImage\"),\
  1009. \009\009\009\009path = \".kernel/programs/settings\",\
  1010. \009\009\009\009settings = {\
  1011. \009\009\009\009\009fullscreen = false,\
  1012. \009\009\009\009\009sandboxFiles = false,\
  1013. \009\009\009\009\009fullRights = true,\
  1014. \009\009\009\009},\
  1015. \009\009\009},\
  1016. \009\009},\
  1017. \009}\
  1018. \009prefs[user] = tmp\
  1019. \009sys.save(sys.var(\"userPrefs\"), textutils.serialise(prefs))\
  1020. end\
  1021. \
  1022. loadImage = function(path)\
  1023. \009return paintutils.loadImage(path)\
  1024. end\
  1025. \
  1026. load = function(path)\
  1027. \009if fs.exists(path) then\
  1028. \009\009local h = fs.open(path, \"r\")\
  1029. \009\009local raw = h.readAll()\
  1030. \009\009h.close()\
  1031. \009\009return textutils.unserialise(raw)\
  1032. \009end\
  1033. end\
  1034. \
  1035. var = function(object)\
  1036. \009tblVars = {\
  1037. \009\009console = \".kernel/programs/console\",\
  1038. \009\009explorer = \".kernel/programs/explorer\",\
  1039. \009\009userPrefs = \".kernel/usrData/preferences\",\
  1040. \009\009userLogins = \".kernel/usrData/login\",\
  1041. \009\009homeAppsDefaultImage = \".kernel/core/files/images/homeAppsDefaultImage\",\
  1042. \009\009homeAppsSettingsImage = \".kernel/core/files/images/settingsIcon\",\
  1043. \009\009--userDir = \".kernel/usrData/files/\" .. preferences.name,\
  1044. \009}\
  1045. \009return tblVars[object]\
  1046. end\
  1047. \
  1048. login = function(users, window, top)\
  1049. \009reload = true\
  1050. \009local beg = term.current()\
  1051. \
  1052. \009userPos = {}\
  1053. \009userPos[1] = {x = 2, y = 7} --Ends at x = 10, y = 10\
  1054. \009userPos[2] = {x = 12, y = 7} -- Ends at x = 20, y = 10\
  1055. \009userPos[3] = {x = 22, y = 7}\
  1056. \009userPos[4] = {x = 32, y = 7}\
  1057. \009userPos[5] = {x = 42, y = 7}\
  1058. \
  1059. \009local function drawMain()\
  1060. \009\009if top ~= nil then\
  1061. \009\009\009term.redirect(top)\
  1062. \009\009\009term.setTextColor(colors.white)\
  1063. \009\009\009term.setBackgroundColor(colors.lightGray)\
  1064. \009\009\009term.clear()\
  1065. \009\009\009txt.ctxt(\"Login Screen\", 1)\
  1066. \009\009\009term.setTextColor(colors.red)\
  1067. \009\009\009txt.ptxt(\"x\", 51, 1)\
  1068. \009\009end\
  1069. \
  1070. \009\009term.redirect(window)\
  1071. \
  1072. \009\009term.setBackgroundColor(colors.white)\
  1073. \009\009term.clear()\
  1074. \009\009term.setTextColor(colors.black)\
  1075. \009\009txt.ctxt(\"Please select a user\", 2)\
  1076. \
  1077. \009\009for i = 6, 12 do\
  1078. \009\009\009paintutils.drawLine(1, i, 51, i, colors.lightGray)\
  1079. \009\009end\
  1080. \
  1081. \009\009for i = 1, 5 do\
  1082. \009\009\009if users[i] ~= nil then\
  1083. \009\009\009\009term.setBackgroundColor(colors.lightGray)\
  1084. \009\009\009\009txt.ptxt(users[i].name, userPos[i].x, 11)\
  1085. \009\009\009\009for i2 = 7, 9 do\
  1086. \009\009\009\009\009paintutils.drawLine(userPos[i].x, i2, userPos[i].x+8, i2, preferences[users[i].name].mainColour)\
  1087. \009\009\009\009end\
  1088. \009\009\009end\
  1089. \009\009end\
  1090. \
  1091. \009\009paintutils.drawLine(2, 15, 50, 15, colors.lightGray)\
  1092. \009\009txt.ctxt(\"Create a new account\", 15)\
  1093. \009end\
  1094. \
  1095. \009repeat\
  1096. \009\009if reload then\
  1097. \009\009\009users = sys.load(sys.var(\"userLogins\"))\
  1098. \009\009\009preferences = sys.load(sys.var(\"userPrefs\"))\
  1099. \009\009\009reload = false\
  1100. \009\009end\
  1101. \009\009drawMain()\
  1102. \009\009local _, b, x, y = os.pullEvent(\"mouse_click\")\
  1103. \009\009if y == 0 then\
  1104. \009\009\009if x == 51 then\
  1105. \009\009\009\009loginEnd = true\
  1106. \009\009\009end\
  1107. \009\009end\
  1108. \
  1109. \009\009if x >= 2 and x <= 50 and y == 15 then -- Clicked on create new account\
  1110. \009\009\009while true do\
  1111. \009\009\009\009user = gui.popup(2, \"Please enter a username\", \"Create Account: 1/2\")\
  1112. \009\009\009\009if user ~= nil and sys.userExists(user, users) then\
  1113. \009\009\009\009\009gui.popup(1, \"That user already exists!\", \"Create Account 1/2\")\
  1114. \009\009\009\009else\
  1115. \009\009\009\009\009break\
  1116. \009\009\009\009end\
  1117. \009\009\009end\
  1118. \009\009\009if user ~= nil and #user > 0 then\
  1119. \009\009\009\009local pass = gui.popup(2, \"Please enter a password\", \"Create Account: 2/2\", \"*\")\
  1120. \009\009\009\009sys.newUser(user, pass, users)\
  1121. \009\009\009\009reload = true\
  1122. \009\009\009end\
  1123. \
  1124. \009\009elseif x >= 2 and x <= 10 and y >= 7 and y <= 11 and users[1] ~= nil then --User 1\
  1125. \009\009\009local pass = gui.popup(2, \"Please enter your password\", \"Login\", \"*\")\
  1126. \009\009\009if users[1].pass == pass then\
  1127. \009\009\009\009_G.preferences = sys.load(sys.var(\"userPrefs\"))[users[1].name]\
  1128. \009\009\009\009return users[1]\
  1129. \009\009\009else\
  1130. \009\009\009\009gui.popup(1, \"Incorrect Password!\", \"Login\")\
  1131. \009\009\009end\
  1132. \009\009elseif x >= 12 and x <= 20 and y >= 7 and y <= 11 and users[2] ~= nil then --User 2\
  1133. \009\009\009local pass = gui.popup(2, \"Please enter your password\", \"Login\", \"*\")\
  1134. \009\009\009if users[2].pass == pass then\
  1135. \009\009\009\009_G.preferences = sys.load(sys.var(\"userPrefs\"))[users[2].name]\
  1136. \009\009\009\009return users[2]\
  1137. \009\009\009else\
  1138. \009\009\009\009gui.popup(2, \"Incorrect Password!\", \"Login\")\
  1139. \009\009\009end\
  1140. \
  1141. \009\009elseif x >= 22 and x <= 30 and y >= 7 and y <= 11 and users[3] ~= nil then --User 3\
  1142. \009\009\009local pass = gui.popup(2, \"Please enter your password\", \"Login\", \"*\")\
  1143. \009\009\009if users[3].pass == pass then\
  1144. \009\009\009\009_G.preferences = sys.load(sys.var(\"userPrefs\"))[users[3].name]\
  1145. \009\009\009\009return users[3]\
  1146. \009\009\009else\
  1147. \009\009\009\009gui.popup(1, \"Incorrect Password!\", \"Login\")\
  1148. \009\009\009end\
  1149. \
  1150. \009\009elseif x >= 32 and x <= 40 and y >= 7 and y <= 11 and users[4] ~= nil then --User 4\
  1151. \009\009\009local pass = gui.popup(2, \"Please enter your password\", \"Login\", \"*\")\
  1152. \009\009\009if users[4].pass == pass then\
  1153. \009\009\009\009_G.preferences = sys.load(sys.var(\"userPrefs\"))[users[4].name]\
  1154. \009\009\009\009return users[4]\
  1155. \009\009\009else\
  1156. \009\009\009\009gui.popup(1, \"Incorrect Password!\", \"Login\")\
  1157. \009\009\009end\
  1158. \
  1159. \009\009elseif x >= 42 and x <= 50 and y >= 7 and y <= 11 and users[5] ~= nil then --User 5\
  1160. \009\009\009local pass = gui.popup(2, \"Please enter your password\", \"Login\", \"*\")\
  1161. \009\009\009if users[5].pass == pass then\
  1162. \009\009\009\009_G.preferences = sys.load(sys.var(\"userPrefs\"))[users[5].name]\
  1163. \009\009\009\009return users[5]\
  1164. \009\009\009else\
  1165. \009\009\009\009gui.popup(1, \"Incorrect Password!\", \"Login\")\
  1166. \009\009\009end\
  1167. \009\009end\
  1168. \009until loginEnd == true\
  1169. \
  1170. \009term.redirect(beg)\
  1171. end",
  1172.   },
  1173.   programs = {
  1174.     console = "--[[\
  1175. \
  1176. \009Base V1.1 by Sam Gunner.\
  1177. Patch pack 1\
  1178. \009\
  1179. ]]--\
  1180. \
  1181. -- Variables --\
  1182. \
  1183. commands = {\
  1184.  [ 'exit' ] = function()\
  1185.    mainLoopTerm = true\
  1186.  end,\
  1187.  [ 'about' ] = function()\
  1188.    term.setTextColor(colors.gray)\
  1189.    print('BASE Console, Version 1.1 Built for BASE 2')\
  1190.  end,\
  1191.  [ 'help' ] = function()\
  1192.    term.setTextColor(colors.green)\
  1193.    print('Available commands:')\
  1194.    local tmpTbl = {}\
  1195.    for k, v in pairs(commands) do\
  1196.      table.insert(tmpTbl, k)\
  1197.    end\
  1198.    table.sort(tmpTbl)\
  1199.    textutils.pagedTabulate(colors.red, tmpTbl)\
  1200.  end,\
  1201.  [ 'compress' ] = function(cmd)\
  1202.    local tmpTbl = {}\
  1203.    \
  1204.    for i=2, #cmd do\
  1205.      table.insert(tmpTbl, cmd[i])\
  1206.    end\
  1207.    \
  1208.    if #tmpTbl ~= 2 then\
  1209.      printError('Usage: compress <Directory> <Destination file>')\
  1210.    else\
  1211.    \
  1212.    if fs.isDir(tmpTbl[1]) and not fs.exists(tmpTbl[2]) then\
  1213.    \
  1214.    local h = fs.open('.kernel/programs/compress', 'r')\
  1215.    local app = h.readAll()\
  1216.    h.close()\
  1217.    \
  1218.    loadstring(app)(tmpTbl[1], tmpTbl[2])\
  1219.    else\
  1220.      printError('Usage: compress <Directory> <Destination file>')\
  1221.    end\
  1222.    end\
  1223.  end,\
  1224.  [ 'clear' ] = function()\
  1225.    term.setBackgroundColor(colors.white)\
  1226.    term.clear()\
  1227.    term.setCursorPos(1, 1)\
  1228.  end,\
  1229.  [ 'cp' ] = function(cmd)\
  1230.    if cmd[2] ~= nil and cmd[3] ~= nil and fs.exists(fs.combine(dir, cmd[2])) then\
  1231.      fs.copy(fs.combine(dir, cmd[2]), fs.combine(dir, cmd[3]))\
  1232.    end\
  1233.  end,\
  1234.  [ 'run' ] = function(cmd)\
  1235.    shell.run(fs.combine(dir, cmd[2]))\
  1236.    --[[\
  1237.    paintutils.drawLine(35, 19, 51, 19, colors.gray)\
  1238.    term.setTextColor(colors.white)\
  1239.    txt.pwrite('Closing in 2...', 35, 19)\
  1240.    sleep(1)\
  1241.    txt.pwrite('Closing in 1...', 35, 19)\
  1242.    sleep(1)\
  1243.    ]]--\
  1244.  end,\
  1245.  [ 'reboot' ] = function()\
  1246.    cinter.reboot()\
  1247.    term.setBackgroundColor(colors.black)\
  1248.    term.clear()\
  1249.    term.setCursorPos(1, 1)\
  1250.    term.setTextColor(colors.white)\
  1251.    commands.clear()\
  1252.  end,\
  1253.  [ 'shutdown' ] = function()\
  1254.    cinter.shutdown()\
  1255.    term.setBackgroundColor(colors.black)\
  1256.    term.clear()\
  1257.    term.setCursorPos(1, 1)\
  1258.    term.setTextColor(colors.white)\
  1259.    commands.clear()\
  1260.  end,\
  1261.  [ 'ls' ] = function(cmd)\
  1262.    local files2 = {}\
  1263.    local file = {}\
  1264.    local folds = {}\
  1265.    if cmd[2] == nil then\
  1266.      files = fs.list(dir)\
  1267.      tmpDir = ''\
  1268.    elseif fs.isDir(cmd[2]) then\
  1269.      files = fs.list(cmd[2])\
  1270.      tmpDir = cmd[2]\
  1271.    else\
  1272.      printError('That is not a directory.')\
  1273.      return nil\
  1274.    end\
  1275.    for k, v in ipairs(files) do\
  1276.      if string.sub(v, 1, 1) ~= '.' then\
  1277.        table.insert(files2, v)\
  1278.      end\
  1279.    end\
  1280.    for i=1, #files2 do\
  1281.      if fs.isDir(tmpDir..'/'..files2[i]) then\
  1282.        table.insert(folds, files2[i])\
  1283.      else\
  1284.        table.insert(file, files2[i])\
  1285.      end\
  1286.    end\
  1287.    textutils.pagedTabulate(colors.red, folds, colors.gray, file)\
  1288.  end,\
  1289.  [ 'cd' ] = function(cmd)\
  1290.    if fs.exists(dir..'/'..cmd[2]) then\
  1291.      if cmd[2] == '..' then\
  1292.        dir = fs.getDir(dir)\
  1293.      elseif cmd[2] == '/' then\
  1294.        dir = ''\
  1295.      elseif fs.isDir(dir..'/'..cmd[2]) then\
  1296.        dir = dir..'/'..cmd[2]\
  1297.      else\
  1298.        printError('That isn\\'t a directory!')\
  1299.      end\
  1300.    else\
  1301.      printError('That isn\\'t a directory!')\
  1302.    end\
  1303.  end,\
  1304.  [ 'clr'] = function() commands.clear() end,\
  1305.  [ 'rm' ] = function(cmd)\
  1306.    if fs.exists(fs.combine(dir, cmd[2])) then\
  1307.      fs.delete(fs.combine(dir, cmd[2]))\
  1308.      print('File deleted.')\
  1309.    else\
  1310.      printError('That file doesn\\'t exist!')\
  1311.    end\
  1312.  end,\
  1313.  [ 'mkdir' ] = function(cmd)\
  1314.    if not fs.exists(fs.combine(dir, cmd[2])) then\
  1315.      fs.makeDir(fs.combine(dir, cmd[2]))\
  1316.    else\
  1317.      printError('That already exists.')\
  1318.    end\
  1319.  end,\
  1320.  [ 'nano' ] = function(cmd)\
  1321.    shell.run(\"edit\", cmd[2])\
  1322.    commands.clr()\
  1323.  end\
  1324. }\
  1325. \
  1326. -- Functions --\
  1327. \
  1328. function commSplit(comm)\
  1329.  local tmpTbl = {}\
  1330.  for k in string.gmatch(comm, '[^ ]+') do\
  1331.    table.insert(tmpTbl, k)\
  1332.  end\
  1333.  return tmpTbl\
  1334. end\
  1335. \
  1336. function mainLoop(commands)\
  1337. mainLoopTerm = false\
  1338. dir = ''\
  1339. local commHis = {}\
  1340. term.setBackgroundColor(colors.white)\
  1341. term.clear()\
  1342. term.setCursorPos(1, 1)\
  1343. \
  1344. term.setTextColor(colors.black)\
  1345. \
  1346. print('Welcome to BaseOS Shell, V1.1')\
  1347. print('Type \\'help\\' for a list of commands')\
  1348. print(\"Type 'exit' to leave the console\")\
  1349. \
  1350. repeat\
  1351. \
  1352.  --local tmpVal = multishell.getCurrent()\
  1353.  --multishell.setTitle(tmpVal, 'OS')\
  1354. \
  1355.  term.setTextColor(colors.lightGray)\
  1356.  write(dir..'/> ')\
  1357.  term.setTextColor(colors.black)\
  1358.  local comm = read(nil, commHis)\
  1359.  table.insert(commHis, comm)\
  1360.  local commNew = commSplit(comm)\
  1361. \
  1362.  \
  1363.  \
  1364.  if commands[commNew[1]] ~= nil then\
  1365.    local ok, err = pcall(commands[commNew[1]], commNew)\
  1366.    if not ok then\
  1367.      local h = fs.open('.kernel/dumps/consoleCrash', 'w')\
  1368.      h.write(err)\
  1369.      h.close()\
  1370.    end\
  1371.  else\
  1372.    printError('That command doesn\\'t exist. Type \\'help\\' for help.')\
  1373.  end\
  1374. until mainLoopTerm == true\
  1375. end\
  1376. \
  1377. -- Startup\
  1378. \
  1379. sleep(.2)\
  1380. --local tmpVal = cinter.login()\
  1381. \
  1382. mainLoop(commands)",
  1383.     explorer = "-- ROOT_DIR = \".kernel/usrData/files/\" .. sys.currentUser()\
  1384. \
  1385. -- Built for BASE 2\
  1386. \
  1387. -- GUI Based File Explorer, Version 1.0 --\
  1388. -- Copyright (C) 2015, Sam Gunner --\
  1389. -- You may redistribute and modify this, as long--\
  1390. -- as you give credit to the original creator --\
  1391. -- Other than that, enjoy the program! --\
  1392. \
  1393. function diagBox(txt)\
  1394.  for i=8, 12 do\
  1395.    paintutils.drawLine(4, i, 47, i, colors.gray)\
  1396.  end\
  1397.  paintutils.drawLine(5, 9, 46, 9, colors.white)\
  1398.  term.setTextColor(colors.black)\
  1399.  ctxt(txt, 9)\
  1400.  paintutils.drawLine(48, 9, 48, 13, colors.black)\
  1401.  paintutils.drawLine(6, 13, 48, 13, colors.black)\
  1402.  local beg = term.current()\
  1403.  local tmpWin = window.create(term.native(), 5, 11, 42, 1)\
  1404.  term.redirect(tmpWin)\
  1405.  term.setBackgroundColor(colors.white)\
  1406.  term.clear()\
  1407.  term.setCursorPos(1, 1)\
  1408.  term.setTextColor(colors.black)\
  1409.  local tmpVal = read()\
  1410.  term.redirect(beg)\
  1411.  return tmpVal\
  1412. end\
  1413. \
  1414. function drawScroll(things, scrollPos)\
  1415.  --[[\
  1416.  local beg = term.current()\
  1417.  term.redirect(scBar)\
  1418.  local totLen = #things.files + #things.folds\
  1419.  --if \
  1420.    paintutils.drawLine(1, tmpVal, 1, tmpVal, colors.gray)\
  1421.    term.redirect(beg)\
  1422.  --end\
  1423.  ]]--\
  1424. end\
  1425. \
  1426. function drawMain(things, dPos)\
  1427.  local beg = term.current()\
  1428.  if topBar== nil or sideBar == nil or mainSec == nil then\
  1429.    topBar = window.create(term.current(), 1, 1, 51, 3)\
  1430.    sideBar = window.create(term.current(), 31, 4, 21, 16)\
  1431.    mainSec = window.create(term.current(), 1, 4, 29, 17)\
  1432.    scBar = window.create(term.current(), 30, 2, 1, 18)\
  1433.    addBar = window.create(term.current(), 2, 2, 49, 1)\
  1434.  end\
  1435.  \
  1436.  term.redirect(scBar)\
  1437.  term.setBackgroundColor(colors.white)\
  1438.  term.clear()\
  1439.  local allLen = #things.files+#things.folds\
  1440.  print(allLen)\
  1441.  term.redirect(beg)\
  1442.  \
  1443.  term.redirect(topBar)\
  1444.  term.setBackgroundColor(colors.gray)\
  1445.  term.clear()\
  1446.  term.setTextColor(colors.white)\
  1447.  ctxt('File Explorer - Built for BASE 2', 1)\
  1448.  term.setTextColor(colors.red)\
  1449.  ptxt('x', 51, 1)\
  1450. \
  1451.  term.redirect(addBar)\
  1452.  term.setBackgroundColor(colors.black)\
  1453.  term.clear()\
  1454.  term.setTextColor(colors.white)\
  1455.  ptxt(dir, 1, 1)\
  1456.  term.redirect(beg)\
  1457.  \
  1458.  term.redirect(sideBar)\
  1459.  term.setBackgroundColor(colors.gray)\
  1460.  term.clear()\
  1461.  term.setTextColor(colors.white)\
  1462.  if things.sel == '' then\
  1463.    ctxt('File Explorer', 1)\
  1464.    ctxt('Click on a file', 8)\
  1465.    ctxt('to get started!', 9)\
  1466.  elseif fs.isDir(fs.combine(dir, things.sel)) then\
  1467.    ctxt('Options - Folder', 1)\
  1468.    ctxt(string.sub(things.sel, 1, 21), 2)\
  1469.    ctxt('------', 4)\
  1470.    ctxt('Open Folder', 6)\
  1471.    ctxt('Rename', 7)\
  1472.    ctxt('Delete', 8)\
  1473.  elseif not fs.isDir(fs.combine(dir, things.sel)) then\
  1474.    ctxt('Options - File', 1)\
  1475.    ctxt(string.sub(things.sel, 1, 21), 2)\
  1476.    ctxt('------', 4)\
  1477.    ctxt('Run as program', 6)\
  1478.    ctxt('Edit as text file', 7)\
  1479.    ctxt('Rename', 8)\
  1480.    ctxt('Delete', 9)\
  1481.    local size = fs.getSize(fs.combine(dir, things.sel))\
  1482.    local sSize = math.ceil(size/1000, 1)\
  1483.    ctxt('Size: ' .. sSize .. ' KB', 12)\
  1484.  end\
  1485.  term.redirect(beg)\
  1486.  \
  1487.  term.redirect(mainSec)\
  1488.  term.setBackgroundColor(colors.white)\
  1489.  term.clear()\
  1490.  term.redirect(beg)\
  1491.  \
  1492.  local files = things.files\
  1493.  local folds = things.folds\
  1494.  local fSel = things.sel\
  1495.  \
  1496.  table.sort(files)\
  1497.  table.sort(folds)\
  1498.  \
  1499.  local tmpTbl = {}\
  1500.  for i=1, #folds do\
  1501.    table.insert(tmpTbl, folds[i])\
  1502.  end\
  1503.  \
  1504.  for i=1, #files do\
  1505.    table.insert(tmpTbl, files[i])\
  1506.  end\
  1507.  \
  1508.  term.redirect(mainSec)\
  1509.  term.setTextColor(colors.black)\
  1510.  \
  1511.  for i=dPos, dPos+15 do\
  1512.    if tmpTbl[i] ~= nil then\
  1513. \009  if fs.isDir(fs.combine(dir, tmpTbl[i])) then\
  1514. \009    if fs.combine(dir, fSel) == fs.combine(dir, tmpTbl[i]) then\
  1515. \009\009  term.setTextColor(colors.lightGray)\
  1516. \009\009  write('[] ' .. string.sub(tmpTbl[i], 1, 26) .. '\\n')\
  1517. \009\009else\
  1518. \009\009  term.setTextColor(colors.black)\
  1519. \009      write('[] ' .. string.sub(tmpTbl[i], 1, 26) .. '\\n')\
  1520. \009\009end\
  1521. \009  else\
  1522. \009    if fs.combine(dir, fSel) == fs.combine(dir, tmpTbl[i]) then\
  1523. \009\009  term.setTextColor(colors.lightGray)\
  1524. \009      write('() ' .. string.sub(tmpTbl[i], 1, 26) .. '\\n')\
  1525. \009\009else\
  1526. \009\009  term.setTextColor(colors.black)\
  1527. \009\009  write('() ' .. string.sub(tmpTbl[i], 1, 26) .. '\\n')\
  1528. \009\009end\
  1529. \009  end\
  1530. \009end\
  1531.  end\
  1532.  \
  1533.  term.redirect(beg)\
  1534.  \
  1535. end\
  1536. \
  1537. function nread()\
  1538.  tmpVal = read()\
  1539. end\
  1540. \
  1541. function handClick(b, x, y, stuff)\
  1542.  if b == 1 then\
  1543.  \
  1544.    if x>=1 and x<=51 and y>=1 and y<=3 then\
  1545.      if x == 51 and y == 1 then\
  1546.        terminate = true\
  1547.      elseif x>=2 and x<=50 and y == 2 then\
  1548.        local beg = term.current()\
  1549.        term.redirect(addBar)\
  1550.        term.clear()\
  1551.        term.setTextColor(colors.white)\
  1552.        term.setCursorPos(1, 1)\
  1553.        local pid = parallel.waitForAny(click, nread)\
  1554.        if pid == 2 then\
  1555.          if fs.isDir(tmpVal) then\
  1556.            dir = \"/\" .. tmpVal\
  1557.          end\
  1558.        end\
  1559.        term.redirect(beg)\
  1560.      end\
  1561.    elseif x>=1 and x<=29 and y>=4 and y<=19 then\
  1562.      local fileSel = ((y-3)+drawPos)-1\
  1563.      local totLen = #stuff.files + #stuff.folds\
  1564.      if fileSel > #stuff.folds then\
  1565.        local fileSel = fileSel - #stuff.folds\
  1566.        selVal = stuff.files[fileSel]\
  1567.      else\
  1568.        selVal = stuff.folds[fileSel]\
  1569.      end\
  1570.    elseif x>=31 and x<=51 and y>=4 and y<=19 then\
  1571.      local xP = x-30\
  1572.      local yP = y-3\
  1573.      local beg = term.current()\
  1574.      if selVal ~= nil then\
  1575.      if fs.isDir(fs.combine(dir, selVal)) then -- Assume folder mode\
  1576.        if yP==6 then\
  1577.          dir = \"/\" .. fs.combine(dir, selVal)\
  1578.          selVal = ('')\
  1579.        elseif yP==7 then\
  1580.          term.redirect(sideBar)\
  1581.          ctxt('Enter a new name', 15)\
  1582.          paintutils.drawLine(1, 16, 21, 16, colors.white)\
  1583.          term.setTextColor(colors.black)\
  1584.          term.setCursorPos(1, 16)\
  1585.          local pid = parallel.waitForAny(click, nread)\
  1586.          if pid == 2 then\
  1587.            if #tmpVal>0 then\
  1588.              fs.move(fs.combine(dir, selVal),fs.combine(dir, tmpVal))\
  1589.              selVal = ''\
  1590.            end\
  1591.          end\
  1592.          term.redirect(beg)\
  1593.        elseif yP == 8 then\
  1594.          local beg = term.current()\
  1595.          local ans = gui.popup(1, 'Are you sure you want to delete this?', 'Confirm Deletion')\
  1596.          term.redirect(beg)\
  1597.          if ans then\
  1598.            fs.delete(fs.combine(dir, selVal))\
  1599.          end\
  1600.          selVal = ''\
  1601.          term.redirect(beg)\
  1602.        end\
  1603.      elseif not fs.isDir(fs.combine(dir, selVal)) then -- Assume file mode\
  1604.        if yP == 6 then\
  1605.          term.setBackgroundColor(colors.black)\
  1606.          term.setTextColor(colors.white)\
  1607.          term.clear()\
  1608.          term.setCursorPos(1, 1)\
  1609.          shell.run(fs.combine(dir, selVal))\
  1610.        elseif yP == 7 then\
  1611.          local h = fs.open(\".kernel/dumps/explorerCrash\", \"w\")\
  1612.          shell.run(\"edit\", fs.combine(dir, selVal))\
  1613.        elseif yP == 8 then\
  1614.          term.redirect(sideBar)\
  1615.          ctxt('Enter a new name', 15)\
  1616.          paintutils.drawLine(1, 16, 31, 16, colors.white)\
  1617.          term.setCursorPos(1, 16)\
  1618.          local pid = parallel.waitForAny(click, nread)\
  1619.          if pid == 2 then\
  1620.            if #tmpVal > 0 then\
  1621.              fs.move(fs.combine(dir, selVal), fs.combine(dir, tmpVal))\
  1622.              selVal = ''\
  1623.            end\
  1624.          end\
  1625.          term.redirect(beg)\
  1626.        elseif yP == 9 then\
  1627.          local beg = term.current()\
  1628.          local ans = gui.popup(1, 'Are you sure you want to delete this?', 'Confirm Deletion')\
  1629.          term.redirect(beg)\
  1630.          if ans then\
  1631.            fs.delete(fs.combine(dir, selVal))\
  1632.          end\
  1633.          selVal = ''\
  1634.          term.redirect(beg)\
  1635.        end\
  1636.      end\
  1637.      end\
  1638.    end\
  1639.  elseif b == 2 then\
  1640.    if x>=1 and x<=30 and y>3 then\
  1641.      local ans = dropMenu(x, y)\
  1642.        if ans == 1 then\
  1643.          if dir ~= '/' and dir ~= '' then\
  1644.            dir = \"/\" .. fs.getDir(dir)\
  1645.            selVal = nil\
  1646.          end\
  1647.        elseif ans == 2 then\
  1648.          local tmp = diagBox('Enter the name of the new file')\
  1649.          local tmpFile = fs.combine(dir, tmp)\
  1650.          if not fs.exists(tmpFile) then\
  1651.            local h = fs.open(fs.combine(dir, tmp), 'w')\
  1652.            h.close()\
  1653.          end\
  1654.        elseif ans == 3 then\
  1655.          local tmp = diagBox('Enter the name of the new folder')\
  1656.          if not fs.exists(fs.combine(dir, tmp)) then\
  1657.            fs.makeDir(fs.combine(dir, tmp))\
  1658.          end\
  1659.        end\
  1660.    end\
  1661.  end\
  1662. end\
  1663. \
  1664. function dropMenu(x, y)\
  1665.  for i=1, 3 do\
  1666.    paintutils.drawLine(x, (y+i)-1, x+10, (y+i)-1, colors.gray)\
  1667.  end\
  1668.  term.setTextColor(colors.white)\
  1669.  ptxt('Back up', x+2, y)\
  1670.  ptxt('New file', x+2, y+1)\
  1671.  ptxt('New folder', x+1, y+2)\
  1672.  paintutils.drawLine(x+11, y+1, x+11, y+3, colors.black)\
  1673.  paintutils.drawLine(x+1, y+3, x+11, y+3, colors.black)\
  1674.  local event, button, xP, yP = os.pullEvent('mouse_click')\
  1675.  if xP>=x and xP<=x+10 and yP>=y and yP<=y+2 then\
  1676.    return (yP-y)+1\
  1677.  end\
  1678. end\
  1679. \
  1680. function getStuff(dir)\
  1681.  if fs.isDir(dir) then\
  1682.    local tmpVal = fs.list(dir)\
  1683.    local files = {}\
  1684.    local folds = {}\
  1685.    for k, v in ipairs(tmpVal) do\
  1686.      if not fs.isDir(fs.combine(dir, v)) then\
  1687.        table.insert(files, v)\
  1688.      else\
  1689.        table.insert(folds, v)\
  1690.      end\
  1691.    end\
  1692.    \
  1693.    local tmpTbl = {}\
  1694.    tmpTbl.files, tmpTbl.folds = files, folds\
  1695.    return tmpTbl\
  1696.    \
  1697.  end\
  1698. end\
  1699. \
  1700. function handScroll(dir, x, y)\
  1701.  if dir == 1 then\
  1702.    if drawPos+15 < (#stuff.files+#stuff.folds) then\
  1703.      drawPos = drawPos+1\
  1704. \009end\
  1705.  elseif dir == -1 then\
  1706.    if drawPos >1 then\
  1707.      drawPos = drawPos-1\
  1708.  \009 end\
  1709.  end\
  1710. end\
  1711. \
  1712. function ctxt(txt, y)\
  1713.  local w, h = term.getSize()\
  1714.  local x = ((w/2)-(#txt/2))+1\
  1715.  term.setCursorPos(x, y)\
  1716.  write(txt)\
  1717. end\
  1718. \
  1719. function ptxt(txt, x, y)\
  1720.  term.setCursorPos(x, y)\
  1721.  write(txt)\
  1722. end\
  1723. \
  1724. function mScroll()\
  1725.  _, sDir, x, y = os.pullEvent('mouse_scroll')\
  1726. end\
  1727. \
  1728. \
  1729. \
  1730. function click()\
  1731.  _, button, x, y = os.pullEvent('mouse_click')\
  1732. end\
  1733. \
  1734. function mainLoop()\
  1735.  dir = '/'\
  1736. \
  1737.  selVal = nil\
  1738.  terminate = nil\
  1739.  drawPos = 1\
  1740. \
  1741.  repeat\
  1742.    mainSec, sideBar, topBar = nil\
  1743.    stuff = getStuff(dir)\
  1744.    if selVal == nil then\
  1745.      stuff.sel = ''\
  1746.    else\
  1747.      stuff.sel = selVal\
  1748.    end\
  1749.    drawMain(stuff, drawPos)\
  1750.    --drawScroll(stuff)\
  1751.    --[[\
  1752.    local h = fs.open('tmp', 'w')\
  1753.    h.write(textutils.serialize(stuff))\
  1754.    h.close()\
  1755.    ]]--\
  1756.    local pid = parallel.waitForAny(click, mScroll)\
  1757.    if pid == 1 then\
  1758.      local tB = button\
  1759.  \009local tX = x\
  1760.  \009local tY = y\
  1761.  \009handClick(tB, tX, tY, stuff)\
  1762.    elseif pid == 2 then\
  1763.      handScroll(sDir, x, y)\
  1764.    end\
  1765.  until terminate == true\
  1766. \
  1767.  term.setBackgroundColor(colors.black)\
  1768.  term.clear()\
  1769.  term.setCursorPos(1, 1)\
  1770. end\
  1771. \
  1772. local ok, err = pcall(mainLoop)\
  1773. if not ok then\
  1774.  local h = fs.open(\".kernel/dumps/latestAppCrash\", \"w\")\
  1775.  h.write(err)\
  1776.  h.close()\
  1777. end",
  1778.     info = "slideNo = 1\
  1779. \
  1780. function redraw(slide)\
  1781.        term.setBackgroundColor(colors.white)\
  1782.        term.clear()\
  1783.        term.setTextColor(colors.white)\
  1784.        paintutils.drawLine(1, 1, 51, 1, colors.gray)\
  1785.        txt.ctxt(\"BASE 2 Information - BASE Reader\", 1)\
  1786.        term.setTextColor(colors.red)\
  1787.        txt.ptxt(\"x\", 51, 1)\
  1788.        term.setTextColor(colors.white)\
  1789. \
  1790.        if slideNo > 1 then\
  1791.            paintutils.drawLine(1, 8, 1, 10, colors.gray)\
  1792.            txt.ptxt(\"<\", 1, 9)\
  1793.        end\
  1794. \
  1795.        if slideNo < #slides then\
  1796.            paintutils.drawLine(51, 8, 51, 10, colors.gray)\
  1797.            txt.ptxt(\">\", 51, 9)\
  1798.        end\
  1799. \
  1800.        term.setBackgroundColor(colors.white)\
  1801.        term.setTextColor(colors.black)\
  1802. \
  1803.        for i = 1, #slides[slideNo] do\
  1804.            term.setCursorPos(3, i + 2)\
  1805.            term.write(slides[slideNo][i])\
  1806.        end\
  1807. end\
  1808. \
  1809. function mainLoop()\
  1810.    slides = {\
  1811.        {\
  1812.            \"Information about BASE 2 Preview Release\",\
  1813.            \"\",\
  1814.            \"This is a beta release, and should be considered\",\
  1815.            \"as such. This means that any bugs or glitches in\",\
  1816.            \"the current version will most likely be fixed in\",\
  1817.            \"a future update. Any problems with BASE can be\",\
  1818.            \"reported on the ComputerCraft forums topic page.\",\
  1819.            \"\",\
  1820.            \"Do not expect that this current release will\",\
  1821.            \"include all final features. Lots more will be\",\
  1822.            \"added in future versions.\"\
  1823.        },\
  1824.        {\
  1825.            \"Planned future features\",\
  1826.            \"\",\
  1827.            \"- An app store for the easy downloading of\",\
  1828.            \"  programs and apps.\",\
  1829.            \"- A settings app to allow customisation of the\",\
  1830.            \"  OS.\",\
  1831.            \"- Multitasking. Allowing several apps to run at\",\
  1832.            \"  once in the background.\",\
  1833.            \"- Different user accounts, each with separate\",\
  1834.            \"  files and different personalised parts of the\",\
  1835.            \"  OS.\"\
  1836.        },\
  1837.        {\
  1838.            \"BASE 2 Changelog\",\
  1839.            \"-- Version 1.0.3 --\",\
  1840.            \"\",\
  1841.            \"- Added baseForms. This is an easy way to develop\",\
  1842.            \"  for BASE 2, with custom functions easily added.\",\
  1843.            \"- Created a new installer, using baseForms.\",\
  1844.            \"- Moved taskbar to bottom of screen, better\",\
  1845.            \"  support for more apps.\",\
  1846.        },\
  1847.        {\
  1848.            \"BASE 2 Changelog\",\
  1849.            \"-- Version 1.0.2 --\",\
  1850.            \"\",\
  1851.            \"- Added support for custom desktop. Editing\",\
  1852.            \"  ability coming soon.\",\
  1853.        },\
  1854.        {\
  1855.            \"BASE 2 Changelog\",\
  1856.            \"-- Version 1.0.1 --\",\
  1857.            \"\",\
  1858.            \"- Added user accounts. No separate files yet.\",\
  1859.            \"- Added settings app and the ability to change\",\
  1860.            \"  the OS a little. More coming in the future.\",\
  1861.            \"- Added a fancy new login screen\",\
  1862.        }\
  1863.    }\
  1864. \
  1865.    endInfo = nil\
  1866.    repeat\
  1867.        redraw()\
  1868.        local _, b, x, y = os.pullEvent(\"mouse_click\")\
  1869.        if b == 1 then\
  1870.            if x == 51 and y == 1 then\
  1871.                endInfo = true\
  1872.            elseif x == 51 and y>= 8 and y<= 10 and slideNo < #slides then\
  1873.                slideNo = slideNo + 1\
  1874.            elseif x == 1 and y>=8 and y<=10 and slideNo > 1 then\
  1875.                slideNo = slideNo - 1\
  1876.            end\
  1877.        end\
  1878.    until endInfo == true\
  1879. end\
  1880. \
  1881. mainLoop()",
  1882.     [ "explorer.lua" ] = "bNo = '0.1.1'\
  1883. \
  1884. -- GUI Based File Explorer, Version 1.0 --\
  1885. -- Copyright (C) 2015, Sam Gunner --\
  1886. -- You may redistribute and modify this, as long--\
  1887. -- as you give credit to the original creator --\
  1888. -- Other than that, enjoy the program! --\
  1889. \
  1890. function diagBox(txt)\
  1891.  for i=8, 12 do\
  1892.    paintutils.drawLine(4, i, 47, i, colors.gray)\
  1893.  end\
  1894.  paintutils.drawLine(5, 9, 46, 9, colors.white)\
  1895.  term.setTextColor(colors.black)\
  1896.  ctxt(txt, 9)\
  1897.  paintutils.drawLine(48, 9, 48, 13, colors.black)\
  1898.  paintutils.drawLine(6, 13, 48, 13, colors.black)\
  1899.  local beg = term.current()\
  1900.  local tmpWin = window.create(term.native(), 5, 11, 42, 1)\
  1901.  term.redirect(tmpWin)\
  1902.  term.setBackgroundColor(colors.white)\
  1903.  term.clear()\
  1904.  term.setCursorPos(1, 1)\
  1905.  term.setTextColor(colors.black)\
  1906.  local tmpVal = read()\
  1907.  term.redirect(beg)\
  1908.  return tmpVal\
  1909. end\
  1910. \
  1911. function drawScroll(things, scrollPos)\
  1912.  --[[\
  1913.  local beg = term.current()\
  1914.  term.redirect(scBar)\
  1915.  local totLen = #things.files + #things.folds\
  1916.  --if \
  1917.    paintutils.drawLine(1, tmpVal, 1, tmpVal, colors.gray)\
  1918.    term.redirect(beg)\
  1919.  --end\
  1920.  ]]--\
  1921. end\
  1922. \
  1923. function drawMain(things, dPos)\
  1924.  if topBar== nil or sideBar == nil or mainSec == nil then\
  1925.    topBar = window.create(term.current(), 1, 1, 51, 1)\
  1926.    sideBar = window.create(term.current(), 31, 2, 21, 18)\
  1927.    mainSec = window.create(term.current(), 1, 2, 29, 19)\
  1928.    scBar = window.create(term.current(), 30, 2, 1, 18)\
  1929.  end\
  1930.  local beg = term.current()\
  1931.  \
  1932.  term.redirect(scBar)\
  1933.  term.setBackgroundColor(colors.white)\
  1934.  term.clear()\
  1935.  local allLen = #things.files+#things.folds\
  1936.  print(allLen)\
  1937.  term.redirect(beg)\
  1938.  \
  1939.  term.redirect(topBar)\
  1940.  term.setBackgroundColor(colors.gray)\
  1941.  term.clear()\
  1942.  term.setTextColor(colors.white)\
  1943.  ctxt('File Explorer - Version '..bNo..' - by Sam Gunner', 1)\
  1944.  term.setTextColor(colors.red)\
  1945.  ptxt('x', 51, 1)\
  1946.  term.setTextColor(colors.black)\
  1947.  term.redirect(beg)\
  1948.  \
  1949.  term.redirect(sideBar)\
  1950.  term.setBackgroundColor(colors.lightGray)\
  1951.  term.clear()\
  1952.  term.setTextColor(colors.black)\
  1953.  if things.sel == '' then\
  1954.    ctxt('File Explorer', 1)\
  1955.    ctxt('Version '..bNo, 2)\
  1956.    ctxt('Click on a file', 8)\
  1957.    ctxt('to get started!', 9)\
  1958.  elseif fs.isDir(fs.combine(dir, things.sel)) then\
  1959.    ctxt('Options - Folder', 1)\
  1960.    ctxt(string.sub(things.sel, 1, 21), 2)\
  1961.    ctxt('------', 4)\
  1962.    ctxt('Open Folder', 6)\
  1963.    ctxt('Rename', 7)\
  1964.    ctxt('Delete', 8)\
  1965.  elseif not fs.isDir(fs.combine(dir, things.sel)) then\
  1966.    ctxt('Options - File', 1)\
  1967.    ctxt(string.sub(things.sel, 1, 21), 2)\
  1968.    ctxt('------', 4)\
  1969.    ctxt('Run as program', 6)\
  1970.    ctxt('Edit as text file', 7)\
  1971.    ctxt('Rename', 8)\
  1972.    ctxt('Delete', 9)\
  1973.    local size = fs.getSize(fs.combine(dir, things.sel))\
  1974.    local sSize = math.ceil(size/1000, 1)\
  1975.    ctxt('Size: ' .. sSize .. ' KB', 12)\
  1976.  end\
  1977.  term.redirect(beg)\
  1978.  \
  1979.  term.redirect(mainSec)\
  1980.  term.setBackgroundColor(colors.white)\
  1981.  term.clear()\
  1982.  term.redirect(beg)\
  1983.  \
  1984.  local files = things.files\
  1985.  local folds = things.folds\
  1986.  local fSel = things.sel\
  1987.  \
  1988.  table.sort(files)\
  1989.  table.sort(folds)\
  1990.  \
  1991.  local tmpTbl = {}\
  1992.  for i=1, #folds do\
  1993.    table.insert(tmpTbl, folds[i])\
  1994.  end\
  1995.  \
  1996.  for i=1, #files do\
  1997.    table.insert(tmpTbl, files[i])\
  1998.  end\
  1999.  \
  2000.  term.redirect(mainSec)\
  2001.  term.setTextColor(colors.black)\
  2002.  \
  2003.  for i=dPos, dPos+17 do\
  2004.    if tmpTbl[i] ~= nil then\
  2005. \009  if fs.isDir(fs.combine(dir, tmpTbl[i])) then\
  2006. \009    if fs.combine(dir, fSel) == fs.combine(dir, tmpTbl[i]) then\
  2007. \009\009  term.setTextColor(colors.lightGray)\
  2008. \009\009  write('[] ' .. string.sub(tmpTbl[i], 1, 26) .. '\\n')\
  2009. \009\009else\
  2010. \009\009  term.setTextColor(colors.black)\
  2011. \009      write('[] ' .. string.sub(tmpTbl[i], 1, 26) .. '\\n')\
  2012. \009\009end\
  2013. \009  else\
  2014. \009    if fs.combine(dir, fSel) == fs.combine(dir, tmpTbl[i]) then\
  2015. \009\009  term.setTextColor(colors.lightGray)\
  2016. \009      write('() ' .. string.sub(tmpTbl[i], 1, 26) .. '\\n')\
  2017. \009\009else\
  2018. \009\009  term.setTextColor(colors.black)\
  2019. \009\009  write('() ' .. string.sub(tmpTbl[i], 1, 26) .. '\\n')\
  2020. \009\009end\
  2021. \009  end\
  2022. \009end\
  2023.  end\
  2024.  \
  2025.  term.redirect(beg)\
  2026.  \
  2027. end\
  2028. \
  2029. function nread()\
  2030.  tmpVal = read()\
  2031. end\
  2032. \
  2033. function handClick(b, x, y, stuff)\
  2034.  if b == 1 then\
  2035.  \
  2036.    if x>=1 and x<=51 and y==1 then\
  2037.      if x == 51 then\
  2038.        terminate = true\
  2039.      end\
  2040.    elseif x>=1 and x<=29 and y>=2 and y<=19 then\
  2041.      local fileSel = ((y-1)+drawPos)-1\
  2042.      local totLen = #stuff.files + #stuff.folds\
  2043.      if fileSel > #stuff.folds then\
  2044.        local fileSel = fileSel - #stuff.folds\
  2045.        selVal = stuff.files[fileSel]\
  2046.      else\
  2047.        selVal = stuff.folds[fileSel]\
  2048.      end\
  2049.    elseif x>=31 and x<=51 and y>=2 and y<=19 then\
  2050.      local xP = x-30\
  2051.      local yP = y-1\
  2052.      local beg = term.current()\
  2053.      if selVal ~= nil then\
  2054.      if fs.isDir(fs.combine(dir, selVal)) then -- Assume folder mode\
  2055.        if yP==6 then\
  2056.          dir = fs.combine(dir, selVal)\
  2057.          selVal = ('')\
  2058.        elseif yP==7 then\
  2059.          term.redirect(sideBar)\
  2060.          ctxt('Enter a new name', 15)\
  2061.          paintutils.drawLine(1, 16, 21, 16, colors.white)\
  2062.          term.setTextColor(colors.black)\
  2063.          term.setCursorPos(1, 16)\
  2064.          local pid = parallel.waitForAny(click, nread)\
  2065.          if pid == 2 then\
  2066.            if #tmpVal>0 then\
  2067.              fs.move(fs.combine(dir, selVal),fs.combine(dir, tmpVal))\
  2068.              selVal = ''\
  2069.            end\
  2070.          end\
  2071.          term.redirect(beg)\
  2072.        elseif yP == 8 then\
  2073.          term.redirect(sideBar)\
  2074.          ctxt('Are you sure you want', 14)\
  2075.          ctxt('to delete this?', 15)\
  2076.          paintutils.drawLine(1, 16, 10, 16, colors.green)\
  2077.          ptxt('Yes', 4, 16)\
  2078.          paintutils.drawLine(11, 16, 21, 16, colors.red)\
  2079.          ptxt('No', 15, 16)\
  2080.          local _, button, x, y = os.pullEvent('mouse_click')\
  2081.          local x, y = x-30, y-1\
  2082.          if button == 1 and x>=1 and x<=10 and y==16 then\
  2083.            fs.delete(fs.combine(dir, selVal))\
  2084.          end\
  2085.          selVal = ''\
  2086.          term.redirect(beg)\
  2087.        end\
  2088.      elseif not fs.isDir(fs.combine(dir, selVal)) then -- Assume file mode\
  2089.        if yP == 6 then\
  2090.          term.setBackgroundColor(colors.black)\
  2091.          term.setTextColor(colors.white)\
  2092.          term.clear()\
  2093.          term.setCursorPos(1, 1)\
  2094.          shell.run(fs.combine(dir, selVal))\
  2095.        elseif yP == 7 then\
  2096.          os.run({}, 'edit', fs.combine(dir, selVal))\
  2097.        elseif yP == 8 then\
  2098.          term.redirect(sideBar)\
  2099.          ctxt('Enter a new name', 15)\
  2100.          paintutils.drawLine(1, 16, 31, 16, colors.white)\
  2101.          term.setCursorPos(1, 16)\
  2102.          local pid = parallel.waitForAny(click, nread)\
  2103.          if pid == 2 then\
  2104.            if #tmpVal > 0 then\
  2105.              fs.move(fs.combine(dir, selVal), fs.combine(dir, tmpVal))\
  2106.              selVal = ''\
  2107.            end\
  2108.          end\
  2109.          term.redirect(beg)\
  2110.        elseif yP == 9 then\
  2111.          term.redirect(sideBar)\
  2112.          ctxt('Are you sure you want', 14)\
  2113.          ctxt('to delete this?', 15)\
  2114.          paintutils.drawLine(1, 16, 11, 16, colors.green)\
  2115.          ptxt('Yes', 5, 16)\
  2116.          paintutils.drawLine(12, 16, 21, 16, colors.red)\
  2117.          ptxt('No', 16, 16)\
  2118.          local _, button, x, y = os.pullEvent('mouse_click')\
  2119.          local x, y = x-30, y-1\
  2120.          if button == 1 and x>=1 and x<=11 and y==16 then\
  2121.            fs.delete(fs.combine(dir, selVal))\
  2122.            selVal = ''\
  2123.          end\
  2124.          term.redirect(beg)\
  2125.        end\
  2126.      end\
  2127.      end\
  2128.    end\
  2129.  elseif b == 2 then\
  2130.    if x>=1 and x<=30 and y>1 then\
  2131.      local ans = dropMenu(x, y)\
  2132.        if ans == 1 then\
  2133.          if dir ~= '/' and dir ~= '' then\
  2134.            dir = fs.getDir(dir)\
  2135.            selVal = nil\
  2136.          end\
  2137.        elseif ans == 2 then\
  2138.          local tmp = diagBox('Enter the name of the new file')\
  2139.          local tmpFile = fs.combine(dir, tmp)\
  2140.          if not fs.exists(tmpFile) then\
  2141.            local h = fs.open(fs.combine(dir, tmp), 'w')\
  2142.            h.close()\
  2143.          end\
  2144.        elseif ans == 3 then\
  2145.          local tmp = diagBox('Enter the name of the new folder')\
  2146.          if not fs.exists(fs.combine(dir, tmp)) then\
  2147.            fs.makeDir(fs.combine(dir, tmp))\
  2148.          end\
  2149.        end\
  2150.    end\
  2151.  end\
  2152. end\
  2153. \
  2154. function dropMenu(x, y)\
  2155.  for i=1, 3 do\
  2156.    paintutils.drawLine(x, (y+i)-1, x+10, (y+i)-1, colors.gray)\
  2157.  end\
  2158.  term.setTextColor(colors.white)\
  2159.  ptxt('Back up', x+2, y)\
  2160.  ptxt('New file', x+2, y+1)\
  2161.  ptxt('New folder', x+1, y+2)\
  2162.  paintutils.drawLine(x+11, y+1, x+11, y+3, colors.black)\
  2163.  paintutils.drawLine(x+1, y+3, x+11, y+3, colors.black)\
  2164.  local event, button, xP, yP = os.pullEvent('mouse_click')\
  2165.  if xP>=x and xP<=x+10 and yP>=y and yP<=y+2 then\
  2166.    return (yP-y)+1\
  2167.  end\
  2168. end\
  2169. \
  2170. function getStuff(dir)\
  2171.  if fs.isDir(dir) then\
  2172.    local tmpVal = fs.list(dir)\
  2173.    local files = {}\
  2174.    local folds = {}\
  2175.    for k, v in ipairs(tmpVal) do\
  2176.      if not fs.isDir(fs.combine(dir, v)) then\
  2177.        table.insert(files, v)\
  2178.      else\
  2179.        table.insert(folds, v)\
  2180.      end\
  2181.    end\
  2182.    \
  2183.    local tmpTbl = {}\
  2184.    tmpTbl.files, tmpTbl.folds = files, folds\
  2185.    return tmpTbl\
  2186.    \
  2187.  end\
  2188. end\
  2189. \
  2190. function handScroll(dir, x, y)\
  2191.  if dir == 1 then\
  2192.    if drawPos+17 < (#stuff.files+#stuff.folds) then\
  2193.      drawPos = drawPos+1\
  2194. \009end\
  2195.  elseif dir == -1 then\
  2196.    if drawPos >1 then\
  2197.      drawPos = drawPos-1\
  2198.  \009 end\
  2199.  end\
  2200. end\
  2201. \
  2202. function ctxt(txt, y)\
  2203.  local w, h = term.getSize()\
  2204.  local x = ((w/2)-(#txt/2))+1\
  2205.  term.setCursorPos(x, y)\
  2206.  write(txt)\
  2207. end\
  2208. \
  2209. function ptxt(txt, x, y)\
  2210.  term.setCursorPos(x, y)\
  2211.  write(txt)\
  2212. end\
  2213. \
  2214. function mScroll()\
  2215.  _, sDir, x, y = os.pullEvent('mouse_scroll')\
  2216. end\
  2217. \
  2218. \
  2219. \
  2220. function click()\
  2221.  _, button, x, y = os.pullEvent('mouse_click')\
  2222. end\
  2223. \
  2224. \
  2225. dir = '/'\
  2226. \
  2227. selVal = nil\
  2228. terminate = nil\
  2229. drawPos = 1\
  2230. \
  2231. term.setBackgroundColor(colors.white)\
  2232. term.clear()\
  2233. term.setTextColor(colors.black)\
  2234. ctxt('File Browser  - Version '..bNo, 9)\
  2235. sleep(2)\
  2236. \
  2237. repeat\
  2238.  mainSec, sideBar, topBar = nil\
  2239.  stuff = getStuff(dir)\
  2240.  if selVal == nil then\
  2241.    stuff.sel = ''\
  2242.  else\
  2243.    stuff.sel = selVal\
  2244.  end\
  2245.  drawMain(stuff, drawPos)\
  2246.  --drawScroll(stuff)\
  2247.  --[[\
  2248.  local h = fs.open('tmp', 'w')\
  2249.  h.write(textutils.serialize(stuff))\
  2250.  h.close()\
  2251.  ]]--\
  2252.  local pid = parallel.waitForAny(click, mScroll)\
  2253.  if pid == 1 then\
  2254.    local tB = button\
  2255. \009local tX = x\
  2256. \009local tY = y\
  2257. \009handClick(tB, tX, tY, stuff)\
  2258.  elseif pid == 2 then\
  2259.    handScroll(sDir, x, y)\
  2260.  end\
  2261. until terminate == true\
  2262. \
  2263. term.setBackgroundColor(colors.black)\
  2264. term.clear()\
  2265. term.setCursorPos(1, 1)",
  2266.     compress = "--[[\
  2267. \009Filesystem\
  2268. \009explorer\
  2269. \009by Creator\
  2270. ]]--\
  2271. \
  2272. args = {...}\
  2273. \
  2274. local filesystem = {}\
  2275. \
  2276. local function readFile(path)\
  2277. \009local file = fs.open(path,\"r\")\
  2278. \009local variable = file.readAll()\
  2279. \009file.close()\
  2280. \009return variable\
  2281. end\
  2282. \
  2283. local function explore(dir)\
  2284. \009local buffer = {}\
  2285. \009local sBuffer = fs.list(dir)\
  2286. \009for i,v in pairs(sBuffer) do\
  2287. \009\009sleep(0.05)\
  2288. \009\009if fs.isDir(dir..\"/\"..v) then\
  2289. \009\009\009if v ~= \".git\" then\
  2290. \009\009\009\009buffer[v] = explore(dir..\"/\"..v)\
  2291. \009\009\009end\
  2292. \009\009else\
  2293. \009\009\009buffer[v] = readFile(dir..\"/\"..v)\
  2294. \009\009end\
  2295. \009end\
  2296. \009return buffer\
  2297. end\
  2298. \
  2299. append = [[\
  2300. local function writeFile(path,content)\
  2301. \009local file = fs.open(path,\"w\")\
  2302. \009file.write(content)\
  2303. \009file.close()\
  2304. end\
  2305. function writeDown(input,dir)\
  2306. \009\009for i,v in pairs(input) do\
  2307. \009\009if type(v) == \"table\" then\
  2308. \009\009\009writeDown(v,dir..\"/\"..i)\
  2309. \009\009elseif type(v) == \"string\" then\
  2310. \009\009\009writeFile(dir..\"/\"..i,v)\
  2311. \009\009end\
  2312. \009end\
  2313. end\
  2314. \
  2315. args = {...}\
  2316. if #args == 0 then\
  2317. \009print(\"Please input a destination folder.\")\
  2318. else\
  2319. \009writeDown(inputTable, args[1])\
  2320. end\
  2321. \
  2322. ]]\
  2323. \
  2324. if #args < 2 then\
  2325.  printError('Usage: <from folder> <destination file>')\
  2326. else\
  2327. \
  2328. local filesystem = explore(args[1])\
  2329. local file = fs.open(args[2],\"w\")\
  2330. file.write(\"inputTable = \"..textutils.serialize(filesystem)..\"\\n\\n\\n\\n\\n\\n\\n\\n\\n\"..append)\
  2331. file.close()\
  2332. end",
  2333.     settings = "slideNo = 1\
  2334. \
  2335. function redraw(slide)\
  2336.        term.setBackgroundColor(colors.white)\
  2337.        term.clear()\
  2338.        term.setTextColor(colors.white)\
  2339.        paintutils.drawLine(1, 1, 51, 1, colors.gray)\
  2340.        txt.ctxt(\"User Settings\", 1)\
  2341.        term.setTextColor(colors.red)\
  2342.        txt.ptxt(\"x\", 51, 1)\
  2343.        term.setTextColor(colors.white)\
  2344. \
  2345.        if slideNo > 1 then\
  2346.            paintutils.drawLine(1, 8, 1, 10, colors.gray)\
  2347.            txt.ptxt(\"<\", 1, 9)\
  2348.        end\
  2349. \
  2350.        if slideNo < pages then\
  2351.            paintutils.drawLine(51, 8, 51, 10, colors.gray)\
  2352.            txt.ptxt(\">\", 51, 9)\
  2353.        end\
  2354. \
  2355.        term.setBackgroundColor(colors.white)\
  2356.        term.setTextColor(colors.black)\
  2357. \
  2358.        if slideNo == 1 then\
  2359.            txt.ptxt(\"Main Colour\", 2, 3)\
  2360.            txt.ptxt(\"Secondary Colour\", 2, 5)\
  2361.            paintutils.drawLine(48, 5, 50, 5, preferences.secColour)\
  2362.            paintutils.drawLine(48, 3, 50, 3, preferences.mainColour)\
  2363.        end\
  2364. \
  2365.        paintutils.drawLine(2, 15, 50, 15, colors.blue)\
  2366.        txt.ctxt(\"Change Password\", 15)\
  2367.        paintutils.drawLine(2, 17, 50, 17, colors.red)\
  2368.        txt.ctxt(\"Delete Account\", 17)\
  2369. end\
  2370. \
  2371. function mainLoop()\
  2372.    endInfo = nil\
  2373.    pages = 1\
  2374.    repeat\
  2375.        redraw()\
  2376.        local _, b, x, y = os.pullEvent(\"mouse_click\")\
  2377.        if b == 1 then\
  2378.            if x == 51 and y == 1 then\
  2379.                endInfo = true\
  2380.            elseif x == 51 and y>= 8 and y<= 10 and slideNo < #slides then\
  2381.                slideNo = slideNo + 1\
  2382.            elseif x == 1 and y>=8 and y<=10 and slideNo > 1 then\
  2383.                slideNo = slideNo - 1\
  2384.            elseif x>=48 and x<=50 and y==3 then\
  2385.                local newCol = gui.popup(2, \"Enter a new colour\", \"Settings\")\
  2386.                if type(textutils.unserialise(newCol)) == \"number\" then\
  2387.                    local users = sys.load(sys.var(\"userPrefs\"))\
  2388.                    preferences.mainColour = textutils.unserialise(newCol)\
  2389.                    users[preferences.name] = preferences\
  2390.                    sys.save(sys.var(\"userPrefs\"), textutils.serialise(users))\
  2391.                end\
  2392.            elseif x>=2 and x<=50 and y == 17 then\
  2393.                local confirm = gui.popup(1, \"Are you sure?\", \"Delete Account\")\
  2394.                local pass = gui.popup(2, \"Please enter your password\", \"Delete Account\", \"*\")\
  2395.                if confirm then\
  2396.                    sys.deleteAccount(preferences.name)\
  2397.                    cinter.logout(originalWindow)\
  2398.                    endInfo = true\
  2399.                end\
  2400.            elseif x>=2 and x<=50 and y == 15 then\
  2401.                local pass = gui.popup(2, \"Please enter your password\", \"Change Password 1/2\", \"*\")\
  2402.                local users = sys.load(sys.var(\"userLogins\"))\
  2403.                local curUser\
  2404.                local userNum\
  2405.                for i = 1, #users do\
  2406.                    if users[i].name == preferences.name then\
  2407.                        curUser = users[i]\
  2408.                        userNum = i\
  2409.                        break\
  2410.                    end\
  2411.                end\
  2412.                if pass == curUser.pass then\
  2413.                    local newPass = gui.popup(2, \"Please enter a new password\", \"Change Password 2/2\", \"*\")\
  2414.                    curUser.pass = newPass\
  2415.                    users[userNum] = curUser\
  2416.                    sys.save(sys.var(\"userLogins\"), users)\
  2417.                end\
  2418.            elseif x>=48 and x<=50 and y==5 then\
  2419.                local newCol = gui.popup(2, \"Enter a new colour\", \"Settings\")\
  2420.                if type(textutils.unserialise(newCol)) == \"number\" then\
  2421.                    local users = sys.load(sys.var(\"userPrefs\"))\
  2422.                    preferences.secColour = textutils.unserialise(newCol)\
  2423.                    users[preferences.name] = preferences\
  2424.                    sys.save(sys.var(\"userPrefs\"), textutils.serialise(users))\
  2425.                end\
  2426.            end\
  2427.        end\
  2428.    until endInfo == true\
  2429. end\
  2430. \
  2431. mainLoop()",
  2432.   },
  2433.   dumps = {
  2434.     [ "sysCrash (latest)" ] = "--[[\
  2435. \
  2436. \009Base V1.1 by Sam Gunner.\
  2437. Patch pack 1\
  2438. \009\
  2439. ]]--\
  2440. \
  2441. -- Variables --\
  2442. \
  2443. commands = {\
  2444.  [ 'edit' ] = function()\
  2445.    printError('This function has been deprecated. Please use: \\'nano <file>\\'')\
  2446.  end,\
  2447.  [ 'exit' ] = function()\
  2448.    mainLoopTerm = true\
  2449.  end,\
  2450.  [ 'about' ] = function()\
  2451.    term.setTextColor(colors.gray)\
  2452.    print('This OS was made by Sam Gunner, otherwise known as SGunner2014.')\
  2453.    print('You are allowed to modify, redistribute and do anything to this \\'OS\\' as long as you give me credit.')\
  2454.    print('Please note that the compress function was made by \\'Creator\\'. Thanks, buddy! :D')\
  2455.  end,\
  2456.  [ 'help' ] = function()\
  2457.    term.setTextColor(colors.green)\
  2458.    print('Available commands:')\
  2459.    local tmpTbl = {}\
  2460.    for k, v in pairs(commands) do\
  2461.      table.insert(tmpTbl, k)\
  2462.    end\
  2463.    table.sort(tmpTbl)\
  2464.    textutils.pagedTabulate(colors.red, tmpTbl)\
  2465.  end,\
  2466.  [ 'compress' ] = function(cmd)\
  2467.    local tmpTbl = {}\
  2468.    \
  2469.    for i=2, #cmd do\
  2470.      table.insert(tmpTbl, cmd[i])\
  2471.    end\
  2472.    \
  2473.    if #tmpTbl ~= 2 then\
  2474.      printError('Usage: compress <Directory> <Destination file>')\
  2475.    else\
  2476.    \
  2477.    if fs.isDir(tmpTbl[1]) and not fs.exists(tmpTbl[2]) then\
  2478.    \
  2479.    local h = fs.open('.kernel/programs/compress', 'r')\
  2480.    local app = h.readAll()\
  2481.    h.close()\
  2482.    \
  2483.    loadstring(app)(tmpTbl[1], tmpTbl[2])\
  2484.    else\
  2485.      printError('Usage: compress <Directory> <Destination file>')\
  2486.    end\
  2487.    end\
  2488.  end,\
  2489.  [ 'clear' ] = function()\
  2490.    term.setBackgroundColor(colors.white)\
  2491.    term.clear()\
  2492.    term.setCursorPos(1, 1)\
  2493.  end,\
  2494.  [ 'run' ] = function(cmd)\
  2495.    shell.run(cmd[2])\
  2496.    --[[\
  2497.    paintutils.drawLine(35, 19, 51, 19, colors.gray)\
  2498.    term.setTextColor(colors.white)\
  2499.    txt.pwrite('Closing in 2...', 35, 19)\
  2500.    sleep(1)\
  2501.    txt.pwrite('Closing in 1...', 35, 19)\
  2502.    sleep(1)\
  2503.    ]]--\
  2504.    commands.clear()\
  2505.  end,\
  2506.  [ 'reboot' ] = function()\
  2507.    cinter.reboot()\
  2508.    term.setBackgroundColor(colors.black)\
  2509.    term.clear()\
  2510.    term.setCursorPos(1, 1)\
  2511.    term.setTextColor(colors.white)\
  2512.    commands.clear()\
  2513.  end,\
  2514.  [ 'shutdown' ] = function()\
  2515.    cinter.shutdown()\
  2516.    term.setBackgroundColor(colors.black)\
  2517.    term.clear()\
  2518.    term.setCursorPos(1, 1)\
  2519.    term.setTextColor(colors.white)\
  2520.    commands.clear()\
  2521.  end,\
  2522.  [ 'ls' ] = function(cmd)\
  2523.    local files2 = {}\
  2524.    local file = {}\
  2525.    local folds = {}\
  2526.    if cmd[2] == nil then\
  2527.      files = fs.list(dir)\
  2528.      tmpDir = ''\
  2529.    elseif fs.isDir(cmd[2]) then\
  2530.      files = fs.list(cmd[2])\
  2531.      tmpDir = cmd[2]\
  2532.    else\
  2533.      printError('That is not a directory.')\
  2534.      return nil\
  2535.    end\
  2536.    for k, v in ipairs(files) do\
  2537.      if string.sub(v, 1, 1) ~= '.' then\
  2538.        table.insert(files2, v)\
  2539.      end\
  2540.    end\
  2541.    for i=1, #files2 do\
  2542.      if fs.isDir(tmpDir..'/'..files2[i]) then\
  2543.        table.insert(folds, files2[i])\
  2544.      else\
  2545.        table.insert(file, files2[i])\
  2546.      end\
  2547.    end\
  2548.    textutils.pagedTabulate(colors.red, folds, colors.gray, file)\
  2549.  end,\
  2550.  [ 'cd' ] = function(cmd)\
  2551.    if fs.exists(dir..'/'..cmd[2]) then\
  2552.      if cmd[2] == '..' then\
  2553.        dir = fs.getDir(dir)\
  2554.      elseif cmd[2] == '/' then\
  2555.        dir = ''\
  2556.      elseif fs.isDir(dir..'/'..cmd[2]) then\
  2557.        dir = dir..'/'..cmd[2]\
  2558.      else\
  2559.        printError('That isn\\'t a directory!')\
  2560.      end\
  2561.    else\
  2562.      printError('That isn\\'t a directory!')\
  2563.    end\
  2564.  end,\
  2565.  [ 'clr'] = function() commands.clear() end,\
  2566.  [ 'rm' ] = function(cmd)\
  2567.    if fs.exists(fs.combine(dir, cmd[2])) then\
  2568.      fs.delete(fs.combine(dir, cmd[2]))\
  2569.      print('File deleted.')\
  2570.    else\
  2571.      printError('That file doesn\\'t exist!')\
  2572.    end\
  2573.  end,\
  2574.  [ 'mkdir' ] = function(cmd)\
  2575.    if not fs.exists(fs.combine(dir, cmd[2])) then\
  2576.      fs.makeDir(fs.combine(dir, cmd[2]))\
  2577.    else\
  2578.      printError('That already exists.')\
  2579.    end\
  2580.  end,\
  2581.  [ 'nano' ] = function(cmd)\
  2582.    if not fs.exists(fs.combine(dir, cmd[2])) then\
  2583.      local h = fs.open(fs.combine(dir, cmd[2]), \"w\")\
  2584.      h.write(\"\")\
  2585.      h.close()\
  2586.    end\
  2587.    local h = fs.open(\"/.kernel/programs/ink\", \"r\")\
  2588.    local raw = h.readAll()\
  2589.    h.close()\
  2590.    loadstring(raw)(fs.combine(dir, cmd[2])\
  2591.  end\
  2592. }\
  2593. \
  2594. -- Functions --\
  2595. \
  2596. function commSplit(comm)\
  2597.  local tmpTbl = {}\
  2598.  for k in string.gmatch(comm, '[^ ]+') do\
  2599.    table.insert(tmpTbl, k)\
  2600.  end\
  2601.  return tmpTbl\
  2602. end\
  2603. \
  2604. function mainLoop(commands)\
  2605. mainLoopTerm = false\
  2606. dir = ''\
  2607. local commHis = {}\
  2608. term.setBackgroundColor(colors.white)\
  2609. term.clear()\
  2610. term.setCursorPos(1, 1)\
  2611. \
  2612. term.setTextColor(colors.black)\
  2613. \
  2614. print('Welcome to BaseOS Shell, V1.1')\
  2615. print('Type \\'help\\' for a list of commands')\
  2616. \
  2617. repeat\
  2618. \
  2619.  --local tmpVal = multishell.getCurrent()\
  2620.  --multishell.setTitle(tmpVal, 'OS')\
  2621. \
  2622.  term.setTextColor(colors.lightGray)\
  2623.  write(dir..'/> ')\
  2624.  term.setTextColor(colors.black)\
  2625.  local comm = read(nil, commHis)\
  2626.  table.insert(commHis, comm)\
  2627.  local commNew = commSplit(comm)\
  2628. \
  2629.  \
  2630.  \
  2631.  if commands[commNew[1]] ~= nil then\
  2632.    local ok, err = pcall(commands[commNew[1]], commNew)\
  2633.    if not ok then\
  2634.      local h = fs.open('latestCrash', 'w')\
  2635.      h.write(err)\
  2636.      h.close()\
  2637.      local ans = gui.popup(1, 'Uh oh. Looks like this app has crashed. Reboot?', 'An error has occurred.')\
  2638.      if ans == true then\
  2639.        cinter.reboot()\
  2640.      else\
  2641.        commands.clear()\
  2642.      end\
  2643.    end\
  2644.  else\
  2645.    printError('That command doesn\\'t exist. Type \\'help\\' for help.')\
  2646.  end\
  2647. until mainLoopTerm == true\
  2648. end\
  2649. \
  2650. -- Startup\
  2651. \
  2652. sleep(.2)\
  2653. --local tmpVal = cinter.login()\
  2654. \
  2655. mainLoop(commands)",
  2656.     explorer = "",
  2657.     latestAppCrash = "os.main:138: attempt to call number",
  2658.     latest = "Terminated",
  2659.     explorerCrash = "",
  2660.     prog = "sys:16: attempt to call boolean",
  2661.   },
  2662.   core = {
  2663.     screenManageTask = "while true do\
  2664. \009screenManage.redraw()\
  2665. \009coroutine.yield()\
  2666. end",
  2667.     [ "os.main" ] = "--[[\
  2668. \009Core BASE file. If modified, this could result in serious stability problems with the OS.\
  2669. ]]--\
  2670. \
  2671. --[[\
  2672. \009OS Standard error codes:\
  2673. \009\
  2674. \0094 - File does not exist.\
  2675. ]]--\
  2676. _G.originalWindow = term.current() -- Set variables\
  2677. _G.mainWindow = window.create(originalWindow, 1, 1, 51, 18) -- Create main windows\
  2678. _G.taskBar = window.create(originalWindow, 1, 19, 51, 1)\
  2679. tasks.launchBackgroundTaskAsAPI(\".kernel/apis/screenManage\", \".kernel/core/screenManageTask\")\
  2680. for k, v in pairs(screenManage) do\
  2681. \009base_core.graphics.k = v\
  2682. end\
  2683. \
  2684. \
  2685. osPopMenuOpts = { -- Popup menu from taskbar\
  2686. \009{\"Shutdown\", func = function() cinter.shutdown(originalWindow) end},\
  2687. \009{\"Reboot\", func = function() cinter.reboot(originalWindow) end},\
  2688. \009{\"Logout\", func = function() cinter.logout(originalWindow) end},\
  2689. \009{\"--\", func = function() end},\
  2690. \009{\"File Manager\", func = function() launch(\"explorer\") end},\
  2691. \009{\"Console\", func = function() launch(\"console\") end},\
  2692. \009{\"--\", func = function() end},\
  2693. \009{\"BASE 2 Info\", func = function() launch(\"info\") end},\
  2694. \009{\"Settings\", func = function() launch(\"settings\") end},\
  2695. }\
  2696. \
  2697. oldTerm = term\
  2698. _G.oldOsPull = os.pullEvent\
  2699. _G.term.native = function()\
  2700. \009return mainWindow\
  2701. end\
  2702. \
  2703. _G.oldOS = {}\
  2704. _G.oldOS.shutdown = os.shutdown\
  2705. _G.oldOS.reboot = os.reboot\
  2706. os.shutdown = function() cinter.shutdown(originalWindow) end\
  2707. os.reboot = function() cinter.reboot(originalWindow) end -- End of variable setting\
  2708. \
  2709. -- tmp = fs\
  2710. -- oldFS = fs\
  2711. \
  2712. -- tmp.list = function(path)\
  2713. -- \009dir = fs.combine(sys.var(\"userDir\"), path)\
  2714. -- \009return oldFS.list(dir)\
  2715. -- end\
  2716. \
  2717. -- tmp.exists = function(path)\
  2718. -- \009path = fs.combine(sys.var(\"userDir\"), path)\
  2719. -- \009return oldFS.exists(path)\
  2720. -- end\
  2721. \
  2722. -- tmp.isDir = function(path)\
  2723. -- \009path = fs.combine(sys.var(\"userDir\"), path)\
  2724. -- \009return oldFS.isDir(path)\
  2725. -- end\
  2726. \
  2727. -- tmp.isReadOnly = function(path)\
  2728. -- \009path = fs.combine(sys.var(\"userDir\"), path)\
  2729. -- \009return oldFS.isReadOnly(path)\
  2730. -- end\
  2731. \
  2732. -- tmp.getName = function(path)\
  2733. -- \009path = fs.combine(sys.var(\"userDir\"), path)\
  2734. -- \009return oldFS.getName(path)\
  2735. -- end\
  2736. \
  2737. \
  2738. \
  2739. os.pullEvent = function(event) -- Redoing os.pullEvent\
  2740. \009if event == \"mouse_click\" then\
  2741. \009\009local _, b, x, y = oldOsPull(\"mouse_click\")\
  2742. \009\009if y == 19 then\
  2743. \009\009\009taskbarLaunch(b, x, y)\
  2744. \009\009\009return nil, 0, 0, 0\
  2745. \009\009else\
  2746. \009\009\009return \"mouse_click\", b, x, y\
  2747. \009\009end\
  2748. \009elseif event == \"mouse_scroll\" then\
  2749. \009\009local _, dir, x, y = oldOsPull(\"mouse_scroll\")\
  2750. \009\009if y == 1 then\
  2751. \009\009else\
  2752. \009\009\009return \"mouse_click\", dir, x, y - 1\
  2753. \009\009end\
  2754. \009elseif event == \"mouse_drag\" then\
  2755. \009\009local _, b, x, y = oldOsPull(\"mouse_drag\")\
  2756. \009\009if y == 1 then\
  2757. \009\009else\
  2758. \009\009\009return \"mouse_drag\", b, x, y\
  2759. \009\009end\
  2760. \009else\
  2761. \009\009return oldOsPull(event)\
  2762. \009end\
  2763. end\
  2764. \
  2765. function taskbarLaunch(b, x, y) -- Launches the 'start' menu\
  2766. \009if x>=1 and x<=3 then\
  2767. \009\009drawStart(mainWindow, taskBar)\
  2768. \009\009local _, b, x, y = oldOsPull(\"mouse_click\")\
  2769. \009\009if b == 1 then\
  2770. \009\009\009if x >= 1 and x <= 51 and y == 19 then\
  2771.    screenManage.redrawTaskbar()\
  2772. \009\009\009\009return\
  2773. \009\009\009elseif x >= 1 and x <= 15 and y >= (18 - #osPopMenuOpts) and y <= 18 then\
  2774.    screenManage.redrawTaskbar()\
  2775. \009\009\009\009osPopMenuOpts[y - (18 - #osPopMenuOpts)].func()\
  2776.   else\
  2777.     screenManage.redrawTaskbar()\
  2778.     return\
  2779. \009\009\009end\
  2780. \009\009end\
  2781. \009end\
  2782. end\
  2783. \
  2784. function launch(item, args) -- Launches a program with any arguments specified (as a table)\
  2785.  screenManage.redrawTaskbar()\
  2786. \009local function runProg()\
  2787. \009\009os.run({shell = shell}, fs.combine(\".kernel/programs\", item))\
  2788. \009end\
  2789. \009if type(item) == \"string\" and fs.exists(fs.combine(\".kernel/programs\", item)) then\
  2790. \009\009local ok, err = pcall(tasks.newTask(loadfile(fs.combine(\".kernel/programs\", item))))\
  2791. \009\009if not ok then\
  2792. \009\009\009sys.save(\".kernel/dumps/latestAppCrash\", err)\
  2793. \009\009end\
  2794. \009elseif type(item) == \"table\" and fs.exists(item.path) then\
  2795. \009\009local ok, err = pcall(os.run({shell = shell}, item.path))\
  2796. \009\009if not ok then\
  2797. \009\009\009sys.save(\".kernel/dumps/latestAppCrash\", err)\
  2798. \009\009end\
  2799. \009--else\
  2800. \009\009--term.redirect(mainWindow)\
  2801. \009\009--term.setBackgroundColor(colors.white)\
  2802. \009\009--term.clear()\
  2803. \009\009--term.setTextColor(colors.black)\
  2804. \009\009--txt.ctxt(\"File not found\", 1)\
  2805. \009\009--os.pullEvent(\"mouse_click\")\
  2806. \009end\
  2807. end\
  2808. \
  2809. local function drawStart(main, taskBar) -- Draws the start menu, not universally accessible\
  2810. \009term.setBackgroundColor(colors.lightGray)\
  2811. \009term.clear()\
  2812. \009paintutils.drawLine(1, 1, 3, 1, colors.gray)\
  2813. \009term.setTextColor(colors.white)\
  2814. \009txt.ptxt(\"[^]\", 1, 1)\
  2815. local startPos = 18 - #osPopMenuOpts\
  2816. \009for i = 1, #osPopMenuOpts do\
  2817. \009\009paintutils.drawLine(1, startPos + i, 15, startPos + i, colors.gray)\
  2818. \009end\
  2819. \009for i = 1, #osPopMenuOpts do\
  2820. \009\009term.setTextColor(colors.white)\
  2821. \009\009txt.ptxt(osPopMenuOpts[i][1], 1, startPos + i)\
  2822. \009end\
  2823. end\
  2824. \
  2825. function mainLoop() -- Main loop. This includes the main functionality of the OS. The 'core' bit.\
  2826. endAll = nil\
  2827. \009local appPositions = {\
  2828. \009\009{xS = 2, xF = 10, yS = 2, yF = 6}, -- Row 1\
  2829. \009\009{xS = 12, xF = 20, yS = 2, yF = 6},\
  2830. \009\009{xS = 22, xF = 30, yS = 2, yF = 6},\
  2831. \009\009{xS = 32, xF = 40, yS = 2, yF = 6},\
  2832. \009\009{xS = 42, xF = 50, yS = 2, yF = 6},\
  2833. \009\009{xS = 2, xF = 10, yS = 8, yF = 12}, -- Row 2\
  2834. \009\009{xS = 12, xF = 20, yS = 8, yF = 12},\
  2835. \009\009{xS = 22, xF = 30, yS = 8, yF = 12},\
  2836. \009\009{xS = 32, xF = 40, yS = 8, yF = 12},\
  2837. \009\009{xS = 42, xF = 50, yS = 8, yF = 12},\
  2838. \009\009{xS = 2, xF = 10, yS = 14, yF = 18}, -- Row 3\
  2839. \009\009{xS = 12, xF = 20, yS = 14, yF = 18},\
  2840. \009\009{xS = 22, xF = 30, yS = 14, yF = 18},\
  2841. \009\009{xS = 32, xF = 40, yS = 14, yF = 18},\
  2842. \009\009{xS = 42, xF = 50, yS = 14, yF = 18},\
  2843. \009}\
  2844. \009homeApps = preferences.homeApps\
  2845. \
  2846. \009local function redraw(positions)\
  2847. \009\009term.setBackgroundColor(colors.white)\
  2848. \009\009term.clear()\
  2849.  paintutils.drawLine(1, 1, 51, 1, colors.lightGray)\
  2850. \009\009term.setTextColor(colors.white)\
  2851. \009\009txt.ptxt(\"[v]\", 1, 1)\
  2852. \
  2853. \009\009term.setBackgroundColor(colors.white)\
  2854. \009\009term.clear()\
  2855. \009\009for i = 1, 15 do\
  2856. \009\009\009if homeApps[i] ~= nil then\
  2857. \009\009\009\009if homeApps[i].image == nil then\
  2858. \009\009\009\009\009homeApps[i].image = homeApps.default.image\
  2859. \009\009\009\009end\
  2860. \009\009\009\009paintutils.drawImage(sys.loadImage(homeApps[i].image), appPositions[i].xS, appPositions[i].yS)\
  2861. \009\009\009end\
  2862. \009\009end\
  2863. \009end\
  2864. \
  2865. \009repeat\
  2866. \009\009redraw(appPositions)\
  2867. \009\009local _, b, x, y = os.pullEvent(\"mouse_click\")\
  2868. \009\009if y>=2 and y<=6 then\
  2869. \009\009\009-- Each app is 10x5 in size.\
  2870. \009\009\009-- The grid of apps is 5x3\
  2871. \009\009\009if x>=2 and x<=10 then\
  2872. \009\009\009\009-- App 1\
  2873. \009\009\009\009launch(homeApps[1])\
  2874. \009\009\009elseif x>=12 and x<=20 then\
  2875. \009\009\009\009-- App 2\
  2876. \009\009\009\009launch(homeApps[2])\
  2877. \009\009\009elseif x>=22 and x<=30 then\
  2878. \009\009\009\009-- App 3\
  2879. \009\009\009\009launch(homeApps[3])\
  2880. \009\009\009elseif x>=32 and x<=40 then\
  2881. \009\009\009\009-- App 4\
  2882. \009\009\009\009launch(homeApps[4])\
  2883. \009\009\009elseif x>=42 and x<=50 then\
  2884. \009\009\009\009-- App 5\
  2885. \009\009\009\009launch(homeApps[5])\
  2886. \009\009\009end\
  2887. \009\009elseif y>=8 and y<=12 then\
  2888. \009\009\009-- Second row of apps\
  2889. \009\009\009if x>=2 and x<=10 then\
  2890. \009\009\009\009-- App 6\
  2891. \009\009\009\009launch(homeApps[6])\
  2892. \
  2893. \009\009\009elseif x>=12 and x<=20 then\
  2894. \009\009\009\009-- App 7\
  2895. \009\009\009\009launch(homeApps[7])\
  2896. \
  2897. \009\009\009elseif x>=22 and x<=30 then\
  2898. \009\009\009\009-- App 8\
  2899. \009\009\009\009launch(homeApps[8])\
  2900. \
  2901. \009\009\009elseif x>=32 and x<=40 then\
  2902. \009\009\009\009-- App 9\
  2903. \009\009\009\009launch(homeApps[9])\
  2904. \
  2905. \009\009\009elseif x>=42 and x<=50 then\
  2906. \009\009\009\009-- App 10\
  2907. \009\009\009\009launch(homeApps[10])\
  2908. \009\009\009end\
  2909. \009\009elseif y>=14 and y<=18 then\
  2910. \009\009\009-- Third row of apps\
  2911. \009\009\009if x>=2 and x<=10 then\
  2912. \009\009\009\009-- App 11\
  2913. \009\009\009\009launch(homeApps[11])\
  2914. \
  2915. \009\009\009elseif x>=12 and x<=20 then\
  2916. \009\009\009\009-- App 12\
  2917. \009\009\009\009launch(homeApps[12])\
  2918. \
  2919. \009\009\009elseif x>=22 and x<=30 then\
  2920. \009\009\009\009-- App 13\
  2921. \009\009\009\009launch(homeApps[13])\
  2922. \
  2923. \009\009\009elseif x>=32 and x<=40 then\
  2924. \009\009\009\009-- App 14\
  2925. \009\009\009\009launch(homeApps[14])\
  2926. \009\009\009elseif x>=42 and x<=50 then\
  2927. \009\009\009\009-- App 15\
  2928. \009\009\009\009launch(homeApps[15])\
  2929. \009\009\009end\
  2930. \009\009end\
  2931. \009until endAll == true\
  2932. end\
  2933. \
  2934. function all()\
  2935. \009while true do\
  2936. \009\009_G.activeUser = sys.login(sys.load(sys.var(\"userLogins\")), mainWindow, taskBar) --Makes sure that there is a user logged in.\
  2937. \009\009if _G.activeUser == nil then\
  2938. \009\009\009break\
  2939. \009\009end\
  2940. \009\009local ok, err = pcall(mainLoop)\
  2941. \009\009if not ok then\
  2942. \009\009  local h = fs.open(\".kernel/dumps/latest\", \"w\")\
  2943. \009\009  h.write(err)\
  2944. \009\009  h.close()\
  2945. \009\009  local ans = gui.popup(1, '   An error has occured. The   system can no longer function. Reboot?', 'An Error Has Occured')\
  2946. \009\009  if ans == true then\
  2947. \009\009\009os.reboot()\
  2948. \009\009  end\
  2949. \009\009end\
  2950. \009end\
  2951. end\
  2952. \
  2953. local ok, err = pcall(all)\
  2954. if not ok then\
  2955. \009local h = fs.open(\"/.latest\", \"w\")\
  2956. \009h.write(err)\
  2957. \009h.close()\
  2958. end",
  2959.     files = {
  2960.       backgrounds = {},
  2961.       images = {
  2962.         homeAppsDefaultImage = "1111111111\
  2963. 1222222221\
  2964. 1222222221\
  2965. 1222222221\
  2966. 1111111111",
  2967.         settingsIcon = "788fff887\
  2968. 877f77778\
  2969. 877fff778\
  2970. 87777f778\
  2971. 788fff887",
  2972.       },
  2973.     },
  2974.     shutdown = "cinter.shutdown()\
  2975. term.setBackgroundColor(colors.black)\
  2976. term.clear()\
  2977. term.setCursorPos(1, 1)",
  2978.     startup = "--[[\
  2979.  BASE 2 Bootstrap File\
  2980.  Loads core APIs and system files.\
  2981. ]]--\
  2982. \
  2983. function main()\
  2984.  tempWin = window.create(term.current(), 1, 1, 1, 1)\
  2985.  local function shift()\
  2986.      local _, scancode = os.pullEvent('key')\
  2987.      if scancode == 1 then\
  2988.        esc = true\
  2989.      end\
  2990.  end\
  2991. \
  2992.  local function twoSec()\
  2993.    sleep(2)\
  2994.  end\
  2995. \
  2996.  shell.setAlias('shutdown', '.kernel/core/shutdown')\
  2997.  shell.setAlias('reboot', '.kernel/core/reboot')\
  2998. \
  2999.  -- Clearing screen\
  3000.  term.clear()\
  3001.  term.setCursorPos(1, 1)\
  3002.  term.setBackgroundColor(colors.lightGray)\
  3003.  term.setTextColor(colors.black)\
  3004.  write('[SYS]')\
  3005.  term.setBackgroundColor(colors.black)\
  3006.  term.setTextColor(colors.white)\
  3007.  print(' Starting boot procedure...')\
  3008. \
  3009.  -- Clear caches\
  3010.  local h = fs.open('.kernel/.mdata/plist', 'w')\
  3011.  h.write('{}')\
  3012.  h.close()\
  3013.  term.setBackgroundColor(colors.lightGray)\
  3014.  term.setTextColor(colors.black)\
  3015.  write('[SYS]')\
  3016.  term.setBackgroundColor(colors.black)\
  3017.  term.setTextColor(colors.white)\
  3018.  print(' Cleared system caches.')\
  3019. \
  3020.  -- Listing apis in .kernel/apis/\
  3021. \
  3022.  term.setBackgroundColor(colors.lightGray)\
  3023.  term.setTextColor(colors.black)\
  3024.  write('[SYS]')\
  3025.  term.setBackgroundColor(colors.black)\
  3026.  term.setTextColor(colors.white)\
  3027.  print(' Checking integrity of files...')\
  3028. \
  3029.  local tmpTbl = {\
  3030.    '.kernel',\
  3031.    '.kernel/apis',\
  3032.    '.kernel/core',\
  3033.    '.kernel/apis/txt',\
  3034.    '.kernel/apis/gui',\
  3035.    '.kernel/apis/cinter',\
  3036.    '.kernel/apis/baseForms',\
  3037.    '.kernel/core/os.main',\
  3038.    '.kernel/core/startup',\
  3039.    '.kernel/usrData',\
  3040.    '.kernel/usrData/login',\
  3041.    '.kernel/apis/sys',\
  3042.    '.kernel/apis/tasks',\
  3043.  }\
  3044. \
  3045.  if not fs.exists('.kernel/usrData/login') then\
  3046.    local h = fs.open('.kernel/usrData/login', 'w')\
  3047.    h.write('{}')\
  3048.    h.close()\
  3049.  end\
  3050. \
  3051.  if not fs.exists(\".kernel/usrData/preferences\") then\
  3052.    local h = fs.open(\".kernel/usrData/preferences\", \"w\")\
  3053.    h.write(\"{}\")\
  3054.    h.close()\
  3055.  end\
  3056. \
  3057.  for i=1, #tmpTbl do\
  3058.    if not fs.exists(tmpTbl[i]) then\
  3059.      term.setBackgroundColor(colors.lightGray)\
  3060.      term.setTextColor(colors.black)\
  3061.      write('[SYS]')\
  3062.      term.setBackgroundColor(colors.black)\
  3063.      term.setTextColor(colors.red)\
  3064.      print(' [CRITICAL] Missing ' .. tmpTbl[i] .. '!')\
  3065.    end\
  3066.  end\
  3067. \
  3068.  term.setBackgroundColor(colors.lightGray)\
  3069.  term.setTextColor(colors.black)\
  3070.  write('[SYS]')\
  3071.  term.setBackgroundColor(colors.black)\
  3072.  term.setTextColor(colors.white)\
  3073.  print(' Loading kernel core APIs...')\
  3074. \
  3075.  local apis = fs.list('.kernel/apis')\
  3076. \
  3077.  local tmpTbl = {}\
  3078. \
  3079.  for k, v in ipairs(apis) do\
  3080.    if not fs.isDir(v) then\
  3081.      table.insert(tmpTbl, v)\
  3082.      --print(v)\
  3083.    end\
  3084.  end\
  3085. \
  3086.  for i=1, #tmpTbl do\
  3087.    --print('Loading ' .. tmpTbl[i])\
  3088.    os.loadAPI('.kernel/apis/'..tmpTbl[i])\
  3089.    term.setTextColor(colors.black)\
  3090.    term.setBackgroundColor(colors.white)\
  3091.    write('[API]-['..tmpTbl[i]..']')\
  3092.    term.setBackgroundColor(colors.black)\
  3093.    term.setTextColor(colors.green)\
  3094.    print(' OK')\
  3095.  end\
  3096. \
  3097.  term.setBackgroundColor(colors.lightGray)\
  3098.  term.setTextColor(colors.black)\
  3099.  write('[SYS]')\
  3100.  term.setBackgroundColor(colors.black)\
  3101.  term.setTextColor(colors.green)\
  3102.  print(' APIs OK')\
  3103.  term.setTextColor(colors.black)\
  3104.  term.setBackgroundColor(colors.lightGray)\
  3105.  write('[SYS]')\
  3106.  term.setBackgroundColor(colors.black)\
  3107. \
  3108.  term.setBackgroundColor(colors.lightGray)\
  3109.  term.setTextColor(colors.black)\
  3110.  write('[SYS]')\
  3111.  term.setBackgroundColor(colors.black)\
  3112.  term.setTextColor(colors.white)\
  3113.  print(' Loading system preferences...')\
  3114. \
  3115.  term.setBackgroundColor(colors.gray)\
  3116.  term.setTextColor(colors.black)\
  3117.  write('[USER SERVICES]')\
  3118.  term.setTextColor(colors.white)\
  3119.  term.setBackgroundColor(colors.black)\
  3120.  print(' Loading user profiles...')\
  3121. \
  3122.  local h = fs.open(\".kernel/usrData/login\", \"r\")\
  3123.  local rawData = h.readAll()\
  3124.  h.close()\
  3125.  local users = textutils.unserialise(rawData)\
  3126.  term.setBackgroundColor(colors.gray)\
  3127.  term.setTextColor(colors.black)\
  3128.  write('[USER SERVICES]')\
  3129.  term.setTextColor(colors.white)\
  3130.  term.setBackgroundColor(colors.black)\
  3131.  print(' User profiles loaded.')\
  3132. \
  3133.  \
  3134. \
  3135.  --cinter.login()\
  3136. \
  3137.  term.setTextColor(colors.black)\
  3138.  term.setBackgroundColor(colors.lightGray)\
  3139.  write('[SYS]')\
  3140.  term.setBackgroundColor(colors.black)\
  3141.  term.setTextColor(colors.white)\
  3142.  print(' Press the esc key now to enter advanced boot options')\
  3143. \
  3144.  local id = parallel.waitForAny(shift, twoSec)\
  3145. \
  3146.  if id == 1 and esc ~= nil and esc == true then\
  3147.    local ans = gui.popup(1, 'Do you want debugging on?', 'Debugging')\
  3148.  end\
  3149. \
  3150.  \
  3151. _G.base_core = {}\
  3152. _G.base_core.graphics = {}\
  3153. _G.base_core.graphics = term\
  3154. _G.base_core.graphics.oldTerm = term\
  3155. _G.base_core.graphics.current = function()\
  3156. \009return tempWin\
  3157. end\
  3158. _G.base_core.graphics.redirect = function()\
  3159. \009return nil\
  3160. end\
  3161. \
  3162. _G.base_core.graphics.blit = function(txt, col1, col2, x, y) -- Temporary 'blit' function to handle screen redrawing\
  3163. \
  3164. \009if txt ~= nil and col1 ~= nil and col2 ~= nil then\
  3165. \009\009base_core.graphics.oldTerm.setCursorPos(x, y)\
  3166. \009\009base_core.graphics.oldTerm.setBackgroundColor(col2)\
  3167. \009\009base_core.graphics.oldTerm.setTextColor(col1)\
  3168. \009\009base_core.graphics.oldTerm.write(txt)\
  3169. \009end\
  3170. end\
  3171. \
  3172. _G.term = base_core.graphics\
  3173.  -- End bootstrap\
  3174.  -- Begin os load\
  3175. \
  3176.  --shell.run('.kernel/core/os.main')\
  3177. end\
  3178. \
  3179. function start()\
  3180. \009main()\
  3181. \009--tasks.start()\
  3182. \009local h = fs.open(\".kernel/core/os.main\", \"r\")\
  3183. \009local data = h.readAll()\
  3184. \009h.close()\
  3185. \009local ok, err = pcall(tasks.start)\
  3186. \009if not ok then\
  3187. \009\009local h = fs.open(\"/.latest\", \"w\")\
  3188. \009\009h.write(err)\
  3189. \009\009h.close()\
  3190. \009end\
  3191. end\
  3192. \
  3193. local ok, err = pcall(start)\
  3194. if not ok then\
  3195. \009local h = fs.open(\"/.latest\", \"w\")\
  3196. \009h.write(err)\
  3197. \009h.close()\
  3198. end",
  3199.     console = "--[[\
  3200. \
  3201. \009Base V1.1 by Sam Gunner.\
  3202. Patch pack 1\
  3203. \009\
  3204. ]]--\
  3205. \
  3206. -- Variables --\
  3207. \
  3208. commands = {\
  3209.  [ 'edit' ] = function()\
  3210.    printError('This function has been deprecated. Please use: \\'nano <file>\\'')\
  3211.  end,\
  3212.  [ 'exit' ] = function()\
  3213.    mainLoopTerm = true\
  3214.  end,\
  3215.  [ 'about' ] = function()\
  3216.    term.setTextColor(colors.gray)\
  3217.    print('BASE Console, Version 1.1 Built for BASE 2')\
  3218.  end,\
  3219.  [ 'help' ] = function()\
  3220.    term.setTextColor(colors.green)\
  3221.    print('Available commands:')\
  3222.    local tmpTbl = {}\
  3223.    for k, v in pairs(commands) do\
  3224.      table.insert(tmpTbl, k)\
  3225.    end\
  3226.    table.sort(tmpTbl)\
  3227.    textutils.pagedTabulate(colors.red, tmpTbl)\
  3228.  end,\
  3229.  [ 'compress' ] = function(cmd)\
  3230.    local tmpTbl = {}\
  3231.    \
  3232.    for i=2, #cmd do\
  3233.      table.insert(tmpTbl, cmd[i])\
  3234.    end\
  3235.    \
  3236.    if #tmpTbl ~= 2 then\
  3237.      printError('Usage: compress <Directory> <Destination file>')\
  3238.    else\
  3239.    \
  3240.    if fs.isDir(tmpTbl[1]) and not fs.exists(tmpTbl[2]) then\
  3241.    \
  3242.    local h = fs.open('.kernel/programs/compress', 'r')\
  3243.    local app = h.readAll()\
  3244.    h.close()\
  3245.    \
  3246.    loadstring(app)(tmpTbl[1], tmpTbl[2])\
  3247.    else\
  3248.      printError('Usage: compress <Directory> <Destination file>')\
  3249.    end\
  3250.    end\
  3251.  end,\
  3252.  [ 'clear' ] = function()\
  3253.    term.setBackgroundColor(colors.white)\
  3254.    term.clear()\
  3255.    term.setCursorPos(1, 1)\
  3256.  end,\
  3257.  [ 'run' ] = function(cmd)\
  3258.    shell.run(cmd[2])\
  3259.    --[[\
  3260.    paintutils.drawLine(35, 19, 51, 19, colors.gray)\
  3261.    term.setTextColor(colors.white)\
  3262.    txt.pwrite('Closing in 2...', 35, 19)\
  3263.    sleep(1)\
  3264.    txt.pwrite('Closing in 1...', 35, 19)\
  3265.    sleep(1)\
  3266.    ]]--\
  3267.    commands.clear()\
  3268.  end,\
  3269.  [ 'reboot' ] = function()\
  3270.    cinter.reboot()\
  3271.    term.setBackgroundColor(colors.black)\
  3272.    term.clear()\
  3273.    term.setCursorPos(1, 1)\
  3274.    term.setTextColor(colors.white)\
  3275.    commands.clear()\
  3276.  end,\
  3277.  [ 'shutdown' ] = function()\
  3278.    cinter.shutdown()\
  3279.    term.setBackgroundColor(colors.black)\
  3280.    term.clear()\
  3281.    term.setCursorPos(1, 1)\
  3282.    term.setTextColor(colors.white)\
  3283.    commands.clear()\
  3284.  end,\
  3285.  [ 'ls' ] = function(cmd)\
  3286.    local files2 = {}\
  3287.    local file = {}\
  3288.    local folds = {}\
  3289.    if cmd[2] == nil then\
  3290.      files = fs.list(dir)\
  3291.      tmpDir = ''\
  3292.    elseif fs.isDir(cmd[2]) then\
  3293.      files = fs.list(cmd[2])\
  3294.      tmpDir = cmd[2]\
  3295.    else\
  3296.      printError('That is not a directory.')\
  3297.      return nil\
  3298.    end\
  3299.    for k, v in ipairs(files) do\
  3300.      if string.sub(v, 1, 1) ~= '.' then\
  3301.        table.insert(files2, v)\
  3302.      end\
  3303.    end\
  3304.    for i=1, #files2 do\
  3305.      if fs.isDir(tmpDir..'/'..files2[i]) then\
  3306.        table.insert(folds, files2[i])\
  3307.      else\
  3308.        table.insert(file, files2[i])\
  3309.      end\
  3310.    end\
  3311.    textutils.pagedTabulate(colors.red, folds, colors.gray, file)\
  3312.  end,\
  3313.  [ 'cd' ] = function(cmd)\
  3314.    if fs.exists(dir..'/'..cmd[2]) then\
  3315.      if cmd[2] == '..' then\
  3316.        dir = fs.getDir(dir)\
  3317.      elseif cmd[2] == '/' then\
  3318.        dir = ''\
  3319.      elseif fs.isDir(dir..'/'..cmd[2]) then\
  3320.        dir = dir..'/'..cmd[2]\
  3321.      else\
  3322.        printError('That isn\\'t a directory!')\
  3323.      end\
  3324.    else\
  3325.      printError('That isn\\'t a directory!')\
  3326.    end\
  3327.  end,\
  3328.  [ 'clr'] = function() commands.clear() end,\
  3329.  [ 'rm' ] = function(cmd)\
  3330.    if fs.exists(fs.combine(dir, cmd[2])) then\
  3331.      fs.delete(fs.combine(dir, cmd[2]))\
  3332.      print('File deleted.')\
  3333.    else\
  3334.      printError('That file doesn\\'t exist!')\
  3335.    end\
  3336.  end,\
  3337.  [ 'mkdir' ] = function(cmd)\
  3338.    if not fs.exists(fs.combine(dir, cmd[2])) then\
  3339.      fs.makeDir(fs.combine(dir, cmd[2]))\
  3340.    else\
  3341.      printError('That already exists.')\
  3342.    end\
  3343.  end,\
  3344.  [ 'nano' ] = function(cmd)\
  3345.    shell.run(\"edit\", cmd[2])\
  3346.  end\
  3347. }\
  3348. \
  3349. -- Functions --\
  3350. \
  3351. function commSplit(comm)\
  3352.  local tmpTbl = {}\
  3353.  for k in string.gmatch(comm, '[^ ]+') do\
  3354.    table.insert(tmpTbl, k)\
  3355.  end\
  3356.  return tmpTbl\
  3357. end\
  3358. \
  3359. function mainLoop(commands)\
  3360. mainLoopTerm = false\
  3361. dir = ''\
  3362. local commHis = {}\
  3363. term.setBackgroundColor(colors.white)\
  3364. term.clear()\
  3365. term.setCursorPos(1, 1)\
  3366. \
  3367. term.setTextColor(colors.black)\
  3368. \
  3369. print('Welcome to BaseOS Shell, V1.1')\
  3370. print('Type \\'help\\' for a list of commands')\
  3371. \
  3372. repeat\
  3373. \
  3374.  --local tmpVal = multishell.getCurrent()\
  3375.  --multishell.setTitle(tmpVal, 'OS')\
  3376. \
  3377.  term.setTextColor(colors.lightGray)\
  3378.  write(dir..'/> ')\
  3379.  term.setTextColor(colors.black)\
  3380.  local comm = read(nil, commHis)\
  3381.  table.insert(commHis, comm)\
  3382.  local commNew = commSplit(comm)\
  3383. \
  3384.  \
  3385.  \
  3386.  if commands[commNew[1]] ~= nil then\
  3387.    local ok, err = pcall(commands[commNew[1]], commNew)\
  3388.    if not ok then\
  3389.      local h = fs.open('.kernel/dumps/consoleCrash', 'w')\
  3390.      h.write(err)\
  3391.      h.close()\
  3392.    end\
  3393.  else\
  3394.    printError('That command doesn\\'t exist. Type \\'help\\' for help.')\
  3395.  end\
  3396. until mainLoopTerm == true\
  3397. end\
  3398. \
  3399. -- Startup\
  3400. \
  3401. sleep(.2)\
  3402. --local tmpVal = cinter.login()\
  3403. \
  3404. mainLoop(commands)",
  3405.     notFound = "term.setTextColor(colors.black)\
  3406. txt.ctxt(\"File not found\")\
  3407. os.pullEvent(\"mouse_click\")",
  3408.     reboot = "cinter.reboot()\
  3409. term.setBackgroundColor(colors.black)\
  3410. term.clear()\
  3411. term.setCursorPos(1, 1)",
  3412.   },
  3413. }
  3414.  
  3415.  
  3416.  
  3417.  
  3418.  
  3419.  
  3420.  
  3421.  
  3422. local function writeFile(path,content)
  3423.     local file = fs.open(path,"w")
  3424.     file.write(content)
  3425.     file.close()
  3426. end
  3427. function writeDown(input,dir)
  3428.         for i,v in pairs(input) do
  3429.         if type(v) == "table" then
  3430.             writeDown(v,dir.."/"..i)
  3431.         elseif type(v) == "string" then
  3432.             writeFile(dir.."/"..i,v)
  3433.         end
  3434.     end
  3435. end
  3436.  
  3437. args = {...}
  3438. if #args == 0 then
  3439.     print("Please input a destination folder.")
  3440. else
  3441.     writeDown(inputTable, args[1])
  3442. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement