Advertisement
superkh

A conf

Jan 8th, 2016
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.77 KB | None | 0 0
  1. function getT(src)
  2.       local file = fs.open(src,"r")
  3.       local data = file.readAll()
  4.       file.close()
  5.       local conf = textutils.unserialize(data)
  6.       return conf
  7. end
  8. function setT(src,save)
  9.       local file = fs.open(src,"w")
  10.       file.write(textutils.serialize(save))
  11.       file.close()
  12. end
  13. --vars------------------------------------------------------------------
  14. local w,h = term.getSize()
  15. local conf = getT("os/files/config")
  16. local Cpath = nil
  17. local User = nil
  18. local code = conf["CODE"]
  19. local ver = conf["VER"]
  20. local Exit = nil
  21. ---MEUNS-------------------------------------------------------------------
  22. function LoadConf(Uin)
  23.     User = Uin
  24.     Cpath = "os/users/"..User.."/Uconfig"
  25.     conf = getT(Cpath)
  26. end
  27. function ExitIS(Set,value)
  28.     if Set then
  29.         Exit = value
  30.     else
  31.         return Exit
  32.     end
  33. end
  34. function RCpath()
  35.     return Cpath
  36. end
  37. function RUser()
  38.     return User
  39. end
  40. --Load meuns--
  41. local function meun1()
  42.   buf.bc(conf["SMC"])
  43.   buf.tc(conf["SMTC"])
  44.   xy = buf.getSizeBuff(bmeun1)
  45.   buf.pos(1,1)
  46.   buf.bWriteL(bmeun1,"+==========+")
  47.   buf.pos(1,2)
  48.   buf.bWriteL(bmeun1,"| Sign Out |")
  49.   buf.pos(1,3)
  50.   buf.bWriteL(bmeun1,"| ShutDown |")
  51.   buf.pos(1,4)
  52.   buf.bWriteL(bmeun1,"|  ReBoot  |")
  53.   buf.pos(1,5)
  54.   buf.bWriteL(bmeun1,"|  Manage  |")
  55.   buf.pos(1,6)
  56.   buf.bWriteL(bmeun1,"|  Config  |")
  57.   buf.pos(1,7)
  58.   buf.bWriteL(bmeun1,"+==========+")
  59. end
  60. local function meun2()
  61.   buf.bc(conf["SMC"])
  62.   buf.tc(conf["SMTC"])
  63.   buf.pos(1,1)
  64.   buf.bWriteL(bmeun2,"+==========+")
  65.   buf.pos(1,2)
  66.   buf.bWriteL(bmeun2,"| Add Icon |")
  67.   buf.pos(1,3)
  68.   buf.bWriteL(bmeun2,"| New Prog.|")
  69.   buf.pos(1,4)
  70.   buf.bWriteL(bmeun2,"| New Icon |")
  71.   buf.pos(1,5)
  72.   buf.bWriteL(bmeun2,"|   Help   |")
  73.   buf.pos(1,6)
  74.   buf.bWriteL(bmeun2,"+==========+")
  75. end
  76. local function meun3()
  77.     buf.bc(conf["SMC"])
  78.     buf.tc(conf["SMTC"])
  79.     buf.pos(1,1)
  80.     buf.bWriteL(bmeun3,"+============+")
  81.     buf.pos(1,2)
  82.     buf.bWriteL(bmeun3,"| Change Img |")
  83.     buf.pos(1,3)
  84.     buf.bWriteL(bmeun3,"|  Programs  |")
  85.     buf.pos(1,4)
  86.     buf.bWriteL(bmeun3,"|   Remove   |")
  87.     buf.pos(1,5)
  88.     buf.bWriteL(bmeun3,"+============+")
  89. end
  90. local function meun4()
  91.     buf.bc(conf["SMC"])
  92.     buf.tc(conf["SMTC"])
  93.     buf.pos(1,1)
  94.     buf.bWriteL(bmeun4,"+========+")
  95.     buf.pos(1,2)
  96.     buf.bWriteL(bmeun4,"|  Edit  |")
  97.     buf.pos(1,3)
  98.     buf.bWriteL(bmeun4,"| Remove |")
  99.     buf.pos(1,4)
  100.     buf.bWriteL(bmeun4,"+========+")
  101. end
  102. local function meun5()
  103.   buf.bc(conf["SMC"])
  104.   buf.tc(conf["SMTC"])
  105.   buf.pos(1,1)
  106.   buf.bWriteL(bmeun5,"+==========+")
  107.   buf.pos(1,2)
  108.   buf.bWriteL(bmeun5,"| Sign Out |")
  109.   buf.pos(1,3)
  110.   buf.bWriteL(bmeun5,"| ShutDown |")
  111.   buf.pos(1,4)
  112.   buf.bWriteL(bmeun5,"|  ReBoot  |")
  113.   buf.pos(1,5)
  114.   buf.bWriteL(bmeun5,"|   Back   |")
  115.   buf.pos(1,6)
  116.   buf.bWriteL(bmeun5,"+==========+")
  117. end
  118. local function meun6()
  119.     buf.bc(conf["SMC"])
  120.     buf.tc(conf["SMTC"])
  121.     buf.pos(1,1)
  122.     buf.bWriteL(bmeun6,"+===========+")
  123.     buf.pos(1,2)
  124.     buf.bWriteL(bmeun6,"| Add Image |")
  125.     buf.pos(1,3)
  126.     buf.bWriteL(bmeun6,"+===========+")
  127. end
  128. local function meun7()
  129.     buf.bc(conf["SMC"])
  130.     buf.tc(conf["SMTC"])
  131.     buf.pos(1,1)
  132.     buf.bWriteL(bmeun7,"+==========+")
  133.     buf.pos(1,2)
  134.     buf.bWriteL(bmeun7,"| Desktop  |")
  135.     buf.pos(1,3)
  136.     buf.bWriteL(bmeun7,"| Public   |")
  137.     buf.pos(1,4)
  138.     buf.bWriteL(bmeun7,"| Private  |")
  139.     buf.pos(1,5)
  140.     buf.bWriteL(bmeun7,"| PasteBin |")
  141.     buf.pos(1,6)
  142.     buf.bWriteL(bmeun7,"+==========+")
  143. end
  144. --handel meuns--s
  145. function createbufs()
  146.     createFigBufs()
  147.     bmeun = buf.createBuffer()
  148.     bmeun1 = buf.createBuffer(12,7)
  149.     bmeun2 = buf.createBuffer(12,6)
  150.     bmeun3 = buf.createBuffer(14,5)
  151.     bmeun4 = buf.createBuffer(10,4)
  152.     bmeun5 = buf.createBuffer(12,6)
  153.     bmeun6 = buf.createBuffer(13,3)
  154.     bmeun7 = buf.createBuffer(12,6)
  155.     binput = buf.createBuffer(24,3)
  156.     buf.drawImage(binput,1,1,"os/images/input")
  157.     meun1()
  158.     meun2()
  159.     meun3()
  160.     meun4()
  161.     meun5()
  162.     meun6()
  163.     meun7()
  164. end
  165. function reloadMeuns()
  166.     conf = A.getT(Cpath)
  167.     meun1()
  168.     meun2()
  169.     meun3()
  170.     meun4()
  171.     meun5()
  172.     meun6()
  173.     meun7()
  174. end
  175. --Retun Meuns--
  176. function Rmeun()
  177.     return bmeun
  178. end
  179. --Draw Meuns--
  180. function dmeun(i,x,y)
  181.   conf = A.getT(Cpath) 
  182.   buf.clsB(bmeun)
  183.   buf.drawImage(bmeun,x,y,i)
  184.   buf.pos(1,1)
  185.   buf.bc(conf["MC"])
  186.   buf.clsLx(bmeun)
  187.   buf.tc(conf["MTC"])
  188.   buf.bWriteL(bmeun," (start)")
  189.   buf.pos(52-(2+#ver),1)
  190.   buf.bWriteL(bmeun,"V:"..ver)
  191.   buf.pos(1,19)
  192.   buf.clsLx(bmeun)
  193.   buf.bWriteL(bmeun,"Made By: SuperKH")
  194.   buf.pos(1,2)
  195. end
  196. function dmeun1()
  197.     buf.drawBuffer(bmeun1,1,2)
  198. end
  199. function dmeun2(x,y)
  200.     local xy = {x,y}
  201.     if y==1 then
  202.         xy[2]=2
  203.     end
  204.     if y>=19-6 then
  205.         xy[2]=19-6
  206.     end
  207.     if x>=52-12 then
  208.         xy[1]=52-12
  209.     end
  210.     buf.drawBuffer(bmeun2,xy[1],xy[2])
  211.     return xy
  212. end
  213. function dmeun3(xy)
  214.     if xy[2]<14 then
  215.         xy[2]=xy[2]+5
  216.     else
  217.         xy[2]=xy[2]-5
  218.     end
  219.     buf.drawBuffer(bmeun3,xy[1],xy[2])
  220. end
  221. function dmeun4(x,y)
  222.     buf.drawBuffer(bmeun4,x,y)
  223. end
  224. function dmeun5()
  225.     buf.drawBuffer(bmeun5,1,2)
  226. end
  227. function dmeun6(x,y)
  228.     if y<=1 then
  229.         y=2
  230.     end
  231.     if y>=h-3 then
  232.         y=h-3
  233.     end
  234.     if x>=w-12 then
  235.         x=w-12
  236.     end
  237.     buf.drawBuffer(bmeun6,x,y)
  238.     return x,y
  239. end
  240. function dmeun7(xy)
  241.     buf.drawBuffer(bmeun7,xy[1],xy[2])
  242. end
  243. --Fig Meuns---------------------------------------------------------------------
  244. --Load Meuns--
  245. function cline()
  246.     local tColorLookup = {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768}
  247.     x = 1
  248.     y = 1
  249.     for v,k in ipairs(tColorLookup) do
  250.         buf.pos(x,y)
  251.         buf.bc(k)
  252.         buf.bWrite(bcline," ")
  253.         x=x+1
  254.     end
  255. end
  256. --Handel Meuns--
  257. function createFigBufs()
  258.     bfig = buf.createBuffer()
  259.     bcline = buf.createBuffer(16,1)
  260.     cline()
  261. end
  262. --Retun Meuns--
  263. function RFmeun()
  264.     return bfig
  265. end
  266. --Draw Meuns--
  267. function dfig()
  268.     --set un back backgrounds
  269.     conf = A.getT(Cpath)   
  270.     buf.bc(conf["CBC"])
  271.     buf.clsB(bfig)
  272.     buf.drawImage(bfig,1,1,conf["CBI"])
  273.     buf.pos(1,1)
  274.     buf.bc(conf["MC"])
  275.     buf.clsLx(bfig)
  276.     buf.tc(conf["MTC"])
  277.     buf.bWriteL(bfig," (start)")
  278.     buf.pos(52-(2+#ver),1)
  279.     buf.bWriteL(bfig,"V:"..ver)
  280.     buf.pos(1,19)
  281.     buf.clsLx(bfig)
  282.     buf.bWriteL(bfig,"Made By: SuperKH")
  283.     buf.pos(1,2)
  284. end
  285. function dcline(x,y)
  286.     buf.drawBuffer(bcline,x,y)
  287. end
  288. -------------------------------------------------------------------------
  289. function Error(err)
  290.     local function Cwrite(y,words,Tc,Bc)
  291.         local Tc = Tc or term.getTextColor()
  292.         local cpos = term.getCursorPos()
  293.         local x = math.ceil((w/2)-(#words/2)+1)
  294.         local y = y or cpos[2]
  295.         local Bc = Bc or term.getBackgroundColor()
  296.         term.setBackgroundColor(Bc)
  297.         term.setTextColor(Tc)
  298.         term.setCursorPos(x,y)
  299.         write(words)
  300.     end
  301.     local function clsX(y,c,w,s,e)
  302.         local ccolor = term.getBackgroundColor()
  303.         local c = c or ccolor
  304.         local cpos = {term.getCursorPos()}
  305.         local y = y or cpos[2]
  306.         local w = w or " "
  307.         local Start = s or 1
  308.         local End = e or w
  309.         term.setBackgroundColor(c)
  310.         for i=Start, End do
  311.             term.setCursorPos(i,y)
  312.             write(w)
  313.         end
  314.     end
  315.     local function clsY(x,c,w,s,e)
  316.         local ccolor = term.getBackgroundColor()
  317.         local c = c or ccolor
  318.         local cpos = {term.getCursorPos()}
  319.         local x = x or cpos[1]
  320.         local w = w or " "
  321.         local Start = s or 1
  322.         local End = e or h
  323.         term.setBackgroundColor(c)
  324.         for i=Start, End do
  325.             term.setCursorPos(x,i)
  326.             write(w)
  327.         end
  328.     end
  329.     local function pString(s)
  330.         s = s .. " "
  331.         local function sString(x)
  332.             local t = {}
  333.             while true do
  334.                 local y = string.find(x," ")
  335.                 if y == nil then
  336.                     table.insert(t,x)
  337.                     return t
  338.                 end
  339.                 table.insert(t,string.sub(x,1,y))  
  340.                 x = string.sub(x,y+1)      
  341.             end
  342.         end
  343.         local t = sString(s)
  344.         local newT = {}
  345.         local size = 0
  346.         local str = ""
  347.         for v,k in ipairs(t) do
  348.             if size+#k<=48 then
  349.                 str = str..k
  350.                 size = #str
  351.                 if v==#t then
  352.                     table.insert(newT,str)
  353.                 end
  354.             else
  355.                 table.insert(newT,str)
  356.                 size = 0
  357.                 str = ""
  358.                 --
  359.                 str = str..k
  360.                 size = #str
  361.                 if v==#t then
  362.                     table.insert(newT,str)
  363.                 end
  364.             end
  365.         end
  366.         return newT
  367.     end
  368.     term.setTextColor(colors.white)
  369.     term.setBackgroundColor(colors.blue)
  370.     term.clear()
  371.     term.setCursorPos(1,1)
  372.     write("+")
  373.     clsX(1,colors.blue,"-",2,w-1)
  374.     write("+")
  375.     clsY(1,colors.blue,"|",2,h-1)
  376.     clsY(w,colors.blue,"|",2,h-1)
  377.     term.setCursorPos(1,h)
  378.     write("+")
  379.     clsX(h,colors.blue,"-",2,w-1)
  380.     write("+")
  381.     Cwrite(2,"Error:")
  382.     clsX(3,colors.blue,"-",2,w-1)
  383.     local errorT = pString(err)
  384.     y = 5
  385.     for v,k in ipairs(errorT) do
  386.         term.setCursorPos(1,y)
  387.         Cwrite(y,k)
  388.         y=y+1
  389.     end
  390.     term.setCursorPos(2,h-1)
  391.     -----------------------------------------------------------------------
  392.     if not fs.exists("os/files/ErrorLog") then
  393.         local f = fs.open("os/files/ErrorLog","w")
  394.         f.writeLine("---------------------------------------------------")
  395.         f.writeLine("           Thank You For Using SuperOS!            ")
  396.         f.writeLine("            -------------------------              ")
  397.         f.writeLine("        Sorry For All The Inconveniencses!         ")
  398.         f.writeLine("   If Errors Continually Accor Please Upload This  ")
  399.         f.writeLine("   File To PasteBin And Then Email Me The Link To  ")
  400.         f.writeLine("'             ~noobykyle@gmail.com                  '")
  401.         f.writeLine("---------------------------------------------------")
  402.         f.close()
  403.     end
  404.     local f = fs.open("os/files/ErrorLog","a")
  405.         f.writeLine(err)
  406.     f.close()
  407. end
  408. function pastebin(sCode,path)
  409.     local sFile = path
  410.     local sPath = sFile
  411.     if fs.exists( sPath ) then
  412.         fs.delete(sPath)
  413.     end
  414.     --gets the contents from pastebin
  415.     local function get(paste)
  416.         local response = http.get(
  417.             "http://pastebin.com/raw/"..textutils.urlEncode( paste )
  418.         )
  419.         if response then
  420.             local sResponcse = response.readAll()
  421.             response.close()
  422.             return sResponcse
  423.         else
  424.             error(paste)
  425.         end
  426.     end
  427.     local res = get(sCode)
  428.     if res then
  429.         local file = fs.open( sPath, "w" )
  430.         file.write( res )
  431.         file.close()
  432.     end
  433. end
  434. function checkupdate()
  435.   pastebin("L2xbGSm5","os/files/update")
  436.   local src = "os/files/update"
  437.   local file = fs.open(src,"r")
  438.   local data = file.readAll()
  439.   file.close()
  440.   if data ~= code then
  441.     return true
  442.   else
  443.     return false
  444.   end
  445. end
  446. function check2()
  447.     local bufC = buf.createBuffer()
  448.     buf.bc(colors.black)
  449.     buf.tc(colors.white)
  450.     buf.clsB(bufC)
  451.     buf.drawImage(bufC,1,1,"os/images/update")
  452.     buf.pos(15,6)
  453.     buf.bc(colors.blue)
  454.     buf.bWriteL(bufC,"Do you Wish to Update?")
  455.     buf.pos(17,8)
  456.     buf.bc(colors.green)
  457.     buf.bWriteL(bufC,"YES!")
  458.     buf.pos(30,8)
  459.     buf.bc(colors.red)
  460.     buf.bWriteL(bufC,"NO!")
  461.     buf.pos(1,1)
  462.     buf.drawBuffer(bufC)
  463.     while true do
  464.         local arg = { os.pullEvent() }
  465.         if arg[1]=="mouse_click" then
  466.             if arg[2]==1 then
  467.                 if arg[3]>=14 and arg[3]<=24 then
  468.                     if arg[4]>=8 and arg[4]<=11 then
  469.                         return true
  470.                     end
  471.                 elseif  arg[3]>=26 and arg[3]<=36 then
  472.                     if arg[4]>=8 and arg[4]<=11 then
  473.                         return false
  474.                     end
  475.                 end
  476.             end
  477.         elseif arg[1]=="key" then
  478.             if arg[2]==28 then
  479.                 return true
  480.             end
  481.         end
  482.     end
  483. end
  484. function userin(x,y,o)
  485.     buf.drawBuffer(binput,x,y)
  486.     term.setCursorPos(x+1,y+1)
  487.     term.setBackgroundColor(colors.white)
  488.     term.setTextColor(colors.black)
  489.     if o==0 then
  490.         write("Program Name: ")
  491.         local input = read()
  492.         input = input
  493.         return input
  494.     elseif o==1 then
  495.         write("../icons/")
  496.         local input = read()
  497.         input = "os/images/icons/"..input
  498.         return input
  499.     elseif o==2 then
  500.         local confl = getT("os/users/Admin/Uconfig")
  501.         pass = confl["PW"]
  502.         write(" Pass:")
  503.         local input = read("*")
  504.         if input == pass then
  505.             return true
  506.         else
  507.             return false -- change to false to disable
  508.         end
  509.     elseif o==3 then
  510.         write("../images/")
  511.         local input = read()
  512.         input = "os/images/"..input
  513.         return input
  514.     elseif o==4 then
  515.         write("User: ")
  516.         local input = read()
  517.         return input
  518.     end
  519. end
  520. function Time(x,y,bc,tc)
  521.     local mTime = true
  522.     local tTime = textutils.formatTime(os.time(),mTime)
  523.     term.setBackgroundColor(bc)
  524.     term.setTextColor(tc)
  525.     term.setCursorPos(w-#tTime+1,y)
  526.     write(tTime)
  527.     term.setCursorPos(2,2)
  528. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement