minif

settings1.1

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