minif

settings

Jan 23rd, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.11 KB | None | 0 0
  1. --Minif OS Edit Tool
  2.  
  3. --Functions and Variables
  4. osDisableSearch = false
  5. osSettingsSelectedUser = osEnteredUser
  6.  
  7. local function getUserAdmin(user)
  8. if fs.exists("/system/user/"..user.."/config") then
  9. local pref = fs.open("/system/user/"..user.."/config", "r")
  10. local oldbg = pref.readLine()
  11. local admin = pref.readLine()
  12. pref.close()
  13. if admin == "true" then
  14. return true
  15. else
  16. return false
  17. end
  18. else return false end
  19. end
  20.  
  21. local function changeBG(location)
  22. local pref = fs.open("/system/user/"..osEnteredUser.."/config", "r")
  23. local oldbg = pref.readLine()
  24. local admin = pref.readLine()
  25. pref.close()
  26. local pref = fs.open("/system/user/"..osEnteredUser.."/config", "w")
  27. pref.writeLine(location)
  28. pref.writeLine(admin)
  29. pref.close()
  30. end
  31.  
  32. local function toggleAdmin(user)
  33. local pref = fs.open("/system/user/".. user.."/config", "r")
  34. local oldbg = pref.readLine()
  35. local admin = pref.readLine()
  36. pref.close()
  37. local pref = fs.open("/system/user/"..user.."/config", "w")
  38. pref.writeLine(oldbg)
  39. if admin == "true" then
  40. pref.writeLine("false")
  41. else
  42. pref.writeLine("true")
  43. end
  44. pref.close()
  45. end
  46.  
  47. local function limitIcon()
  48. local pref = fs.open("/system/user/"..osEnteredUser.."/icon", "r")
  49. local line1 = pref.readLine()
  50. local line2 = pref.readLine()
  51. local line3 = pref.readLine()
  52. local line4 = pref.readLine()
  53. local line5 = pref.readLine()
  54. local line6 = pref.readLine()
  55. pref.close()
  56. local pref = fs.open("/system/user/"..osEnteredUser.."/icon", "w")
  57. pref.writeLine(string.sub(line1,1,8))
  58. pref.writeLine(string.sub(line2,1,8))
  59. pref.writeLine(string.sub(line3,1,8))
  60. pref.writeLine(string.sub(line4,1,8))
  61. pref.writeLine(string.sub(line5,1,8))
  62. pref.writeLine(string.sub(line6,1,8))
  63. pref.close()
  64. end
  65.  
  66. local function drawWindow()
  67. paintutils.drawFilledBox(3,3,osScreenSizeX-2,osScreenSizeY-2,colors.white)
  68. paintutils.drawBox(3,3,osScreenSizeX-2,5,colors.lightGray)
  69. term.setBackgroundColor(colors.white)
  70. term.setTextColor(colors.black)
  71. term.setCursorPos(4,4)
  72. term.write("Settings")
  73. end
  74.  
  75. local function drawMainMenu()
  76. drawWindow()
  77. paintutils.drawBox(4,7,osScreenSizeX-3,7,colors.lightBlue)
  78. term.setTextColor(colors.black)
  79. term.setCursorPos(5,7)
  80. term.write("Appearance")
  81. paintutils.drawBox(4,9,osScreenSizeX-3,9,colors.lightBlue)
  82. if osUserAdmin == false then
  83. paintutils.drawBox(4,9,osScreenSizeX-3,9,colors.lightGray)
  84. end
  85. term.setTextColor(colors.black)
  86. term.setCursorPos(5,9)
  87. term.write("Programs")
  88. paintutils.drawBox(4,11,osScreenSizeX-3,11,colors.lightBlue)
  89. term.setTextColor(colors.black)
  90. term.setCursorPos(5,11)
  91. term.write("User Management")
  92. paintutils.drawBox(4,13,osScreenSizeX-3,13,colors.lightBlue)
  93. if osUserAdmin == false then
  94. paintutils.drawBox(4,13,osScreenSizeX-3,13,colors.lightGray)
  95. end
  96. term.setTextColor(colors.black)
  97. term.setCursorPos(5,13)
  98. term.write("OS Management")
  99. term.setBackgroundColor(colors.red)
  100. term.setCursorPos(4,osScreenSizeY-3)
  101. term.write("Exit")
  102. end
  103.  
  104. local function drawAppear()
  105. drawWindow()
  106. paintutils.drawFilledBox(4,7,9,9,colors.lightBlue)
  107. paintutils.drawBox(4,7,9,9,colors.yellow)
  108. paintutils.drawFilledBox(4,12,9,14,colors.lightBlue)
  109. paintutils.drawBox(4,12,9,14,colors.black)
  110. term.setBackgroundColor(colors.white)
  111. term.setCursorPos(11,8)
  112. term.write("Background")
  113. term.setCursorPos(11,13)
  114. term.write("Icon")
  115. term.setBackgroundColor(colors.red)
  116. term.setCursorPos(4,osScreenSizeY-3)
  117. term.write("Back")
  118. end
  119.  
  120. local function drawAppearChoose(option)
  121. drawWindow()
  122. term.setBackgroundColor(colors.white)
  123. term.setTextColor(colors.black)
  124. term.setCursorPos(5,7)
  125. if option == 1 then
  126. term.write("Change Background Image")
  127. else
  128. term.write("Change Icon Image")
  129. end
  130. paintutils.drawBox(4,9,osScreenSizeX-3,9,colors.lightBlue)
  131. term.setTextColor(colors.black)
  132. term.setCursorPos(5,9)
  133. term.write("Select File")
  134. paintutils.drawBox(4,11,osScreenSizeX-3,11,colors.lightBlue)
  135. term.setTextColor(colors.black)
  136. term.setCursorPos(5,11)
  137. term.write("Draw Your Own")
  138. paintutils.drawBox(4,13,osScreenSizeX-3,13,colors.lightBlue)
  139. term.setTextColor(colors.black)
  140. term.setCursorPos(5,13)
  141. term.write("Use Default")
  142. term.setBackgroundColor(colors.red)
  143. term.setCursorPos(4,osScreenSizeY-3)
  144. term.write("Exit")
  145. end
  146.  
  147. local function drawProg()
  148. drawWindow()
  149. term.setBackgroundColor(colors.white)
  150. term.setTextColor(colors.black)
  151. term.setCursorPos(5,7)
  152. term.write("Manage Software")
  153. paintutils.drawBox(4,9,osScreenSizeX-3,9,colors.lightBlue)
  154. term.setTextColor(colors.black)
  155. term.setCursorPos(5,9)
  156. term.write("Install Pastebin Code")
  157. paintutils.drawBox(4,11,osScreenSizeX-3,11,colors.lightBlue)
  158. term.setTextColor(colors.black)
  159. term.setCursorPos(5,11)
  160. term.write("Copy from Disk")
  161. paintutils.drawBox(4,13,osScreenSizeX-3,13,colors.lightBlue)
  162. term.setTextColor(colors.black)
  163. term.setCursorPos(5,13)
  164. term.write("Manage Software")
  165. term.setBackgroundColor(colors.red)
  166. term.setCursorPos(4,osScreenSizeY-3)
  167. term.write("Back")
  168. end
  169.  
  170. local function drawUser()
  171. drawWindow()
  172. term.setBackgroundColor(colors.white)
  173. term.setTextColor(colors.black)
  174. term.setCursorPos(5,7)
  175. term.write("Manage User: ".. osSettingsSelectedUser)
  176. paintutils.drawBox(4,9,osScreenSizeX-3,9,colors.lightBlue)
  177. term.setTextColor(colors.black)
  178. term.setCursorPos(5,9)
  179. term.write("Change Password")
  180. if osUserAdmin == false then
  181. paintutils.drawBox(4,11,osScreenSizeX-3,11,colors.lightGray)
  182. else
  183. if getUserAdmin(osSettingsSelectedUser) == true then
  184. paintutils.drawBox(4,11,osScreenSizeX-3,11,colors.green)
  185. else
  186. paintutils.drawBox(4,11,osScreenSizeX-3,11,colors.red)
  187. end
  188. end
  189. term.setTextColor(colors.black)
  190. term.setCursorPos(5,11)
  191. term.write("Toggle Admin")
  192. paintutils.drawBox(4,13,osScreenSizeX-3,13,colors.lightBlue)
  193. if osUserAdmin == false then
  194. paintutils.drawBox(4,13,osScreenSizeX-3,13,colors.lightGray)
  195. end
  196. term.setTextColor(colors.black)
  197. term.setCursorPos(5,13)
  198. term.write("Change User")
  199. term.setBackgroundColor(colors.red)
  200. term.setCursorPos(4,osScreenSizeY-3)
  201. term.write("Back")
  202. end
  203.  
  204. local function runUser()
  205. osSettingsSelectedUser = osEnteredUser
  206. while true do
  207. drawUser()
  208. osPEvent, osPB, osPX, osPY = os.pullEvent("mouse_click")
  209. if osPX >= 3 and osPX <= osScreenSizeX-2 then
  210. if osPY == osScreenSizeY-3 and osPX <= 7 then
  211. return
  212. else
  213. if osPY == 9 then
  214. paintutils.drawBox(4,9,osScreenSizeX-3,9,colors.lightBlue)
  215. term.setTextColor(colors.black)
  216. term.setCursorPos(5,9)
  217. local newpass = read("*")
  218. paintutils.drawBox(4,9,osScreenSizeX-3,9,colors.lightBlue)
  219. term.setTextColor(colors.black)
  220. term.setCursorPos(5,9)
  221. term.write("Confirm: ")
  222. local newpassc = read("*")
  223. if newpass == newpassc then
  224. local pref = fs.open("/system/user/"..osSettingsSelectedUser.."/.pass", "w")
  225. pref.writeLine(newpass)
  226. pref.close()
  227. else
  228. paintutils.drawBox(4,9,osScreenSizeX-3,9,colors.red)
  229. term.setTextColor(colors.black)
  230. term.setCursorPos(5,9)
  231. term.write("Passwords do not match!")
  232. sleep(2)
  233. end
  234. else
  235. if osPY == 11 then
  236. if osUserAdmin == true then
  237. if osSettingsSelectedUser == osEnteredUser then
  238. paintutils.drawBox(4,11,osScreenSizeX-3,11,colors.lightBlue)
  239. term.setCursorPos(5,11)
  240. term.write("Cannot disable yourself!")
  241. sleep(2)
  242. else
  243. toggleAdmin(osSettingsSelectedUser)
  244. end
  245. else
  246. osDrawPerm("Toggle Admin")
  247. end
  248. else
  249. if osPY == 13 then
  250. if osUserAdmin == true then
  251. paintutils.drawBox(4,13,osScreenSizeX-3,13,colors.lightBlue)
  252. term.setTextColor(colors.black)
  253. term.setCursorPos(5,13)
  254. local newUser = read()
  255. if fs.isDir("/user/".. newUser) then
  256. osSettingsSelectedUser = newUser
  257. else
  258. local hi = osConfirm("Create User","Are you sure?","Create user: ".. newUser.."?")
  259. if hi then
  260. local pref = fs.open("/system/user/".. newUser.."/config", "w")
  261. pref.writeLine(location)
  262. pref.writeLine("false")
  263. pref.close()
  264.  
  265. local pref = fs.open("/system/user/".. newUser.."/.pass", "w")
  266. pref.writeLine("")
  267. pref.close()
  268.  
  269. fs.delete("/user/".. newUser)
  270. fs.makeDir("/user/".. newUser)
  271. fs.delete("/system/user/".. newUser.."/icon")
  272. if fs.exists("system/images/user1") then
  273. fs.copy("system/images/user1","/system/user/".. newUser.."/icon")
  274. end
  275. osSettingsSelectedUser = newUser
  276. end
  277. end
  278. else
  279. osDrawPerm("Change User")
  280. end
  281. end
  282. end
  283. end
  284. end
  285. end
  286. end
  287. end
  288.  
  289.  
  290. local function runProg()
  291. while true do
  292. drawProg()
  293. osPEvent, osPB, osPX, osPY = os.pullEvent("mouse_click")
  294. if osPX >= 3 and osPX <= osScreenSizeX-2 then
  295. if osPY == osScreenSizeY-3 and osPX <= 7 then
  296. return
  297. else
  298. if osPY == 9 then
  299. paintutils.drawBox(4,9,osScreenSizeX-3,9,colors.lightBlue)
  300. term.setCursorPos(5,9)
  301. term.write("Code: ")
  302. local code = read()
  303. paintutils.drawBox(4,9,osScreenSizeX-3,9,colors.lightBlue)
  304. term.setCursorPos(5,9)
  305. term.write("Name: ")
  306. local name = read()
  307. osFillBG(colors.black)
  308. print("Installing from Pastebin:")
  309. print('pastebin get '..code..' "/apps/'..name..'"')
  310. shell.run('pastebin get '..code..' "/apps/'..name..'"')
  311. sleep(2)
  312. osDrawAll()
  313. else
  314. if osPY == 11 then
  315. paintutils.drawBox(4,11,osScreenSizeX-3,11,colors.lightBlue)
  316. term.setCursorPos(5,11)
  317. term.write("Location: ")
  318. local location = read()
  319. if fs.exists(location) then
  320. paintutils.drawBox(4,11,osScreenSizeX-3,11,colors.lightBlue)
  321. term.setCursorPos(5,11)
  322. term.write("New Name: ")
  323. local name = read()
  324. if fs.exists("apps/"..name) then
  325. term.setCursorPos(4,osScreenSizeY-3)
  326. term.setBackgroundColor(colors.white)
  327. term.setTextColor(colors.red)
  328. term.write("File Exists")
  329. sleep(2)
  330. else
  331. fs.copy(location,"apps/"..name)
  332. end
  333. else
  334. term.setCursorPos(4,osScreenSizeY-3)
  335. term.setBackgroundColor(colors.white)
  336. term.setTextColor(colors.red)
  337. term.write("Program Does Not Exist")
  338. sleep(2)
  339. end
  340. else
  341. if osPY == 13 then
  342. if fs.exists("system/tools/look") then
  343. osDisableSearch = true
  344. shell.run("system/tools/look")
  345. osDisableSearch = false
  346. osListFiles("/apps/")
  347. osDrawAll()
  348. else
  349. osBSOD("Critical file missing.","/system/tools/look is missing, and is needed to run.","Please re-install this file")
  350. osDrawAll()
  351. end
  352. end
  353. end
  354. end
  355. end
  356. end
  357. end
  358. end
  359.  
  360. local function runAppearChoose(option)
  361. while true do
  362. drawAppearChoose(option)
  363. osPEvent, osPB, osPX, osPY = os.pullEvent("mouse_click")
  364. if osPX >= 3 and osPX <= osScreenSizeX-2 then
  365. if osPY == osScreenSizeY-3 and osPX <= 7 then
  366. return
  367. else
  368. if osPY == 9 then
  369. if option == 1 then
  370. paintutils.drawBox(4,9,osScreenSizeX-3,9,colors.lightBlue)
  371. term.setCursorPos(5,9)
  372. local image = read()
  373. if fs.exists("/user/"..osEnteredUser.."/"..image) then
  374. changeBG("/user/"..osEnteredUser.."/".. image)
  375. else
  376. changeBG("/system/images/minif")
  377. end
  378. osLoadPrefs()
  379. osDrawAll()
  380. else
  381. paintutils.drawBox(4,9,osScreenSizeX-3,9,colors.lightBlue)
  382. term.setCursorPos(5,9)
  383. local image = read()
  384. fs.delete("/system/user/"..osEnteredUser.."/icon")
  385. if fs.exists("/user/"..osEnteredUser.."/"..image) then
  386. fs.copy("/user/"..osEnteredUser.."/"..image,"/system/user/"..osEnteredUser.."/icon")
  387. limitIcon()
  388. end
  389. osLoadPrefs()
  390. osDrawAll()
  391. end
  392. else
  393. if osPY == 11 then
  394. if option == 1 then
  395. shell.run('paint "/user/'..osEnteredUser..'/background_image"')
  396. if fs.exists("/user/"..osEnteredUser.."/background_image") then
  397. changeBG("/user/"..osEnteredUser.."/background_image")
  398. else
  399. changeBG("/system/images/minif")
  400. end
  401. osLoadPrefs()
  402. osDrawAll()
  403. else
  404. shell.run('paint "/system/user/'..osEnteredUser..'/icon"')
  405. limitIcon()
  406. osDrawAll()
  407. end
  408. else
  409. if osPY == 13 then
  410. if option == 1 then
  411. changeBG("/system/images/minif")
  412. osLoadPrefs()
  413. osDrawAll()
  414. else
  415. fs.delete("/system/user/"..osEnteredUser.."/icon")
  416. if fs.exists("system/images/user1") then
  417. fs.copy("system/images/user1","/system/user/"..osEnteredUser.."/icon")
  418. end
  419. osDrawAll()
  420. end
  421. end
  422. end
  423. end
  424. end
  425. end
  426. end
  427. end
  428.  
  429. local function runAppear()
  430. while true do
  431. drawAppear()
  432. osPEvent, osPB, osPX, osPY = os.pullEvent("mouse_click")
  433. if osPX >= 3 and osPX <= osScreenSizeX-2 then
  434. if osPY == osScreenSizeY-3 and osPX <= 7 then
  435. return
  436. else
  437. if osPY >= 6 and osPY <= 10 then
  438. runAppearChoose(1)
  439. else
  440. if osPY >= 11 and osPY <= 15 then
  441. runAppearChoose(2)
  442. end
  443. end
  444. end
  445. end
  446. end
  447. end
  448.  
  449. local function run()
  450. while true do
  451. drawMainMenu()
  452. osPEvent, osPB, osPX, osPY = os.pullEvent("mouse_click")
  453. if osPX >= 3 and osPX <= osScreenSizeX-2 then
  454. if osPY == osScreenSizeY-3 and osPX <= 7 then
  455. return
  456. else
  457. if osPY == 7 then
  458. runAppear()
  459. else
  460. if osPY == 9 then
  461. if osUserAdmin == true then
  462. runProg()
  463. else
  464. osDrawPerm("Programs")
  465. end
  466. else
  467. if osPY == 11 then
  468. runUser()
  469. else
  470. if osPY == 13 then
  471. if osUserAdmin == true then
  472. if fs.exists("system/tools/installer") then
  473. shell.run("system/tools/installer")
  474. osDrawAll()
  475. else
  476. osBSOD("Critical file missing.","/system/tools/installer is missing, and is needed to run.","Please re-install this file")
  477. osDrawAll()
  478. end
  479. else
  480. osDrawPerm("OS Management")
  481. end
  482. end
  483. end
  484. end
  485. end
  486. end
  487. end
  488. end
  489. end
  490.  
  491. --Execution
  492.  
  493. osLoadPrefs()
  494. drawWindow()
  495. run()
Add Comment
Please, Sign In to add comment