Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Minif OS Edit Tool
- --Functions and Variables
- osSettingsSelectedUser = mos.osEnteredUser
- local function getUserAdmin(user)
- if fs.exists("/system/user/"..user.."/config") then
- local pref = fs.open("/system/user/"..user.."/config", "r")
- local oldbg = pref.readLine()
- local admin = pref.readLine()
- pref.close()
- if admin == "true" then
- return true
- else
- return false
- end
- else return false end
- end
- local function changeBG(location)
- local pref = fs.open("/system/user/"..mos.osEnteredUser.."/config", "r")
- local oldbg = pref.readLine()
- local admin = pref.readLine()
- pref.close()
- local pref = fs.open("/system/user/"..mos.osEnteredUser.."/config", "w")
- pref.writeLine(location)
- pref.writeLine(admin)
- pref.close()
- end
- local function toggleAdmin(user)
- local pref = fs.open("/system/user/".. user.."/config", "r")
- local oldbg = pref.readLine()
- local admin = pref.readLine()
- pref.close()
- local pref = fs.open("/system/user/"..user.."/config", "w")
- pref.writeLine(oldbg)
- if admin == "true" then
- pref.writeLine("false")
- else
- pref.writeLine("true")
- end
- pref.close()
- end
- local function limitIcon()
- local pref = fs.open("/system/user/"..mos.osEnteredUser.."/icon", "r")
- local line1 = pref.readLine()
- local line2 = pref.readLine()
- local line3 = pref.readLine()
- local line4 = pref.readLine()
- local line5 = pref.readLine()
- local line6 = pref.readLine()
- pref.close()
- local pref = fs.open("/system/user/"..mos.osEnteredUser.."/icon", "w")
- pref.writeLine(string.sub(line1,1,8))
- pref.writeLine(string.sub(line2,1,8))
- pref.writeLine(string.sub(line3,1,8))
- pref.writeLine(string.sub(line4,1,8))
- pref.writeLine(string.sub(line5,1,8))
- pref.writeLine(string.sub(line6,1,8))
- pref.close()
- end
- local function drawWindow()
- mos.osDrawWindow("Settings")
- end
- local function drawMainMenu()
- drawWindow()
- paintutils.drawBox(4,7,mos.osScreenSizeX-3,7,colors.lightBlue)
- term.setTextColor(colors.black)
- term.setCursorPos(5,7)
- term.write("Appearance")
- paintutils.drawBox(4,9,mos.osScreenSizeX-3,9,colors.lightBlue)
- if mos.osUserAdmin == false then
- paintutils.drawBox(4,9,mos.osScreenSizeX-3,9,colors.lightGray)
- end
- term.setTextColor(colors.black)
- term.setCursorPos(5,9)
- term.write("Programs")
- paintutils.drawBox(4,11,mos.osScreenSizeX-3,11,colors.lightBlue)
- term.setTextColor(colors.black)
- term.setCursorPos(5,11)
- term.write("User Management")
- paintutils.drawBox(4,13,mos.osScreenSizeX-3,13,colors.lightBlue)
- if mos.osUserAdmin == false then
- paintutils.drawBox(4,13,mos.osScreenSizeX-3,13,colors.lightGray)
- end
- term.setTextColor(colors.black)
- term.setCursorPos(5,13)
- term.write("OS Management")
- term.setBackgroundColor(colors.red)
- term.setCursorPos(4,mos.osScreenSizeY-3)
- term.write("Exit")
- term.setBackgroundColor(colors.white)
- end
- local function drawAppear()
- drawWindow()
- paintutils.drawFilledBox(4,7,9,9,colors.lightBlue)
- paintutils.drawBox(4,7,9,9,colors.yellow)
- paintutils.drawFilledBox(4,12,9,14,colors.lightBlue)
- paintutils.drawBox(4,12,9,14,colors.black)
- term.setBackgroundColor(colors.white)
- term.setCursorPos(11,8)
- term.write("Background")
- term.setCursorPos(11,13)
- term.write("Icon")
- term.setBackgroundColor(colors.red)
- term.setCursorPos(4,mos.osScreenSizeY-3)
- term.write("Back")
- term.setBackgroundColor(colors.white)
- end
- local function drawAppearChoose(option)
- drawWindow()
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.setCursorPos(5,7)
- if option == 1 then
- term.write("Change Background Image")
- else
- term.write("Change Icon Image")
- end
- paintutils.drawBox(4,9,mos.osScreenSizeX-3,9,colors.lightBlue)
- term.setTextColor(colors.black)
- term.setCursorPos(5,9)
- term.write("Select File")
- paintutils.drawBox(4,11,mos.osScreenSizeX-3,11,colors.lightBlue)
- term.setTextColor(colors.black)
- term.setCursorPos(5,11)
- term.write("Draw Your Own")
- paintutils.drawBox(4,13,mos.osScreenSizeX-3,13,colors.lightBlue)
- term.setTextColor(colors.black)
- term.setCursorPos(5,13)
- term.write("Use Default")
- term.setBackgroundColor(colors.red)
- term.setCursorPos(4,mos.osScreenSizeY-3)
- term.write("Exit")
- term.setBackgroundColor(colors.white)
- end
- local function drawProg()
- drawWindow()
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.setCursorPos(5,7)
- term.write("Manage Software")
- paintutils.drawBox(4,9,mos.osScreenSizeX-3,9,colors.lightBlue)
- term.setTextColor(colors.black)
- term.setCursorPos(5,9)
- term.write("Install Pastebin Code")
- paintutils.drawBox(4,11,mos.osScreenSizeX-3,11,colors.lightBlue)
- term.setTextColor(colors.black)
- term.setCursorPos(5,11)
- term.write("Copy from Disk")
- paintutils.drawBox(4,13,mos.osScreenSizeX-3,13,colors.lightBlue)
- term.setTextColor(colors.black)
- term.setCursorPos(5,13)
- term.write("Manage Software")
- term.setBackgroundColor(colors.red)
- term.setCursorPos(4,mos.osScreenSizeY-3)
- term.write("Back")
- term.setBackgroundColor(colors.white)
- end
- local function drawUser()
- drawWindow()
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.setCursorPos(5,7)
- term.write("Manage User: ".. osSettingsSelectedUser)
- paintutils.drawBox(4,9,mos.osScreenSizeX-3,9,colors.lightBlue)
- term.setTextColor(colors.black)
- term.setCursorPos(5,9)
- term.write("Change Password")
- if mos.osUserAdmin == false then
- paintutils.drawBox(4,11,mos.osScreenSizeX-3,11,colors.lightGray)
- else
- if getUserAdmin(osSettingsSelectedUser) == true then
- paintutils.drawBox(4,11,mos.osScreenSizeX-3,11,colors.green)
- else
- paintutils.drawBox(4,11,mos.osScreenSizeX-3,11,colors.red)
- end
- end
- term.setTextColor(colors.black)
- term.setCursorPos(5,11)
- term.write("Toggle Admin")
- paintutils.drawBox(4,13,mos.osScreenSizeX-3,13,colors.lightBlue)
- if mos.osUserAdmin == false then
- paintutils.drawBox(4,13,mos.osScreenSizeX-3,13,colors.lightGray)
- end
- term.setTextColor(colors.black)
- term.setCursorPos(5,13)
- term.write("Change User")
- term.setBackgroundColor(colors.red)
- term.setCursorPos(4,mos.osScreenSizeY-3)
- term.write("Back")
- term.setBackgroundColor(colors.white)
- end
- local function runUser()
- osSettingsSelectedUser = mos.osEnteredUser
- while true do
- drawUser()
- osPEvent, osPB, osPX, osPY = os.pullEvent("mouse_click")
- if osPX >= 3 and osPX <= mos.osScreenSizeX-2 then
- if osPY == mos.osScreenSizeY-3 and osPX <= 7 then
- return
- else
- if osPY == 9 then
- paintutils.drawBox(4,9,mos.osScreenSizeX-3,9,colors.lightBlue)
- term.setTextColor(colors.black)
- term.setCursorPos(5,9)
- local newpass = read("*")
- paintutils.drawBox(4,9,mos.osScreenSizeX-3,9,colors.lightBlue)
- term.setTextColor(colors.black)
- term.setCursorPos(5,9)
- term.write("Confirm: ")
- local newpassc = read("*")
- if newpass == newpassc then
- local pref = fs.open("/system/user/"..osSettingsSelectedUser.."/.pass", "w")
- pref.writeLine(newpass)
- pref.close()
- else
- paintutils.drawBox(4,9,mos.osScreenSizeX-3,9,colors.red)
- term.setTextColor(colors.black)
- term.setCursorPos(5,9)
- term.write("Passwords do not match!")
- sleep(2)
- end
- else
- if osPY == 11 then
- if mos.osUserAdmin == true then
- if osSettingsSelectedUser == mos.osEnteredUser then
- paintutils.drawBox(4,11,mos.osScreenSizeX-3,11,colors.lightBlue)
- term.setCursorPos(5,11)
- term.write("Cannot disable yourself!")
- sleep(2)
- else
- toggleAdmin(osSettingsSelectedUser)
- end
- else
- osDrawPerm("Toggle Admin")
- end
- else
- if osPY == 13 then
- if mos.osUserAdmin == true then
- paintutils.drawBox(4,13,mos.osScreenSizeX-3,13,colors.lightBlue)
- term.setTextColor(colors.black)
- term.setCursorPos(5,13)
- local newUser = read()
- if fs.isDir("/user/".. newUser) then
- osSettingsSelectedUser = newUser
- else
- local hi = mos.osConfirm("Create User","Are you sure?","Create user: ".. newUser.."?")
- if hi then
- local pref = fs.open("/system/user/".. newUser.."/config", "w")
- pref.writeLine(location)
- pref.writeLine("false")
- pref.close()
- local pref = fs.open("/system/user/".. newUser.."/.pass", "w")
- pref.writeLine("")
- pref.close()
- fs.delete("/user/".. newUser)
- fs.makeDir("/user/".. newUser)
- fs.delete("/system/user/".. newUser.."/icon")
- if fs.exists("system/images/user1") then
- fs.copy("system/images/user1","/system/user/".. newUser.."/icon")
- end
- osSettingsSelectedUser = newUser
- end
- end
- else
- osDrawPerm("Change User")
- end
- end
- end
- end
- end
- end
- end
- end
- local function runProg()
- while true do
- drawProg()
- osPEvent, osPB, osPX, osPY = os.pullEvent("mouse_click")
- if osPX >= 3 and osPX <= mos.osScreenSizeX-2 then
- if osPY == mos.osScreenSizeY-3 and osPX <= 7 then
- return
- else
- if osPY == 9 then
- paintutils.drawBox(4,9,mos.osScreenSizeX-3,9,colors.lightBlue)
- term.setCursorPos(5,9)
- term.write("Code: ")
- local code = read()
- paintutils.drawBox(4,9,mos.osScreenSizeX-3,9,colors.lightBlue)
- term.setCursorPos(5,9)
- term.write("Name: ")
- local name = read()
- mos.osFillBG(colors.black)
- print("Installing from Pastebin:")
- print('pastebin get '..code..' "/apps/'..name..'"')
- shell.run('pastebin get '..code..' "/apps/'..name..'"')
- sleep(2)
- mos.osDrawAll()
- else
- if osPY == 11 then
- paintutils.drawBox(4,11,mos.osScreenSizeX-3,11,colors.lightBlue)
- term.setCursorPos(5,11)
- term.write("Location: ")
- local location = read()
- if fs.exists(location) then
- paintutils.drawBox(4,11,mos.osScreenSizeX-3,11,colors.lightBlue)
- term.setCursorPos(5,11)
- term.write("New Name: ")
- local name = read()
- if fs.exists("apps/"..name) then
- term.setCursorPos(4,mos.osScreenSizeY-3)
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.red)
- term.write("File Exists")
- sleep(2)
- else
- fs.copy(location,"apps/"..name)
- end
- else
- term.setCursorPos(4,mos.osScreenSizeY-3)
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.red)
- term.write("Program Does Not Exist")
- sleep(2)
- end
- else
- if osPY == 13 then
- if fs.exists("system/cores/file") then
- os.loadAPI("/system/cores/file")
- action, name = file.osListFilesAtRoot("/apps/")
- if action == "edit" then
- shell.run('edit "'..name..'"')
- end
- if action == "paint" then
- shell.run('paint "'..name..'"')
- end
- mos.osDrawAll()
- else
- mos.osBSOD("Critical core missing.","/system/cores/file is missing, and is needed to run.","Please re-install this file")
- mos.osDrawAll()
- end
- end
- end
- end
- end
- end
- end
- end
- local function runAppearChoose(option)
- while true do
- drawAppearChoose(option)
- osPEvent, osPB, osPX, osPY = os.pullEvent("mouse_click")
- if osPX >= 3 and osPX <= mos.osScreenSizeX-2 then
- if osPY == mos.osScreenSizeY-3 and osPX <= 7 then
- return
- else
- if osPY == 9 then
- if option == 1 then
- paintutils.drawBox(4,9,mos.osScreenSizeX-3,9,colors.lightBlue)
- term.setCursorPos(5,9)
- local image = read()
- if fs.exists("/user/"..mos.osEnteredUser.."/"..image) then
- changeBG("/user/"..mos.osEnteredUser.."/".. image)
- else
- changeBG("/system/images/minif")
- end
- mos.osLoadPrefs()
- mos.osDrawAll()
- else
- paintutils.drawBox(4,9,mos.osScreenSizeX-3,9,colors.lightBlue)
- term.setCursorPos(5,9)
- local image = read()
- fs.delete("/system/user/"..mos.osEnteredUser.."/icon")
- if fs.exists("/user/"..mos.osEnteredUser.."/"..image) then
- fs.copy("/user/"..mos.osEnteredUser.."/"..image,"/system/user/"..mos.osEnteredUser.."/icon")
- limitIcon()
- end
- mos.osLoadPrefs()
- mos.osDrawAll()
- end
- else
- if osPY == 11 then
- if option == 1 then
- shell.run('paint "/user/'..mos.osEnteredUser..'/background_image"')
- if fs.exists("/user/"..mos.osEnteredUser.."/background_image") then
- changeBG("/user/"..mos.osEnteredUser.."/background_image")
- else
- changeBG("/system/images/minif")
- end
- mos.osLoadPrefs()
- mos.osDrawAll()
- else
- shell.run('paint "/system/user/'..mos.osEnteredUser..'/icon"')
- limitIcon()
- mos.osDrawAll()
- end
- else
- if osPY == 13 then
- if option == 1 then
- changeBG("/system/images/minif")
- mos.osLoadPrefs()
- mos.osDrawAll()
- else
- fs.delete("/system/user/"..mos.osEnteredUser.."/icon")
- if fs.exists("system/images/user1") then
- fs.copy("system/images/user1","/system/user/"..mos.osEnteredUser.."/icon")
- end
- mos.osDrawAll()
- end
- end
- end
- end
- end
- end
- end
- end
- local function runAppear()
- while true do
- drawAppear()
- osPEvent, osPB, osPX, osPY = os.pullEvent("mouse_click")
- if osPX >= 3 and osPX <= mos.osScreenSizeX-2 then
- if osPY == mos.osScreenSizeY-3 and osPX <= 7 then
- return
- else
- if osPY >= 6 and osPY <= 10 then
- runAppearChoose(1)
- else
- if osPY >= 11 and osPY <= 15 then
- runAppearChoose(2)
- end
- end
- end
- end
- end
- end
- local function run()
- while true do
- drawMainMenu()
- osPEvent, osPB, osPX, osPY = os.pullEvent("mouse_click")
- if osPX >= 3 and osPX <= mos.osScreenSizeX-2 then
- if osPY == mos.osScreenSizeY-3 and osPX <= 7 then
- return
- else
- if osPY == 7 then
- runAppear()
- else
- if osPY == 9 then
- if mos.osUserAdmin == true then
- runProg()
- else
- osDrawPerm("Programs")
- end
- else
- if osPY == 11 then
- runUser()
- else
- if osPY == 13 then
- if mos.osUserAdmin == true then
- if fs.exists("system/tools/installer") then
- shell.run("system/tools/installer")
- mos.osDrawAll()
- else
- mos.osBSOD("Critical file missing.","/system/tools/installer is missing, and is needed to run.","Please re-install this file")
- mos.osDrawAll()
- end
- else
- osDrawPerm("OS Management")
- end
- end
- end
- end
- end
- end
- end
- end
- end
- --Execution
- mos.osLoadPrefs()
- drawWindow()
- run()
Add Comment
Please, Sign In to add comment