MaximumFrank

ui

Mar 25th, 2016
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.11 KB | None | 0 0
  1. function changeLock(uname)
  2. func.clear(uname)
  3. local lSel = 1
  4. local i = 0
  5. local lockz = true
  6.  
  7. while lockz do
  8. local menu = {"Back", "10 Seconds", "20 Seconds", "30 Seconds", "40 Seconds", "50 Seconds", "60 Seconds"}
  9. tMenu = menu
  10.  
  11. func.drawRect(1, 1, w, 1, tbCol)
  12. func.drawCenteredX("Choose New Lockout Time", 1, tbCol, txCol)
  13. func.drawTableCentered(menu, tbxCol, txCol, lSel, uname)
  14.  
  15. local keyPress = func.getMenuKey()
  16.  
  17. if keyPress ~=2 then
  18. if (keyPress == 1 and lSel > 1) or (keyPress == -1 and lSel < #menu) then
  19. lSel = lSel - keyPress
  20. end
  21. else
  22. local file = fs.open(usrPath .. uname .. "/settings", "r")
  23. local data = file.readAll()
  24. file.close()
  25.  
  26. os.loadAPI(usrPath .. uname .. "/settings")
  27. local curTime = settings.lockout
  28. os.unloadAPI(usrPath .. uname .. "/settings")
  29.  
  30. if lSel == 1 then
  31. lockz = false
  32. elseif lSel == 2 then
  33. newTime = 10
  34. elseif lSel == 3 then
  35. newTime = 20
  36. elseif lSel == 4 then
  37. newTime = 30
  38. elseif lSel == 5 then
  39. newTime = 40
  40. elseif lSel == 6 then
  41. newTime = 50
  42. elseif lSel == 7 then
  43. newTime = 60
  44. end
  45.  
  46. data = string.gsub(data, "lockout = " .. curTime, "lockout = " .. newTime)
  47. file = fs.open(usrPath .. uname .. "/settings", "w")
  48. file.write(data)
  49. file.close()
  50. lockz = false
  51. end
  52. end
  53. end
  54.  
  55. function users(uname)
  56. func.clear(uname)
  57. local lSel = 1
  58. local i = 0
  59. local use = true
  60.  
  61. os.unloadAPI(regPath .. "usr")
  62. local file = fs.open(regPath .. "usr", "r")
  63. local data = file.readAll()
  64. file.close()
  65.  
  66. local menu = {}
  67.  
  68. while use do
  69. --is an admin
  70. if string.find(data, uname .. " = 2") then
  71.  
  72. menu = {"Back", "Change Password", "Lockout Time", "Add User", "Remove User"}
  73. --is not an admin
  74. else
  75. menu = {"Back", "Change Password", "Lockout Time"}
  76. end
  77.  
  78. func.drawRect(1, 1, w, 1, tbCol)
  79. func.drawCenteredX("User Settings", 1, tbCol, txCol)
  80. func.drawTableCentered(menu, tbxCol, txCol, lSel, uname)
  81.  
  82. local keyPress = func.getMenuKey()
  83.  
  84. if keyPress ~=2 then
  85. if (keyPress == 1 and lSel > 1) or (keyPress == -1 and lSel < #menu) then
  86. lSel = lSel - keyPress
  87. end
  88. else
  89. if lSel == 1 then
  90. use = false
  91. --change password
  92. elseif lSel == 2 then
  93. func.clear(uname)
  94. cred.pChange(uname)
  95. --change lockout time
  96. elseif lSel == 3 then
  97. changeLock(uname)
  98. func.clear(uname)
  99. --add user
  100. elseif lSel == 4 then
  101. if uname == "Admin" or cred.verify(uname) then
  102. cred.register()
  103. end
  104. func.clear(uname)
  105. --remove user
  106. elseif lSel == 5 then
  107. cred.remove(uname)
  108. func.clear(uname)
  109. end
  110. end
  111. end
  112. end
  113.  
  114. function colorChoose(uname)
  115. func.clear(uname)
  116. local lSel = 1
  117. local i = 0
  118. local col = true
  119.  
  120. while col do
  121. menu = {"Back", "White", "Orange", "Magenta", "Light Blue", "Yellow", "Lime", "Pink", "Gray", "Light Gray", "Cyan", "Purple", "Blue", "Brown", "Green", "Red", "Black"}
  122. tMenu = menu
  123.  
  124. func.drawRect(1, 1, w, 1, tbCol)
  125. func.drawCenteredX("Choose a Color", 1, tbCol, txCol)
  126. func.drawTableCentered(menu, tbxCol, txCol, lSel, uname)
  127.  
  128. local keyPress = func.getMenuKey()
  129.  
  130. if keyPress ~=2 then
  131. if (keyPress == 1 and lSel > 1) or (keyPress == -1 and lSel < #menu) then
  132. lSel = lSel - keyPress
  133. end
  134. else
  135. if lSel == 1 then
  136. local cols = {func.getCol(uname)}
  137. func.clear(uname)
  138. return cols[5]
  139. --white
  140. elseif lSel == 2 then
  141. func.clear(uname)
  142. return colors.white
  143. --orange
  144. elseif lSel == 3 then
  145. func.clear(uname)
  146. return colors.orange
  147. --magenta
  148. elseif lSel == 4 then
  149. func.clear(uname)
  150. return colors.magenta
  151. --light blue
  152. elseif lSel == 5 then
  153. func.clear(uname)
  154. return colors.lightBlue
  155. --yellow
  156. elseif lSel == 6 then
  157. func.clear(uname)
  158. return colors.yellow
  159. --lime
  160. elseif lSel == 7 then
  161. func.clear(uname)
  162. return colors.lime
  163. --pink
  164. elseif lSel == 8 then
  165. func.clear(uname)
  166. return colors.pink
  167. --gray
  168. elseif lSel == 9 then
  169. func.clear(uname)
  170. return colors.gray
  171. --light gray
  172. elseif lSel == 10 then
  173. func.clear(uname)
  174. return colors.lightGray
  175. --cyan
  176. elseif lSel == 11 then
  177. func.clear(uname)
  178. return colors.cyan
  179. --purple
  180. elseif lSel == 12 then
  181. func.clear(uname)
  182. return colors.purple
  183. --blue
  184. elseif lSel == 13 then
  185. func.clear(uname)
  186. return colors.blue
  187. --brown
  188. elseif lSel == 14 then
  189. func.clear(uname)
  190. return colors.brown
  191. --green
  192. elseif lSel == 15 then
  193. func.clear(uname)
  194. return colors.green
  195. --red
  196. elseif lSel == 16 then
  197. func.clear(uname)
  198. return colors.red
  199. --black
  200. elseif lSel == 17 then
  201. func.clear(uname)
  202. return colors.black
  203. end
  204. end
  205. end
  206. end
  207.  
  208. function colSet(uname, tb, bg, tx, tbx, stx)
  209. local file = fs.open(usrPath .. uname .. "/settings", "r")
  210. local data = file.readAll()
  211. file.close()
  212.  
  213. os.loadAPI(usrPath .. uname .. "/settings")
  214.  
  215. data = string.gsub(data, "tbCol = " .. settings.tbCol, "tbCol = " .. tb)
  216. data = string.gsub(data, "bgCol = " .. settings.bgCol, "bgCol = " .. bg)
  217. data = string.gsub(data, "txCol = " .. settings.txCol, "txCol = " .. tx)
  218. data = string.gsub(data, "tbxCol = " .. settings.tbxCol, "tbxCol = " .. tbx)
  219. data = string.gsub(data, "stxCol = " .. settings.stxCol, "stxCol = " .. stx)
  220.  
  221. os.unloadAPI(usrPath .. uname .. "/settings")
  222.  
  223. file = fs.open(usrPath .. uname .. "/settings", "w")
  224. file.write(data)
  225. file.close()
  226. end
  227.  
  228. function color(uname)
  229. func.clear(uname)
  230. local lSel = 1
  231. local i = 0
  232. local col = true
  233.  
  234. while col do
  235. if params.locale == "US" then
  236. menu = {"Back", "Taskbar Color", "Text Color", "Background Color", "Menu Color", "Selected Text Color"}
  237. else
  238. menu = {"Back", "Taskbar Colour", "Text Colour", "Background Colour", "Menu Colour", "Selected Text Colour"}
  239. end
  240.  
  241. tMenu = menu
  242.  
  243. func.drawRect(1, 1, w, 1, tbCol)
  244. func.drawCenteredX("Color Settings", 1, tbCol, txCol)
  245. func.drawTableCentered(menu, tbxCol, txCol, lSel, uname)
  246.  
  247. local keyPress = func.getMenuKey()
  248.  
  249. if keyPress ~=2 then
  250. if (keyPress == 1 and lSel > 1) or (keyPress == -1 and lSel < #menu) then
  251. lSel = lSel - keyPress
  252. end
  253. else
  254. if lSel == 1 then
  255. col = false
  256. --taskbar color
  257. elseif lSel == 2 then
  258. tbCol = colorChoose(uname)
  259. colSet(uname, tbCol, bgCol, txCol, tbxCol, stxCol)
  260. func.clear(uname)
  261. --text color
  262. elseif lSel == 3 then
  263. txCol = colorChoose(uname)
  264. colSet(uname, tbCol, bgCol, txCol, tbxCol, stxCol)
  265. func.clear(uname)
  266. --background color
  267. elseif lSel == 4 then
  268. bgCol = colorChoose(uname)
  269. colSet(uname, tbCol, bgCol, txCol, tbxCol, stxCol)
  270. func.clear(uname)
  271. --menu color
  272. elseif lSel == 5 then
  273. tbxCol = colorChoose(uname)
  274. colSet(uname, tbCol, bgCol, txCol, tbxCol, stxCol)
  275. func.clear(uname)
  276. elseif lSel == 6 then
  277. stxCol = colorChoose(uname)
  278. colSet(uname, tbCol, bgCol, txCol, tbxCol, stxCol)
  279. func.clear(uname)
  280. end
  281. end
  282. end
  283. end
  284.  
  285. function programs(uname)
  286. func.clear(uname)
  287. local menu = prg.progs
  288. func.drawRect(1, 1, w, 1, tbCol)
  289. func.drawCenteredX("Programs", 1, tbCol, txCol)
  290.  
  291. local lSel = 1
  292. local doit = true
  293.  
  294. while doit do
  295. func.clear(uname)
  296. func.drawTableCentered(menu, tbxCol, txCol, lSel, uname)
  297.  
  298. local keyPress = func.getMenuKey()
  299.  
  300. if keyPress ~=2 then
  301. if (keyPress == 1 and lSel > 1) or (keyPress == -1 and lSel < #menu) then
  302. lSel = lSel - keyPress
  303. end
  304. else
  305. if lSel == 1 then
  306. doit = false
  307. --taskbar color
  308. elseif lSel == 2 then
  309. func.clear(uname)
  310. os.run({prgPath}, prgPath .. 'calcPlus')
  311. --text color
  312. elseif lSel == 3 then
  313. func.clear(uname)
  314. os.run({}, prgPath .. "ink")
  315. elseif lSel == 4 then
  316. func.clear(uname)
  317. os.run({rootPath}, prgPath .. "luaIDE")
  318. end
  319. end
  320. end
  321. end
  322.  
  323. function recover(uname)
  324. func.clear(uname)
  325.  
  326. local lSel = 1
  327. local doit = true
  328.  
  329. menu = {"Back", "Keep User Data", "Lose User Data"}
  330.  
  331. func.drawRect(1, 1, w, 1, tbCol)
  332. func.drawCenteredX("Recovery Options", 1, tbCol, txCol)
  333. while doit do
  334. func.drawTableCentered(menu, tbxCol, txCol, lSel, uname)
  335.  
  336. local keyPress = func.getMenuKey()
  337.  
  338. if keyPress ~=2 then
  339. if (keyPress == 1 and lSel > 1) or (keyPress == -1 and lSel < #menu) then
  340. lSel = lSel - keyPress
  341. end
  342. else
  343. if lSel == 1 then
  344. doit = false
  345. --taskbar color
  346. elseif lSel == 2 then
  347. recovery.recover(1)
  348. func.clear(uname)
  349. --text color
  350. elseif lSel == 3 then
  351. recovery.recover(2)
  352. func.clear(uname)
  353. end
  354. end
  355. end
  356. end
  357.  
  358. function set(uname)
  359. tbCol, tbxCol, txCol, bgCol, stxCol = func.getCol(uname)
  360. func.clear(uname)
  361. local lSel = 1
  362. local i = 0
  363. local doit = true
  364.  
  365. while doit do
  366. func.clear(uname)
  367. local menu = {}
  368. if params.locale == "US" then
  369. menu = {"Back", "Users", "Colors", "Recovery"}
  370. tMenu = menu
  371. else
  372. menu = {"Back", "Users", "Colours", "Recovery"}
  373. tMenu = menu
  374. end
  375.  
  376. func.drawRect(1, 1, w, 1, tbCol)
  377. func.drawCenteredX("Settings", 1, tbCol, txCol)
  378. func.drawTableCentered(menu, tbxCol, txCol, lSel, uname)
  379.  
  380. local keyPress = func.getMenuKey()
  381.  
  382. if keyPress ~=2 then
  383. if (keyPress == 1 and lSel > 1) or (keyPress == -1 and lSel < #menu) then
  384. lSel = lSel - keyPress
  385. end
  386. else
  387. if lSel == 1 then
  388. doit = false
  389. --users
  390. elseif lSel == 2 then
  391. func.clear(uname)
  392. users(uname)
  393. --colors
  394. elseif lSel == 3 then
  395. func.clear(uname)
  396. color(uname)
  397. --recovery
  398. elseif lSel == 4 then
  399. func.clear(uname)
  400. recover(uname)
  401. end
  402. end
  403. end
  404. end
  405.  
  406. function logged(uname)
  407. os.loadAPI(usrPath .. uname .. "/settings")
  408. bgCol = settings.bgCol
  409. tbCol = settings.tbCol
  410. txCol = settings.txCol
  411. tbxCol = settings.tbxCol
  412. stxCol = settings.stxCol
  413. _G.lockTime = settings.lockout
  414. os.unloadAPI(usrPath .. uname .. "/settings")
  415.  
  416. _G.lockout = os.startTimer(lockTime)
  417.  
  418. func.clear(uname)
  419.  
  420. local lSel = 1
  421. local i = 0
  422. local log = true
  423.  
  424. while log do
  425. local menu = {"Programs", "Settings", "Logout", "Shutdown", "Restart"}
  426. local tMenu = menu
  427.  
  428. func.drawRect(1, 1, w, 1, tbCol)
  429. func.drawCenteredX("Logged in as " .. uname, 1, tbCol, txCol)
  430. func.drawTableCentered(menu, tbxCol, txCol, lSel, uname)
  431.  
  432. local keyPress = func.getMenuKey()
  433.  
  434. if keyPress ~=2 then
  435. if (keyPress == 1 and lSel > 1) or (keyPress == -1 and lSel < #menu) then
  436. os.cancelTimer(lockout)
  437. lockout = os.startTimer(lockTime)
  438. lSel = lSel - keyPress
  439. elseif keyPress == 3 then
  440. os.cancelTimer(lockout)
  441. lockout = os.startTimer(lockTime)
  442. tbCol, tbxCol, txCol, bgCol, stxCol = func.resetCol()
  443. func.clear(uname)
  444. log = false
  445. end
  446. else
  447. --programs
  448. if lSel == 1 then
  449. programs(uname)
  450. func.clear(uname)
  451. --settings
  452. elseif lSel == 2 then
  453. set(uname)
  454. tbCol, tbxCol, txCol, bgCol, stxCol = func.getCol(uname)
  455. func.clear(uname)
  456. os.cancelTimer(lockout)
  457. lockout = os.startTimer(lockTime)
  458. --logout
  459. elseif lSel == 3 then
  460. tbCol, tbxCol, txCol, bgCol, stxCol = func.resetCol()
  461. func.clear(uname)
  462. log = false
  463. --shutdown
  464. elseif lSel == 4 then
  465. func.shutdown()
  466. --restart
  467. elseif lSel == 5 then
  468. func.restart()
  469. end
  470. end
  471. end
  472. end
  473.  
  474. function main()
  475. local mainSel = 1
  476. local i = 0
  477. local doit = true
  478.  
  479. while doit do
  480. local menu = {"Login", "Shutdown"}
  481. local tMenu = menu
  482.  
  483. func.drawRect(1, 1, w, 1, tbCol)
  484. func.drawCenteredX("Welcome to TestOS", 1, tbCol, txCol)
  485. func.drawTableCentered(menu, tbxCol, txCol, mainSel)
  486.  
  487. local keyPress = func.getMenuKey()
  488.  
  489. if keyPress ~= 2 then
  490. if (keyPress == 1 and mainSel > 1) or (keyPress == -1 and mainSel < #menu) then
  491. mainSel = mainSel - keyPress
  492. end
  493. else
  494. --login
  495. if mainSel == 1 then
  496. local log, uname = cred.login()
  497. if log then
  498. logged(uname)
  499. end
  500. --register
  501. elseif mainSel == 2 then
  502. cred.register()
  503. --shutdown
  504. elseif mainSel == 3 then
  505. func.shutdown()
  506. end
  507. end
  508. tbCol, tbxCol, txCol, bgCol, stxCol = func.resetCol()
  509. func.clear()
  510. end
  511. end
Add Comment
Please, Sign In to add comment