ProjectB

O2.5.2

Feb 9th, 2016
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 65.20 KB | None | 0 0
  1. {
  2.   [ "/systemO/launchpad" ] = "x,y=term.getSize()\
  3. os.loadAPI(\"/systemO/odata/O\")\
  4. shell.run(\"/systemO/lockscreen\")\
  5. if validPassword ~= true then\
  6. \009os.reboot()\
  7. end\
  8. local whitelistedFiles = {\"/systemO/odata/notification\", \"/systemO/stream\", \"/systemO/temp/boot\", \"/systemO/odata/theme\", \"/systemO/temp/newPIN\"}\
  9. \
  10. local versionFileLocation = O.resolveUpdateLocation()\
  11. local versionFilePack = O.getVersion(versionFileLocation)\
  12. \
  13. local function deepCopy(original)\
  14.    local copy = {}\
  15.    for k, v in pairs(original) do\
  16.        if type(v) == 'table' then\
  17.            v = deepCopy(v)\
  18.        end\
  19.        copy[k] = v\
  20.    end\
  21.    return copy\
  22. end\
  23. \
  24. local oldstring = deepCopy(string)\
  25. local oldfsrename = fs.rename\
  26. local oldfsopen = fs.open\
  27. local olddelete = fs.delete\
  28. local oldfsmove = fs.move\
  29. local oldfscopy = fs.copy\
  30. local oldtermclear = term.clear\
  31. local oldtableconcat = table.concat\
  32. local oldstringgmatch = string.gmatch\
  33. function fs.normalise(...)\
  34.        local path = '/' .. oldtableconcat({...}, '')\
  35.        local res = {};\
  36.        local len = 0;\
  37.        path = path:gsub('\\\\', '/')\
  38.        path = path:gsub('/+', '/')\
  39.        for seg in oldstring.gmatch(path, '[^/]+') do\
  40.                if seg == '..' then\
  41.                        if len > 0 then\
  42.                                res[len] = nil;\
  43.                                len = len - 1;\
  44.                        end\
  45.                elseif seg ~= '.' then\
  46.                        len = len + 1;\
  47.                        res[len] = seg;\
  48.                end\
  49.        end\
  50.        return '/' .. oldtableconcat(res, '/')\
  51. end\
  52. fs.normalize = fs.normalise\
  53. local oldShellResolve = fs.normalise\
  54. \
  55. local controlBar = window.create(term.current(), 1, y-5, x, 5)\
  56. local bottomBar = window.create(term.current(), 1, y, x, 1)\
  57. local oos = window.create(term.current(), 1, 1, x, y-1)\
  58. local notificationBar = window.create(term.current(), 1, 1, x, 1)\
  59. \
  60. if versionFilePack ~= nil then\
  61. \009if versionFilePack[3] ~= nil then\
  62. \009\009local file = fs.open(\"/systemO/temp/cachedText\", \"w\")\
  63. \009\009file.write(versionFilePack[3])\
  64. \009\009file.close()\
  65. \009end\
  66. end\
  67. if versionFilePack ~= nil then\
  68. \009if versionFilePack[1] ~= O.getVersionNumber() then\
  69. \009\009O.promptUpdate = true\
  70. \009end\
  71. end\
  72. local function highlightButton(buttonLoc, buttonText, toInvert)\
  73. \009if toInvert ~= true then\
  74. \009\009bottomBar.setBackgroundColor(colors.white)\
  75. \009\009bottomBar.setTextColor(colors.black)\
  76. \009else\
  77. \009\009bottomBar.setBackgroundColor(colors.black)\
  78. \009\009bottomBar.setTextColor(colors.white)\
  79. \009end\
  80. \009bottomBar.setCursorPos(buttonLoc, 1)\
  81. \009bottomBar.write(buttonText)\
  82. end\
  83. term.redirect(oos)\
  84. shell.setAlias(\"clr\", \"/rom/programs/clear\")\
  85. shell.setAlias(\"settings\", \"/systemO/programs/settings\")\
  86. shell.setAlias(\"about\", \"/systemO/programs/about\")\
  87. shell.setAlias(\"update\", \"/systemO/programs/update\")\
  88. shell.setAlias(\"lock\", \"/rom/programs/reboot\")\
  89. local function redrawButtons(drawBlack, backColor)\
  90. \009local xhome, yhome = bottomBar.getSize()\
  91. \009bottomBarHome = \"  O  \"\
  92. \009bottomBarBack = \"  <  \"\
  93. \009bottomBarSomething = \"     \"\
  94. \009--Determine the location of buttons\
  95. \009bottomBarHomeLoc = (xhome-string.len(bottomBarHome))/2\
  96. \009bottomBarBackLoc = (xhome-string.len(bottomBarBack))/4\
  97. \009bottomBarSomethingLoc = ((xhome-string.len(bottomBarBack))*3)/4\
  98. \009if drawBlack then\
  99. \009\009bottomBar.setBackgroundColor(colors.black)\
  100. \009\009bottomBar.clear()\
  101. \009\009bottomBar.setTextColor(colors.white)\
  102. \009else\
  103. \009\009bottomBar.setBackgroundColor(colors.white)\
  104. \009\009bottomBar.clear()\
  105. \009\009bottomBar.setTextColor(colors.black)\
  106. \009end\
  107. \009--Print home button\
  108. \009bottomBar.setCursorPos(bottomBarHomeLoc, 1)\
  109. \009bottomBar.write(bottomBarHome)\
  110. \009--Print back button\
  111. \009bottomBar.setCursorPos(bottomBarBackLoc, 1)\
  112. \009bottomBar.write(bottomBarBack)\
  113. \009--Print the mystery button\
  114. \009bottomBar.setCursorPos(bottomBarSomethingLoc, 1)\
  115. \009bottomBar.write(bottomBarSomething)\
  116. \009bottomBar.setTextColor(colors.black)\
  117. end\
  118. local function homeButton()\
  119. \009local bottomBarActivated = false\
  120. \009local xhome, yhome = bottomBar.getSize()\
  121. \009bottomBar.setCursorPos(xhome+1, 1)\
  122. \009if term.isColor() then\
  123. \009\009redrawButtons(true)\
  124. \009else\
  125. \009\009redrawButtons(true)\
  126. \009end\
  127. \009while true do\
  128. \009\009event, inputArg, clickx, clicky = os.pullEvent()\
  129. \009\009bottomBar.restoreCursor()\
  130. \009\009local x,y=term.getSize()\
  131. \009\009if event == \"mouse_click\" then\
  132. \009\009\009if clickx > x/2-3 and clickx < x/2+2 and clicky == y+1 then\
  133. \009\009\009\009highlightButton(bottomBarHomeLoc, bottomBarHome)\
  134. \009\009\009\009properExit = true\
  135. \009\009\009\009break\
  136. \009\009\009end\
  137. \009\009\009if clickx > x/4-2 and clickx < x/4+3 and clicky == y+1 then\
  138. \009\009\009\009highlightButton(bottomBarBackLoc, bottomBarBack)\
  139. \009\009\009\009os.queueEvent(\"back_button\")\
  140. \009\009\009\009sleep(0.08)\
  141. \009\009\009\009redrawButtons(true)\
  142. \009\009\009end\
  143. \009\009\009--[[if clickx > (x*3)/4-5 and clickx < (x*3)/4 and clicky == y+1 then\
  144. \009\009\009\009highlightButton(bottomBarSomethingLoc, bottomBarSomething)\
  145. \009\009\009\009sleep(0.08)\
  146. \009\009\009\009if clickx > (x*3)/4-5 and clickx < (x*3)/4 and clicky == y+1 then\
  147. \009\009\009\009\009isControlBarVisible = true\
  148. \009\009\009\009\009controlBar.setVisible(true)\
  149. \009\009\009\009\009if term.isColor() then\
  150. \009\009\009\009\009\009controlBar.setBackgroundColor(colors.black)\
  151. \009\009\009\009\009else\
  152. \009\009\009\009\009\009controlBar.setBackgroundColor(colors.white)\
  153. \009\009\009\009\009end\
  154. \009\009\009\009\009while true do\
  155. \009\009\009\009\009\009local event, inputArg, clickx, clicky = os.pullEvent()\
  156. \009\009\009\009\009\009if event == \"mouse_click\" then\
  157. \009\009\009\009\009\009\009if clickx > (x*3)/4-5 and clickx < (x*3)/4 and clicky == y+1 then\
  158. \009\009\009\009\009\009\009\009controlBar.setVisible(false)\
  159. \009\009\009\009\009\009\009\009oos.redraw()\
  160. \009\009\009\009\009\009\009\009isControlBarVisible = false\
  161. \009\009\009\009\009\009\009\009redrawButtons(true)\
  162. \009\009\009\009\009\009\009\009break\
  163. \009\009\009\009\009\009\009end\
  164. \009\009\009\009\009\009end\
  165. \009\009\009\009\009end\
  166. \009\009\009\009end\
  167. \009\009\009end]]--\
  168. \009\009\009else\
  169. \009\009\009if event == \"key\" then\
  170. \009\009\009\009if inputArg == 56 or inputArg == 184 then\
  171. \009\009\009\009\009redrawButtons(false)\
  172. \009\009\009\009\009event, inputArg, clickx, clicky = os.pullEvent(\"key\")\
  173. \009\009\009\009\009if inputArg == keys.up or inputArg == keys.down then\
  174. \009\009\009\009\009\009highlightButton(bottomBarHomeLoc, bottomBarHome, true)\
  175. \009\009\009\009\009\009properExit = true\
  176. \009\009\009\009\009\009break\
  177. \009\009\009\009\009elseif inputArg == keys.left then\
  178. \009\009\009\009\009\009highlightButton(bottomBarBackLoc, bottomBarBack, true)\
  179. \009\009\009\009\009\009os.queueEvent(\"back_button\")\
  180. \009\009\009\009\009\009sleep(0.08)\
  181. \009\009\009\009\009end\
  182. \009\009\009\009\009--[[elseif inputArg == keys.right then\
  183. \009\009\009\009\009\009highlightButton(bottomBarSomethingLoc, bottomBarSomething, true)\
  184. \009\009\009\009\009\009sleep(0.08)\
  185. \009\009\009\009\009\009isControlBarVisible = true\
  186. \009\009\009\009\009\009controlBar.setVisible(true)\
  187. \009\009\009\009\009\009if term.isColor() then\
  188. \009\009\009\009\009\009\009controlBar.setBackgroundColor(colors.gray)\
  189. \009\009\009\009\009\009else\
  190. \009\009\009\009\009\009\009controlBar.setBackgroundColor(colors.white)\
  191. \009\009\009\009\009\009end\
  192. \009\009\009\009\009\009while true do\
  193. \009\009\009\009\009\009\009event, inputArg, clickx, clicky = os.pullEvent(\"key\")\
  194. \009\009\009\009\009\009\009if inputArg == keys.right then\
  195. \009\009\009\009\009\009\009\009controlBar.setVisible(false)\
  196. \009\009\009\009\009\009\009\009oos.redraw()\
  197. \009\009\009\009\009\009\009\009isControlBarVisible = false\
  198. \009\009\009\009\009\009\009\009redrawButtons(false)\
  199. \009\009\009\009\009\009\009\009break\
  200. \009\009\009\009\009\009\009end\
  201. \009\009\009\009\009\009end\
  202. \009\009\009\009\009end--]]\
  203. \009\009\009\009end\
  204. \009\009\009end\
  205. \009\009\009redrawButtons(true)\
  206. \009\009end\
  207. \009end\
  208. end\
  209. local function Oshell()\
  210. \009shell.run(\"/systemO/frame\")\
  211. end\
  212. local function checkNotificationFile()\
  213. \009notificationBar.setVisible(false)\
  214. \009notificationBar.redraw()\
  215. \009while true do\
  216. \009\009controlBar.setCursorBlink(false)\
  217. \009\009notificationBar.setVisible(false)\
  218. \009\009notificationBar.clear()\
  219. \009\009notificationBar.redraw()\
  220. \009\009if fs.exists(\"/systemO/odata/notification\") then\
  221. \009\009\009notificationBar.setCursorBlink(false)\
  222. \009\009\009local file = fs.open(\"/systemO/odata/notification\", \"r\")\
  223. \009\009\009local notificationContents = file.readAll()\
  224. \009\009\009file.close()\
  225. \009\009\009local notificationFile = textutils.unserialize(notificationContents)\
  226. \009\009\009--Rendering the notification\
  227. \
  228. \009\009\009fs.delete(\"/systemO/odata/notification\")\
  229. \009\009\009notificationBar.setCursorPos(1,1)\
  230. \009\009\009--Filling in defaults and appying setting\
  231. \009\009\009--Text color\
  232. \009\009\009if not term.isColor() then\
  233. \009\009\009\009notificationFile[2] = nil\
  234. \009\009\009\009notificationFile[3] = nil\
  235. \009\009\009end\
  236. \009\009\009if notificationFile[1] == nil then\
  237. \009\009\009\009notificationFile[1] = (\"Error: Text not supplied\")\
  238. \009\009\009end\
  239. \009\009\009if notificationFile[2] ~= nil then\
  240. \009\009\009\009notificationBar.setTextColor(notificationFile[2])\
  241. \009\009\009else\
  242. \009\009\009\009notificationBar.setTextColor(colors.black)\
  243. \009\009\009end\
  244. \009\009\009if notificationFile[3] ~= nil then\
  245. \009\009\009\009notificationBar.setBackgroundColor(notificationFile[3])\
  246. \009\009\009else\
  247. \009\009\009\009notificationBar.setBackgroundColor(colors.white)\
  248. \009\009\009end\
  249. \009\009\009if notificationFile[4] ~= nil then\
  250. \009\009\009\009notificationTime = tonumber(notificationFile[4])\
  251. \009\009\009else\
  252. \009\009\009\009notificationTime = 1\
  253. \009\009\009end\
  254. \009\009\009notificationBar.clear()\
  255. \009\009\009notificationBar.setVisible(true)\
  256. \009\009\009local x,y=notificationBar.getSize()\
  257. \009\009\009notificationBar.setCursorPos((x-string.len(notificationFile[1]))/2, y)\
  258. \009\009\009notificationBar.write(notificationFile[1])\
  259. \009\009\009notificationBar.redraw()\
  260. \009\009\009sleep(notificationTime)\
  261. \009\009\009notificationBar.setCursorBlink(true)\
  262. \009\009\009notificationBar.setVisible(false)\
  263. \009\009\009notificationBar.redraw()\
  264. \009\009\009oos.redraw()\
  265. \009\009end\
  266. \009\009coroutine.yield()\
  267. \009end\
  268. end\
  269. \
  270. local function fixCursorThing()\
  271. \009while true do\
  272. \009\009bottomBar.setCursorBlink(false)\
  273. \009\009if isControlBarVisible == true then\
  274. \009\009\009controlBar.setCursorBlink(false)\
  275. \009\009\009oos.setCursorBlink(false)\
  276. \009\009\009controlBar.redraw()\
  277. \009\009else\
  278. \009\009\009oos.restoreCursor()\
  279. \009\009end\
  280. \009\009notificationBar.redraw()\
  281. \009\009coroutine.yield()\
  282. \009end\
  283. end\
  284. local function backgroundProcesses()\
  285. \009while true do\
  286. \009\009controlBar.setCursorBlink(false)\
  287. \009\009if isControlBarVisible then\
  288. \009\009\009controlBar.redraw()\
  289. \009\009\009controlBar.clear()\
  290. \009\009\009if term.isColor() then\
  291. \009\009\009\009controlBar.setTextColor(colors.white)\
  292. \009\009\009else\
  293. \009\009\009\009controlBar.setTextColor(colors.black)\
  294. \009\009\009end\
  295. \009\009\009controlBar.setCursorPos(1,1)\
  296. \009\009\009controlBar.write(\"Time: \"..textutils.formatTime(os.time(), false))\
  297. \009\009end\
  298. \009\009controlBar.setCursorBlink(false)\
  299. \009\009sleep(0.1)\
  300. \009end\
  301. end\
  302. local backupTerm = term.current()\
  303. \
  304. local function checkAllowance(filePath, filePath2, changeType)\
  305. \009local safeFile = true\
  306. \009if oldShellResolve(filePath) == \"/startup\" or oldstring.sub(oldShellResolve(filePath), 1, 8) == \"/systemO\" or oldShellResolve(filePath) == \"/.settings\" then\
  307. \009\009safeFile = false\
  308. \009end\
  309. \009if oldShellResolve(filePath2) == \"/startup\" or oldstring.sub(oldShellResolve(filePath2), 1, 8) == \"/systemO\" or oldShellResolve(filePath) == \"/.settings\" then\
  310. \009\009safeFile = false\
  311. \009end\
  312. \009--Begin custom declerations\
  313. \009if changeType == \"r\" then\
  314. \009\009if oldShellResolve(filePath) == \"/startup\" or oldShellResolve(filePath) == \"/systemO/bootloader\" or oldShellResolve(filePath) == \"/systemO/launchpad\" then\
  315. \009\009\009safeFile = false\
  316. \009\009else\
  317. \009\009\009safeFile = true\
  318. \009\009end\
  319. \009end\
  320. \009for i=1,#whitelistedFiles do\
  321. \009\009if oldShellResolve(filePath) == whitelistedFiles[i] then\
  322. \009\009\009safeFile = true\
  323. \009\009end\
  324. \009end\
  325. \009return safeFile\
  326. end\
  327. \
  328. function fs.open(filePath, changeType)\
  329. \009if checkAllowance(filePath, nil, changeType) == true then\
  330. \009\009return oldfsopen(filePath, changeType)\
  331. \009else\
  332. \009\009error(\"Access Denied\")\
  333. \009end\
  334. end\
  335. \
  336. function fs.delete(filePath)\
  337. \009if checkAllowance(filePath, nil, changeType) == true then\
  338. \009\009olddelete(filePath)\
  339. \009else\
  340. \009\009error(\"Access Denied\")\
  341. \009end\
  342. end\
  343. \
  344. function fs.move(filePath, filePath2)\
  345. \009if checkAllowance(filePath, filePath2) == true then\
  346. \009\009oldfsmove(filePath, filePath2)\
  347. \009else\
  348. \009\009error(\"Access Denied\")\
  349. \009end\
  350. end\
  351. \
  352. function fs.copy(filePath, filePath2)\
  353. \009if checkAllowance(filePath, filePath2) == true then\
  354. \009\009oldfscopy(filePath, filePath2)\
  355. \009else\
  356. \009\009error(\"Access Denied\")\
  357. \009end\
  358. end\
  359. function fs.isReadOnly(filePath)\
  360. \009if checkAllowance(filePath) == true then\
  361. \009\009return false\
  362. \009else\
  363. \009\009return true\
  364. \009end\
  365. end\
  366. function fs.rename(filePath)\
  367. \009if checkAllowance(filePath, filePath2) == true then\
  368. \009\009oldfsrename(filePath, filePath2)\
  369. \009else\
  370. \009\009error(\"Access Denied\")\
  371. \009end\
  372. end\
  373. O.highlightColor = colors.gray\
  374. if term.isColor() then\
  375. \009O.highlightTextColor = colors.white\
  376. else\
  377. \009O.highlightTextColor = colors.black\
  378. end\
  379. O.bottomBarColor = colors.black\
  380. if fs.exists(\"/ostartup\") and safeBoot == nil then\
  381. \009local message = \"Running ostartup...\"\
  382. \009term.setTextColor(colors.white)\
  383. \009term.setCursorPos((x-string.len(message))/2, y/2)\
  384. \009term.write(message)\
  385. \009sleep(1)\
  386. \009term.clear()\
  387. \009term.setCursorPos(1,1)\
  388. \009shell.run(\"/ostartup\")\
  389. end\
  390. if safeBoot == true then\
  391. \009fs.delete(\"/systemO/odata/theme\")\
  392. \009O.getThemeData()\
  393. end\
  394. if O.promptUpdate == true then\
  395. \009O.promptUpdate = false\
  396. \009shell.run(\"/systemO/programs/update\")\
  397. end\
  398. \
  399. while true do\
  400. \009properExit = false\
  401. \009parallel.waitForAny(Oshell, homeButton, checkNotificationFile, backgroundProcesses, fixCursorThing)\
  402. \009term.redirect(backupTerm)\
  403. \009if properExit == false then\
  404. \009\009break\
  405. \009end\
  406. \009oos.setBackgroundColor(colors.black)\
  407. \009shell.run(\"/rom/programs/cd /\")\
  408. \009sleep(0.08)\
  409. end",
  410.   [ "/systemO/odata/themes/Default" ] = "{\
  411.  [ \"Shell-indentCharacter\" ] = \"> \",\
  412.  [ \"Shell-highlightColor\" ] = 128,\
  413.  [ \"Shell-highlightAutocompleteText\" ] = 1,\
  414.  [ \"Shell-backgroundColor\" ] = 32768,\
  415.  [ \"Shell-highlightAutocomplete\" ] = 256,\
  416.  [ \"Shell-indentColor\" ] = 1,\
  417.  [ \"Shell-highlightTextColor\" ] = 1,\
  418. }",
  419.   [ "/systemO/programs/about" ] = "shell.run(\"/systemO/programs/settings\", \"about\")",
  420.   [ "/startup" ] = "shell.run(\"/systemO/bootloader\")\
  421. os.shutdown()",
  422.   [ "/systemO/programs/settings" ] = "local numberPad = {[0] = 82, 79, 80, 81, 75, 76, 77, 71, 72, 73}\
  423. local topNumbers = {[0] = 11, 2, 3, 4, 5, 6, 7, 8, 9, 10}\
  424. tArgs = {...}\
  425. x,y=term.getSize()\
  426. term.clear()\
  427. term.setCursorPos(1,1)\
  428. --Language stuff\
  429. topText = \"Settings\"\
  430. confirmScreen = {\"Confirm\", \"Cancel\"}\
  431. mainList = {\"General\", \"Update\", \"Reset & Uninstall\", \"About\", \"Credits\"}\
  432. backupAndRecover = {\"Reset O\", \"Remove O\"}\
  433. \
  434. generalList = {\"Password\", \"Theme\"}\
  435. passwordList = {\"Change PIN\", \"Remove PIN\"}\
  436. if tArgs[1] == \"about\" then\
  437. \009direct = \"about\"\
  438. end\
  439. local function drawPixel(y, x, color)\
  440. \009term.setCursorPos(x, y)\
  441. \009term.setBackgroundColor(color)\
  442. \009term.write(\" \")\
  443. end\
  444. local function renderCircles(numberThrough, colororverride, renderEverything, message)\
  445. \009local loopThrough = 1\
  446. \009term.setCursorPos((x-string.len(message))/2, y/2-3)\
  447. \009term.setBackgroundColor(colors.black)\
  448. \009O.cprint(message, colors.white)\
  449. \009for i=-2,2 do\
  450. \009\009for ly=(y/2),(y/2)+1 do\
  451. \009\009\009for lx=(x/2)-1,(x/2)+1 do\
  452. \009\009\009\009if colororverride == nil then\
  453. \009\009\009\009\009if numberThrough >= loopThrough then\
  454. \009\009\009\009\009\009drawPixel(ly, lx-(i*4), colors.white)\
  455. \009\009\009\009\009else\
  456. \009\009\009\009\009\009drawPixel(ly, lx-(i*4), colors.black)\
  457. \009\009\009\009\009end\
  458. \009\009\009\009end\
  459. \009\009\009end\
  460. \009\009end\
  461. \009\009loopThrough = loopThrough + 1\
  462. \009end\
  463. end\
  464. function resolveNumber(key)\
  465. \009if numberKey ~= \"none\" then\
  466. \009\009for i=0,#numberPad do\
  467. \009\009\009if numberPad[i] == key then\
  468. \009\009\009\009return i\
  469. \009\009\009end\
  470. \009\009end\
  471. \009\009for i=0,#topNumbers do\
  472. \009\009\009if topNumbers[i] == key then\
  473. \009\009\009\009return i\
  474. \009\009\009end\
  475. \009\009end\
  476. \009end\
  477. end\
  478. function renderTop()\
  479. \009term.setCursorPos((x-string.len(topText))/2,  1)\
  480. \009term.setBackgroundColor(colors.white)\
  481. \009term.clearLine()\
  482. \009O.cprint(topText, colors.black)\
  483. \009term.setBackgroundColor(colors.black)\
  484. end\
  485. \
  486. function printAbout(text, color, line)\
  487. \009term.setCursorPos((x-string.len(text))/2, line)\
  488. \009O.cprint(text, color)\
  489. end\
  490. \
  491. function renderScreen(list, highlightedLine, confirmation)\
  492. \009term.setBackgroundColor(colors.black)\
  493. \009term.clear()\
  494. \009renderTop()\
  495. \009if confirmation ~= nil then\
  496. \009\009term.setCursorPos((x-string.len(confirmation))/2, 2)\
  497. \009\009O.cprint(confirmation, colors.white)\
  498. \009end\
  499. \009for i=1,#list do\
  500. \009\009term.setCursorPos((x-string.len(list[i]))/2, 3+i)\
  501. \009\009if highlightedLine == i then\
  502. \009\009\009if term.isColor() then\
  503. \009\009\009\009term.setBackgroundColor(colors.gray)\
  504. \009\009\009\009term.clearLine()\
  505. \009\009\009\009O.cprint(list[i], colors.white, true)\
  506. \009\009\009else\
  507. \009\009\009\009term.setBackgroundColor(colors.white)\
  508. \009\009\009\009term.clearLine()\
  509. \009\009\009\009O.cprint(list[i], colors.black, true)\
  510. \009\009\009end\
  511. \009\009else\
  512. \009\009\009term.setBackgroundColor(colors.black)\
  513. \009\009\009term.clearLine()\
  514. \009\009\009O.cprint(list[i], colors.white, true)\
  515. \009\009end\
  516. \009end\
  517. end\
  518. function interactiveOption(list, confirmation)\
  519. \009if direct == \"about\" then\
  520. \009\009direct = nil\
  521. \009\009return 4\
  522. \009end\
  523. \009selected = 1\
  524. \009renderScreen(list, selected, confirmation)\
  525. \009while true do\
  526. \009\009local event, key = os.pullEvent()\
  527. \009\009if event == \"key\" then\
  528. \009\009\009if key == keys.up then\
  529. \009\009\009\009selected = selected - 1\
  530. \009\009\009\009if selected < 1 then\
  531. \009\009\009\009\009selected = 1\
  532. \009\009\009\009else\
  533. \009\009\009\009\009renderScreen(list, selected, confirmation)\
  534. \009\009\009\009end\
  535. \009\009\009elseif key == keys.down then\
  536. \009\009\009\009selected = selected + 1\
  537. \009\009\009\009if selected > #list then\
  538. \009\009\009\009\009selected = # list\
  539. \009\009\009\009else\
  540. \009\009\009\009\009renderScreen(list, selected, confirmation)\
  541. \009\009\009\009end\
  542. \009\009\009elseif key == keys.enter then\
  543. \009\009\009\009return selected\
  544. \009\009\009end\
  545. \009\009elseif event == \"back_button\" then\
  546. \009\009\009return -1\
  547. \009\009end\
  548. \009end\
  549. end\
  550. while true do\
  551. \009topText = \"Settings\"\
  552. \009renderTop()\
  553. \009selectedOption = interactiveOption(mainList)\
  554. \009if selectedOption == -1 then\
  555. \009\009break\
  556. \009end\
  557. \009if selectedOption == 1 then\
  558. \009\009term.clear()\
  559. \009\009topText = \"General\"\
  560. \009\009renderTop()\
  561. \009\009selectedOption = interactiveOption(generalList)\
  562. \009\009if selectedOption == 1 then\
  563. \009\009\009selectedOption = interactiveOption(passwordList)\
  564. \009\009\009if selectedOption == 1 then\
  565. \009\009\009\009local inputPassword1 = \"\"\
  566. \009\009\009\009local inputPassword2 = \"\"\
  567. \009\009\009\009while true do\
  568. \009\009\009\009\009topText = \"New Password\"\
  569. \009\009\009\009\009term.clear()\
  570. \009\009\009\009\009renderTop()\
  571. \009\009\009\009\009local loopThrough = 5\
  572. \009\009\009\009\009while loopThrough > 0 do\
  573. \009\009\009\009\009\009renderCircles(loopThrough, nil, nil, \"Enter new password\")\
  574. \009\009\009\009\009\009local event, key = os.pullEvent(\"key\")\
  575. \009\009\009\009\009\009if resolveNumber(key) ~= nil then\
  576. \009\009\009\009\009\009\009inputPassword1 = inputPassword1..resolveNumber(key)\
  577. \009\009\009\009\009\009\009loopThrough = loopThrough - 1\
  578. \009\009\009\009\009\009end\
  579. \009\009\009\009\009end\
  580. \009\009\009\009\009topText = \"Confirm Password\"\
  581. \009\009\009\009\009term.clear()\
  582. \009\009\009\009\009renderTop()\
  583. \009\009\009\009\009local loopThrough = 5\
  584. \009\009\009\009\009while loopThrough > 0 do\
  585. \009\009\009\009\009\009renderCircles(loopThrough, nil, nil, \"Confirm new password\")\
  586. \009\009\009\009\009\009local event, key = os.pullEvent(\"key\")\
  587. \009\009\009\009\009\009if resolveNumber(key) ~= nil then\
  588. \009\009\009\009\009\009\009inputPassword2 = inputPassword2..resolveNumber(key)\
  589. \009\009\009\009\009\009\009loopThrough = loopThrough - 1\
  590. \009\009\009\009\009\009end\
  591. \009\009\009\009\009end\
  592. \009\009\009\009\009if inputPassword1 == inputPassword2 then\
  593. \009\009\009\009\009\009confirmedMatch = true\
  594. \009\009\009\009\009\009break\
  595. \009\009\009\009\009else\
  596. \009\009\009\009\009\009confirmedMath = false\
  597. \009\009\009\009\009\009break\
  598. \009\009\009\009\009end\
  599. \009\009\009\009end\
  600. \009\009\009\009if confirmedMatch then\
  601. \009\009\009\009\009term.setBackgroundColor(colors.black)\
  602. \009\009\009\009\009term.clear()\
  603. \009\009\009\009\009local exitMess = \"Updating password...\"\
  604. \009\009\009\009\009term.setCursorPos((x-string.len(exitMess))/2, y/2)\
  605. \009\009\009\009\009O.cprint(exitMess, colors.white)\
  606. \009\009\009\009\009sleep(1)\
  607. \009\009\009\009\009local file = fs.open(\"/systemO/temp/boot\", \"w\")\
  608. \009\009\009\009\009file.write(\"resetpassword\"..inputPassword2)\
  609. \009\009\009\009\009file.close()\
  610. \009\009\009\009\009os.reboot()\
  611. \009\009\009\009else\
  612. \009\009\009\009\009term.setCursorPos((x-string.len(\"Password didn't match\"))/2, y)\
  613. \009\009\009\009\009term.write(\"Password didn't match\")\
  614. \009\009\009\009\009sleep(1)\
  615. \009\009\009\009end\
  616. \009\009\009elseif selectedOption == 2 then\
  617. \009\009\009\009topText = \"Remove Password?\"\
  618. \009\009\009\009renderTop()\
  619. \009\009\009\009selectedOption = interactiveOption(confirmScreen)\
  620. \009\009\009\009if selectedOption == 1 then\
  621. \009\009\009\009\009local file = fs.open(\"/systemO/temp/boot\", \"w\")\
  622. \009\009\009\009\009file.write(\"removepassword\")\
  623. \009\009\009\009\009file.close()\
  624. \009\009\009\009\009os.reboot()\
  625. \009\009\009\009end\
  626. \009\009\009end\
  627. \009\009elseif selectedOption == 2 then\
  628. \009\009\009term.clear()\
  629. \009\009\009topText = \"Select Theme\"\
  630. \009\009\009renderTop()\
  631. \009\009\009local themesList = fs.list(\"/systemO/odata/themes\")\
  632. \009\009\009selectedOption = interactiveOption(themesList)\
  633. \009\009\009if selectedOption ~= -1 then\
  634. \009\009\009\009local file = fs.open(\"/systemO/odata/themes/\"..themesList[selectedOption], \"r\")\
  635. \009\009\009\009local newThemeRaw = file.readAll()\
  636. \009\009\009\009file.close()\
  637. \009\009\009\009local themeFile = fs.open(\"/systemO/odata/theme\", \"w\")\
  638. \009\009\009\009themeFile.write(newThemeRaw)\
  639. \009\009\009\009themeFile.close()\
  640. \009\009\009\009break\
  641. \009\009\009end\
  642. \009\009end\
  643. \009elseif selectedOption == 2 then\
  644. \009\009shell.run(\"/systemO/programs/update\")\
  645. \009elseif selectedOption == 3 then\
  646. \009\009while true do\
  647. \009\009\009topText = \"Reset & Uninstall\"\
  648. \009\009\009renderTop()\
  649. \009\009\009selectedOption = interactiveOption(backupAndRecover)\
  650. \009\009\009if selectedOption == -1 then\
  651. \009\009\009\009break\
  652. \009\009\009elseif selectedOption == 1 then\
  653. \009\009\009\009selectedOption = interactiveOption(confirmScreen, \"Reset all contents?\")\
  654. \009\009\009\009if selectedOption == 1 then\
  655. \009\009\009\009\009local file = fs.open(\"/systemO/temp/boot\", \"w\")\
  656. \009\009\009\009\009file.write(\"reset\")\
  657. \009\009\009\009\009file.close()\
  658. \009\009\009\009\009os.reboot()\
  659. \009\009\009\009end\
  660. \009\009\009elseif selectedOption == 2 then\
  661. \009\009\009\009selectedOption = interactiveOption(confirmScreen, \"Removing O?\")\
  662. \009\009\009\009if selectedOption == 1 then\
  663. \009\009\009\009\009local file = fs.open(\"/systemO/temp/boot\", \"w\")\
  664. \009\009\009\009\009file.write(\"removeO\")\
  665. \009\009\009\009\009file.close()\
  666. \009\009\009\009\009os.reboot()\
  667. \009\009\009\009end\
  668. \009\009\009end\009\
  669. \009\009end\
  670. \009elseif selectedOption == 4 then\
  671. \009\009local aboutText = {\"Running O \", \"On \", \" stream\", os.version(), \"(C) ProjectB 2016\", \"ID: \", \"No label set\", \"Labelled: \", \"Running normal\", \"Loading...\"}\
  672. \009\009term.setBackgroundColor(colors.black)\
  673. \009\009term.clear()\
  674. \009\009topText = \"About\"\
  675. \009\009renderTop()\
  676. \009\009term.setCursorPos((x-string.len(aboutText[10]))/2, y/2)\
  677. \009\009O.cprint(aboutText[10], colors.white)\
  678. \009\009\
  679. \009\009versionNumber = O.getVersionNumber()\
  680. \009\009O.resolveUpdateLocation()\
  681. \009\009\
  682. \009\009local file = fs.open(\"/systemO/stream\", \"r\")\
  683. \009\009updateStream = file.readAll()\
  684. \009\009file.close()\
  685. \009\009\
  686. \009\009term.setBackgroundColor(colors.black)\
  687. \009\009term.clear()\
  688. \009\009topText = \"About\"\
  689. \009\009renderTop()\
  690. \009\009printAbout(aboutText[1]..versionNumber, colors.cyan, 3)\
  691. \009\009if string.sub(updateStream, 1, 1) == \"_\" then\
  692. \009\009\009printAbout(aboutText[2]..string.sub(updateStream, 2, string.len(updateStream))..aboutText[3], colors.white, 4)\
  693. \009\009else\
  694. \009\009\009printAbout(aboutText[2]..updateStream..aboutText[3], colors.white, 4)\
  695. \009\009end\
  696. \009\009printAbout(os.version(), colors.lightGray, 6)\
  697. \009\009printAbout(aboutText[6]..os.getComputerID(), colors.lightGray, 7)\
  698. \009\009if os.getComputerLabel() == nil then\
  699. \009\009\009printAbout(aboutText[7], colors.lightGray, 8)\
  700. \009\009else\
  701. \009\009\009printAbout(aboutText[8]..os.getComputerLabel(), colors.lightGray, 8)\
  702. \009\009end\
  703. \009\009printAbout(aboutText[5], colors.gray, y-1)\
  704. \009\009os.pullEvent(\"back_button\")\
  705. \009elseif selectedOption == 5 then\
  706. \009\009shell.run(\"/rom/programs/edit\", \"/systemO/odata/credits\")\
  707. \009end\
  708. end\
  709. term.setBackgroundColor(colors.black)\
  710. term.setTextColor(colors.white)\
  711. term.clear()\
  712. term.setCursorPos(1,1)",
  713.   [ "/systemO/odata/themes/Lava" ] = "{\
  714.  [ \"Shell-indentCharacter\" ] = \"> \",\
  715.  [ \"Shell-highlightColor\" ] = 2,\
  716.  [ \"Shell-highlightAutocompleteText\" ] = 128,\
  717.  [ \"Shell-backgroundColor\" ] = 128,\
  718.  [ \"Shell-highlightAutocomplete\" ] = 1,\
  719.  [ \"Shell-indentColor\" ] = 16384,\
  720.  [ \"Shell-highlightTextColor\" ] = 1,\
  721. }",
  722.   [ "/systemO/stream" ] = "standard",
  723.   [ "/systemO/frame" ] = "function applyTheme()\
  724. \009if term.isColor() then\
  725. \009\009theme = O.getThemeData()\
  726. \009else\
  727. \009\009theme = {[ \"Shell-indentCharacter\" ] = \"> \",[ \"Shell-highlightColor\" ] = 128,[ \"Shell-highlightAutocompleteText\" ] = 1,[ \"Shell-backgroundColor\" ] = 32768,[ \"Shell-highlightAutocomplete\" ] = 256,[ \"Shell-indentColor\" ] = 1,[ \"Shell-highlightTextColor\" ] = 1}\
  728. \009end\
  729. end\
  730. \
  731. applyTheme()\
  732. term.setCursorBlink(false)\
  733. term.setBackgroundColor(theme[\"Shell-backgroundColor\"])\
  734. local x,y = term.getSize()\
  735. if frameLaunched == true then\
  736. \009local loop = 1\
  737. \009for i=1,y do\
  738. \009\009loop = loop + 1\
  739. \009\009term.setCursorPos(1, y-i+1)\
  740. \009\009term.clearLine()\
  741. \009\009if loop > 3 then\
  742. \009\009\009coroutine.yield()\
  743. \009\009\009loop = 1\
  744. \009\009end\
  745. \009end\
  746. end\
  747. frameLaunched = true\
  748. if not term.isColor() then\
  749. \009theme[\"Shell-highlightAutocomplete\"] = colors.gray\
  750. end\
  751. local function shellAutoComplete(a,b,c)term.setCursorBlink(true)local d=\"\"local e;local f=0;if a then a=string.sub(a,1,1)end;local g;local h;local function i()if c and f==string.len(d)then g=c(d)if g and#g>0 then h=1 else h=nil end else g=nil;h=nil end end;local function j()g=nil;h=nil end;local k=term.getSize()local l=term.getCursorPos()local function m(n)local o=0;if l+f>=k then o=l+f-k end;local p,q=term.getCursorPos()term.setCursorPos(l,q)local r=n and\" \"or a;if r then term.write(string.rep(r,math.max(string.len(d)-o,0)))else term.write(string.sub(d,o+1))end;if h then local s=g[h]local t,u;if not n then t=term.getTextColor()u=term.getBackgroundColor()term.setTextColor(theme[\"Shell-highlightAutocompleteText\"])term.setBackgroundColor(theme[\"Shell-highlightAutocomplete\"])end;if r then term.write(string.rep(r,string.len(s)))else term.write(s)end;if not n then term.setTextColor(t)term.setBackgroundColor(u)end end;term.setCursorPos(l+f-o,q)end;local function v()m(true)end;i()m()local function w()if h then v()local s=g[h]local x=string.sub(s,1,1)local y=s;for z=1,#g do local A=g[z]if z~=h and string.find(A,x,1,true)==1 then while#y>1 do if string.find(A,y,1,true)==1 then break else y=string.sub(y,1,#y-1)end end end end;d=d..y;f=string.len(d)end;i()m()end;while true do local B,C=os.pullEvent()if B==\"char\"then v()d=string.sub(d,1,f)..C..string.sub(d,f+1)f=f+1;i()m()elseif B==\"paste\"then v()d=string.sub(d,1,f)..C..string.sub(d,f+1)f=f+string.len(C)i()m()elseif B==\"key\"then if C==keys.enter then if h then v()j()m()end;break elseif C==keys.left then if f>0 then v()f=f-1;i()m()end elseif C==keys.right then if f<string.len(d)then v()f=f+1;i()m()else w()end elseif C==keys.up or C==keys.down then if h then v()if C==keys.up then h=h-1;if h<1 then h=#g end elseif C==keys.down then h=h+1;if h>#g then h=1 end end;m()elseif b then v()if C==keys.up then if e==nil then if#b>0 then e=#b end elseif e>1 then e=e-1 end else if e==#b then e=nil elseif e~=nil then e=e+1 end end;if e then d=b[e]f=string.len(d)else d=\"\"f=0 end;j()m()end elseif C==keys.backspace then if f>0 then v()d=string.sub(d,1,f-1)..string.sub(d,f+1)f=f-1;i()m()end elseif C==keys.home then if f>0 then v()f=0;i()m()end elseif C==keys.delete then if f<string.len(d)then v()d=string.sub(d,1,f)..string.sub(d,f+2)i()m()end elseif C==keys[\"end\"]then if f<string.len(d)then v()f=string.len(d)i()m()end elseif C==keys.tab then w()end elseif B==\"term_resize\"then k=term.getSize()m()end end;local p,q=term.getCursorPos()term.setCursorBlink(false)term.setCursorPos(k+1,q)print()return d end\
  752. if not term.isColor() then\
  753. \009O.shellBackgroundColor = colors.black\
  754. end\
  755. local shellHeader = \"O\"\
  756. \
  757. term.clear()\
  758. term.setCursorPos(1,1)\
  759. \
  760. x,y=term.getSize()\
  761. term.setCursorPos((x-string.len(shellHeader))/2, 1)\
  762. O.cprint(shellHeader, colors.white)\
  763. \
  764. displayText = nil\
  765. if fs.exists(\"/systemO/temp/cachedText\") then\
  766. \009local file = fs.open(\"/systemO/temp/cachedText\", \"r\")\
  767. \009displayText = file.readAll()\
  768. \009file.close()\
  769. end\
  770. term.setCursorPos(1,2)\
  771. local backgroundColors = {colors.lime, colors.blue, colors.purple, colors.gray, colors.cyan}\
  772. if term.isColor() then\
  773. \009local selected = math.random(1, #backgroundColors)\
  774. \009backgroundColor = backgroundColors[selected]\
  775. end\
  776. \
  777. if displayText ~= nil then\
  778. \009x,y=term.getSize()\
  779. \009term.setCursorPos((x-string.len(displayText))/2, 2)\
  780. \009if theme[\"Shell-backgroundColor\"] == backgroundColor then\
  781. \009\009O.cprint(displayText, colors.white)\
  782. \009else\
  783. \009\009O.cprint(displayText, backgroundColor)\
  784. \009end\
  785. end\
  786. backgroundColor = nil\
  787. OColor = nil\
  788. --Working for the parallel to detect back button presses\
  789. function waitForBack()\
  790. \009os.pullEvent(\"back_button\")\
  791. end\
  792. \
  793. inputHistory = {}\
  794. function readInput()\
  795. \009term.setTextColor(theme[\"Shell-highlightTextColor\"])\
  796. \009if not term.isColor() then\
  797. \009\009term.setTextColor(colors.black)\
  798. \009end\
  799. \009if _CC_VERSION ~= nil or _HOST ~= nil then\
  800. \009\009input = shellAutoComplete(nil, inputHistory, shell.complete)\
  801. \009else\
  802. \009\009input = read(nil, inputHistory)\
  803. \009end\
  804. end\
  805. \
  806. function getBlink()\
  807. \009while true do\
  808. \009\009term.setCursorBlink(true)\
  809. \009\009coroutine.yield()\
  810. \009end\
  811. end\
  812. \009\
  813. while true do\
  814. \009if term.isColor() then\
  815. \009\009term.setBackgroundColor(theme[\"Shell-highlightColor\"])\
  816. \009\009term.setTextColor(theme[\"Shell-highlightTextColor\"])\
  817. \009else\
  818. \009\009term.setBackgroundColor(colors.white)\
  819. \009\009term.setTextColor(colors.black)\
  820. \009end\
  821. \009x,y=term.getSize()\
  822. \009local xpos, ypos = term.getCursorPos()\
  823. \009term.setCursorPos(1, ypos)\
  824. \009term.clearLine()\
  825. \009term.setCursorPos(1, ypos)\
  826. \009if term.isColor() then\
  827. \009\009O.cprint(shell.dir()..theme[\"Shell-indentCharacter\"], theme[\"Shell-indentColor\"], true)\
  828. \009else\
  829. \009\009O.cprint(shell.dir()..theme[\"Shell-indentCharacter\"], colors.black, true)\
  830. \009end\
  831. \009local stoppedOn = parallel.waitForAny(readInput, waitForBack, getBlink)\
  832. \009if stoppedOn == 2 then\
  833. \009\009input = \"/rom/programs/cd /\"\
  834. \009end\
  835. \009local xpos, ypos = term.getCursorPos()\
  836. \009term.setTextColor(colors.white)\
  837. \009if term.isColor() then\
  838. \009\009term.setBackgroundColor(theme[\"Shell-backgroundColor\"])\
  839. \009else\
  840. \009\009term.setBackgroundColor(colors.black)\
  841. \009end\
  842. \009if ypos == y then\
  843. \009\009term.setCursorPos(1, ypos)\
  844. \009\009term.clearLine()\
  845. \009\009term.setCursorPos(1, ypos)\
  846. \009else\
  847. \009\009term.setCursorPos(1, ypos+2)\
  848. \009\009term.clearLine()\
  849. \009\009term.setCursorPos(1, ypos)\
  850. \009end\
  851. \009if input ~= \"\" then\
  852. \009\009table.insert(inputHistory, input)\
  853. \009end\
  854. \009--Allowing termination of programs above the shell\
  855. \009shell.run(input)\
  856. \009applyTheme()\
  857. \009term.setBackgroundColor(theme[\"Shell-backgroundColor\"])\
  858. \009term.setTextColor(theme[\"Shell-highlightTextColor\"])\
  859. \009--Thanks to cyanisaac for this V\
  860. \009local cX, cY = term.getCursorPos()\
  861. \009local tX, tY = term.getSize()\
  862. \009for x = cY, tY do\
  863. \009  term.setCursorPos(1, x)\
  864. \009  term.clearLine()\
  865. \009end\
  866. \009term.setCursorPos(cX,cY)\
  867. end",
  868.   [ "/systemO/bootloader" ] = "local optionsInRecovery = {\"Press [ENTER] to re-install O\", \"Press [X] to continue boot\", \"Press [S] to boot safe\"}\
  869. os.pullEvent = os.pullEventRaw\
  870. retail = false\
  871. if retail == true then\
  872. \009function http.get()\
  873. \009end\
  874. \009function http.post()\
  875. \009end\
  876. end\
  877. local oldUnload = os.unloadAPI\
  878. if fs.exists(\"/systemO/temp/boot\") then\
  879. \009local file = fs.open(\"/systemO/temp/boot\", \"r\")\
  880. \009bootMode = file.readAll()\
  881. \009file.close()\
  882. \009fs.delete(\"/systemO/temp/boot\")\
  883. end\
  884. local function drawPixel(y, x, color)\
  885. \009term.setCursorPos(x, y)\
  886. \009term.setBackgroundColor(color)\
  887. \009term.write(\" \")\
  888. end\
  889. local function printCent(mess, y)\
  890. \009term.setCursorPos((x-string.len(mess))/2, y)\
  891. \009term.write(mess)\
  892. end\
  893. local function boot()\
  894. \009fs.delete(\"/systemO/temp\")\
  895. \009fs.makeDir(\"/systemO/temp\")\
  896. \009shell.run(\"/systemO/launchpad\")\
  897. \009if term.isColor() then\
  898. \009\009term.setBackgroundColor(colors.blue)\
  899. \009\009term.setTextColor(colors.white)\
  900. \009else\
  901. \009\009term.setBackgroundColor(colors.black)\
  902. \009\009term.setTextColor(colors.white)\
  903. \009end\
  904. \009print(\"Unfortunately O has crashed! :(\")\
  905. \009print(\"Press any key to reboot...\")\
  906. \009os.pullEvent(\"key\")\
  907. \009os.reboot()\
  908. end\
  909. local function renderRecovery(toFix)\
  910. \009term.setBackgroundColor(colors.white)\
  911. \009term.setTextColor(colors.black)\
  912. \009term.clear()\
  913. \009if term.isColor() then\
  914. \009\009OColor = colors.red\
  915. \009else\
  916. \009\009OColor = colors.black\
  917. \009end\
  918. \009for ly=(y/2)-3,(y/2)+3 do\
  919. \009\009for lx=(x/2)-4,(x/2)+4 do\
  920. \009\009\009drawPixel(ly, lx, OColor)\
  921. \009\009end\
  922. \009end\
  923. \009if toFix then\
  924. \009\009term.setTextColor(colors.black)\
  925. \009\009term.setBackgroundColor(colors.white)\
  926. \009end\
  927. end\
  928. local function printAndClear(message, yl)\
  929. \009term.setCursorPos(1, yl)\
  930. \009term.clearLine()\
  931. \009printCent(message, yl)\
  932. end\
  933. local function recovery(isBroken)\
  934. \009renderRecovery()\
  935. \009term.setBackgroundColor(colors.white)\
  936. \009if isBroken == true then\
  937. \009\009printCent(\"Critical files are missing in O\", y/2+3)\
  938. \009end\
  939. \009term.setBackgroundColor(colors.black)\
  940. \009term.setTextColor(colors.white)\
  941. \009printAndClear(optionsInRecovery[1], y/2+5)\
  942. \009printAndClear(optionsInRecovery[2], y/2+6)\
  943. \009printAndClear(optionsInRecovery[3], y/2+7)\
  944. \009while true do\
  945. \009\009local event, key = os.pullEvent(\"key\")\
  946. \009\009if key == keys.x then\
  947. \009\009\009boot()\
  948. \009\009elseif key == keys.s then\
  949. \009\009\009safeBoot = true\
  950. \009\009\009boot()\
  951. \009\009elseif key == keys.enter then\
  952. \009\009\009if http then\
  953. \009\009\009\009local response = http.get(\"http://pastebin.com/raw.php?i=\"..textutils.urlEncode(\"EHY1eRBE\"))\
  954. \009\009\009\009if response then\
  955. \009\009\009\009\009writtenFile = response.readAll()\
  956. \009\009\009\009\009response.close()\
  957. \009\009\009\009\009if string.sub(writtenFile, 1, 11) == \"--Confirmed\" then\
  958. \009\009\009\009\009\009local file = fs.open(\"/systemO/temp/recovery\", \"w\")\
  959. \009\009\009\009\009\009file.write(writtenFile)\
  960. \009\009\009\009\009\009file.close()\
  961. \009\009\009\009\009\009shell.run(\"/systemO/temp/recovery\")\
  962. \009\009\009\009\009\009os.reboot()\
  963. \009\009\009\009\009else\
  964. \009\009\009\009\009\009term.setCursorPos(1, y/2+7)\
  965. \009\009\009\009\009\009term.clearLine()\
  966. \009\009\009\009\009\009printCent(\"Problems connecting to O\", y/2+7)\
  967. \009\009\009\009\009end\
  968. \009\009\009\009else\
  969. \009\009\009\009\009term.setCursorPos(1, y/2+7)\
  970. \009\009\009\009\009term.clearLine()\
  971. \009\009\009\009\009printCent(\"Couldn't connect to O\", y/2+7)\
  972. \009\009\009\009end\
  973. \009\009\009end\
  974. \009\009end\
  975. \009end\
  976. end\
  977. function os.unloadAPI(apito)\
  978. \009if apito ~= \"O\" then\
  979. \009\009oldUnload(apito)\
  980. \009end\
  981. end\
  982. x,y=term.getSize()\
  983. local backgroundColors = {colors.lime, colors.blue, colors.purple, colors.gray, colors.cyan}\
  984. if term.isColor() then\
  985. \009selected = math.random(1, #backgroundColors)\
  986. \009backgroundColor = backgroundColors[selected]\
  987. \009OColor = colors.white\
  988. else\
  989. \009backgroundColor = colors.white\
  990. \009OColor = colors.black\
  991. end\
  992. term.setBackgroundColor(backgroundColor)\
  993. term.clear()\
  994. term.setCursorPos(1,1)\
  995. for ly=(y/2)-3,(y/2)+3 do\
  996. \009for lx=(x/2)-4,(x/2)+4 do\
  997. \009\009drawPixel(ly, lx, OColor)\
  998. \009end\
  999. end\
  1000. term.setBackgroundColor(backgroundColor)\
  1001. continueBoot = true\
  1002. term.setBackgroundColor(backgroundColor)\
  1003. term.setTextColor(OColor)\
  1004. if retail == true then\
  1005. \009bootMode = nil\
  1006. end\
  1007. if bootMode ~= nil then\
  1008. \009sleep(1)\
  1009. \009if bootMode == \"update\" then\
  1010. \009\009renderRecovery(true)\
  1011. \009\009printCent(\"Preparing update...\", y)\
  1012. \009\009if http then\
  1013. \009\009\009local response = http.get(\"http://pastebin.com/raw.php?i=\"..textutils.urlEncode(\"EHY1eRBE\"))\
  1014. \009\009\009if response then\
  1015. \009\009\009\009writtenFile = response.readAll()\
  1016. \009\009\009\009response.close()\
  1017. \009\009\009\009if string.sub(writtenFile, 1, 11) == \"--Confirmed\" then\
  1018. \009\009\009\009\009local file = fs.open(\"/systemO/temp/recovery\", \"w\")\
  1019. \009\009\009\009\009file.write(writtenFile)\
  1020. \009\009\009\009\009file.close()\
  1021. \009\009\009\009\009printCent(\"Downloading update...\", y)\
  1022. \009\009\009\009\009shell.run(\"/systemO/temp/recovery true\")\
  1023. \009\009\009\009\009os.reboot()\
  1024. \009\009\009\009else\
  1025. \009\009\009\009\009term.clear()\
  1026. \009\009\009\009\009renderRecovery(true)\
  1027. \009\009\009\009\009printCent(\"Problem updating O\", y)\
  1028. \009\009\009\009end\
  1029. \009\009\009else\
  1030. \009\009\009\009term.clear()\
  1031. \009\009\009\009renderRecovery(true)\
  1032. \009\009\009\009printCent(\"Couldn't connect to O\", y)\
  1033. \009\009\009end\
  1034. \009\009end\
  1035. \009\009os.reboot()\
  1036. \009elseif bootMode == \"reset\" then\
  1037. \009\009renderRecovery(true)\
  1038. \009\009printCent(\"Press [ENTER] to reset O\", y -3)\
  1039. \009\009printCent(\"Press any key to cancel\", y - 2)\
  1040. \009\009local event, key = os.pullEvent(\"key\")\
  1041. \009\009if key == keys.enter then\
  1042. \009\009\009renderRecovery(true)\
  1043. \009\009\009printCent(\"Resetting O...\", y)\
  1044. \009\009\009shell.run(\"/rom/programs/cd /\")\
  1045. \009\009\009files = fs.list(\"/\")\
  1046. \009\009\009for i=1,#files do\
  1047. \009\009\009\009if files[i] == \"rom\" or files[i] == \"systemO\" or files[i] == \"startup\" then\
  1048. \009\009\009\009\009sleep(0)\
  1049. \009\009\009\009else\
  1050. \009\009\009\009\009fs.delete(files[i])\
  1051. \009\009\009\009end\
  1052. \009\009\009end\
  1053. \009\009\009sleep(2)\
  1054. \009\009\009os.reboot()\
  1055. \009\009else\
  1056. \009\009\009os.reboot()\
  1057. \009\009end\
  1058. \009elseif bootMode == \"removeO\" then\
  1059. \009\009renderRecovery(true)\
  1060. \009\009printCent(\"Press [ENTER] to remove O\", y-3)\
  1061. \009\009printCent(\"Press any key to cancel\", y-2)\
  1062. \009\009local event, key = os.pullEvent(\"key\")\
  1063. \009\009if key == keys.enter then\
  1064. \009\009\009renderRecovery(true)\
  1065. \009\009\009printCent(\"Removing O\", y)\
  1066. \009\009\009fs.delete(\"/systemO\")\
  1067. \009\009\009fs.delete(\"/startup\")\
  1068. \009\009\009sleep(2)\
  1069. \009\009\009os.reboot()\
  1070. \009\009else\
  1071. \009\009\009os.reboot()\
  1072. \009\009end\
  1073. \009elseif bootMode == \"removepassword\" then\
  1074. \009\009if fs.exists(\"/systemO/odata/pin\") then\
  1075. \009\009\009fs.delete(\"/systemO/odata/pin\")\
  1076. \009\009end\
  1077. \009elseif string.sub(bootMode, 1, 13) == \"resetpassword\" then\
  1078. \009\009local file = fs.open(\"/systemO/odata/password\", \"w\")\
  1079. \009\009file.write(string.sub(bootMode, 14, 18))\
  1080. \009\009file.close()\
  1081. \009elseif string.sub(bootMode, 1, 10) == \"devupdate \" then\
  1082. \009\009renderRecovery(true)\
  1083. \009\009printCent(\"Preparing update...\", y)\
  1084. \009\009if http then\
  1085. \009\009\009local response = http.get(\"http://pastebin.com/raw.php?i=\"..textutils.urlEncode(\"EHY1eRBE\"))\
  1086. \009\009\009if response then\
  1087. \009\009\009\009writtenFile = response.readAll()\
  1088. \009\009\009\009response.close()\
  1089. \009\009\009\009if string.sub(writtenFile, 1, 11) == \"--Confirmed\" then\
  1090. \009\009\009\009\009local file = fs.open(\"/systemO/temp/recovery\", \"w\")\
  1091. \009\009\009\009\009file.write(writtenFile)\
  1092. \009\009\009\009\009file.close()\
  1093. \009\009\009\009\009printCent(\"Downloading update...\", y)\
  1094. \009\009\009\009\009shell.run(\"/systemO/temp/recovery true \"..string.sub(bootMode, 11, #bootMode))\
  1095. \009\009\009\009\009os.reboot()\
  1096. \009\009\009\009else\
  1097. \009\009\009\009\009term.clear()\
  1098. \009\009\009\009\009renderRecovery(true)\
  1099. \009\009\009\009\009printCent(\"Problem updating O\", y)\
  1100. \009\009\009\009end\
  1101. \009\009\009else\
  1102. \009\009\009\009term.clear()\
  1103. \009\009\009\009renderRecovery(true)\
  1104. \009\009\009\009printCent(\"Couldn't connect to O\", y)\
  1105. \009\009\009end\
  1106. \009\009end\
  1107. \009\009os.reboot()\
  1108. \009end\
  1109. end\
  1110. local freezeTimer = os.startTimer(0.4)\
  1111. \
  1112. while true do\
  1113. \009local event, par1 = os.pullEvent()\
  1114. \009if event == \"timer\" and par1 == freezeTimer then\
  1115. \009\009break\
  1116. \009elseif event == \"key\" then\
  1117. \009\009if par1 == keys.leftShift or par1 == keys.rightShift then\
  1118. \009\009\009if retail == false then\
  1119. \009\009\009\009recovery(false)\
  1120. \009\009\009end\
  1121. \009\009end\
  1122. \009end\
  1123. end\
  1124. \
  1125. if continueBoot == true then\
  1126. \009boot()\
  1127. else\
  1128. \009recovery(true)\
  1129. end",
  1130.   [ "/systemO/odata/O" ] = "--Starting the O API WOOHOO!\
  1131. function cprint(message, color, toWrite)\
  1132. \009if term.isColor() then\
  1133. \009\009term.setTextColor(color)\
  1134. \009\009cprinttowrite(message, toWrite)\
  1135. \009\009term.setTextColor(colors.white)\
  1136. \009else\
  1137. \009\009if color == colors.white then\
  1138. \009\009\009term.setTextColor(color)\
  1139. \009\009elseif color == colors.black then\
  1140. \009\009\009term.setTextColor(color)\
  1141. \009\009else\
  1142. \009\009\009term.setTextColor(colors.white)\
  1143. \009\009end\
  1144. \009\009cprinttowrite(message, toWrite)\
  1145. \009end\
  1146. end\
  1147. --INTERNAL FUNCTION NO NEED FOR IT\
  1148. function cprinttowrite(message, toWrite)\
  1149. \009if toWrite == true then\
  1150. \009\009term.write(message)\
  1151. \009else\
  1152. \009\009print(message)\
  1153. \009end\
  1154. end\
  1155. \
  1156. function getVersion(updateFileLink)\
  1157. \009local responseTable = {}\
  1158. \009if not http then\
  1159. \009\009table.insert(responseTable, \"N\")\
  1160. \009else\
  1161. \009\009local response = http.get(\"http://pastebin.com/raw.php?i=\"..textutils.urlEncode(updateFileLink))\
  1162. \009\009if response then\
  1163. \009\009\009local rawVersion = response.readAll()\
  1164. \009\009\009responseTable = textutils.unserialize(rawVersion)\
  1165. \009\009\009return responseTable\
  1166. \009\009else\
  1167. \009\009\009table.insert(responseTable, \"F\")\
  1168. \009\009end\
  1169. \009end\
  1170. end\
  1171. \
  1172. function getVersionNumber()\
  1173. \009return \"2.5.2\"\
  1174. end\
  1175. \
  1176. function getDevRelease()\
  1177. \009return \"release\"\
  1178. end\
  1179. \
  1180. function getReleaseVersion()\
  1181. \009return \"2.5.2\"\
  1182. end\
  1183. \
  1184. function getSpecializedVersion()\
  1185. \009return \"general\"\
  1186. end\
  1187. \
  1188. function resolveUpdateLocation()\
  1189. \009local response = http.get(\"http://pastebin.com/raw.php?i=\"..textutils.urlEncode(\"i8LkEYQW\"))\
  1190. \009if response then\
  1191. \009\009local rawUpdateLocations = response.readAll()\
  1192. \009\009response.close()\
  1193. \009\009local updateLocations = textutils.unserialize(rawUpdateLocations)\
  1194. \009\009if not fs.exists(\"/systemO/stream\") then\
  1195. \009\009\009local file = fs.open(\"/systemO/stream\", \"w\")\
  1196. \009\009\009file.write(\"standard\")\
  1197. \009\009\009file.close()\
  1198. \009\009end\
  1199. \009\009local file = fs.open(\"/systemO/stream\", \"r\")\
  1200. \009\009local storedUpdateLable = file.readAll()\
  1201. \009\009file.close()\
  1202. \009\009for key,value in pairs(updateLocations) do\
  1203. \009\009\009if key == storedUpdateLable then\
  1204. \009\009\009\009return value\
  1205. \009\009\009end\
  1206. \009\009end\
  1207. \009\009local file = fs.open(\"/systemO/stream\", \"w\")\
  1208. \009\009file.write(\"standard\")\
  1209. \009\009file.close()\
  1210. \009\009return \"WhaRBZ8Q\"\
  1211. \009else\
  1212. \009\009return \"WhaRBZ8Q\"\
  1213. \009end\
  1214. end\
  1215. function backButtonPress()\
  1216. \009local x,y=term.getSize()\
  1217. \009while true do\
  1218. \009\009local event, inputArg, clickx, clicky = os.pullEvent()\
  1219. \009\009if event == \"mouse_click\" then\
  1220. \009\009\009if clickx > x/4-2 and clickx < x/4+3 and clicky == y+1 then\
  1221. \009\009\009\009os.queueEvent(\"back_button\")\
  1222. \009\009\009end\
  1223. \009\009end\
  1224. \009end\
  1225. end\
  1226. \
  1227. function pushNotification(message, color, backColor, duration)\
  1228. \009local file = fs.open(\"systemO/odata/notification\", \"w\")\
  1229. \009inputArg = {message, color, backColor, duration}\
  1230. \009file.write(textutils.serialize(inputArg))\
  1231. \009file.close()\
  1232. end\
  1233. function getThemeData(theme)\
  1234. \009if fs.exists(\"/systemO/odata/theme\") then\
  1235. \009\009local file = fs.open(\"/systemO/odata/theme\", \"r\")\
  1236. \009\009local rawThemeData = file.readAll()\
  1237. \009\009file.close()\
  1238. \009\009return textutils.unserialize(rawThemeData)\
  1239. \009else\
  1240. \009\009local theme = {}\
  1241. \009\009theme[\"Shell-highlightColor\"] = colors.gray\
  1242. \009\009theme[\"Shell-highlightTextColor\"] = colors.white\
  1243. \009\009theme[\"Shell-highlightAutocomplete\"] = colors.lightGray\
  1244. \009\009theme[\"Shell-indentCharacter\"] = \"> \"\
  1245. \009\009theme[\"Shell-indentColor\"] = colors.white\
  1246. \009\009theme[\"Shell-backgroundColor\"] = colors.black\
  1247. \009\009theme[\"Shell-highlightAutocompleteText\"] = colors.white\
  1248. \009\009local file = fs.open(\"/systemO/odata/theme\", \"w\")\
  1249. \009\009file.write(textutils.serialize(theme))\
  1250. \009\009file.close()\
  1251. \009\009return theme\
  1252. \009end\
  1253. end",
  1254.   [ "/systemO/lockscreen" ] = "local MOD = 2^32\
  1255. local MODM = MOD-1\
  1256. \
  1257. local function memoize(f)\
  1258. \009local mt = {}\
  1259. \009local t = setmetatable({}, mt)\
  1260. \009function mt:__index(k)\
  1261. \009\009local v = f(k)\
  1262. \009\009t[k] = v\
  1263. \009\009return v\
  1264. \009end\
  1265. \009return t\
  1266. end\
  1267. \
  1268. local function make_bitop_uncached(t, m)\
  1269. \009local function bitop(a, b)\
  1270. \009\009local res,p = 0,1\
  1271. \009\009while a ~= 0 and b ~= 0 do\
  1272. \009\009\009local am, bm = a % m, b % m\
  1273. \009\009\009res = res + t[am][bm] * p\
  1274. \009\009\009a = (a - am) / m\
  1275. \009\009\009b = (b - bm) / m\
  1276. \009\009\009p = p*m\
  1277. \009\009end\
  1278. \009\009res = res + (a + b) * p\
  1279. \009\009return res\
  1280. \009end\
  1281. \009return bitop\
  1282. end\
  1283. \
  1284. local function make_bitop(t)\
  1285. \009local op1 = make_bitop_uncached(t,2^1)\
  1286. \009local op2 = memoize(function(a) return memoize(function(b) return op1(a, b) end) end)\
  1287. \009return make_bitop_uncached(op2, 2 ^ (t.n or 1))\
  1288. end\
  1289. \
  1290. local bxor1 = make_bitop({[0] = {[0] = 0,[1] = 1}, [1] = {[0] = 1, [1] = 0}, n = 4})\
  1291. \
  1292. local function bxor(a, b, c, ...)\
  1293. \009local z = nil\
  1294. \009if b then\
  1295. \009\009a = a % MOD\
  1296. \009\009b = b % MOD\
  1297. \009\009z = bxor1(a, b)\
  1298. \009\009if c then z = bxor(z, c, ...) end\
  1299. \009\009return z\
  1300. \009elseif a then return a % MOD\
  1301. \009else return 0 end\
  1302. end\
  1303. \
  1304. local function band(a, b, c, ...)\
  1305. \009local z\
  1306. \009if b then\
  1307. \009\009a = a % MOD\
  1308. \009\009b = b % MOD\
  1309. \009\009z = ((a + b) - bxor1(a,b)) / 2\
  1310. \009\009if c then z = bit32_band(z, c, ...) end\
  1311. \009\009return z\
  1312. \009elseif a then return a % MOD\
  1313. \009else return MODM end\
  1314. end\
  1315. \
  1316. local function bnot(x) return (-1 - x) % MOD end\
  1317. \
  1318. local function rshift1(a, disp)\
  1319. \009if disp < 0 then return lshift(a,-disp) end\
  1320. \009return math.floor(a % 2 ^ 32 / 2 ^ disp)\
  1321. end\
  1322. \
  1323. local function rshift(x, disp)\
  1324. \009if disp > 31 or disp < -31 then return 0 end\
  1325. \009return rshift1(x % MOD, disp)\
  1326. end\
  1327. \
  1328. local function lshift(a, disp)\
  1329. \009if disp < 0 then return rshift(a,-disp) end \
  1330. \009return (a * 2 ^ disp) % 2 ^ 32\
  1331. end\
  1332. \
  1333. local function rrotate(x, disp)\
  1334.    x = x % MOD\
  1335.    disp = disp % 32\
  1336.    local low = band(x, 2 ^ disp - 1)\
  1337.    return rshift(x, disp) + lshift(low, 32 - disp)\
  1338. end\
  1339. \
  1340. local k = {\
  1341. \0090x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,\
  1342. \0090x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,\
  1343. \0090xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,\
  1344. \0090x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,\
  1345. \0090xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,\
  1346. \0090x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,\
  1347. \0090x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,\
  1348. \0090xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,\
  1349. \0090x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,\
  1350. \0090x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,\
  1351. \0090xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,\
  1352. \0090xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,\
  1353. \0090x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,\
  1354. \0090x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,\
  1355. \0090x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,\
  1356. \0090x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,\
  1357. }\
  1358. \
  1359. local function str2hexa(s)\
  1360. \009return (string.gsub(s, \".\", function(c) return string.format(\"%02x\", string.byte(c)) end))\
  1361. end\
  1362. \
  1363. local function num2s(l, n)\
  1364. \009local s = \"\"\
  1365. \009for i = 1, n do\
  1366. \009\009local rem = l % 256\
  1367. \009\009s = string.char(rem) .. s\
  1368. \009\009l = (l - rem) / 256\
  1369. \009end\
  1370. \009return s\
  1371. end\
  1372. \
  1373. local function s232num(s, i)\
  1374. \009local n = 0\
  1375. \009for i = i, i + 3 do n = n*256 + string.byte(s, i) end\
  1376. \009return n\
  1377. end\
  1378. \
  1379. local function preproc(msg, len)\
  1380. \009local extra = 64 - ((len + 9) % 64)\
  1381. \009len = num2s(8 * len, 8)\
  1382. \009msg = msg .. \"\\128\" .. string.rep(\"\\0\", extra) .. len\
  1383. \009assert(#msg % 64 == 0)\
  1384. \009return msg\
  1385. end\
  1386. \
  1387. local function initH256(H)\
  1388. \009H[1] = 0x6a09e667\
  1389. \009H[2] = 0xbb67ae85\
  1390. \009H[3] = 0x3c6ef372\
  1391. \009H[4] = 0xa54ff53a\
  1392. \009H[5] = 0x510e527f\
  1393. \009H[6] = 0x9b05688c\
  1394. \009H[7] = 0x1f83d9ab\
  1395. \009H[8] = 0x5be0cd19\
  1396. \009return H\
  1397. end\
  1398. \
  1399. local function digestblock(msg, i, H)\
  1400. \009local w = {}\
  1401. \009for j = 1, 16 do w[j] = s232num(msg, i + (j - 1)*4) end\
  1402. \009for j = 17, 64 do\
  1403. \009\009local v = w[j - 15]\
  1404. \009\009local s0 = bxor(rrotate(v, 7), rrotate(v, 18), rshift(v, 3))\
  1405. \009\009v = w[j - 2]\
  1406. \009\009w[j] = w[j - 16] + s0 + w[j - 7] + bxor(rrotate(v, 17), rrotate(v, 19), rshift(v, 10))\
  1407. \009end\
  1408. \
  1409. \009local a, b, c, d, e, f, g, h = H[1], H[2], H[3], H[4], H[5], H[6], H[7], H[8]\
  1410. \009for i = 1, 64 do\
  1411. \009\009local s0 = bxor(rrotate(a, 2), rrotate(a, 13), rrotate(a, 22))\
  1412. \009\009local maj = bxor(band(a, b), band(a, c), band(b, c))\
  1413. \009\009local t2 = s0 + maj\
  1414. \009\009local s1 = bxor(rrotate(e, 6), rrotate(e, 11), rrotate(e, 25))\
  1415. \009\009local ch = bxor (band(e, f), band(bnot(e), g))\
  1416. \009\009local t1 = h + s1 + ch + k[i] + w[i]\
  1417. \009\009h, g, f, e, d, c, b, a = g, f, e, d + t1, c, b, a, t1 + t2\
  1418. \009end\
  1419. \
  1420. \009H[1] = band(H[1] + a)\
  1421. \009H[2] = band(H[2] + b)\
  1422. \009H[3] = band(H[3] + c)\
  1423. \009H[4] = band(H[4] + d)\
  1424. \009H[5] = band(H[5] + e)\
  1425. \009H[6] = band(H[6] + f)\
  1426. \009H[7] = band(H[7] + g)\
  1427. \009H[8] = band(H[8] + h)\
  1428. end\
  1429. \
  1430. local function sha256(msg)\
  1431. \009msg = preproc(msg, #msg)\
  1432. \009local H = initH256({})\
  1433. \009for i = 1, #msg, 64 do digestblock(msg, i, H) end\
  1434. \009return str2hexa(num2s(H[1], 4) .. num2s(H[2], 4) .. num2s(H[3], 4) .. num2s(H[4], 4) ..\
  1435. \009\009num2s(H[5], 4) .. num2s(H[6], 4) .. num2s(H[7], 4) .. num2s(H[8], 4))\
  1436. end\
  1437. if fs.exists(\"/systemO/odata/password\") then\
  1438. \009local passwordFile = fs.open(\"/systemO/odata/password\", \"r\")\
  1439. \009local inputPassword2 = passwordFile.readAll()\
  1440. \009local salt1 = math.random(1,1000000)\
  1441. \009local salt2 = math.random(1,1000000)\
  1442. \009local rawHashed = sha256(salt1..inputPassword2..salt2)\
  1443. \009local outputPass = {\"version=1\", salt1, salt2, rawHashed}\
  1444. \009local hashedPIN = textutils.serialize(outputPass)\
  1445. \009local file = fs.open(\"/systemO/temp/Verifypin\", \"w\")\
  1446. \009file.write(hashedPIN)\
  1447. \009file.close()\
  1448. \009passwordRaw = passwordFile.readAll()\
  1449. \009passwordFile.close()\
  1450. \009fs.delete(\"/systemO/odata/password\")\
  1451. end\
  1452. if fs.exists(\"/systemO/odata/pin\") then\
  1453. \009local passwordFile = fs.open(\"/systemO/odata/pin\", \"r\")\
  1454. \009passwordRaw = passwordFile.readAll()\
  1455. \009passwordFile.close()\
  1456. \009locked = true\
  1457. else\
  1458. \009locked = false\
  1459. end\
  1460. if fs.exists(\"/systemO/temp/Verifypin\") then\
  1461. \009local passwordFile = fs.open(\"/systemO/temp/Verifypin\", \"r\")\
  1462. \009passwordRaw = passwordFile.readAll()\
  1463. \009passwordFile.close()\
  1464. \009locked = true\
  1465. \009verifyPin = true\
  1466. end\
  1467. \
  1468. \
  1469. \
  1470. local numberPad = {[0] = 82, 79, 80, 81, 75, 76, 77, 71, 72, 73}\
  1471. local topNumbers = {[0] = 11, 2, 3, 4, 5, 6, 7, 8, 9, 10}\
  1472. local number = {[0] = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}\
  1473. if verifyPin == true then\
  1474. \009passwordText = \"Verify PIN\"\
  1475. else\
  1476. \009passwordText = \"Enter PIN\"\
  1477. end\
  1478. local function drawPixel(y, x, color)\
  1479. \009term.setCursorPos(x, y)\
  1480. \009term.setBackgroundColor(color)\
  1481. \009term.write(\" \")\
  1482. end\
  1483. local function renderCircles(numberThrough, colororverride, renderEverything)\
  1484. \009local loopThrough = 1\
  1485. \009term.setCursorPos((x-string.len(passwordText))/2, y/2+2)\
  1486. \009if term.isColor() then\
  1487. \009\009term.setBackgroundColor(backgroundColor)\
  1488. \009\009O.cprint(passwordText, OColor, true)\
  1489. \009else\
  1490. \009\009term.setBackgroundColor(colors.white)\
  1491. \009\009O.cprint(passwordText, colors.black, true)\
  1492. \009end\
  1493. \009for i=-2,2 do\
  1494. \009\009for ly=(y/2)+4,(y/2)+5 do\
  1495. \009\009\009for lx=(x/2)-1,(x/2)+1 do\
  1496. \009\009\009\009if colororverride == nil then\
  1497. \009\009\009\009\009if numberThrough >= loopThrough then\
  1498. \009\009\009\009\009\009if term.isColor() then\
  1499. \009\009\009\009\009\009\009drawPixel(ly, lx-(i*4), colors.white)\
  1500. \009\009\009\009\009\009else\
  1501. \009\009\009\009\009\009\009drawPixel(ly, lx-(i*4), colors.black)\
  1502. \009\009\009\009\009\009end\
  1503. \009\009\009\009\009else\
  1504. \009\009\009\009\009\009if term.isColor() then\
  1505. \009\009\009\009\009\009\009drawPixel(ly, lx-(i*4), colors.lightGray)\
  1506. \009\009\009\009\009\009else\
  1507. \009\009\009\009\009\009\009drawPixel(ly, lx-(i*4), colors.white)\
  1508. \009\009\009\009\009\009end\
  1509. \009\009\009\009\009end\
  1510. \009\009\009\009else\
  1511. \009\009\009\009\009drawPixel(ly, lx-(i*4), colororverride)\
  1512. \009\009\009\009end\
  1513. \009\009\009end\
  1514. \009\009end\
  1515. \009\009loopThrough = loopThrough + 1\
  1516. \009end\
  1517. end\
  1518. if locked == true then\
  1519. \009passwordPackage = textutils.unserialize(passwordRaw)\
  1520. end\
  1521. local function checkPass(input)\
  1522. \009local unhashed = passwordPackage[2]..input..passwordPackage[3]\
  1523. \009local hashCompare = sha256(unhashed)\
  1524. \009if hashCompare == passwordPackage[4] then\
  1525. \009\009return true\
  1526. \009else\
  1527. \009\009return false\
  1528. \009end\
  1529. end\
  1530. if locked == true then\
  1531. \009term.clear()\
  1532. \009local highlighted = 5\
  1533. \009local selectedColor = backgroundColor\
  1534. \009if not term.isColor() then\
  1535. \009\009selectedColor = colors.white\
  1536. \009end\
  1537. \009local hasRun = false\
  1538. \009local inputPassword = {}\
  1539. \009while true do\
  1540. \009\009if hasRun == false then\
  1541. \009\009\009term.setBackgroundColor(selectedColor)\
  1542. \009\009\009term.clear()\
  1543. \009\009\009for ly=(y/2)-4,(y/2)+2 do\
  1544. \009\009\009\009for lx=(x/2)-4,(x/2)+4 do\
  1545. \009\009\009\009\009if term.isColor() then\
  1546. \009\009\009\009\009\009drawPixel(ly-2, lx, colors.white)\
  1547. \009\009\009\009\009else\
  1548. \009\009\009\009\009\009drawPixel(ly-2, lx, colors.black)\
  1549. \009\009\009\009\009end\
  1550. \009\009\009\009end\
  1551. \009\009\009end\
  1552. \009\009\009renderCircles(highlighted, nil, true)\
  1553. \009\009\009hasRun = true\
  1554. \009\009end\
  1555. \009\009term.setBackgroundColor(selectedColor)\
  1556. \009\009if highlighted < 1 then\
  1557. \009\009\009local combinedPassword = \"\"\
  1558. \009\009\009for i=1, 5 do\
  1559. \009\009\009\009combinedPassword = combinedPassword..inputPassword[i]\
  1560. \009\009\009end\
  1561. \009\009\009if checkPass(combinedPassword) == true then\
  1562. \009\009\009\009if verifyPin == true then\
  1563. \009\009\009\009\009if fs.exists(\"/systemO/odata/pin\") then\
  1564. \009\009\009\009\009\009fs.delete(\"/systemO/odata/pin\")\
  1565. \009\009\009\009\009end\
  1566. \009\009\009\009\009fs.move(\"/systemO/temp/Verifypin\", \"/systemO/odata/pin\")\
  1567. \009\009\009\009\009os.reboot()\
  1568. \009\009\009\009end\
  1569. \009\009\009\009if term.isColor() then\
  1570. \009\009\009\009\009renderCircles(highlighted, colors.green)\
  1571. \009\009\009\009\009sleep(0.4)\
  1572. \009\009\009\009else\
  1573. \009\009\009\009\009renderCircles(highlighted, colors.white)\
  1574. \009\009\009\009\009sleep(0.4)\
  1575. \009\009\009\009end\
  1576. \009\009\009\009validPassword = true\
  1577. \009\009\009\009break\
  1578. \009\009\009else\
  1579. \009\009\009\009if term.isColor() then\
  1580. \009\009\009\009\009renderCircles(highlighted, colors.red)\
  1581. \009\009\009\009else\
  1582. \009\009\009\009\009renderCircles(highlighted, colors.white)\
  1583. \009\009\009\009end\
  1584. \009\009\009\009if verifyPin == true then\
  1585. \009\009\009\009\009passwordText = \"Password did not match.\"\
  1586. \009\009\009\009\009term.setCursorPos((x-string.len(passwordText))/2, y/2+2)\
  1587. \009\009\009\009\009if term.isColor() then\
  1588. \009\009\009\009\009\009term.setBackgroundColor(backgroundColor)\
  1589. \009\009\009\009\009\009O.cprint(passwordText, OColor, true)\
  1590. \009\009\009\009\009else\
  1591. \009\009\009\009\009\009term.setBackgroundColor(colors.white)\
  1592. \009\009\009\009\009\009O.cprint(passwordText, colors.black, true)\
  1593. \009\009\009\009\009end\
  1594. \009\009\009\009\009sleep(1)\
  1595. \009\009\009\009\009os.reboot()\
  1596. \009\009\009\009end\
  1597. \009\009\009end\
  1598. \009\009\009sleep(1.2)\
  1599. \009\009\009highlighted = 5\
  1600. \009\009\009renderCircles(highlighted)\
  1601. \009\009\009inputPassword = {}\
  1602. \009\009else\
  1603. \009\009\009renderCircles(highlighted)\
  1604. \009\009end\
  1605. \009\009local event, key, repeated = os.pullEvent(\"key\")\
  1606. \009\009local numberKey = \"none\"\
  1607. \009\009for i=0,#numberPad do\
  1608. \009\009\009if key == numberPad[i] then\
  1609. \009\009\009\009numberKey = \"numberPad\"\
  1610. \009\009\009end\
  1611. \009\009end\
  1612. \009\009for i=0,#topNumbers do\
  1613. \009\009\009if key == topNumbers[i] then\
  1614. \009\009\009\009numberKey = \"topNumber\"\
  1615. \009\009\009end\
  1616. \009\009end\
  1617. \009\009if numberKey ~= \"none\" then\
  1618. \009\009\009for i=0,#numberPad do\
  1619. \009\009\009\009if numberPad[i] == key then\
  1620. \009\009\009\009\009table.insert(inputPassword, i)\
  1621. \009\009\009\009end\
  1622. \009\009\009end\
  1623. \009\009\009for i=0,#topNumbers do\
  1624. \009\009\009\009if topNumbers[i] == key then\
  1625. \009\009\009\009\009table.insert(inputPassword, i)\
  1626. \009\009\009\009end\
  1627. \009\009\009end\
  1628. \009\009\009highlighted = highlighted - 1\
  1629. \009\009end\
  1630. \009end\
  1631. \009term.setBackgroundColor(backgroundColor)\
  1632. else\
  1633. \009validPassword = true\
  1634. end\
  1635. password = nil\
  1636. passwordRaw = nil",
  1637.   [ "/systemO/odata/themes/Water" ] = "{\
  1638.  [ \"Shell-indentCharacter\" ] = \"> \",\
  1639.  [ \"Shell-highlightColor\" ] = 512,\
  1640.  [ \"Shell-highlightAutocompleteText\" ] = 1,\
  1641.  [ \"Shell-backgroundColor\" ] = 2048,\
  1642.  [ \"Shell-highlightAutocomplete\" ] = 8,\
  1643.  [ \"Shell-indentColor\" ] = 8192,\
  1644.  [ \"Shell-highlightTextColor\" ] = 1,\
  1645. }",
  1646.   [ "/systemO/programs/update" ] = "updateFileLink = O.resolveUpdateLocation()\
  1647. local x, y = term.getSize()\
  1648. currentVersion = O.getVersionNumber\
  1649. --Get version information\
  1650. function getVersion()\
  1651. \009local responseTable = {}\
  1652. \009if not http then\
  1653. \009\009table.insert(responseTable, \"N\")\
  1654. \009else\
  1655. \009\009local response = http.get(\"http://pastebin.com/raw.php?i=\"..textutils.urlEncode(updateFileLink))\
  1656. \009\009if response then\
  1657. \009\009\009local rawVersion = response.readAll()\
  1658. \009\009\009responseTable = textutils.unserialize(rawVersion)\
  1659. \009\009\009return responseTable\
  1660. \009\009else\
  1661. \009\009\009table.insert(responseTable, \"F\")\
  1662. \009\009end\
  1663. \009end\
  1664. end\
  1665. local function centerPrint(mess, yloc, textcolor)\
  1666. \009term.setCursorPos((x-string.len(mess))/2, yloc)\
  1667. \009O.cprint(mess, textcolor, true)\
  1668. end\
  1669. local function drawPixel(y, x, color)\
  1670. \009term.setCursorPos(x, y)\
  1671. \009term.setBackgroundColor(color)\
  1672. \009term.write(\" \")\
  1673. end\
  1674. local function renderScreen(list, highlightedLine, confirmation)\
  1675. \009term.setBackgroundColor(colors.black)\
  1676. \009if confirmation ~= nil then\
  1677. \009\009term.setCursorPos((x-string.len(confirmation))/2, 10)\
  1678. \009\009O.cprint(confirmation, colors.white)\
  1679. \009end\
  1680. \009for i=1,#list do\
  1681. \009\009term.setCursorPos((x-string.len(list[i]))/2, 10+i)\
  1682. \009\009if highlightedLine == i then\
  1683. \009\009\009if term.isColor() then\
  1684. \009\009\009\009term.setBackgroundColor(colors.gray)\
  1685. \009\009\009\009term.clearLine()\
  1686. \009\009\009\009O.cprint(list[i], colors.white, true)\
  1687. \009\009\009else\
  1688. \009\009\009\009term.setBackgroundColor(colors.white)\
  1689. \009\009\009\009term.clearLine()\
  1690. \009\009\009\009O.cprint(list[i], colors.black, true)\
  1691. \009\009\009end\
  1692. \009\009else\
  1693. \009\009\009term.setBackgroundColor(colors.black)\
  1694. \009\009\009term.clearLine()\
  1695. \009\009\009O.cprint(list[i], colors.white, true)\
  1696. \009\009end\
  1697. \009end\
  1698. end\
  1699. local function interactiveOption(list, confirmation)\
  1700. \009selected = 1\
  1701. \009renderScreen(list, selected, confirmation)\
  1702. \009while true do\
  1703. \009\009local event, key = os.pullEvent()\
  1704. \009\009if event == \"key\" then\
  1705. \009\009\009if key == keys.up then\
  1706. \009\009\009\009selected = selected - 1\
  1707. \009\009\009\009if selected < 1 then\
  1708. \009\009\009\009\009selected = 1\
  1709. \009\009\009\009else\
  1710. \009\009\009\009\009renderScreen(list, selected, confirmation)\
  1711. \009\009\009\009end\
  1712. \009\009\009elseif key == keys.down then\
  1713. \009\009\009\009selected = selected + 1\
  1714. \009\009\009\009if selected > #list then\
  1715. \009\009\009\009\009selected = # list\
  1716. \009\009\009\009else\
  1717. \009\009\009\009\009renderScreen(list, selected, confirmation)\
  1718. \009\009\009\009end\
  1719. \009\009\009elseif key == keys.enter then\
  1720. \009\009\009\009return selected\
  1721. \009\009\009end\
  1722. \009\009elseif event == \"back_button\" then\
  1723. \009\009\009return -1\
  1724. \009\009end\
  1725. \009end\
  1726. end\
  1727. local function drawTop()\
  1728. \009local x,y=term.getSize()\
  1729. \009term.setBackgroundColor(colors.white)\
  1730. \009for i=3,9 do\
  1731. \009\009term.setCursorPos(1, i)\
  1732. \009\009term.clearLine()\
  1733. \009end\
  1734. \009for ly=4,7 do\
  1735. \009\009for lx=2, 6 do\
  1736. \009\009\009drawPixel(ly, lx, colors.black)\
  1737. \009\009end\
  1738. \009end\
  1739. end\
  1740. responseTable = getVersion()\
  1741. if responseTable == nil then\
  1742. \009continue = false\
  1743. \009term.clear()\
  1744. \009drawTop()\
  1745. \009term.setCursorPos(8, 4)\
  1746. \009term.setBackgroundColor(colors.white)\
  1747. \009O.cprint(\"Couldn't connect to O\", colors.black)\
  1748. \009term.setCursorPos(1, y)\
  1749. \009if term.isColor() == true then\
  1750. \009\009term.setBackgroundColor(colors.gray)\
  1751. \009\009term.clearLine()\
  1752. \009else\
  1753. \009\009term.setBackgroundColor(colors.black)\
  1754. \009\009term.clearLine()\
  1755. \009end\
  1756. \009centerPrint(\"^\", y, colors.white)\
  1757. \009term.setBackgroundColor(colors.black)\
  1758. \009os.pullEvent(\"key\")\
  1759. end\
  1760. \
  1761. if responseTable[1] == O.getVersionNumber() then\
  1762. \009continue = false\
  1763. \009term.clear()\
  1764. \009drawTop()\
  1765. \009term.setCursorPos(8, 4)\
  1766. \009term.setBackgroundColor(colors.white)\
  1767. \009O.cprint(\"O is up to date\", colors.black)\
  1768. \009term.setCursorPos(1, y)\
  1769. \009if term.isColor() == true then\
  1770. \009\009term.setBackgroundColor(colors.gray)\
  1771. \009\009term.clearLine()\
  1772. \009else\
  1773. \009\009term.setBackgroundColor(colors.black)\
  1774. \009\009term.clearLine()\
  1775. \009end\
  1776. \009centerPrint(\"^\", y, colors.white)\
  1777. \009term.setBackgroundColor(colors.black)\
  1778. \009os.pullEvent(\"key\")\
  1779. end\
  1780. if continue ~= false then\
  1781. while true do\
  1782. \009term.clear()\
  1783. \009drawTop()\
  1784. \009term.setBackgroundColor(colors.white)\
  1785. \009term.setCursorPos(8, 4)\
  1786. \009O.cprint(\"Update Available!\", colors.black)\
  1787. \009term.setCursorPos(8, 6)\
  1788. \009O.cprint(responseTable[1], colors.gray)\
  1789. \009local updateOptions = {\"More Info\", \"Update Now\", \"Cancel\"}\
  1790. \009local output = interactiveOption(updateOptions)\
  1791. \009if output == -1 then\
  1792. \009\009break\
  1793. \009elseif output == 2 then\
  1794. \009\009local file = fs.open(\"/systemO/temp/boot\", \"w\")\
  1795. \009\009file.write(\"update\")\
  1796. \009\009file.close()\
  1797. \009\009os.reboot()\
  1798. \009elseif output == 3 then\
  1799. \009\009break\
  1800. \009elseif output == 1 then\
  1801. \009\009term.setBackgroundColor(colors.white)\
  1802. \009\009for i=9,y do\
  1803. \009\009\009term.setCursorPos(1, i)\
  1804. \009\009\009term.clearLine()\
  1805. \009\009end\
  1806. \009\009term.setCursorPos(1, 9)\
  1807. \009\009for i=4,#responseTable do\
  1808. \009\009\009O.cprint(responseTable[i], colors.black)\
  1809. \009\009end\
  1810. \009\009term.setCursorPos(1, y)\
  1811. \009\009if term.isColor() == true then\
  1812. \009\009\009term.setBackgroundColor(colors.gray)\
  1813. \009\009\009term.clearLine()\
  1814. \009\009else\
  1815. \009\009\009term.setBackgroundColor(colors.black)\
  1816. \009\009\009term.clearLine()\
  1817. \009\009end\
  1818. \009\009centerPrint(\"^\", y, colors.white)\
  1819. \009\009term.setBackgroundColor(colors.black)\
  1820. \009\009os.pullEvent(\"key\")\
  1821. \009end\
  1822. end\
  1823. end\
  1824. \
  1825. term.setBackgroundColor(colors.black)\
  1826. term.clear()\
  1827. term.setCursorPos(1,1)",
  1828. }
Advertisement
Add Comment
Please, Sign In to add comment