Advertisement
Guest User

OS

a guest
Jul 16th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.71 KB | None | 0 0
  1. function cleer()
  2.   term.setCursorPos(1,1)
  3.   term.setBackgroundColor(colors.black)
  4.   term.setTextColor(colors.white)
  5.   term.clear()
  6. end
  7.  
  8. if fs.exists("saves") then
  9.   print("yes")
  10.   sleep(1)
  11. else
  12.   fs.makeDir("saves")
  13.   fs.makeDir("saves/OS")
  14.   fs.open("saves/OS/accounts","w")
  15.   print("no but i made one")
  16.   sleep(1)
  17. end
  18.  
  19. function rCreateFile(User,y)
  20.   cleer()
  21.   local fileList = fs.list("saves/"..User.."/Desktop")
  22.   local fileContents = {}
  23.   local internalNum2 = 1
  24.   for _,file2 in ipairs(fileList) do
  25.     print(file2)
  26.     table.insert(fileContents,internalNum2,file2)
  27.     internalNum2 = internalNum2 + 1
  28.   end
  29.   term.setCursorPos(1,y)
  30.   term.setBackgroundColor(colors.gray)
  31.   write("                                                 ")
  32.   term.setCursorPos(1,y)
  33.   local input = read()
  34.   local file = fs.open("saves/"..User.."/Desktop/"..input,"w")
  35.   file.close()
  36. end
  37.  
  38. function rRenameFile(User,y,fName)
  39.   cleer()
  40.   local fileList = fs.list("saves/"..User.."/Desktop")
  41.   local fileContents = {}
  42.   local internalNum2 = 1
  43.   for _,file2 in ipairs(fileList) do
  44.     print(file2)
  45.     table.insert(fileContents,internalNum2,file2)
  46.     internalNum2 = internalNum2 + 1
  47.   end
  48.   term.setCursorPos(1,y)
  49.   term.setBackgroundColor(colors.gray)
  50.   write("                                                 ")
  51.   term.setCursorPos(1,y)
  52.   local input = read()
  53.   fs.move("saves/"..User.."/Desktop/"..fName,"saves/"..User.."/Desktop/"..input)
  54. end
  55.  
  56.  
  57. function rOpt(User,x,y,fName)
  58.   term.setCursorPos(x+1,y)
  59.   term.setBackgroundColor(colors.gray)
  60.   write("New   ")
  61.   term.setCursorPos(x+1,y+1)
  62.   write("Rename")
  63.   term.setCursorPos(x+1,y+2)
  64.   write("Delete")
  65.   local event,button,x1,y1 = os.pullEvent("mouse_click")
  66.   if x1 >= x+1 and x1 <= x+7 and y1 == y then
  67.     rCreateFile(User,y)
  68.   elseif x1 >= x+1 and x1 <= x+7 and y1 == y+1 then
  69.     rRenameFile(User,y,fName)
  70.   elseif x1 >= x+1 and x1 <= x+7 and y1 == y+2 then
  71.     fs.delete("saves/"..User.."/Desktop/"..fName)
  72.   end
  73. end
  74.  
  75. function rFile(fName,User)
  76.   cleer()
  77.   local tContents = {}
  78.   local internalNum = 1
  79.   local file = fs.open("saves/"..User.."/Desktop/"..fName,"r")
  80.   for line in file.readLine do
  81.     table.insert(tContents,internalNum,line)
  82.     print(tContents[internalNum])
  83.     internalNum = internalNum + 1
  84.   end
  85.   file.close()
  86.   term.setCursorPos(1,19)
  87.   write(">Back")
  88.   local event,button,x,y = os.pullEvent("mouse_click")
  89.   if y < 19 then
  90.     term.setCursorPos(1,y)
  91.     term.setBackgroundColor(colors.gray)
  92.     term.write("                                ")
  93.     term.setCursorPos(1,y)
  94.     local input = read()
  95.     table.remove(tContents,y)
  96.     table.insert(tContents,y,input)
  97.     local file2 = fs.open("saves/"..User.."/Desktop/"..fName,"w")
  98.     for i,v in ipairs(tContents) do
  99.       file2.writeLine(v)
  100.     end
  101.     file2.close()
  102.     rFile(fName,User)
  103.   end
  104. end
  105.  
  106. function login(User)
  107.   cleer()
  108.   write("Password: ")
  109.   local Pass = read("*")
  110.   local file = fs.open("saves/"..User.."/info","r")
  111.   inputPass = file.readLine()
  112.   file.close()
  113.   cleer()
  114.   if inputPass == Pass then
  115.     local cUserFile = fs.open("saves/OS/cUser","w")
  116.     cUserFile.writeLine(User)
  117.     cUserFile.close()
  118.   else
  119.     cleer()
  120.     term.setTextColor(colors.red)
  121.     write("Incorrect.")
  122.     sleep(2)
  123.     os.reboot()
  124.   end
  125. end
  126.  
  127. function makeAcc()
  128.   cleer()
  129.   write("Username: ")
  130.   local Username = read()
  131.   if fs.exists("saves/"..Username) then
  132.     cleer()
  133.     term.setTextColor(colors.red)
  134.     write("Account already exists")
  135.     os.reboot()
  136.   end
  137.   term.setCursorPos(1,2)
  138.   write("Password: ")
  139.   local Pass = read("*")
  140.   fs.makeDir("saves/"..Username)
  141.   fs.makeDir("saves/"..Username.."/desktop")
  142.   local readmeFile = fs.open("saves/"..Username.."/desktop/ReadMe","w")
  143.   local tContents = {"You are currently viewing a text file","Press the back button to go back","Once you are back you can","right click to get more options"}
  144.   for i,v in ipairs(tContents) do
  145.     readmeFile.writeLine(v)
  146.   end
  147.   readmeFile.close()
  148.   local file = fs.open("saves/"..Username.."/info","w")
  149.   file.writeLine(Pass)
  150.   file.close()
  151.   cleer()
  152.   write("Rebooting")
  153.   sleep(1)
  154.   os.reboot()
  155. end
  156.  
  157. cleer()
  158. local width, height = term.getSize()
  159. term.setCursorPos(math.floor(width-string.len("Welcome"))/2,1)
  160. print("Welcome")
  161. term.setCursorPos(1,2)
  162.  
  163. local FileList = fs.list("saves")
  164. local menuContents = {}
  165. local internalNum = 1
  166. for _,file in ipairs(FileList) do
  167.   print(file)
  168.   table.insert(menuContents, internalNum, file)
  169.   internalNum = internalNum + 1
  170. end
  171.  
  172. term.setCursorPos(1,19)
  173. write("Create Account")
  174. local event,button,x,y = os.pullEvent("mouse_click")
  175. if x <= string.len("Create Account") and y == 19 then
  176.   cleer()
  177.   makeAcc()
  178. elseif x <= string.len(menuContents[y-1]) then
  179.   local User = tostring(menuContents[y-1])
  180.   if User == "OS" then
  181.     cleer()
  182.     term.setTextColor(colors.red)
  183.     write("Access Denied.")
  184.     sleep(2)
  185.     os.reboot()
  186.   else
  187.     login(User)
  188.   end
  189. end
  190.  
  191. while true do
  192.   cleer()
  193.   local cUser = fs.open("saves/OS/cUser","r")
  194.   local User = cUser.readLine()
  195.   cUser.close()
  196.   local fileList = fs.list("saves/"..User.."/desktop")
  197.   local fileContents = {}
  198.   local internalNum2 = 1
  199.   for _,file2 in ipairs(fileList) do
  200.     table.insert(fileContents,internalNum2,file2)
  201.     print(fileContents[internalNum2])
  202.     internalNum2 = internalNum2 + 1
  203.   end
  204.   term.setCursorPos(1,19)
  205.   write("Sign Off")
  206.   local event,button,x,y = os.pullEvent("mouse_click")
  207.   if button == 1 and y < 19 then
  208.     local fName = tostring(fileContents[y])
  209.     rFile(fName,User)
  210.   elseif button == 2 and y < 19 then
  211.     local fName = tostring(fileContents[y])
  212.     rOpt(User,x,y,fName)
  213.   elseif button == 1 and y == 19 then
  214.     os.reboot()
  215.   end
  216. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement