Advertisement
Guest User

Startup.lua

a guest
Apr 24th, 2015
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.80 KB | None | 0 0
  1. local on="$5&0 I$0&f"
  2. local off="$e&0I $0&f"
  3. local function round(num, idp)
  4.   local mult = 10^(idp or 0)
  5.   return math.floor(num * mult + 0.5) / mult
  6. end
  7. local function revert(value)
  8. if value==true then return false else return true end
  9. end
  10. local function getSize(path)
  11.   local size = 0
  12.   for _, file in ipairs(fs.list(path)) do
  13.   if file~="rom" then
  14.     if fs.isDir(fs.combine(path, file)) then
  15.       --# if it is a directory, recurse.
  16.       size = size + getSize(fs.combine(path, file))
  17.     else
  18.       size = size + fs.getSize(fs.combine(path, file))
  19.     end
  20.   end
  21.   end
  22.   return size
  23. end
  24. fs.getSpaceLimit = function(_path, _space, _final)
  25. local final = true
  26. if(_final ~= nil) then
  27. final = _final
  28. end
  29. local space = 0
  30. if(_space ~= nil) then
  31. space = _space
  32. end
  33. local sDir = ""
  34. if _path ~= nil then sDir = _path end
  35. local tContent = fs.list( sDir )
  36. for i, j in pairs( tContent ) do
  37. local sPath = fs.combine( sDir, j )
  38. if fs.isDir( sPath ) then
  39. if(sPath ~= "rom") then
  40. space = space + 512
  41. space = fs.getSpaceLimit(sPath, space, false)
  42. end
  43. else
  44. space = space + fs.getSize(sPath)
  45. end
  46. end
  47. if(final == true) then
  48. return space + fs.getFreeSpace(_path)
  49. else
  50. return space
  51. end
  52. end
  53. local function getSpace(number,round)
  54. if number<1024 then
  55. unit=" B"
  56. else
  57. local units={" kB"," MB"," GB"," TB"," PB"}
  58. for i=1,5 do
  59. if number/1024^i < 768 then
  60. number=number/1024^i
  61. unit=units[i]
  62. break
  63. end
  64. end
  65. end
  66. return number, unit
  67. end
  68. Data=Core.getData()
  69. nUsed,sUsedUnit=getSpace(getSize("/"))
  70. nFree,sFreeUnit=getSpace(fs.getSpaceLimit("/")-getSize("/"))
  71. local settings=true
  72. Draw.clear(1)
  73. Draw.isStatusVisible(true)
  74. Draw.setStatusColor(1)
  75. Draw.status()
  76. term.setBackgroundColor(1)
  77. paintutils.drawLine(7,4,Screen.Width-4,4,256)
  78. term.setCursorPos(8,4)
  79. print(os.getComputerLabel())
  80. term.setBackgroundColor(1)
  81. term.setCursorPos(2,4)
  82. Draw.cprint("&fName")
  83. term.setCursorPos(1,6)
  84. Draw.cprint(" OS Version "..Data.Version.."\n &8Update&f")
  85. term.setCursorPos(Screen.Width-2,8)
  86. Draw.cprint("\n HTTP ")
  87. term.setCursorPos(Screen.Width-2,9)
  88. Draw.cprint(http and on or off.."$0")
  89. Draw.cprint(" Modem ")
  90. term.setCursorPos(Screen.Width-2,10)
  91. Draw.cprint(Data.bModem==true and on or off.."$0")
  92. Draw.cprint(" Notifications ")
  93. term.setCursorPos(Screen.Width-2,11)
  94. Draw.cprint(Data.Notification==true and on or off.."$0")
  95. Draw.cprint(" Use AM/PM ")
  96. term.setCursorPos(Screen.Width-2,12)
  97. Draw.cprint(Data.H24==false and on or off.."$0")
  98. print("\n "..round(nFree,2)..sFreeUnit.." Available")
  99. print(" "..round(nUsed,2)..sUsedUnit.." Used")
  100. term.setCursorPos((Screen.Width-4)/2,Screen.Height)
  101. write("Back")
  102. while settings do
  103. tEvent={os.pullEventRaw()}
  104. if tEvent[1]=="mouse_click" then
  105. if tEvent[4]==4 then
  106. paintutils.drawLine(7,4,Screen.Width-4,4,256)
  107. term.setCursorPos(8,4)
  108. label=read()
  109. os.setComputerLabel(label)
  110. term.setCursorPos(8,4)
  111. Draw.cprint(label.."$0")
  112. change=true
  113. elseif tEvent[4]==10 then
  114. Data.bModem=revert(Data.bModem)
  115. term.setCursorPos(1,10)
  116. Draw.cprint("$0&f Modem ")
  117. term.setCursorPos(Screen.Width-2,10)
  118. Draw.cprint(Data.bModem==true and on or off.."$0")
  119. elseif tEvent[4]==11 then
  120. Data.Notification=revert(Data.Notification)
  121. term.setCursorPos(1,11)
  122. Draw.cprint("$0&f Notifications ")
  123. term.setCursorPos(Screen.Width-2,11)
  124. Draw.cprint(Data.Notification==true and on or off.."$0")
  125. elseif tEvent[4]==12 then
  126. Data.H24=revert(Data.H24)
  127. term.setCursorPos(1,12)
  128. Draw.cprint("$0&f Use AM/PM ")
  129. term.setCursorPos(Screen.Width-2,12)
  130. Draw.cprint(Data.H24==false and on or off.."$0")
  131. elseif tEvent[4]==7 then
  132. shell.run("Apps/Update/Startup.lua")
  133. elseif tEvent[4]==Screen.Height then
  134. settings=false
  135. f=fs.open("System/Config.lua","w")
  136. f.write(textutils.serialize(Data))
  137. f.close()
  138. shell.run("System/Desktop.lua")
  139. end
  140. f=fs.open("System/Config.lua","w") f.write(textutils.serialize(Data)) f.close()
  141. end
  142. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement